/* * * (c) Copyright Ascensio System SIA 2010-2021 * * 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 * */ /** * ProtectDialog.js * * Created by Julia Radzhabova on 21.06.2021 * Copyright (c) 2021 Ascensio System SIA. All rights reserved. * */ define([ 'common/main/lib/component/Window' ], function () { 'use strict'; SSE.Views.ProtectDialog = Common.UI.Window.extend(_.extend({ initialize : function (options) { var t = this, _options = {}; _.extend(_options, { title: options.type=='sheet' ? this.txtSheetTitle : this.txtWBTitle, cls: 'modal-dlg', width: 350, height: options.type=='sheet' ? 447 : 306, buttons: [{ value: 'ok', caption: this.txtProtect }, 'cancel'] }, options); this.handler = options.handler; this.txtDescription = options.txtDescription || ''; this.type = options.type || 'workbook'; this.props = options.props; this.template = options.template || [ '
', '
', '', '
', '
', '', '
', '
', '
', '', '
', '
', '<% if (type=="sheet") { %>', '
', '', '
', '
', '<% } %>', '', '
' ].join(''); _options.tpl = _.template(this.template)(_options); Common.UI.Window.prototype.initialize.call(this, _options); }, render: function () { Common.UI.Window.prototype.render.call(this); var me = this; this.$window.find('.dlg-btn').on('click', _.bind(this.onBtnClick, this)); this.inputPwd = new Common.UI.InputField({ el: $('#id-password-txt'), type: 'password', allowBlank : true, style : 'width: 100%;', maxLength: 255, validateOnBlur: false }); this.repeatPwd = new Common.UI.InputField({ el: $('#id-repeat-txt'), type: 'password', allowBlank : true, style : 'width: 100%;', maxLength: 255, validateOnBlur: false, validation : function(value) { return me.txtIncorrectPwd; } }); if (this.type == 'sheet') { this.optionsList = new Common.UI.ListView({ el: $('#protect-dlg-options', this.$window), store: new Common.UI.DataViewStore(), simpleAddMode: true, scrollAlwaysVisible: true, template: _.template(['
'].join('')), itemTemplate: _.template([ '
', '', '
', '
<%= Common.Utils.String.htmlEncode(value) %>
', '
', '
' ].join('')) }); this.optionsList.on({ 'item:change': this.onItemChanged.bind(this), 'item:add': this.onItemChanged.bind(this), 'item:select': this.onCellCheck.bind(this) }); this.optionsList.onKeyDown = _.bind(this.onListKeyDown, this); this.optionsList.on('entervalue', _.bind(this.onPrimary, this)); } this.afterRender(); }, getFocusedComponents: function() { return this.optionsList ? [this.inputPwd, this.repeatPwd, this.optionsList] : [this.inputPwd, this.repeatPwd]; }, getDefaultFocusableComponent: function () { return this.inputPwd; }, afterRender: function() { this._setDefaults(this.props); }, onPrimary: function(event) { this._handleInput('ok'); return false; }, onBtnClick: function(event) { this._handleInput(event.currentTarget.attributes['result'].value); }, _handleInput: function(state) { if (this.handler) { if (state == 'ok') { if (this.inputPwd.checkValidate() !== true) { this.inputPwd.focus(); return; } if (this.inputPwd.getValue() !== this.repeatPwd.getValue()) { this.repeatPwd.checkValidate(); this.repeatPwd.focus(); return; } } this.handler.call(this, state, this.inputPwd.getValue(), this.getSheetSettings()); } this.close(); }, _setDefaults: function (props) { this.optionsList && this.updateOptionsList(props); }, onItemChanged: function (view, record) { var state = record.model.get('check'); if ( state == 'indeterminate' ) $('input[type=checkbox]', record.$el).prop('indeterminate', true); else $('input[type=checkbox]', record.$el).prop({checked: state, indeterminate: false}); }, onCellCheck: function (listView, itemView, record) { if (this.checkCellTrigerBlock) return; var target = '', isLabel = false, bound = null; var event = window.event ? window.event : window._event; if (event) { target = $(event.currentTarget).find('.list-item'); if (target.length) { bound = target.get(0).getBoundingClientRect(); var _clientX = event.clientX*Common.Utils.zoom(), _clientY = event.clientY*Common.Utils.zoom(); if (bound.left < _clientX && _clientX < bound.right && bound.top < _clientY && _clientY < bound.bottom) { isLabel = true; } } if (isLabel || event.target.className.match('checkbox')) { this.updateCellCheck(listView, record); _.delay(function () { listView.focus(); }, 100, this); } } }, onListKeyDown: function (e, data) { var record = null, listView = this.optionsList; if (listView.disabled) return; if (_.isUndefined(undefined)) data = e; if (data.keyCode == Common.UI.Keys.SPACE) { data.preventDefault(); data.stopPropagation(); this.updateCellCheck(listView, listView.getSelectedRec()); } else { Common.UI.DataView.prototype.onKeyDown.call(this.optionsList, e, data); } }, updateCellCheck: function (listView, record) { if (record && listView) { record.set('check', !record.get('check')); // listView.scroller.update({minScrollbarLength : 40, alwaysVisibleY: true, suppressScrollX: true}); } }, updateOptionsList: function(props) { var optionsArr = [ { value: this.txtSelLocked, optionName: 'SelectLockedCells'}, { value: this.txtSelUnLocked, optionName: 'SelectUnlockedCells'}, { value: this.txtFormatCells, optionName: 'FormatCells'}, { value: this.txtFormatCols, optionName: 'FormatColumns'}, { value: this.txtFormatRows, optionName: 'FormatRows'}, { value: this.txtInsCols, optionName: 'InsertColumns'}, { value: this.txtInsRows, optionName: 'InsertRows'}, { value: this.txtInsHyper, optionName: 'InsertHyperlinks'}, { value: this.txtDelCols, optionName: 'DeleteColumns'}, { value: this.txtDelRows, optionName: 'DeleteRows'}, { value: this.txtSort, optionName: 'Sort'}, { value: this.txtAutofilter, optionName: 'AutoFilter'}, { value: this.txtPivot, optionName: 'PivotTables'}, { value: this.txtObjs, optionName: 'Objects'}, { value: this.txtScen, optionName: 'Scenarios'} ]; var arr = []; optionsArr.forEach(function (item, index) { arr.push(new Common.UI.DataViewModel({ selected : false, allowSelected : true, value : item.value, optionName : item.optionName, check : props && props['asc_get' + item.optionName] ? !props['asc_get' + item.optionName]() : false })); }); this.optionsList.store.reset(arr); this.optionsList.scroller.update({minScrollbarLength : 40, alwaysVisibleY: true, suppressScrollX: true}); }, getSheetSettings: function() { if (this.type !== 'sheet') return null; var props = this.props ? this.props : new Asc.CSheetProtection(); this.optionsList.store.each(function (item, index) { props && props['asc_set' + item.get('optionName')] && props['asc_set' + item.get('optionName')](!item.get('check')); }); return props; }, txtPassword : "Password", txtRepeat: 'Repeat password', txtIncorrectPwd: 'Confirmation password is not identical', txtWarning: 'Warning: If you lose or forget the password, it cannot be recovered. Please keep it in a safe place.', txtOptional: 'optional', txtProtect: 'Protect', txtSelLocked: 'Select locked cells', txtSelUnLocked: 'Select unlocked cells', txtFormatCells: 'Format cells', txtFormatCols: 'Format columns', txtFormatRows: 'Format rows', txtInsCols: 'Insert columns', txtInsRows: 'Insert rows', txtInsHyper: 'Insert hyperlink', txtDelCols: 'Delete columns', txtDelRows: 'Delete rows', txtSort: 'Sort', txtAutofilter: 'Use AutoFilter', txtPivot: 'Use PivotTable and PivotChart', txtObjs: 'Edit objects', txtScen: 'Edit scenarios', txtWBDescription: 'To prevent other users from viewing hidden worksheets, adding, moving, deleting, or hiding worksheets and renaming worksheets, you can protect the structure of your workbook with a password.', txtWBTitle: 'Protect Workbook structure', txtSheetDescription: 'Prevent unwanted changes from others by limiting their ability to edit.', txtSheetTitle: 'Protect Sheet', txtAllow: 'Allow all users of this sheet to' }, SSE.Views.ProtectDialog || {})); });