web-apps/apps/spreadsheeteditor/main/app/view/FormatRulesManagerDlg.js

903 lines
40 KiB
JavaScript
Raw Normal View History

/*
*
* (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
*
*/
/**
*
* FormatRulesManagerDlg.js
*
* Created by Julia.Radzhabova on 14.04.2020
* Copyright (c) 2020 Ascensio System SIA. All rights reserved.
*
*/
define([ 'text!spreadsheeteditor/main/app/template/FormatRulesManagerDlg.template',
'common/main/lib/view/AdvancedSettingsWindow',
'common/main/lib/component/ComboBox',
'common/main/lib/component/ListView',
2020-04-16 15:43:16 +00:00
'common/main/lib/component/InputField',
'spreadsheeteditor/main/app/view/FormatRulesEditDlg'
], function (contentTemplate) {
'use strict';
SSE.Views = SSE.Views || {};
var _CustomItem = Common.UI.DataViewItem.extend({
initialize : function(options) {
Common.UI.BaseView.prototype.initialize.call(this, options);
var me = this;
me.template = me.options.template || me.template;
2021-01-27 21:57:04 +00:00
me.listenTo(me.model, 'change:name', function() {
me.render();
me.trigger('change', me, me.model);
});
2021-03-11 14:59:19 +00:00
me.listenTo(me.model, 'change:lock', function() {
me.render();
me.trigger('change', me, me.model);
});
2021-01-27 21:57:04 +00:00
me.listenTo(me.model, 'change:tip', function() {
var el = me.$el || $(me.el),
tip = el.data('bs.tooltip');
if (tip) {
var zIndex = tip.options.zIndex;
el.removeData('bs.tooltip');
el.tooltip({
title : me.model.get('tip'),
placement : 'cursor',
zIndex : zIndex
});
}
});
me.listenTo(me.model, 'change:selected', function() {
var el = me.$el || $(me.el);
el.toggleClass('selected', me.model.get('selected') && me.model.get('allowSelected'));
me.onSelectChange(me.model, me.model.get('selected') && me.model.get('allowSelected'));
});
me.listenTo(me.model, 'remove', me.remove);
}
});
SSE.Views.FormatRulesManagerDlg = Common.Views.AdvancedSettingsWindow.extend(_.extend({
options: {
alias: 'FormatRulesManagerDlg',
contentWidth: 510,
height: 361,
buttons: ['ok', 'cancel']
},
initialize: function (options) {
var me = this;
_.extend(this.options, {
title: this.txtTitle,
template: [
'<div class="box" style="height:' + (this.options.height-85) + 'px;">',
'<div class="content-panel" style="padding: 0;">' + _.template(contentTemplate)({scope: this}) + '</div>',
'</div>',
'<div class="separator horizontal"/>'
].join('')
}, options);
this.api = options.api;
this.handler = options.handler;
this.props = options.props;
this.langId = options.langId;
2021-01-28 11:00:40 +00:00
this.rules = [];
2021-01-28 15:21:07 +00:00
this.rulesStores = {};
this.rulesDeleted = [];
this.listSettings = {length: 0, min: 0, max: 0};
2021-03-11 11:54:37 +00:00
this.locked = options.locked || false;
2021-03-11 14:59:19 +00:00
this.userTooltip = true;
2021-03-11 11:54:37 +00:00
this.wrapEvents = {
onLockCFManager: _.bind(this.onLockCFManager, this),
onUnLockCFManager: _.bind(this.onUnLockCFManager, this),
onLockCFRule: _.bind(this.onLockCFRule, this),
onUnLockCFRule: _.bind(this.onUnLockCFRule, this)
};
Common.Views.AdvancedSettingsWindow.prototype.initialize.call(this, this.options);
},
render: function () {
Common.Views.AdvancedSettingsWindow.prototype.render.call(this);
var me = this;
this.cmbScope = new Common.UI.ComboBox({
el : $('#format-manager-combo-scope'),
2021-01-27 21:57:04 +00:00
menuStyle : 'min-width: 100%;max-height: 211px;',
editable : false,
cls : 'input-group-nr',
2021-03-19 09:14:25 +00:00
data : [],
takeFocusOnClose: true
}).on('selected', function(combo, record) {
2021-01-27 21:57:04 +00:00
me.refreshRuleList(record);
});
this.rulesList = new Common.UI.ListView({
el: $('#format-manager-rules-list', this.$window),
store: new Common.UI.DataViewStore(),
emptyText: '',
template: _.template(['<div class="listview inner" style=""></div>'].join('')),
itemTemplate: _.template([
2021-03-11 14:59:19 +00:00
'<div class="list-item" style="width: 100%;display:inline-block;" id="format-manager-item-<%= ruleIndex %>">',
'<div style="width:181px;padding-right: 10px;display: inline-block;vertical-align: middle;overflow: hidden; text-overflow: ellipsis; white-space: nowrap;"><%= name %></div>',
2021-01-28 11:00:40 +00:00
'<div style="width:181px;padding-right: 10px;display: inline-block;vertical-align: middle;"><div id="format-manager-txt-rule-<%= ruleIndex %>" style=""></div></div>',
2021-07-12 15:20:49 +00:00
'<div style="width:112px;display: inline-block;vertical-align: middle;"><div id="format-manager-item-preview-<%= ruleIndex %>" style="height:22px;background-color: #ffffff;"></div></div>',
2021-03-11 11:54:37 +00:00
'<% if (lock) { %>',
'<div class="lock-user"><%=lockuser%></div>',
'<% } %>',
'</div>'
2021-03-19 09:14:25 +00:00
].join('')),
tabindex: 1
});
this.rulesList.createNewItem = function(record) {
return new _CustomItem({
template: this.itemTemplate,
model: record
});
};
this.rulesList.on('item:select', _.bind(this.onSelectRule, this))
.on('item:keydown', _.bind(this.onKeyDown, this));
this.btnNew = new Common.UI.Button({
el: $('#format-manager-btn-new')
});
this.btnNew.on('click', _.bind(this.onEditRule, this, false));
this.btnEdit = new Common.UI.Button({
el: $('#format-manager-btn-edit')
});
this.btnEdit.on('click', _.bind(this.onEditRule, this, true));
this.btnDelete = new Common.UI.Button({
el: $('#format-manager-btn-delete')
});
this.btnDelete.on('click', _.bind(this.onDeleteRule, this));
this.btnUp = new Common.UI.Button({
2020-04-30 13:58:45 +00:00
parentEl: $('#format-manager-btn-up'),
2021-04-14 23:03:33 +00:00
cls: 'btn-toolbar bg-white',
iconCls: 'caret-up',
hint: this.textUp
});
this.btnUp.on('click', _.bind(this.onMoveClick, this, true));
this.btnDown = new Common.UI.Button({
2020-04-30 13:58:45 +00:00
parentEl: $('#format-manager-btn-down'),
2021-04-14 23:03:33 +00:00
cls: 'btn-toolbar bg-white',
iconCls: 'caret-down',
hint: this.textDown
});
this.btnDown.on('click', _.bind(this.onMoveClick, this, false));
this.afterRender();
},
2021-03-19 09:14:25 +00:00
getDefaultFocusableComponent: function () {
return this.cmbScope;
},
afterRender: function() {
this._setDefaults(this.props);
},
_setDefaults: function (props) {
2021-03-19 09:14:25 +00:00
Common.UI.FocusManager.add(this, this.cmbScope);
2021-04-13 22:30:54 +00:00
Common.UI.FocusManager.add(this, this.rulesList);
2021-04-14 22:02:11 +00:00
Common.UI.FocusManager.add(this, this.btnNew);
Common.UI.FocusManager.add(this, this.btnEdit);
2021-04-14 23:19:18 +00:00
Common.UI.FocusManager.add(this, this.btnUp);
Common.UI.FocusManager.add(this, this.btnDown);
2021-04-14 22:02:11 +00:00
Common.UI.FocusManager.add(this, this.btnDelete);
2021-03-19 09:14:25 +00:00
this.rulesList.on('item:add', _.bind(this.addControls, this));
this.rulesList.on('item:change', _.bind(this.addControls, this));
2021-01-28 15:21:07 +00:00
this.currentSheet = this.api.asc_getActiveWorksheetIndex();
2021-01-27 21:57:04 +00:00
this.refreshScopeList();
this.refreshRuleList(this.cmbScope.getSelectedRecord());
2021-03-11 11:54:37 +00:00
this.api.asc_registerCallback('asc_onLockCFManager', this.wrapEvents.onLockCFManager);
this.api.asc_registerCallback('asc_onUnLockCFManager', this.wrapEvents.onUnLockCFManager);
this.api.asc_registerCallback('asc_onLockCFRule', this.wrapEvents.onLockCFRule);
this.api.asc_registerCallback('asc_onUnLockCFRule', this.wrapEvents.onUnLockCFRule);
2021-01-27 21:57:04 +00:00
},
refreshScopeList: function() {
2021-01-28 15:21:07 +00:00
var wc = this.api.asc_getWorksheetsCount(), i = -1;
2021-01-27 21:57:04 +00:00
var items = [
2021-01-28 15:21:07 +00:00
{ value: Asc.c_oAscSelectionForCFType.selection, displayValue: this.textSelection, sheetIndex: -1 },
{ value: Asc.c_oAscSelectionForCFType.worksheet, displayValue: this.textThisSheet, sheetIndex: -1 },
{ value: Asc.c_oAscSelectionForCFType.table, displayValue: this.textThisTable, sheetIndex: -1 },
{ value: Asc.c_oAscSelectionForCFType.pivot, displayValue: this.textThisPivot, sheetIndex: -1 }
2021-01-27 21:57:04 +00:00
];
// if (wc>1) {
// while (++i < wc) {
// if (!this.api.asc_isWorksheetHidden(i) && i!==this.currentSheet) {
// items.push({
// displayValue:this.api.asc_getWorksheetName(i),
// value: Asc.c_oAscSelectionForCFType.worksheet,
// sheetIndex: i
// });
// }
// }
// }
2021-01-27 21:57:04 +00:00
this.cmbScope.setData(items);
this.cmbScope.setValue(Asc.c_oAscSelectionForCFType.selection);
},
refreshRuleList: function(scope) {
2021-01-28 11:00:40 +00:00
this.rules = [];
2021-01-28 15:21:07 +00:00
var sheetIndex = (scope.sheetIndex>-1) ? scope.sheetIndex : this.currentSheet;
var ruleStore = this.rulesStores[sheetIndex];
if (!ruleStore) {
ruleStore = new Common.UI.DataViewStore();
this.rulesStores[sheetIndex] = ruleStore;
var obj = this.api.asc_getCF(Asc.c_oAscSelectionForCFType.worksheet, sheetIndex);
var rules = obj[0];
this.currentRange = obj[1];
var arr = [];
if (rules) {
for (var i=0; i<rules.length; i++) {
var rule = rules[i],
name = this.getRuleName(rule),
2021-03-12 09:41:05 +00:00
location = rule.asc_getLocation(),
idlock = rule.asc_getIsLock();
2021-01-28 15:21:07 +00:00
arr.push({
ruleIndex: i, // connect store and list with controls. is not changed
ruleId: rule.asc_getId(),
name: name,
tip: name,
range: location[1],
activeSheet: location[0],
priority: rule.asc_getPriority(), // priority of the rule, is changed when move or when new rule is added
ruleChanged: false, // true if was edited in FormatRulesEditDlg or was created, need to send this rule to sdk if true
2021-03-11 11:54:37 +00:00
props: rule,
2021-03-12 09:41:05 +00:00
lock: (idlock!==null && idlock!==undefined),
lockuser: (idlock) ? (this.isUserVisible(idlock) ? this.getUserName(idlock) : this.lockText) : this.guestText
2021-01-28 15:21:07 +00:00
});
}
}
2021-01-28 15:21:07 +00:00
ruleStore.reset(arr);
}
2021-01-28 15:21:07 +00:00
if (sheetIndex == this.currentSheet) {
ruleStore.each(function(item){
var hidden = scope.value!==Asc.c_oAscSelectionForCFType.worksheet && !item.get('props').asc_checkScope(scope.value);
item.set('cls', hidden ? 'hidden' : undefined);
});
}
this.rulesList.setStore(ruleStore);
this.rulesList.onResetItems();
this.rulesList.deselectAll();
this.updateRulesCount();
2021-03-11 11:54:37 +00:00
if (this.listSettings.length>0) {
this.rulesList.selectByIndex(this.listSettings.min);
if (this.userTooltip===true && this.rulesList.cmpEl.find('.lock-user').length>0)
this.rulesList.cmpEl.on('mouseover', _.bind(this.onMouseOverLock, this)).on('mouseout', _.bind(this.onMouseOutLock, this));
}
this.updateButtons();
},
2021-03-11 11:54:37 +00:00
onMouseOverLock: function (evt, el, opt) {
if (this.userTooltip===true && $(evt.target).hasClass('lock-user')) {
var me = this,
tipdata = $(evt.target).tooltip({title: this.tipIsLocked,trigger:'manual'}).data('bs.tooltip');
this.userTooltip = tipdata.tip();
this.userTooltip.css('z-index', parseInt(this.$window.css('z-index')) + 10);
tipdata.show();
setTimeout(function() { me.userTipHide(); }, 5000);
}
},
userTipHide: function () {
if (typeof this.userTooltip == 'object') {
this.userTooltip.remove();
this.userTooltip = undefined;
this.rulesList.cmpEl.off('mouseover').off('mouseout');
}
},
onMouseOutLock: function (evt, el, opt) {
if (typeof this.userTooltip == 'object') this.userTipHide();
},
getRuleName: function(rule) {
var name = '';
switch (rule.asc_getType()) {
case Asc.c_oAscCFType.aboveAverage:
name = this.textAbove;
2020-04-28 12:42:19 +00:00
var above = rule.asc_getAboveAverage(),
eq = rule.asc_getEqualAverage(),
stddev = rule.asc_getStdDev();
subtype = (above) ? 0 : 1;
if (eq)
subtype += 2;
else if (stddev) {
subtype += (2 + stddev*2);
}
switch (subtype) {
case 0:
name = this.textAbove;
2020-04-28 12:42:19 +00:00
break;
case 1:
name = this.textBelow;
2020-04-28 12:42:19 +00:00
break;
case 2:
name = this.textEqAbove;
2020-04-28 12:42:19 +00:00
break;
case 3:
name = this.textEqBelow;
2020-04-28 12:42:19 +00:00
break;
case 4:
name = this.text1Above;
2020-04-28 12:42:19 +00:00
break;
case 5:
name = this.text1Below;
2020-04-28 12:42:19 +00:00
break;
case 6:
name = this.text2Above;
2020-04-28 12:42:19 +00:00
break;
case 7:
name = this.text2Below;
2020-04-28 12:42:19 +00:00
break;
case 8:
name = this.text3Above;
2020-04-28 12:42:19 +00:00
break;
case 9:
name = this.text3Below;
2020-04-28 12:42:19 +00:00
break;
}
break;
case Asc.c_oAscCFType.beginsWith:
name = this.textBeginsWith + ' ' + (rule.asc_getContainsText() || '');
break;
case Asc.c_oAscCFType.cellIs:
name = this.textCellValue;
2020-04-28 12:42:19 +00:00
var subtype = rule.asc_getOperator(),
op;
switch (subtype) {
case Asc.c_oAscCFOperator.greaterThan:
op = '>';
name = name + ' ' + op + ' ' + (rule.asc_getValue1() || '');
break;
case Asc.c_oAscCFOperator.greaterThanOrEqual:
op = '>=';
name = name + ' ' + op + ' ' + (rule.asc_getValue1() || '');
break;
case Asc.c_oAscCFOperator.lessThan:
op = '<';
name = name + ' ' + op + ' ' + (rule.asc_getValue1() || '');
break;
case Asc.c_oAscCFOperator.lessThanOrEqual:
op = '<=';
name = name + ' ' + op + ' ' + (rule.asc_getValue1() || '');
break;
case Asc.c_oAscCFOperator.equal:
op = '=';
name = name + ' ' + op + ' ' + (rule.asc_getValue1() || '');
break;
case Asc.c_oAscCFOperator.notEqual:
op = '<>';
name = name + ' ' + op + ' ' + (rule.asc_getValue1() || '');
break;
case Asc.c_oAscCFOperator.between:
name = name + ' ' + Common.Utils.String.format(this.textBetween, (rule.asc_getValue1() || ''), (rule.asc_getValue2() || ''));
2020-04-28 12:42:19 +00:00
break;
case Asc.c_oAscCFOperator.notBetween:
name = name + ' ' + Common.Utils.String.format(this.textNotBetween, (rule.asc_getValue1() || ''), (rule.asc_getValue2() || ''));
2020-04-28 12:42:19 +00:00
break;
}
break;
case Asc.c_oAscCFType.colorScale:
name = this.textColorScale;
break;
case Asc.c_oAscCFType.containsBlanks:
name = this.textContainsBlank;
break;
case Asc.c_oAscCFType.containsErrors:
name = this.textContainsError;
break;
case Asc.c_oAscCFType.containsText:
name = this.textContains + ' ' + (rule.asc_getContainsText() || '');
break;
case Asc.c_oAscCFType.dataBar:
name = Common.define.conditionalData.textDataBar;
break;
case Asc.c_oAscCFType.duplicateValues:
name = this.textDuplicate;
break;
case Asc.c_oAscCFType.expression:
name = Common.define.conditionalData.textFormula + ': ' + (rule.asc_getValue1() || '');
break;
case Asc.c_oAscCFType.iconSet:
name = this.textIconSet;
break;
case Asc.c_oAscCFType.notContainsBlanks:
name = this.textNotContainsBlank;
break;
case Asc.c_oAscCFType.notContainsErrors:
name = this.textNotContainsError;
break;
case Asc.c_oAscCFType.notContainsText:
name = this.textNotContains + ' ' + (rule.asc_getContainsText() || '');
break;
case Asc.c_oAscCFType.timePeriod:
2020-04-28 12:42:19 +00:00
var subtype = rule.asc_getTimePeriod();
switch (subtype) {
case Asc.c_oAscTimePeriod.yesterday:
name = Common.define.conditionalData.textYesterday;
2020-04-28 12:42:19 +00:00
break;
case Asc.c_oAscTimePeriod.today:
name = Common.define.conditionalData.textToday;
2020-04-28 12:42:19 +00:00
break;
case Asc.c_oAscTimePeriod.tomorrow:
name = Common.define.conditionalData.textTomorrow;
2020-04-28 12:42:19 +00:00
break;
case Asc.c_oAscTimePeriod.last7Days:
name = Common.define.conditionalData.textLast7days;
2020-04-28 12:42:19 +00:00
break;
case Asc.c_oAscTimePeriod.lastWeek:
name = Common.define.conditionalData.textLastWeek;
2020-04-28 12:42:19 +00:00
break;
case Asc.c_oAscTimePeriod.thisWeek:
name = Common.define.conditionalData.textThisWeek;
2020-04-28 12:42:19 +00:00
break;
case Asc.c_oAscTimePeriod.nextWeek:
name = Common.define.conditionalData.textNextWeek;
2020-04-28 12:42:19 +00:00
break;
case Asc.c_oAscTimePeriod.lastMonth:
name = Common.define.conditionalData.textLastMonth;
2020-04-28 12:42:19 +00:00
break;
case Asc.c_oAscTimePeriod.thisMonth:
name = Common.define.conditionalData.textThisMonth;
2020-04-28 12:42:19 +00:00
break;
case Asc.c_oAscTimePeriod.nextMonth:
name = Common.define.conditionalData.textNextMonth;
2020-04-28 12:42:19 +00:00
break;
}
break;
case Asc.c_oAscCFType.top10:
name = rule.asc_getBottom() ? Common.define.conditionalData.textBottom : Common.define.conditionalData.textTop;
2020-04-28 12:42:19 +00:00
name = name + ' ' + (rule.asc_getRank()) + (rule.asc_getPercent() ? '%' : '');
break;
case Asc.c_oAscCFType.uniqueValues:
name = this.textUnique;
break;
case Asc.c_oAscCFType.endsWith:
name = this.textEnds + ' ' + (rule.asc_getContainsText() || '');
break;
}
return name;
},
addControls: function(listView, itemView, item) {
if (!item) return;
var me = this,
2021-01-28 11:00:40 +00:00
i = item.get('ruleIndex'),
cmpEl = this.rulesList.cmpEl.find('#format-manager-item-' + i);
2021-01-28 11:00:40 +00:00
if (!this.rules[i])
this.rules[i] = {};
var rule = this.rules[i];
var input = new Common.UI.InputFieldBtn({
el : cmpEl.find('#format-manager-txt-rule-' + i),
name : 'range',
style : 'width: 100%;',
btnHint : this.textSelectData,
allowBlank : true,
2021-03-11 14:59:19 +00:00
disabled : !item.get('activeSheet') || item.get('lock'),
validateOnChange: true
2021-03-03 21:28:43 +00:00
}).on('changed:after', function(input, newValue, oldValue, e) {
2021-03-10 18:38:58 +00:00
if (rule.dataRangeValid !== newValue) {
if (me.isRangeValid(newValue)) {
rule.dataRangeValid = newValue;
item.set('ruleChanged', true);
item.get('props').asc_setLocation(rule.dataRangeValid);
} else
rule.txtDataRange.setValue(rule.dataRangeValid);
}
2021-02-05 18:09:35 +00:00
}).on('button:click', _.bind(this.onSelectData, this, rule, item));
2021-03-19 09:14:25 +00:00
Common.UI.FocusManager.add(this, input);
var val = item.get('range');
(val!==null) && input.setValue(val);
2021-01-28 11:00:40 +00:00
rule.txtDataRange = input;
rule.dataRangeValid = val;
rule.previewDiv = 'format-manager-item-preview-' + i;
2021-01-27 21:57:04 +00:00
me.drawRulePreview(item);
cmpEl.on('mousedown', 'input', function(){
me.rulesList.selectRecord(item);
});
},
2021-01-27 21:57:04 +00:00
drawRulePreview: function(rule) {
var props = rule.get('props'),
type = props.asc_getType(),
text = '';
2021-02-24 15:49:05 +00:00
2021-01-27 21:57:04 +00:00
if (type == Asc.c_oAscCFType.containsText || type == Asc.c_oAscCFType.notContainsText || type == Asc.c_oAscCFType.beginsWith ||
2021-02-24 15:49:05 +00:00
type == Asc.c_oAscCFType.endsWith || type == Asc.c_oAscCFType.containsBlanks || type == Asc.c_oAscCFType.notContainsBlanks ||
type == Asc.c_oAscCFType.duplicateValues || type == Asc.c_oAscCFType.uniqueValues ||
type == Asc.c_oAscCFType.containsErrors || type == Asc.c_oAscCFType.notContainsErrors ||
type == Asc.c_oAscCFType.timePeriod || type == Asc.c_oAscCFType.aboveAverage ||
2021-01-27 21:57:04 +00:00
type == Asc.c_oAscCFType.top10 || type == Asc.c_oAscCFType.cellIs || type == Asc.c_oAscCFType.expression) {
text = props.asc_getDxf() ? Common.define.conditionalData.exampleText : Common.define.conditionalData.noFormatText;
2021-01-27 21:57:04 +00:00
}
props.asc_getPreview(this.rules[rule.get('ruleIndex')].previewDiv, text);
2021-01-27 21:57:04 +00:00
},
2021-03-10 18:38:58 +00:00
isRangeValid: function(range) {
return (Asc.c_oAscError.ID.No === this.api.asc_checkDataRange(Asc.c_oAscSelectionDialogType.ConditionalFormattingRule, range, true));
},
2021-02-05 18:09:35 +00:00
onSelectData: function(rule, item) {
var me = this;
if (me.api) {
var handlerDlg = function(dlg, result) {
if (result == 'ok') {
2021-03-10 18:38:58 +00:00
if (me.isRangeValid(dlg.getSettings())) {
rule.dataRangeValid = dlg.getSettings();
item.set('ruleChanged', true);
item.get('props').asc_setLocation(rule.dataRangeValid);
}
2021-02-05 18:09:35 +00:00
rule.txtDataRange.setValue(rule.dataRangeValid);
}
};
var win = new SSE.Views.CellRangeDialog({
handler: handlerDlg
}).on('close', function() {
me.show();
});
var xy = me.$window.offset();
me.hide();
win.show(xy.left + 160, xy.top + 125);
win.setSettings({
api : me.api,
2021-03-10 18:38:58 +00:00
range : !_.isEmpty(rule.txtDataRange.getValue()) ? rule.txtDataRange.getValue() : rule.dataRangeValid,
type : Asc.c_oAscSelectionDialogType.ConditionalFormattingRule,
validation: function() {return true;}
});
}
},
onEditRule: function (isEdit) {
var me = this,
xy = me.$window.offset(),
2021-01-28 11:00:40 +00:00
rec = this.rulesList.getSelectedRec(),
previewRec;
2020-04-16 15:43:16 +00:00
var win = new SSE.Views.FormatRulesEditDlg({
api: me.api,
2020-04-16 15:43:16 +00:00
props : (isEdit && rec) ? rec.get('props') : null,
isEdit : isEdit,
langId : me.langId,
handler : function(result, settings) {
if (result == 'ok' && settings) {
var name = me.getRuleName(settings);
if (isEdit) {
rec.set('name', name);
rec.set('tip', name);
2021-01-28 15:21:07 +00:00
rec.set('ruleChanged', true);
rec.set('props', settings);
2021-01-28 11:00:40 +00:00
previewRec = rec;
} else {
2021-01-26 15:50:59 +00:00
settings.asc_setLocation(me.currentRange);
var ruleStore = me.rulesStores[me.currentSheet];
previewRec = ruleStore.add({
ruleIndex: me.rules.length,
name: name,
tip: name,
2021-01-26 15:50:59 +00:00
range: me.currentRange,
2021-01-27 21:57:04 +00:00
activeSheet: true,
2021-01-28 15:21:07 +00:00
ruleChanged: true,
priority: 1,
2021-03-11 11:54:37 +00:00
props: settings,
lock: false,
lockuser: ''
}, {at: 0});
me.updateRulesPriority(ruleStore);
}
}
}
}).on('close', function() {
me.show();
if (isEdit) {
previewRec && me.drawRulePreview(previewRec);
} else if (previewRec) {
me.cmbScope.setValue(Asc.c_oAscSelectionForCFType.selection);
me.refreshRuleList(me.cmbScope.getSelectedRecord());
}
});
me.hide();
2020-04-27 19:17:43 +00:00
win.show();
},
onDeleteRule: function () {
var store = this.rulesList.store,
rec = this.rulesList.getSelectedRec();
if (rec) {
2021-01-28 15:21:07 +00:00
var id = rec.get('ruleId');
(id!==undefined) && this.rulesDeleted.push(id);
2021-01-28 11:00:40 +00:00
var index = rec.get('ruleIndex');
this.rules[index] = undefined;
index = store.indexOf(rec);
store.remove(rec);
2021-01-28 15:21:07 +00:00
this.updateRulesCount();
(this.listSettings.length>0) && this.rulesList.selectByIndex(index<=this.listSettings.max ? index : this.listSettings.max);
this.rulesList.scrollToRecord(this.rulesList.getSelectedRec());
}
this.updateButtons();
},
onMoveClick: function(up) {
var store = this.rulesList.store,
length = store.length,
rec = this.rulesList.getSelectedRec();
if (rec) {
var index = store.indexOf(rec);
2021-07-14 13:25:30 +00:00
var newindex = up ? this.getPrevRuleIndex(index) : this.getNextRuleIndex(index),
newrec = store.at(newindex),
prioritynew = newrec.get('priority');
newrec.set('priority', rec.get('priority'));
rec.set('priority', prioritynew);
2021-07-14 13:25:30 +00:00
store.add(store.remove(rec), {at: up ? Math.max(0, newindex) : Math.min(length-1, newindex)});
store.add(store.remove(newrec), {at: up ? Math.max(0, index) : Math.min(length-1, index)});
this.rulesList.selectRecord(rec);
this.rulesList.scrollToRecord(rec);
}
this.updateMoveButtons();
},
onSelectRule: function(lisvView, itemView, record) {
2021-03-11 11:54:37 +00:00
this.userTipHide();
this.updateButtons();
},
updateButtons: function() {
2021-03-11 11:54:37 +00:00
var rec = this.rulesList.getSelectedRec(),
lock = rec ? rec.get('lock') : false;
this.btnNew.setDisabled(this.rulesList.store.length>63 || this.locked);
this.btnDelete.setDisabled(this.listSettings.length<1 || lock);
this.btnEdit.setDisabled(this.listSettings.length<1 || lock);
this.updateMoveButtons();
this.rulesList.scroller && this.rulesList.scroller.update();
},
updateMoveButtons: function() {
var rec = this.rulesList.getSelectedRec(),
index = rec ? this.rulesList.store.indexOf(rec) : -1;
2021-03-11 11:54:37 +00:00
this.btnUp.setDisabled(index<=this.listSettings.min || this.locked);
this.btnDown.setDisabled(index<0 || index==this.listSettings.max || this.locked);
2021-01-28 15:21:07 +00:00
},
getPrevRuleIndex: function(index) {
var store = this.rulesList.store;
if (this.cmbScope.getValue() == Asc.c_oAscSelectionForCFType.worksheet) {
return Math.max(0, index-1);
} else {
for (var i=index-1; i>=this.listSettings.min; i--) {
if (store.at(i).get('cls')!=='hidden') {
return i;
}
}
return this.listSettings.min;
}
},
getNextRuleIndex: function(index) {
var store = this.rulesList.store;
if (this.cmbScope.getValue() == Asc.c_oAscSelectionForCFType.worksheet) {
return Math.min(store.length-1, index+1);
} else {
for (var i=index+1; i<=this.listSettings.max; i++) {
if (store.at(i).get('cls')!=='hidden') {
return i;
}
}
return this.listSettings.max;
}
},
2021-01-28 15:21:07 +00:00
updateRulesCount: function() {
var store = this.rulesList.store;
if (this.cmbScope.getValue() == Asc.c_oAscSelectionForCFType.worksheet) {
this.listSettings = {length: store.length, min: 0, max: store.length-1};
} else {
this.listSettings = {length: 0, min: -1, max: 0};
for (var i=0; i<store.length; i++) {
if (store.at(i).get('cls')!=='hidden') {
this.listSettings.length++;
this.listSettings.max = i;
(this.listSettings.min<0) && (this.listSettings.min=i);
}
}
}
},
updateRulesPriority: function(store) {
for (var i=1; i<store.length; i++) {
var item = store.at(i);
item.set('priority', item.get('priority')+1);
}
},
getSettings: function() {
2021-01-28 15:21:07 +00:00
var sheets = [];
for (var sheet in this.rulesStores) {
if (this.rulesStores.hasOwnProperty(sheet)) {
var store = this.rulesStores[sheet];
var arr = [];
store && store.each(function(item) {
2021-02-05 18:09:35 +00:00
var props = item.get('props');
if (item.get('priority')!==props.asc_getPriority()) {
props.asc_setPriority(item.get('priority'));
item.set('ruleChanged', true);
}
2021-01-28 15:21:07 +00:00
if (item.get('ruleChanged'))
2021-02-05 18:09:35 +00:00
arr.push(props);
2021-01-28 15:21:07 +00:00
});
(arr.length>0) && (sheets[sheet] = arr);
}
}
return {rules: sheets, deleted: this.rulesDeleted};
},
onKeyDown: function (lisvView, record, e) {
2021-03-03 19:50:19 +00:00
if (e.keyCode==Common.UI.Keys.DELETE && !this.btnDelete.isDisabled() && !/form-control/.test(e.target.className))
this.onDeleteRule();
},
2021-03-11 11:54:37 +00:00
close: function () {
this.userTipHide();
this.api.asc_unregisterCallback('asc_onLockCFManager', this.wrapEvents.onLockCFManager);
this.api.asc_unregisterCallback('asc_onUnLockCFManager', this.wrapEvents.onUnLockCFManager);
this.api.asc_unregisterCallback('asc_onLockCFRule', this.wrapEvents.onLockCFRule);
this.api.asc_unregisterCallback('asc_onUnLockCFRule', this.wrapEvents.onUnLockCFRule);
Common.UI.Window.prototype.close.call(this);
},
onLockCFManager: function(index) {
if (this.currentSheet !== index) return;
this.locked = true;
2021-03-11 14:59:19 +00:00
this.updateButtons();
if (this.userTooltip===true && this.rulesList.cmpEl.find('.lock-user').length>0)
this.rulesList.cmpEl.on('mouseover', _.bind(this.onMouseOverLock, this)).on('mouseout', _.bind(this.onMouseOutLock, this));
2021-03-11 11:54:37 +00:00
},
onUnLockCFManager: function(index) {
if (this.currentSheet !== index) return;
this.locked = false;
2021-03-11 14:59:19 +00:00
this.updateButtons();
2021-03-11 11:54:37 +00:00
},
onLockCFRule: function(index, ruleId, userId) {
if (this.currentSheet !== index) return;
var store = this.rulesList.store,
rec = store.findWhere({ruleId: ruleId});
if (rec) {
rec.set('lockuser', (userId) ? (this.isUserVisible(userId) ? this.getUserName(userId) : this.lockText) : this.guestText);
2021-03-11 14:59:19 +00:00
rec.set('lock', true);
2021-03-11 11:54:37 +00:00
this.updateButtons();
}
2021-03-11 14:59:19 +00:00
if (this.userTooltip===true && this.rulesList.cmpEl.find('.lock-user').length>0)
this.rulesList.cmpEl.on('mouseover', _.bind(this.onMouseOverLock, this)).on('mouseout', _.bind(this.onMouseOutLock, this));
2021-03-11 11:54:37 +00:00
},
onUnLockCFRule: function(index, ruleId) {
if (this.currentSheet !== index) return;
var store = this.rulesList.store,
rec = store.findWhere({ruleId: ruleId});
if (rec) {
rec.set('lockuser', '');
2021-03-11 14:59:19 +00:00
rec.set('lock', false);
2021-03-11 11:54:37 +00:00
this.updateButtons();
}
},
getUserName: function(id){
var usersStore = SSE.getCollection('Common.Collections.Users');
if (usersStore){
var rec = usersStore.findUser(id);
if (rec)
2021-03-26 11:29:16 +00:00
return AscCommon.UserInfoParser.getParsedName(rec.get('username'));
2021-03-11 11:54:37 +00:00
}
return this.guestText;
},
isUserVisible: function(id){
var usersStore = SSE.getCollection('Common.Collections.Users');
if (usersStore){
var rec = usersStore.findUser(id);
if (rec)
return !rec.get('hidden');
}
return true;
},
txtTitle: 'Conditional Formatting',
textNew: 'New',
textEdit: 'Edit',
textDelete: 'Delete',
textUp: 'Move rule up',
textDown: 'Move rule down',
textSelection: 'Current selection',
textThisSheet: 'This worksheet',
textThisTable: 'This table',
textThisPivot: 'This pivot',
textScope: 'Show formatting rules for',
textRules: 'Rules',
textApply: 'Apply to',
textFormat: 'Format',
2021-01-27 21:57:04 +00:00
textSelectData: 'Select data',
textAbove: 'Above average',
textBelow: 'Below average',
textEqAbove: 'Equal to or above average',
textEqBelow: 'Equal to or below average',
text1Above: '1 std dev above average',
text1Below: '1 std dev below average',
text2Above: '2 std dev above average',
text2Below: '2 std dev below average',
text3Above: '3 std dev above average',
text3Below: '3 std dev below average',
textBeginsWith: 'Cell value begins with',
textCellValue: 'Cell value',
textBetween: 'is between {0} and {1}',
textNotBetween: 'is not between {0} and {1}',
textColorScale: 'Graded color scale',
textContainsBlank: 'Cell contains a blank value',
textContainsError: 'Cell contains an error',
textContains: 'Cell value contains',
textNotContains: 'Cell value does not contain',
textNotContainsError: 'Cell does not contain an error',
textNotContainsBlank: 'Cell does not contain a blank value',
textEnds: 'Cell value ends with',
textIconSet: 'Icon set',
textDuplicate: 'Duplicate values',
2021-03-11 11:54:37 +00:00
textUnique: 'Unique values',
tipIsLocked: 'This element is being edited by another user.',
guestText: 'Guest',
lockText: 'Locked'
}, SSE.Views.FormatRulesManagerDlg || {}));
});