[DE] New search: add methods in controller

This commit is contained in:
JuliaSvinareva 2022-02-21 17:22:12 +03:00
parent ab5241d11a
commit 2bf17f6f5a
4 changed files with 65 additions and 2 deletions

View file

@ -35,6 +35,9 @@
<tr>
<td class="padding-small"><div id="search-adv-use-regexp"></div></td>
</tr>
<tr>
<td class="padding-small"><div id="search-adv-match-word"></div></td>
</tr>
</tbody>
</table>
</div>

View file

@ -73,6 +73,7 @@ define([
Common.UI.Window.prototype.initialize.call(this, this.options);
Common.NotificationCenter.on('layout:changed', _.bind(this.onLayoutChanged, this));
$(window).on('resize', _.bind(this.onLayoutChanged, this));
},
render: function() {

View file

@ -88,6 +88,7 @@ define([
dataHint: '1',
dataHintDirection: 'bottom'
});
this.btnBack.on('click', _.bind(this.onBtnClick, this, 'next'));
this.btnNext = new Common.UI.Button({
parentEl: $('#search-adv-next'),
@ -96,14 +97,17 @@ define([
dataHint: '1',
dataHintDirection: 'bottom'
});
this.btnNext.on('click', _.bind(this.onBtnClick, this, 'next'));
this.btnReplace = new Common.UI.Button({
el: $('#search-adv-replace')
});
this.btnReplace.on('click', _.bind(this.onBtnClick, this, 'replace'));
this.btnReplaceAll = new Common.UI.Button({
el: $('#search-adv-replace-all')
});
this.btnReplaceAll.on('click', _.bind(this.onBtnClick, this, 'replaceall'));
this.chCaseSensitive = new Common.UI.CheckBox({
el: $('#search-adv-case-sensitive'),
@ -121,6 +125,14 @@ define([
dataHintOffset: 'small'
});
this.chMatchWord = new Common.UI.CheckBox({
el: $('#search-adv-match-word'),
labelText: this.options.matchwordstr || this.textWholeWords,
dataHint: '1',
dataHintDirection: 'left',
dataHintOffset: 'small'
});
this.buttonClose = new Common.UI.Button({
parentEl: $('#search-btn-close', this.$el),
cls: 'btn-toolbar',
@ -145,6 +157,14 @@ define([
this.fireEvent('hide', this );
},
focus: function() {
var me = this;
setTimeout(function(){
me.inputText.$el.find('input').focus();
me.inputText.$el.find('input').select();
}, 10);
},
ChangeSettings: function(props) {
},
@ -156,6 +176,18 @@ define([
Common.NotificationCenter.trigger('leftmenu:change', 'hide');
},
onBtnClick: function(action) {
var opts = {
textsearch : this.inputText.getValue(),
textreplace : this.inputReplace.getValue(),
matchcase : this.chCaseSensitive.checked,
useregexp : this.chUseRegExp.checked,
matchword : this.chMatchWord.checked,
//highlight : this.miHighlight.checked
};
this.fireEvent('search:'+action, [this, opts]);
},
textFind: 'Find',
textFindAndReplace: 'Find and replace',
textCloseSearch: 'Close search',
@ -164,7 +196,8 @@ define([
textSearchResults: 'Search results: {0}/{1}',
textReplaceWith: 'Replace with',
textCaseSensitive: 'Case sensitive',
textMatchUsingRegExp: 'Match using regular expressions'
textMatchUsingRegExp: 'Match using regular expressions',
textWholeWords: 'Whole words only',
}, Common.Views.SearchPanel || {}));
});

View file

@ -58,6 +58,12 @@ define([
'SearchBar': {
'search:back': _.bind(this.onQuerySearch, this, 'back'),
'search:next': _.bind(this.onQuerySearch, this, 'next'),
},
'Common.Views.SearchPanel': {
'search:back': _.bind(this.onQuerySearch, this, 'back'),
'search:next': _.bind(this.onQuerySearch, this, 'next'),
'search:replace': _.bind(this.onQueryReplace, this),
'search:replaceall': _.bind(this.onQueryReplaceAll, this)
}
});
},
@ -83,7 +89,7 @@ define([
onQuerySearch: function (d, w, opts) {
if (opts.textsearch && opts.textsearch.length) {
if (!this.api.asc_findText(opts.textsearch, d != 'back')) {
if (!this.api.asc_findText(opts.textsearch, d != 'back', opts.matchcase)) {
var me = this;
Common.UI.info({
msg: this.textNoTextFound,
@ -95,6 +101,26 @@ define([
}
},
onQueryReplace: function(w, opts) {
if (!_.isEmpty(opts.textsearch)) {
if (!this.api.asc_replaceText(opts.textsearch, opts.textreplace, false, opts.matchcase)) {
var me = this;
Common.UI.info({
msg: this.textNoTextFound,
callback: function() {
me.view.focus();
}
});
}
}
},
onQueryReplaceAll: function(w, opts) {
if (!_.isEmpty(opts.textsearch)) {
this.api.asc_replaceText(opts.textsearch, opts.textreplace, true, opts.matchcase, opts.matchword);
}
},
textNoTextFound: 'The data you have been searching for could not be found. Please adjust your search options.',
}, DE.Controllers.Search || {}));