2022-02-09 18:15:36 +00:00
|
|
|
/*
|
|
|
|
*
|
|
|
|
* (c) Copyright Ascensio System SIA 2010-2020
|
|
|
|
*
|
|
|
|
* This program is a free software product. You can redistribute it and/or
|
|
|
|
* modify it under the terms of the GNU Affero General Public License (AGPL)
|
|
|
|
* version 3 as published by the Free Software Foundation. In accordance with
|
|
|
|
* Section 7(a) of the GNU AGPL its Section 15 shall be amended to the effect
|
|
|
|
* that Ascensio System SIA expressly excludes the warranty of non-infringement
|
|
|
|
* of any third-party rights.
|
|
|
|
*
|
|
|
|
* This program is distributed WITHOUT ANY WARRANTY; without even the implied
|
|
|
|
* warranty of MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. For
|
|
|
|
* details, see the GNU AGPL at: http://www.gnu.org/licenses/agpl-3.0.html
|
|
|
|
*
|
|
|
|
* You can contact Ascensio System SIA at 20A-12 Ernesta Birznieka-Upisha
|
|
|
|
* street, Riga, Latvia, EU, LV-1050.
|
|
|
|
*
|
|
|
|
* The interactive user interfaces in modified source and object code versions
|
|
|
|
* of the Program must display Appropriate Legal Notices, as required under
|
|
|
|
* Section 5 of the GNU AGPL version 3.
|
|
|
|
*
|
|
|
|
* Pursuant to Section 7(b) of the License you must retain the original Product
|
|
|
|
* logo when distributing the program. Pursuant to Section 7(e) we decline to
|
|
|
|
* grant you any rights under trademark law for use of our trademarks.
|
|
|
|
*
|
|
|
|
* All the Product's GUI elements, including illustrations and icon sets, as
|
|
|
|
* well as technical writing content are licensed under the terms of the
|
|
|
|
* Creative Commons Attribution-ShareAlike 4.0 International. See the License
|
|
|
|
* terms at http://creativecommons.org/licenses/by-sa/4.0/legalcode
|
|
|
|
*
|
|
|
|
*/
|
|
|
|
|
|
|
|
/**
|
|
|
|
* ViewTab.js
|
|
|
|
*
|
|
|
|
* Created by Julia Svinareva on 09.02.2022
|
|
|
|
* Copyright (c) 2022 Ascensio System SIA. All rights reserved.
|
|
|
|
*
|
|
|
|
*/
|
|
|
|
|
|
|
|
define([
|
2022-02-12 12:35:16 +00:00
|
|
|
'core',
|
|
|
|
'common/main/lib/view/SearchPanel'
|
2022-02-09 18:15:36 +00:00
|
|
|
], function () {
|
|
|
|
'use strict';
|
|
|
|
|
|
|
|
DE.Controllers.Search = Backbone.Controller.extend(_.extend({
|
|
|
|
sdkViewName : '#id_main',
|
|
|
|
|
2022-02-12 12:35:16 +00:00
|
|
|
views: [
|
|
|
|
'Common.Views.SearchPanel'
|
|
|
|
],
|
|
|
|
|
2022-02-09 18:15:36 +00:00
|
|
|
initialize: function () {
|
|
|
|
this.addListeners({
|
|
|
|
'SearchBar': {
|
2022-03-16 19:06:42 +00:00
|
|
|
'search:back': _.bind(this.onSearchNext, this, 'back'),
|
|
|
|
'search:next': _.bind(this.onSearchNext, this, 'next'),
|
2022-07-01 16:04:21 +00:00
|
|
|
'search:input': _.bind(function (text) {
|
|
|
|
if (this._state.searchText === text) {
|
|
|
|
Common.NotificationCenter.trigger('search:updateresults', this._state.currentResult, this._state.resultsNumber);
|
|
|
|
return;
|
|
|
|
}
|
|
|
|
this.onInputSearchChange(text);
|
|
|
|
}, this),
|
2022-03-29 17:49:35 +00:00
|
|
|
'search:keydown': _.bind(this.onSearchNext, this, 'keydown'),
|
|
|
|
'show': _.bind(this.onSelectSearchingResults, this, true),
|
|
|
|
'hide': _.bind(this.onSelectSearchingResults, this, false)
|
2022-02-21 14:22:12 +00:00
|
|
|
},
|
|
|
|
'Common.Views.SearchPanel': {
|
2022-03-16 19:06:42 +00:00
|
|
|
'search:back': _.bind(this.onSearchNext, this, 'back'),
|
|
|
|
'search:next': _.bind(this.onSearchNext, this, 'next'),
|
2022-02-21 14:22:12 +00:00
|
|
|
'search:replace': _.bind(this.onQueryReplace, this),
|
2022-03-16 19:06:42 +00:00
|
|
|
'search:replaceall': _.bind(this.onQueryReplaceAll, this),
|
|
|
|
'search:input': _.bind(this.onInputSearchChange, this),
|
|
|
|
'search:options': _.bind(this.onChangeSearchOption, this),
|
2022-03-22 18:41:18 +00:00
|
|
|
'search:keydown': _.bind(this.onSearchNext, this, 'keydown'),
|
|
|
|
'show': _.bind(this.onShowPanel, this),
|
|
|
|
'hide': _.bind(this.onHidePanel, this),
|
2022-03-16 19:06:42 +00:00
|
|
|
},
|
|
|
|
'LeftMenu': {
|
|
|
|
'search:aftershow': _.bind(this.onShowAfterSearch, this)
|
2022-02-09 18:15:36 +00:00
|
|
|
}
|
|
|
|
});
|
|
|
|
},
|
|
|
|
onLaunch: function () {
|
2022-03-16 19:06:42 +00:00
|
|
|
this._state = {
|
|
|
|
searchText: '',
|
|
|
|
matchCase: false,
|
|
|
|
matchWord: false,
|
2022-03-29 17:49:35 +00:00
|
|
|
useRegExp: false,
|
2022-08-24 18:13:50 +00:00
|
|
|
isHighlightedResults: false,
|
|
|
|
isContentChanged: false
|
2022-03-16 19:06:42 +00:00
|
|
|
};
|
2022-02-14 16:16:04 +00:00
|
|
|
},
|
2022-02-12 12:35:16 +00:00
|
|
|
|
2022-02-14 16:16:04 +00:00
|
|
|
setMode: function (mode) {
|
|
|
|
this.view = this.createView('Common.Views.SearchPanel', { mode: mode });
|
2022-02-09 18:15:36 +00:00
|
|
|
},
|
|
|
|
|
|
|
|
setApi: function (api) {
|
|
|
|
if (api) {
|
|
|
|
this.api = api;
|
2022-03-05 12:44:01 +00:00
|
|
|
this.api.asc_registerCallback('asc_onSetSearchCurrent', _.bind(this.onUpdateSearchCurrent, this));
|
2022-03-11 12:28:57 +00:00
|
|
|
this.api.asc_registerCallback('asc_onStartTextAroundSearch', _.bind(this.onStartTextAroundSearch, this));
|
|
|
|
this.api.asc_registerCallback('asc_onEndTextAroundSearch', _.bind(this.onEndTextAroundSearch, this));
|
|
|
|
this.api.asc_registerCallback('asc_onGetTextAroundSearchPack', _.bind(this.onApiGetTextAroundSearch, this));
|
2022-03-16 19:06:42 +00:00
|
|
|
this.api.asc_registerCallback('asc_onRemoveTextAroundSearch', _.bind(this.onApiRemoveTextAroundSearch, this));
|
2022-06-25 11:00:17 +00:00
|
|
|
this.api.asc_registerCallback('asc_onSearchEnd', _.bind(this.onApiSearchEnd, this));
|
2022-07-19 12:46:16 +00:00
|
|
|
this.api.asc_registerCallback('asc_onReplaceAll', _.bind(this.onApiTextReplaced, this));
|
2022-02-09 18:15:36 +00:00
|
|
|
}
|
|
|
|
return this;
|
|
|
|
},
|
|
|
|
|
2022-02-12 12:35:16 +00:00
|
|
|
getView: function(name) {
|
|
|
|
return !name && this.view ?
|
|
|
|
this.view : Backbone.Controller.prototype.getView.call(this, name);
|
|
|
|
},
|
|
|
|
|
2022-03-16 19:06:42 +00:00
|
|
|
onChangeSearchOption: function (option, checked) {
|
|
|
|
switch (option) {
|
|
|
|
case 'case-sensitive':
|
|
|
|
this._state.matchCase = checked;
|
|
|
|
break;
|
|
|
|
case 'match-word':
|
|
|
|
this._state.matchWord = checked;
|
|
|
|
break;
|
|
|
|
case 'regexp':
|
|
|
|
this._state.useRegExp = checked;
|
|
|
|
break;
|
|
|
|
}
|
2022-05-26 14:51:00 +00:00
|
|
|
if (this._state.searchText) {
|
2022-08-24 18:13:50 +00:00
|
|
|
this.onQuerySearch();
|
2022-04-12 14:08:08 +00:00
|
|
|
}
|
2022-03-16 19:06:42 +00:00
|
|
|
},
|
2022-03-11 12:28:57 +00:00
|
|
|
|
2022-03-16 19:06:42 +00:00
|
|
|
onSearchNext: function (type, text, e) {
|
2022-05-24 09:46:59 +00:00
|
|
|
var isReturnKey = type === 'keydown' && e.keyCode === Common.UI.Keys.RETURN;
|
|
|
|
if (text && text.length > 0 && (isReturnKey || type !== 'keydown')) {
|
2022-03-16 19:06:42 +00:00
|
|
|
this._state.searchText = text;
|
2022-08-24 18:13:50 +00:00
|
|
|
this.onQuerySearch(type, !(this.searchTimer || isReturnKey));
|
2022-02-09 18:15:36 +00:00
|
|
|
}
|
|
|
|
},
|
|
|
|
|
2022-03-16 19:06:42 +00:00
|
|
|
onInputSearchChange: function (text) {
|
|
|
|
var me = this;
|
2022-09-12 14:36:40 +00:00
|
|
|
if ((text && this._state.searchText !== text) || (!text && this._state.newSearchText)) {
|
2022-03-16 19:06:42 +00:00
|
|
|
this._state.newSearchText = text;
|
|
|
|
this._lastInputChange = (new Date());
|
|
|
|
if (this.searchTimer === undefined) {
|
|
|
|
this.searchTimer = setInterval(function(){
|
|
|
|
if ((new Date()) - me._lastInputChange < 400) return;
|
2022-03-11 12:28:57 +00:00
|
|
|
|
2022-03-16 19:06:42 +00:00
|
|
|
me._state.searchText = me._state.newSearchText;
|
2022-08-24 18:13:50 +00:00
|
|
|
if (!(me._state.newSearchText !== '' && me.onQuerySearch()) && me._state.newSearchText === '') {
|
2022-09-12 11:26:27 +00:00
|
|
|
me.api.asc_endFindText();
|
|
|
|
me.hideResults();
|
2022-03-18 16:18:11 +00:00
|
|
|
me.view.updateResultsNumber('no-results');
|
2022-07-01 16:04:21 +00:00
|
|
|
me.view.disableNavButtons();
|
2022-03-18 16:18:11 +00:00
|
|
|
me.view.disableReplaceButtons(true);
|
2022-08-24 18:13:50 +00:00
|
|
|
clearInterval(me.searchTimer);
|
|
|
|
me.searchTimer = undefined;
|
2022-02-21 14:22:12 +00:00
|
|
|
}
|
2022-03-16 19:06:42 +00:00
|
|
|
}, 10);
|
2022-02-21 14:22:12 +00:00
|
|
|
}
|
|
|
|
}
|
|
|
|
},
|
|
|
|
|
2022-08-24 18:13:50 +00:00
|
|
|
onQuerySearch: function (d, noUpdate) {
|
|
|
|
var update = !noUpdate || this._state.isContentChanged;
|
|
|
|
this._state.isContentChanged = false;
|
|
|
|
this.searchTimer && clearInterval(this.searchTimer);
|
|
|
|
this.searchTimer = undefined;
|
|
|
|
update && this.hideResults();
|
|
|
|
|
2022-03-16 19:06:42 +00:00
|
|
|
var searchSettings = new AscCommon.CSearchSettings();
|
|
|
|
searchSettings.put_Text(this._state.searchText);
|
|
|
|
searchSettings.put_MatchCase(this._state.matchCase);
|
|
|
|
searchSettings.put_WholeWords(this._state.matchWord);
|
|
|
|
if (!this.api.asc_findText(searchSettings, d != 'back')) {
|
2022-03-22 18:41:18 +00:00
|
|
|
this.resultItems = [];
|
2022-03-16 19:06:42 +00:00
|
|
|
this.view.updateResultsNumber(undefined, 0);
|
2022-03-18 16:18:11 +00:00
|
|
|
this.view.disableReplaceButtons(true);
|
2022-03-22 18:41:18 +00:00
|
|
|
this._state.currentResult = 0;
|
|
|
|
this._state.resultsNumber = 0;
|
|
|
|
this.view.disableNavButtons();
|
2022-03-16 19:06:42 +00:00
|
|
|
return false;
|
|
|
|
}
|
2022-08-24 18:13:50 +00:00
|
|
|
if (update && this.view.$el.is(':visible')) {
|
|
|
|
this.api.asc_StartTextAroundSearch();
|
|
|
|
}
|
|
|
|
this.view.disableReplaceButtons(false);
|
2022-03-16 19:06:42 +00:00
|
|
|
return true;
|
|
|
|
},
|
|
|
|
|
|
|
|
onQueryReplace: function(textSearch, textReplace) {
|
|
|
|
if (textSearch !== '') {
|
2022-03-21 17:39:25 +00:00
|
|
|
var me = this;
|
|
|
|
var str = this.api.asc_GetErrorForReplaceString(textReplace);
|
|
|
|
if (str) {
|
2022-07-25 20:29:49 +00:00
|
|
|
setTimeout(function() {
|
|
|
|
Common.UI.warning({
|
|
|
|
title: me.notcriticalErrorTitle,
|
|
|
|
msg: Common.Utils.String.format(me.warnReplaceString, str),
|
|
|
|
buttons: ['ok'],
|
|
|
|
callback: function(){
|
|
|
|
me.view.focus('replace');
|
|
|
|
}
|
|
|
|
});
|
|
|
|
}, 1);
|
2022-03-21 17:39:25 +00:00
|
|
|
return;
|
|
|
|
}
|
|
|
|
|
2022-03-16 19:06:42 +00:00
|
|
|
var searchSettings = new AscCommon.CSearchSettings();
|
|
|
|
searchSettings.put_Text(textSearch);
|
|
|
|
searchSettings.put_MatchCase(this._state.matchCase);
|
|
|
|
searchSettings.put_WholeWords(this._state.matchWord);
|
|
|
|
if (!this.api.asc_replaceText(searchSettings, textReplace, false)) {
|
2022-06-25 11:00:17 +00:00
|
|
|
this.removeResultItems();
|
2022-03-16 19:06:42 +00:00
|
|
|
}
|
|
|
|
}
|
|
|
|
},
|
2022-03-11 12:28:57 +00:00
|
|
|
|
2022-03-16 19:06:42 +00:00
|
|
|
onQueryReplaceAll: function(textSearch, textReplace) {
|
|
|
|
if (textSearch !== '') {
|
2022-03-21 17:39:25 +00:00
|
|
|
var me = this;
|
|
|
|
var str = this.api.asc_GetErrorForReplaceString(textReplace);
|
|
|
|
if (str) {
|
2022-07-25 20:29:49 +00:00
|
|
|
setTimeout(function() {
|
|
|
|
Common.UI.warning({
|
|
|
|
title: me.notcriticalErrorTitle,
|
|
|
|
msg: Common.Utils.String.format(me.warnReplaceString, str),
|
|
|
|
buttons: ['ok'],
|
|
|
|
callback: function(){
|
|
|
|
me.view.focus('replace');
|
|
|
|
}
|
|
|
|
});
|
|
|
|
}, 1);
|
2022-03-21 17:39:25 +00:00
|
|
|
return;
|
|
|
|
}
|
|
|
|
|
2022-03-09 14:39:03 +00:00
|
|
|
var searchSettings = new AscCommon.CSearchSettings();
|
2022-03-16 19:06:42 +00:00
|
|
|
searchSettings.put_Text(textSearch);
|
|
|
|
searchSettings.put_MatchCase(this._state.matchCase);
|
|
|
|
searchSettings.put_WholeWords(this._state.matchWord);
|
|
|
|
this.api.asc_replaceText(searchSettings, textReplace, true);
|
|
|
|
|
2022-06-25 11:00:17 +00:00
|
|
|
this.removeResultItems();
|
2022-02-21 14:22:12 +00:00
|
|
|
}
|
|
|
|
},
|
|
|
|
|
2022-06-25 11:00:17 +00:00
|
|
|
removeResultItems: function (type) {
|
2022-04-29 13:07:59 +00:00
|
|
|
this.resultItems = [];
|
|
|
|
this.hideResults();
|
2022-06-25 11:00:17 +00:00
|
|
|
this.view.updateResultsNumber(type, 0); // type === undefined, count === 0 -> no matches
|
2022-04-29 13:07:59 +00:00
|
|
|
this.view.disableReplaceButtons(true);
|
|
|
|
this._state.currentResult = 0;
|
|
|
|
this._state.resultsNumber = 0;
|
|
|
|
this.view.disableNavButtons();
|
|
|
|
},
|
|
|
|
|
2022-03-05 12:44:01 +00:00
|
|
|
onUpdateSearchCurrent: function (current, all) {
|
2022-03-23 13:20:51 +00:00
|
|
|
if (current === -1) return;
|
2022-03-22 18:41:18 +00:00
|
|
|
this._state.currentResult = current;
|
|
|
|
this._state.resultsNumber = all;
|
2022-03-05 12:44:01 +00:00
|
|
|
if (this.view) {
|
|
|
|
this.view.updateResultsNumber(current, all);
|
2022-03-22 18:41:18 +00:00
|
|
|
this.view.disableNavButtons(current, all);
|
2022-04-29 13:07:59 +00:00
|
|
|
if (this.resultItems && this.resultItems.length > 0) {
|
2022-03-30 18:07:25 +00:00
|
|
|
this.resultItems.forEach(function (item) {
|
|
|
|
item.selected = false;
|
|
|
|
});
|
|
|
|
if (this.resultItems[current]) {
|
|
|
|
this.resultItems[current].selected = true;
|
|
|
|
$('#search-results').find('.item').removeClass('selected');
|
|
|
|
$(this.resultItems[current].el).addClass('selected');
|
|
|
|
this.scrollToSelectedResult(current);
|
|
|
|
}
|
|
|
|
}
|
2022-03-05 12:44:01 +00:00
|
|
|
}
|
2022-03-14 18:22:14 +00:00
|
|
|
Common.NotificationCenter.trigger('search:updateresults', current, all);
|
2022-03-05 12:44:01 +00:00
|
|
|
},
|
|
|
|
|
2022-03-30 18:07:25 +00:00
|
|
|
scrollToSelectedResult: function (ind) {
|
|
|
|
var index = ind !== undefined ? ind : _.findIndex(this.resultItems, {selected: true});
|
|
|
|
if (index !== -1) {
|
|
|
|
var item = this.resultItems[index].$el,
|
|
|
|
itemHeight = item.outerHeight(),
|
|
|
|
itemTop = item.position().top,
|
|
|
|
container = this.view.$resultsContainer,
|
|
|
|
containerHeight = container.outerHeight(),
|
|
|
|
containerTop = container.scrollTop();
|
|
|
|
if (itemTop < 0 || (containerTop === 0 && itemTop > containerHeight)) {
|
|
|
|
container.scroller.scrollTop(containerTop + itemTop - 12);
|
|
|
|
} else if (itemTop + itemHeight > containerHeight) {
|
|
|
|
container.scroller.scrollTop(containerTop + itemHeight);
|
|
|
|
}
|
|
|
|
}
|
|
|
|
},
|
|
|
|
|
2022-03-11 12:28:57 +00:00
|
|
|
onStartTextAroundSearch: function () {
|
|
|
|
if (this.view) {
|
|
|
|
this._state.isStartedAddingResults = true;
|
|
|
|
}
|
|
|
|
},
|
|
|
|
|
|
|
|
onEndTextAroundSearch: function () {
|
|
|
|
if (this.view) {
|
|
|
|
this._state.isStartedAddingResults = false;
|
|
|
|
this.view.$resultsContainer.scroller.update({alwaysVisibleY: true});
|
|
|
|
}
|
|
|
|
},
|
|
|
|
|
|
|
|
onApiGetTextAroundSearch: function (data) {
|
|
|
|
if (this.view && this._state.isStartedAddingResults) {
|
2022-05-20 11:03:21 +00:00
|
|
|
if (data.length > 300 || !data.length) return;
|
2022-08-24 18:13:50 +00:00
|
|
|
var me = this,
|
|
|
|
selectedInd;
|
2022-03-16 19:06:42 +00:00
|
|
|
me.resultItems = [];
|
2022-03-30 18:07:25 +00:00
|
|
|
data.forEach(function (item, ind) {
|
|
|
|
var el = document.createElement("div"),
|
|
|
|
isSelected = ind === me._state.currentResult;
|
2022-03-16 19:06:42 +00:00
|
|
|
el.className = 'item';
|
|
|
|
el.innerHTML = item[1].trim();
|
2022-03-11 12:28:57 +00:00
|
|
|
me.view.$resultsContainer.append(el);
|
2022-03-30 18:07:25 +00:00
|
|
|
if (isSelected) {
|
|
|
|
$(el).addClass('selected');
|
2022-08-24 18:13:50 +00:00
|
|
|
selectedInd = ind;
|
2022-03-30 18:07:25 +00:00
|
|
|
}
|
|
|
|
|
|
|
|
var resultItem = {id: item[0], $el: $(el), el: el, selected: isSelected};
|
|
|
|
me.resultItems.push(resultItem);
|
2022-03-16 19:06:42 +00:00
|
|
|
$(el).on('click', _.bind(function (el) {
|
2022-08-24 18:13:50 +00:00
|
|
|
if (me._state.isContentChanged) {
|
|
|
|
me.onQuerySearch();
|
|
|
|
return;
|
|
|
|
}
|
2022-03-16 19:06:42 +00:00
|
|
|
var id = item[0];
|
|
|
|
me.api.asc_SelectSearchElement(id);
|
|
|
|
}, me));
|
2022-03-11 12:28:57 +00:00
|
|
|
});
|
2022-03-18 16:18:11 +00:00
|
|
|
|
|
|
|
this.view.$resultsContainer.show();
|
2022-08-24 18:13:50 +00:00
|
|
|
this.scrollToSelectedResult(selectedInd);
|
2022-03-11 12:28:57 +00:00
|
|
|
}
|
|
|
|
},
|
|
|
|
|
2022-03-16 19:06:42 +00:00
|
|
|
onApiRemoveTextAroundSearch: function (arr) {
|
|
|
|
var me = this;
|
|
|
|
arr.forEach(function (id) {
|
|
|
|
var ind = _.findIndex(me.resultItems, {id: id});
|
|
|
|
if (ind !== -1) {
|
|
|
|
me.resultItems[ind].$el.remove();
|
|
|
|
me.resultItems.splice(ind, 1);
|
|
|
|
}
|
|
|
|
});
|
|
|
|
},
|
|
|
|
|
2022-03-11 12:28:57 +00:00
|
|
|
hideResults: function () {
|
|
|
|
if (this.view) {
|
|
|
|
this.view.$resultsContainer.hide();
|
|
|
|
this.view.$resultsContainer.empty();
|
|
|
|
}
|
|
|
|
},
|
|
|
|
|
2022-03-16 19:06:42 +00:00
|
|
|
onShowAfterSearch: function (findText) {
|
|
|
|
var viewport = this.getApplication().getController('Viewport');
|
|
|
|
if (viewport.isSearchBarVisible()) {
|
|
|
|
viewport.searchBar.hide();
|
|
|
|
}
|
|
|
|
|
2022-07-19 18:07:25 +00:00
|
|
|
var selectedText = this.api.asc_GetSelectedText(),
|
|
|
|
text = typeof findText === 'string' ? findText : (selectedText && selectedText.trim() || this._state.searchText);
|
2022-04-10 20:30:24 +00:00
|
|
|
if (this.resultItems && this.resultItems.length > 0 &&
|
2022-06-17 11:35:25 +00:00
|
|
|
(!this._state.matchCase && text && text.toLowerCase() === this.view.inputText.getValue().toLowerCase() ||
|
2022-04-10 20:30:24 +00:00
|
|
|
this._state.matchCase && text === this.view.inputText.getValue())) { // show old results
|
|
|
|
return;
|
|
|
|
}
|
2022-03-16 19:06:42 +00:00
|
|
|
if (text) {
|
|
|
|
this.view.setFindText(text);
|
2022-05-20 11:03:21 +00:00
|
|
|
} else if (text !== undefined) { // panel was opened from empty searchbar, clear to start new search
|
2022-03-16 19:06:42 +00:00
|
|
|
this.view.setFindText('');
|
2022-05-20 11:03:21 +00:00
|
|
|
this._state.searchText = undefined;
|
2022-03-16 19:06:42 +00:00
|
|
|
}
|
|
|
|
|
2022-03-22 18:41:18 +00:00
|
|
|
this.hideResults();
|
2022-06-17 11:35:25 +00:00
|
|
|
if (text && text !== '' && text === this._state.searchText) { // search was made
|
2022-03-18 16:18:11 +00:00
|
|
|
this.view.disableReplaceButtons(false);
|
2022-03-16 19:06:42 +00:00
|
|
|
this.api.asc_StartTextAroundSearch();
|
2022-06-17 11:35:25 +00:00
|
|
|
} else if (text && text !== '') { // search wasn't made
|
2022-03-22 18:41:18 +00:00
|
|
|
this.onInputSearchChange(text);
|
2022-03-18 16:18:11 +00:00
|
|
|
} else {
|
2022-03-22 18:41:18 +00:00
|
|
|
this.resultItems = [];
|
2022-03-18 16:18:11 +00:00
|
|
|
this.view.disableReplaceButtons(true);
|
2022-03-23 13:20:51 +00:00
|
|
|
this.view.clearResultsNumber();
|
2022-03-16 19:06:42 +00:00
|
|
|
}
|
2022-03-22 18:41:18 +00:00
|
|
|
this.view.disableNavButtons(this._state.currentResult, this._state.resultsNumber);
|
|
|
|
},
|
|
|
|
|
|
|
|
onShowPanel: function () {
|
2022-03-29 17:49:35 +00:00
|
|
|
this.onSelectSearchingResults(true);
|
2022-03-22 18:41:18 +00:00
|
|
|
if (this.resultItems && this.resultItems.length > 0 && !this._state.isStartedAddingResults) {
|
|
|
|
var me = this;
|
|
|
|
this.view.$resultsContainer.show();
|
|
|
|
this.resultItems.forEach(function (item) {
|
|
|
|
me.view.$resultsContainer.append(item.el);
|
2022-08-09 15:19:31 +00:00
|
|
|
$(item.el)[item.selected ? 'addClass' : 'removeClass']('selected');
|
2022-03-22 18:41:18 +00:00
|
|
|
$(item.el).on('click', function (el) {
|
|
|
|
me.api.asc_SelectSearchElement(item.id);
|
|
|
|
$('#search-results').find('.item').removeClass('selected');
|
|
|
|
$(el.currentTarget).addClass('selected');
|
|
|
|
});
|
|
|
|
});
|
2022-03-30 18:07:25 +00:00
|
|
|
this.scrollToSelectedResult();
|
2022-03-22 18:41:18 +00:00
|
|
|
}
|
|
|
|
},
|
2022-03-16 19:06:42 +00:00
|
|
|
|
2022-03-22 18:41:18 +00:00
|
|
|
onHidePanel: function () {
|
|
|
|
this.hideResults();
|
2022-03-29 17:49:35 +00:00
|
|
|
this.onSelectSearchingResults(false);
|
|
|
|
},
|
|
|
|
|
|
|
|
onSelectSearchingResults: function (val) {
|
|
|
|
if (!val && this.getApplication().getController('LeftMenu').isSearchPanelVisible()) return;
|
|
|
|
|
|
|
|
if (this._state.isHighlightedResults !== val) {
|
|
|
|
this.api.asc_selectSearchingResults(val);
|
|
|
|
this._state.isHighlightedResults = val;
|
|
|
|
}
|
2022-03-16 19:06:42 +00:00
|
|
|
},
|
2022-02-09 18:15:36 +00:00
|
|
|
|
2022-06-25 11:00:17 +00:00
|
|
|
onApiSearchEnd: function () {
|
2022-08-24 18:13:50 +00:00
|
|
|
if (!this._state.isContentChanged) {
|
|
|
|
this._state.isContentChanged = true;
|
|
|
|
this.view.updateResultsNumber('content-changed');
|
|
|
|
this.view.disableReplaceButtons(true);
|
|
|
|
}
|
2022-06-25 11:00:17 +00:00
|
|
|
},
|
|
|
|
|
2022-07-19 12:46:16 +00:00
|
|
|
onApiTextReplaced: function(found, replaced) {
|
|
|
|
if (found) {
|
|
|
|
!(found - replaced > 0) ?
|
|
|
|
Common.UI.info( {msg: Common.Utils.String.format(this.textReplaceSuccess, replaced)} ) :
|
|
|
|
Common.UI.warning( {msg: Common.Utils.String.format(this.textReplaceSkipped, found-replaced)} );
|
|
|
|
} else {
|
|
|
|
Common.UI.info({msg: this.textNoTextFound});
|
|
|
|
}
|
|
|
|
},
|
|
|
|
|
2022-07-22 14:38:51 +00:00
|
|
|
getSearchText: function () {
|
|
|
|
return this._state.searchText;
|
|
|
|
},
|
|
|
|
|
2022-03-21 17:39:25 +00:00
|
|
|
notcriticalErrorTitle: 'Warning',
|
2022-07-19 12:46:16 +00:00
|
|
|
warnReplaceString: '{0} is not a valid special character for the Replace With box.',
|
|
|
|
textReplaceSuccess: 'Search has been done. {0} occurrences have been replaced',
|
|
|
|
textReplaceSkipped: 'The replacement has been made. {0} occurrences were skipped.',
|
|
|
|
textNoTextFound: 'The data you have been searching for could not be found. Please adjust your search options.'
|
2022-03-21 17:39:25 +00:00
|
|
|
|
2022-02-09 18:15:36 +00:00
|
|
|
}, DE.Controllers.Search || {}));
|
|
|
|
});
|