2022-02-22 17:17:21 +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 22.02.2022
|
|
|
|
* Copyright (c) 2022 Ascensio System SIA. All rights reserved.
|
|
|
|
*
|
|
|
|
*/
|
|
|
|
|
|
|
|
define([
|
|
|
|
'core',
|
|
|
|
'common/main/lib/view/SearchPanel'
|
|
|
|
], function () {
|
|
|
|
'use strict';
|
|
|
|
|
|
|
|
SSE.Controllers.Search = Backbone.Controller.extend(_.extend({
|
|
|
|
sdkViewName : '#id_main',
|
|
|
|
|
|
|
|
views: [
|
|
|
|
'Common.Views.SearchPanel'
|
|
|
|
],
|
|
|
|
|
|
|
|
initialize: function () {
|
|
|
|
this.addListeners({
|
|
|
|
'SearchBar': {
|
2022-04-03 15:17:46 +00:00
|
|
|
'search:back': _.bind(this.onSearchNext, this, 'back'),
|
|
|
|
'search:next': _.bind(this.onSearchNext, this, 'next'),
|
|
|
|
'search:input': _.bind(this.onInputSearchChange, this),
|
2022-04-11 17:16:33 +00:00
|
|
|
'search:keydown': _.bind(this.onSearchNext, this, 'keydown'),
|
|
|
|
'show': _.bind(this.onSelectSearchingResults, this, true),
|
|
|
|
'hide': _.bind(this.onSelectSearchingResults, this, false)
|
2022-02-22 17:17:21 +00:00
|
|
|
},
|
|
|
|
'Common.Views.SearchPanel': {
|
2022-04-03 15:17:46 +00:00
|
|
|
'search:back': _.bind(this.onSearchNext, this, 'back'),
|
|
|
|
'search:next': _.bind(this.onSearchNext, this, 'next'),
|
2022-02-22 17:17:21 +00:00
|
|
|
'search:replace': _.bind(this.onQueryReplace, this),
|
2022-04-03 15:17:46 +00:00
|
|
|
'search:replaceall': _.bind(this.onQueryReplaceAll, this),
|
|
|
|
'search:input': _.bind(this.onInputSearchChange, this),
|
|
|
|
'search:options': _.bind(this.onChangeSearchOption, this),
|
|
|
|
'search:keydown': _.bind(this.onSearchNext, this, 'keydown'),
|
|
|
|
'show': _.bind(this.onShowPanel, this),
|
2022-04-04 19:09:09 +00:00
|
|
|
'hide': _.bind(this.onHidePanel, this)
|
2022-04-03 15:17:46 +00:00
|
|
|
},
|
|
|
|
'LeftMenu': { // TO DO
|
|
|
|
'search:aftershow': _.bind(this.onShowAfterSearch, this)
|
2022-02-22 17:17:21 +00:00
|
|
|
}
|
|
|
|
});
|
|
|
|
},
|
|
|
|
onLaunch: function () {
|
2022-04-03 15:17:46 +00:00
|
|
|
this._state = {
|
|
|
|
searchText: '',
|
|
|
|
matchCase: false,
|
|
|
|
matchWord: false,
|
|
|
|
useRegExp: false,
|
2022-04-04 19:09:09 +00:00
|
|
|
withinSheet: Asc.c_oAscSearchBy.Sheet,
|
2022-04-03 15:17:46 +00:00
|
|
|
searchByRows: true,
|
2022-04-04 19:09:09 +00:00
|
|
|
lookInFormulas: true,
|
|
|
|
isValidSelectedRange: true
|
2022-04-03 15:17:46 +00:00
|
|
|
};
|
2022-02-22 17:17:21 +00:00
|
|
|
},
|
|
|
|
|
|
|
|
setMode: function (mode) {
|
|
|
|
this.view = this.createView('Common.Views.SearchPanel', { mode: mode });
|
2022-04-04 19:09:09 +00:00
|
|
|
this.view.on('render:after', _.bind(this.onAfterRender, this));
|
2022-02-22 17:17:21 +00:00
|
|
|
},
|
|
|
|
|
|
|
|
setApi: function (api) {
|
|
|
|
if (api) {
|
|
|
|
this.api = api;
|
|
|
|
this.api.asc_registerCallback('asc_onRenameCellTextEnd', _.bind(this.onRenameText, this));
|
2022-04-03 15:17:46 +00:00
|
|
|
this.api.asc_registerCallback('asc_onSetSearchCurrent', _.bind(this.onUpdateSearchCurrent, this));
|
|
|
|
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));
|
|
|
|
this.api.asc_registerCallback('asc_onRemoveTextAroundSearch', _.bind(this.onApiRemoveTextAroundSearch, this));
|
2022-06-27 17:31:43 +00:00
|
|
|
this.api.asc_registerCallback('asc_onSearchEnd', _.bind(this.onApiSearchEnd, this));
|
2022-02-22 17:17:21 +00:00
|
|
|
}
|
|
|
|
return this;
|
|
|
|
},
|
|
|
|
|
|
|
|
getView: function(name) {
|
|
|
|
return !name && this.view ?
|
|
|
|
this.view : Backbone.Controller.prototype.getView.call(this, name);
|
|
|
|
},
|
|
|
|
|
2022-04-04 19:09:09 +00:00
|
|
|
onAfterRender: function () {
|
|
|
|
var me = this;
|
|
|
|
this.view.inputSelectRange.validation = function(value) {
|
|
|
|
if (_.isEmpty(value)) {
|
|
|
|
return true;
|
|
|
|
}
|
2022-04-06 19:32:50 +00:00
|
|
|
var isvalid = me.api.asc_checkDataRange(undefined, value);
|
|
|
|
me._state.isValidSelectedRange = isvalid !== Asc.c_oAscError.ID.DataRangeError;
|
2022-04-04 19:09:09 +00:00
|
|
|
return (isvalid === Asc.c_oAscError.ID.DataRangeError) ? me.textInvalidRange : true;
|
|
|
|
};
|
2022-04-06 19:32:50 +00:00
|
|
|
this.view.inputSelectRange.on('button:click', _.bind(this.onRangeSelect, this));
|
2022-04-04 19:09:09 +00:00
|
|
|
},
|
|
|
|
|
2022-04-06 19:32:50 +00:00
|
|
|
onChangeSearchOption: function (option, value, noSearch) {
|
|
|
|
var runSearch = true;
|
2022-04-03 15:17:46 +00:00
|
|
|
switch (option) {
|
|
|
|
case 'case-sensitive':
|
|
|
|
this._state.matchCase = value;
|
|
|
|
break;
|
|
|
|
case 'match-word':
|
|
|
|
this._state.matchWord = value;
|
|
|
|
break;
|
|
|
|
case 'regexp':
|
|
|
|
this._state.useRegExp = value;
|
|
|
|
break;
|
|
|
|
case 'within':
|
2022-04-04 19:09:09 +00:00
|
|
|
this._state.withinSheet = value === 0 ? Asc.c_oAscSearchBy.Sheet : (value === 1 ? Asc.c_oAscSearchBy.Workbook : Asc.c_oAscSearchBy.Range);
|
|
|
|
this.view.inputSelectRange.setDisabled(value !== Asc.c_oAscSearchBy.Range);
|
2022-04-06 19:32:50 +00:00
|
|
|
if (value === Asc.c_oAscSearchBy.Range) {
|
|
|
|
runSearch = false;
|
|
|
|
}
|
2022-04-04 19:09:09 +00:00
|
|
|
break;
|
|
|
|
case 'range':
|
|
|
|
this._state.selectedRange = value;
|
2022-04-06 19:32:50 +00:00
|
|
|
runSearch = !noSearch;
|
2022-04-03 15:17:46 +00:00
|
|
|
break;
|
|
|
|
case 'search':
|
|
|
|
this._state.searchByRows = value;
|
|
|
|
break;
|
|
|
|
case 'lookIn':
|
|
|
|
this._state.lookInFormulas = value;
|
|
|
|
break;
|
2022-04-06 19:32:50 +00:00
|
|
|
}
|
2022-05-26 14:51:00 +00:00
|
|
|
if (runSearch && this._state.searchText) {
|
2022-04-06 19:32:50 +00:00
|
|
|
this.hideResults();
|
2022-05-24 09:46:59 +00:00
|
|
|
if (this.onQuerySearch()) {
|
|
|
|
this.searchTimer && clearInterval(this.searchTimer);
|
|
|
|
this.searchTimer = undefined;
|
|
|
|
this.api.asc_StartTextAroundSearch();
|
|
|
|
}
|
2022-04-03 15:17:46 +00:00
|
|
|
}
|
|
|
|
},
|
2022-02-22 17:17:21 +00:00
|
|
|
|
2022-04-06 19:32:50 +00:00
|
|
|
onRangeSelect: function () {
|
|
|
|
var me = this;
|
|
|
|
var handlerDlg = function(dlg, result) {
|
|
|
|
if (result == 'ok') {
|
|
|
|
var valid = dlg.getSettings();
|
|
|
|
me.view.inputSelectRange.setValue(valid);
|
|
|
|
me.view.inputSelectRange.checkValidate();
|
|
|
|
me.onChangeSearchOption('range', valid);
|
|
|
|
}
|
|
|
|
};
|
|
|
|
|
|
|
|
var win = new SSE.Views.CellRangeDialog({
|
|
|
|
handler: handlerDlg
|
|
|
|
}).on('close', function() {
|
|
|
|
_.delay(function(){
|
|
|
|
me.view.inputSelectRange.focus();
|
|
|
|
},1);
|
|
|
|
});
|
|
|
|
win.show();
|
|
|
|
win.setSettings({
|
|
|
|
api: me.api,
|
|
|
|
range: (!_.isEmpty(me.view.inputSelectRange.getValue()) && (me.view.inputSelectRange.checkValidate()==true)) ? me.view.inputSelectRange.getValue() : me._state.selectedRange,
|
|
|
|
type: Asc.c_oAscSelectionDialogType.PrintTitles
|
|
|
|
});
|
|
|
|
},
|
|
|
|
|
2022-04-03 15:17:46 +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-04-03 15:17:46 +00:00
|
|
|
this._state.searchText = text;
|
2022-05-24 09:46:59 +00:00
|
|
|
if (this.onQuerySearch(type) && (this.searchTimer || isReturnKey)) {
|
2022-04-03 15:17:46 +00:00
|
|
|
this.hideResults();
|
2022-05-24 09:46:59 +00:00
|
|
|
if (this.searchTimer) {
|
|
|
|
clearInterval(this.searchTimer);
|
|
|
|
this.searchTimer = undefined;
|
|
|
|
}
|
2022-04-03 15:17:46 +00:00
|
|
|
if (this.view.$el.is(':visible')) {
|
|
|
|
this.api.asc_StartTextAroundSearch();
|
2022-02-22 17:17:21 +00:00
|
|
|
}
|
2022-04-03 15:17:46 +00:00
|
|
|
}
|
2022-02-22 17:17:21 +00:00
|
|
|
}
|
|
|
|
},
|
|
|
|
|
2022-04-03 15:17:46 +00:00
|
|
|
onInputSearchChange: function (text) {
|
|
|
|
var me = this;
|
|
|
|
if (this._state.searchText !== text) {
|
|
|
|
this._state.newSearchText = text;
|
|
|
|
this._lastInputChange = (new Date());
|
|
|
|
if (this.searchTimer === undefined) {
|
|
|
|
this.searchTimer = setInterval(function(){
|
|
|
|
if ((new Date()) - me._lastInputChange < 400) return;
|
2022-02-22 17:17:21 +00:00
|
|
|
|
2022-04-03 15:17:46 +00:00
|
|
|
me.hideResults();
|
|
|
|
me._state.searchText = me._state.newSearchText;
|
|
|
|
if (me._state.newSearchText !== '' && me.onQuerySearch()) {
|
|
|
|
if (me.view.$el.is(':visible')) {
|
|
|
|
me.api.asc_StartTextAroundSearch();
|
|
|
|
}
|
2022-06-27 12:56:14 +00:00
|
|
|
//me.view.disableReplaceButtons(false);
|
2022-04-03 15:17:46 +00:00
|
|
|
} else if (me._state.newSearchText === '') {
|
|
|
|
me.view.updateResultsNumber('no-results');
|
2022-06-27 12:56:14 +00:00
|
|
|
//me.view.disableReplaceButtons(true);
|
2022-04-03 15:17:46 +00:00
|
|
|
}
|
|
|
|
clearInterval(me.searchTimer);
|
|
|
|
me.searchTimer = undefined;
|
|
|
|
}, 10);
|
|
|
|
}
|
|
|
|
}
|
|
|
|
},
|
|
|
|
|
|
|
|
onQuerySearch: function (d, w, opts, fromPanel) {
|
2022-04-06 19:32:50 +00:00
|
|
|
var me = this;
|
|
|
|
if (this._state.withinSheet === Asc.c_oAscSearchBy.Range && !this._state.isValidSelectedRange) {
|
|
|
|
Common.UI.warning({
|
|
|
|
title: this.notcriticalErrorTitle,
|
|
|
|
msg: this.textInvalidRange,
|
|
|
|
buttons: ['ok'],
|
|
|
|
callback: function () {
|
|
|
|
me.view.focus('range');
|
|
|
|
}
|
|
|
|
});
|
|
|
|
return;
|
|
|
|
}
|
|
|
|
|
2022-02-22 17:17:21 +00:00
|
|
|
var options = new Asc.asc_CFindOptions();
|
2022-04-03 15:17:46 +00:00
|
|
|
options.asc_setFindWhat(this._state.searchText);
|
|
|
|
options.asc_setScanForward(d != 'back');
|
|
|
|
options.asc_setIsMatchCase(this._state.matchCase);
|
|
|
|
options.asc_setIsWholeCell(this._state.matchWord);
|
2022-04-04 19:09:09 +00:00
|
|
|
options.asc_setScanOnOnlySheet(this._state.withinSheet);
|
|
|
|
if (this._state.withinSheet === Asc.c_oAscSearchBy.Range) {
|
|
|
|
options.asc_setSpecificRange(this._state.selectedRange);
|
|
|
|
}
|
2022-04-03 15:17:46 +00:00
|
|
|
options.asc_setScanByRows(this._state.searchByRows);
|
|
|
|
options.asc_setLookIn(this._state.lookInFormulas ? Asc.c_oAscFindLookIn.Formulas : Asc.c_oAscFindLookIn.Value);
|
|
|
|
if (!this.api.asc_findText(options)) {
|
|
|
|
this.resultItems = [];
|
|
|
|
this.view.updateResultsNumber(undefined, 0);
|
2022-06-27 12:56:14 +00:00
|
|
|
//this.view.disableReplaceButtons(true);
|
2022-04-03 15:17:46 +00:00
|
|
|
this._state.currentResult = 0;
|
|
|
|
this._state.resultsNumber = 0;
|
|
|
|
this.view.disableNavButtons();
|
|
|
|
return false;
|
|
|
|
}
|
|
|
|
return true;
|
|
|
|
},
|
2022-02-25 12:31:15 +00:00
|
|
|
|
2022-04-03 15:17:46 +00:00
|
|
|
onQueryReplace: function(textSearch, textReplace) {
|
2022-06-27 12:56:14 +00:00
|
|
|
this.api.isReplaceAll = false;
|
|
|
|
var options = new Asc.asc_CFindOptions();
|
|
|
|
options.asc_setFindWhat(textSearch);
|
|
|
|
options.asc_setReplaceWith(textReplace);
|
|
|
|
options.asc_setIsMatchCase(this._state.matchCase);
|
|
|
|
options.asc_setIsWholeCell(this._state.matchWord);
|
|
|
|
options.asc_setScanOnOnlySheet(this._state.withinSheet);
|
|
|
|
if (this._state.withinSheet === Asc.c_oAscSearchBy.Range) {
|
|
|
|
options.asc_setSpecificRange(this._state.selectedRange);
|
2022-04-03 15:17:46 +00:00
|
|
|
}
|
2022-06-27 12:56:14 +00:00
|
|
|
options.asc_setScanByRows(this._state.searchByRows);
|
|
|
|
options.asc_setLookIn(this._state.lookIn ? Asc.c_oAscFindLookIn.Formulas : Asc.c_oAscFindLookIn.Value);
|
|
|
|
options.asc_setIsReplaceAll(false);
|
|
|
|
|
|
|
|
this.api.asc_replaceText(options);
|
2022-02-22 17:17:21 +00:00
|
|
|
},
|
|
|
|
|
2022-04-03 15:17:46 +00:00
|
|
|
onQueryReplaceAll: function(textSearch, textReplace) {
|
2022-02-22 17:17:21 +00:00
|
|
|
this.api.isReplaceAll = true;
|
|
|
|
var options = new Asc.asc_CFindOptions();
|
2022-04-03 15:17:46 +00:00
|
|
|
options.asc_setFindWhat(textSearch);
|
|
|
|
options.asc_setReplaceWith(textReplace);
|
|
|
|
options.asc_setIsMatchCase(this._state.matchCase);
|
|
|
|
options.asc_setIsWholeCell(this._state.matchWord);
|
2022-04-04 19:09:09 +00:00
|
|
|
options.asc_setScanOnOnlySheet(this._state.withinSheet);
|
|
|
|
if (this._state.withinSheet === Asc.c_oAscSearchBy.Range) {
|
|
|
|
options.asc_setSpecificRange(this._state.selectedRange);
|
|
|
|
}
|
2022-04-03 15:17:46 +00:00
|
|
|
options.asc_setScanByRows(this._state.searchByRows);
|
|
|
|
options.asc_setLookIn(this._state.lookIn ? Asc.c_oAscFindLookIn.Formulas : Asc.c_oAscFindLookIn.Value);
|
2022-02-22 17:17:21 +00:00
|
|
|
options.asc_setIsReplaceAll(true);
|
|
|
|
|
|
|
|
this.api.asc_replaceText(options);
|
|
|
|
},
|
|
|
|
|
|
|
|
onRenameText: function (found, replaced) {
|
|
|
|
var me = this;
|
2022-04-11 17:16:33 +00:00
|
|
|
if (this.api.isReplaceAll) {
|
|
|
|
if (!found) {
|
2022-06-27 17:31:43 +00:00
|
|
|
this.removeResultItems();
|
2022-04-11 17:16:33 +00:00
|
|
|
} else {
|
2022-06-27 17:31:43 +00:00
|
|
|
!(found-replaced) && this.removeResultItems();
|
2022-02-22 17:17:21 +00:00
|
|
|
Common.UI.info({
|
2022-05-24 10:02:06 +00:00
|
|
|
msg: !(found-replaced) ? Common.Utils.String.format(this.textReplaceSuccess,replaced) : Common.Utils.String.format(this.textReplaceSkipped,found-replaced),
|
2022-02-22 17:17:21 +00:00
|
|
|
callback: function() {
|
|
|
|
me.view.focus();
|
|
|
|
}
|
|
|
|
});
|
|
|
|
}
|
2022-04-11 17:16:33 +00:00
|
|
|
} else {
|
|
|
|
var options = new Asc.asc_CFindOptions();
|
|
|
|
options.asc_setFindWhat(this._state.searchText);
|
|
|
|
options.asc_setScanForward(true);
|
|
|
|
options.asc_setIsMatchCase(this._state.matchCase);
|
|
|
|
options.asc_setIsWholeCell(this._state.matchWord);
|
|
|
|
options.asc_setScanOnOnlySheet(this._state.withinSheet);
|
|
|
|
if (this._state.withinSheet === Asc.c_oAscSearchBy.Range) {
|
|
|
|
options.asc_setSpecificRange(this._state.selectedRange);
|
|
|
|
}
|
|
|
|
options.asc_setScanByRows(this._state.searchByRows);
|
|
|
|
options.asc_setLookIn(this._state.lookInFormulas ? Asc.c_oAscFindLookIn.Formulas : Asc.c_oAscFindLookIn.Value);
|
|
|
|
if (!this.api.asc_findText(options)) {
|
2022-06-27 17:31:43 +00:00
|
|
|
this.removeResultItems();
|
2022-04-11 17:16:33 +00:00
|
|
|
}
|
|
|
|
}
|
2022-04-03 15:17:46 +00:00
|
|
|
},
|
|
|
|
|
2022-06-27 17:31:43 +00:00
|
|
|
removeResultItems: function (type) {
|
2022-04-29 13:07:59 +00:00
|
|
|
this.resultItems = [];
|
|
|
|
this.hideResults();
|
2022-06-27 17:31:43 +00:00
|
|
|
this.view.updateResultsNumber(type, 0); // type === undefined, count === 0 -> no matches
|
2022-06-27 12:56:14 +00:00
|
|
|
//this.view.disableReplaceButtons(true);
|
2022-04-29 13:07:59 +00:00
|
|
|
this._state.currentResult = 0;
|
|
|
|
this._state.resultsNumber = 0;
|
|
|
|
this.view.disableNavButtons();
|
|
|
|
},
|
|
|
|
|
2022-04-03 15:17:46 +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);
|
|
|
|
}
|
|
|
|
});
|
|
|
|
},
|
|
|
|
|
|
|
|
onUpdateSearchCurrent: function (current, all) {
|
|
|
|
if (current === -1) return;
|
|
|
|
this._state.currentResult = current;
|
|
|
|
this._state.resultsNumber = all;
|
|
|
|
if (this.view) {
|
|
|
|
this.view.updateResultsNumber(current, all);
|
|
|
|
this.view.disableNavButtons(current, all);
|
2022-04-29 13:07:59 +00:00
|
|
|
if (this.resultItems && this.resultItems.length > 0) {
|
2022-04-03 15:17:46 +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');
|
2022-04-10 20:30:24 +00:00
|
|
|
this.resultItems[current].$el.addClass('selected');
|
2022-04-03 15:17:46 +00:00
|
|
|
this.scrollToSelectedResult(current);
|
|
|
|
}
|
|
|
|
}
|
|
|
|
}
|
|
|
|
Common.NotificationCenter.trigger('search:updateresults', current, all);
|
|
|
|
},
|
|
|
|
|
|
|
|
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,
|
2022-04-10 20:30:24 +00:00
|
|
|
container = this.view.$resultsContainer.find('.search-items'),
|
2022-04-03 15:17:46 +00:00
|
|
|
containerHeight = container.outerHeight(),
|
|
|
|
containerTop = container.scrollTop();
|
|
|
|
if (itemTop < 0 || (containerTop === 0 && itemTop > containerHeight)) {
|
2022-04-10 20:30:24 +00:00
|
|
|
this.view.$resultsContainer.scroller.scrollTop(containerTop + itemTop - 12);
|
2022-04-03 15:17:46 +00:00
|
|
|
} else if (itemTop + itemHeight > containerHeight) {
|
2022-04-10 20:30:24 +00:00
|
|
|
this.view.$resultsContainer.scroller.scrollTop(containerTop + itemHeight);
|
2022-04-03 15:17:46 +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) { // [id, sheet, name, cell, value, formula]
|
|
|
|
if (this.view && this._state.isStartedAddingResults) {
|
2022-05-20 11:03:21 +00:00
|
|
|
if (data.length > 300 || !data.length) return;
|
2022-04-08 10:36:38 +00:00
|
|
|
var me = this,
|
2022-04-10 20:30:24 +00:00
|
|
|
$innerResults = me.view.$resultsContainer.find('.search-items');
|
2022-04-03 15:17:46 +00:00
|
|
|
me.resultItems = [];
|
|
|
|
data.forEach(function (item, ind) {
|
2022-04-08 10:36:38 +00:00
|
|
|
var isSelected = ind === me._state.currentResult;
|
2022-04-10 20:30:24 +00:00
|
|
|
var tr = '<div class="item" style="width: 100%;">' +
|
2022-05-16 16:30:18 +00:00
|
|
|
'<div class="sheet">' + (item[1] ? item[1] : '') + '</div>' +
|
|
|
|
'<div class="name">' + (item[2] ? item[2] : '') + '</div>' +
|
|
|
|
'<div class="cell">' + (item[3] ? item[3] : '') + '</div>' +
|
|
|
|
'<div class="value">' + (item[4] ? item[4] : '') + '</div>' +
|
|
|
|
'<div class="formula">' + (item[5] ? item[5] : '') + '</div>' +
|
2022-04-10 20:30:24 +00:00
|
|
|
'</div>';
|
|
|
|
var $item = $(tr).appendTo($innerResults);
|
2022-04-03 15:17:46 +00:00
|
|
|
if (isSelected) {
|
2022-04-08 10:36:38 +00:00
|
|
|
$item.addClass('selected');
|
2022-04-03 15:17:46 +00:00
|
|
|
}
|
2022-05-16 16:30:18 +00:00
|
|
|
var resultItem = {id: item[0], $el: $item, el: tr, selected: isSelected, data: data};
|
2022-04-03 15:17:46 +00:00
|
|
|
me.resultItems.push(resultItem);
|
2022-04-08 10:36:38 +00:00
|
|
|
$item.on('click', _.bind(function (el) {
|
2022-04-03 15:17:46 +00:00
|
|
|
var id = item[0];
|
|
|
|
me.api.asc_SelectSearchElement(id);
|
|
|
|
}, me));
|
2022-05-16 16:30:18 +00:00
|
|
|
me.addTooltips($item, item);
|
2022-04-03 15:17:46 +00:00
|
|
|
});
|
|
|
|
this.view.$resultsContainer.show();
|
2022-02-22 17:17:21 +00:00
|
|
|
}
|
|
|
|
},
|
|
|
|
|
2022-05-16 16:30:18 +00:00
|
|
|
addTooltips: function (item, data) {
|
|
|
|
var cells = [item.find('.sheet'), item.find('.name'), item.find('.cell'), item.find('.value'), item.find('.formula')],
|
|
|
|
tips = [data[1], data[2], data[3], data[4], data[5]];
|
|
|
|
cells.forEach(function (el, ind) {
|
|
|
|
var tip = tips[ind];
|
|
|
|
if (tip) {
|
|
|
|
el.one('mouseenter', function () {
|
|
|
|
el.attr('data-toggle', 'tooltip');
|
|
|
|
el.tooltip({
|
|
|
|
title: tip,
|
|
|
|
placement: 'cursor',
|
|
|
|
zIndex: 1000
|
|
|
|
});
|
|
|
|
el.mouseenter();
|
|
|
|
});
|
|
|
|
}
|
|
|
|
});
|
|
|
|
},
|
|
|
|
|
2022-04-03 15:17:46 +00:00
|
|
|
hideResults: function () {
|
|
|
|
if (this.view) {
|
|
|
|
this.view.$resultsContainer.hide();
|
2022-04-11 17:16:33 +00:00
|
|
|
this.view.$resultsContainer.find('.search-items').empty();
|
2022-04-03 15:17:46 +00:00
|
|
|
}
|
|
|
|
},
|
|
|
|
|
|
|
|
onShowAfterSearch: function (findText) {
|
|
|
|
var viewport = this.getApplication().getController('Viewport');
|
|
|
|
if (viewport.isSearchBarVisible()) {
|
|
|
|
viewport.searchBar.hide();
|
|
|
|
}
|
|
|
|
|
2022-05-20 11:03:21 +00:00
|
|
|
var text = typeof findText === 'string' ? findText : (this.api.asc_GetSelectedText() || 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-05-20 11:03:21 +00:00
|
|
|
if (text) {
|
2022-04-03 15:17:46 +00:00
|
|
|
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-04-03 15:17:46 +00:00
|
|
|
this.view.setFindText('');
|
2022-05-20 11:03:21 +00:00
|
|
|
this._state.searchText = undefined;
|
2022-04-03 15:17:46 +00:00
|
|
|
}
|
|
|
|
|
|
|
|
this.hideResults();
|
2022-06-17 11:35:25 +00:00
|
|
|
if (text && text !== '' && text === this._state.searchText) { // search was made
|
2022-06-27 12:56:14 +00:00
|
|
|
//this.view.disableReplaceButtons(false);
|
2022-04-03 15:17:46 +00:00
|
|
|
this.api.asc_StartTextAroundSearch();
|
2022-06-17 11:35:25 +00:00
|
|
|
} else if (text && text !== '') { // search wasn't made
|
2022-04-03 15:17:46 +00:00
|
|
|
this.onInputSearchChange(text);
|
|
|
|
} else {
|
|
|
|
this.resultItems = [];
|
2022-06-27 12:56:14 +00:00
|
|
|
//this.view.disableReplaceButtons(true);
|
2022-04-03 15:17:46 +00:00
|
|
|
this.view.clearResultsNumber();
|
|
|
|
}
|
|
|
|
this.view.disableNavButtons(this._state.currentResult, this._state.resultsNumber);
|
|
|
|
},
|
|
|
|
|
|
|
|
onShowPanel: function () {
|
2022-04-11 17:16:33 +00:00
|
|
|
this.onSelectSearchingResults(true);
|
2022-04-03 15:17:46 +00:00
|
|
|
if (this.resultItems && this.resultItems.length > 0 && !this._state.isStartedAddingResults) {
|
2022-04-10 20:30:24 +00:00
|
|
|
var me = this,
|
2022-04-11 17:16:33 +00:00
|
|
|
$tableBody = this.view.$resultsContainer.find('.search-items');
|
2022-04-03 15:17:46 +00:00
|
|
|
this.view.$resultsContainer.show();
|
|
|
|
this.resultItems.forEach(function (item) {
|
2022-04-10 20:30:24 +00:00
|
|
|
var $item = $(item.el).appendTo($tableBody);
|
2022-04-03 15:17:46 +00:00
|
|
|
if (item.selected) {
|
2022-04-10 20:30:24 +00:00
|
|
|
$item.addClass('selected');
|
2022-04-03 15:17:46 +00:00
|
|
|
}
|
2022-04-10 20:30:24 +00:00
|
|
|
$item.on('click', function (el) {
|
2022-04-03 15:17:46 +00:00
|
|
|
me.api.asc_SelectSearchElement(item.id);
|
|
|
|
$('#search-results').find('.item').removeClass('selected');
|
|
|
|
$(el.currentTarget).addClass('selected');
|
|
|
|
});
|
2022-05-16 16:30:18 +00:00
|
|
|
me.addTooltips($item, item.data);
|
2022-04-03 15:17:46 +00:00
|
|
|
});
|
|
|
|
this.scrollToSelectedResult();
|
|
|
|
}
|
|
|
|
},
|
|
|
|
|
|
|
|
onHidePanel: function () {
|
|
|
|
this.hideResults();
|
2022-04-11 17:16:33 +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-04-03 15:17:46 +00:00
|
|
|
},
|
|
|
|
|
2022-06-27 17:31:43 +00:00
|
|
|
onApiSearchEnd: function () {
|
|
|
|
this.removeResultItems('stop');
|
|
|
|
},
|
|
|
|
|
2022-02-22 17:17:21 +00:00
|
|
|
textNoTextFound: 'The data you have been searching for could not be found. Please adjust your search options.',
|
|
|
|
textReplaceSuccess: 'Search has been done. {0} occurrences have been replaced',
|
|
|
|
textReplaceSkipped: 'The replacement has been made. {0} occurrences were skipped.',
|
2022-04-10 20:30:24 +00:00
|
|
|
textInvalidRange: 'ERROR! Invalid cells range'
|
2022-02-22 17:17:21 +00:00
|
|
|
|
|
|
|
}, SSE.Controllers.Search || {}));
|
|
|
|
});
|