/* * * (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', '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; me.listenTo(me.model, 'change:name', function() { me.render(); me.trigger('change', me, me.model); }); me.listenTo(me.model, 'change:lock', function() { me.render(); me.trigger('change', me, me.model); }); 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: [ '
', '
' + _.template(contentTemplate)({scope: this}) + '
', '
', '
' ].join('') }, options); this.api = options.api; this.handler = options.handler; this.props = options.props; this.langId = options.langId; this.rules = []; this.rulesStores = {}; this.rulesDeleted = []; this.listSettings = {length: 0, min: 0, max: 0}; this.locked = options.locked || false; this.userTooltip = true; 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'), menuStyle : 'min-width: 100%;max-height: 211px;', editable : false, cls : 'input-group-nr', data : [], takeFocusOnClose: true }).on('selected', function(combo, record) { me.refreshRuleList(record); }); this.rulesList = new Common.UI.ListView({ el: $('#format-manager-rules-list', this.$window), store: new Common.UI.DataViewStore(), emptyText: '', template: _.template(['
'].join('')), itemTemplate: _.template([ '
', '
<%= name %>
', '
', '
', '<% if (lock) { %>', '
<%=lockuser%>
', '<% } %>', '
' ].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({ parentEl: $('#format-manager-btn-up'), 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({ parentEl: $('#format-manager-btn-down'), cls: 'btn-toolbar bg-white', iconCls: 'caret-down', hint: this.textDown }); this.btnDown.on('click', _.bind(this.onMoveClick, this, false)); this.afterRender(); }, getDefaultFocusableComponent: function () { return this.cmbScope; }, afterRender: function() { this._setDefaults(this.props); }, _setDefaults: function (props) { Common.UI.FocusManager.add(this, this.cmbScope); Common.UI.FocusManager.add(this, this.rulesList); Common.UI.FocusManager.add(this, this.btnNew); Common.UI.FocusManager.add(this, this.btnEdit); Common.UI.FocusManager.add(this, this.btnDelete); this.rulesList.on('item:add', _.bind(this.addControls, this)); this.rulesList.on('item:change', _.bind(this.addControls, this)); this.currentSheet = this.api.asc_getActiveWorksheetIndex(); this.refreshScopeList(); this.refreshRuleList(this.cmbScope.getSelectedRecord()); 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); }, refreshScopeList: function() { var wc = this.api.asc_getWorksheetsCount(), i = -1; var items = [ { 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 } ]; // 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 // }); // } // } // } this.cmbScope.setData(items); this.cmbScope.setValue(Asc.c_oAscSelectionForCFType.selection); }, refreshRuleList: function(scope) { this.rules = []; 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