From 0a63cde13f491fa0c3068342cc6ff59ed4e64a87 Mon Sep 17 00:00:00 2001 From: Julia Radzhabova Date: Tue, 12 Apr 2022 13:23:45 +0300 Subject: [PATCH 001/188] [DE] Add roles manager --- .../main/app/view/RolesManagerDlg.js | 347 ++++++++++++++++++ 1 file changed, 347 insertions(+) create mode 100644 apps/documenteditor/main/app/view/RolesManagerDlg.js diff --git a/apps/documenteditor/main/app/view/RolesManagerDlg.js b/apps/documenteditor/main/app/view/RolesManagerDlg.js new file mode 100644 index 000000000..a7e6fb344 --- /dev/null +++ b/apps/documenteditor/main/app/view/RolesManagerDlg.js @@ -0,0 +1,347 @@ +/* + * + * (c) Copyright Ascensio System SIA 2010-2022 + * + * 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 + * +*/ +/** + * + * RolesManagerDlg.js + * + * Created by Julia.Radzhabova on 12.04.22 + * Copyright (c) 2022 Ascensio System SIA. All rights reserved. + * + */ + +define([ 'text!documenteditor/main/app/template/RolesManagerDlg.template', + 'common/main/lib/view/AdvancedSettingsWindow', + 'common/main/lib/component/ListView' +], function (contentTemplate) { + 'use strict'; + + DE.Views = DE.Views || {}; + + DE.Views.RolesManagerDlg = Common.Views.AdvancedSettingsWindow.extend(_.extend({ + options: { + alias: 'RolesManagerDlg', + contentWidth: 525, + height: 353, + buttons: null + }, + + 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.rolesStore = new Common.UI.DataViewStore(); + + this.wrapEvents = { + onRefreshRolesList: _.bind(this.onRefreshRolesList, this) + }; + + Common.Views.AdvancedSettingsWindow.prototype.initialize.call(this, this.options); + }, + render: function () { + Common.Views.AdvancedSettingsWindow.prototype.render.call(this); + var me = this; + + this.rolesList = new Common.UI.ListView({ + el: $('#name-manager-range-list', this.$window), + store: new Common.UI.DataViewStore(), + simpleAddMode: true, + emptyText: this.textEmpty, + itemTemplate: _.template([ + '
', + '
">
', + '
<%= Common.Utils.String.htmlEncode(name) %>
', + '
<%= scopeName %>
', + '
<%= range %>
', + '<% if (lock) { %>', + '
<%=lockuser%>
', + '<% } %>', + '
' + ].join('')), + tabindex: 1 + }); + this.rolesList.store.comparator = function(item1, item2) { + var n1 = item1.get(me.sort.type).toLowerCase(), + n2 = item2.get(me.sort.type).toLowerCase(); + if (n1==n2) return 0; + return (n10) ? this.textnoNames : this.textEmpty); + } + + var me = this, + store = this.rolesList.store, + models = this.rolesStore.models, + val = this.cmbFilter.getValue(), + isTableFilter = (val<3) ? (val==2) : -1, + isWorkbook = (val>2) ? (val==4) : -1; + if (val>0) + models = this.rolesStore.filter(function(item) { + if (isTableFilter!==-1) + return (isTableFilter===item.get('isTable')); + if (isWorkbook!==-1) + return (isWorkbook===(item.get('scope')===null)); + return false; + }); + + store.reset(models, {silent: false}); + + val = store.length; + this.btnEditRole.setDisabled(!val); + this.btnDeleteRole.setDisabled(!val); + if (val>0) { + if (selectedItem===undefined || selectedItem===null) selectedItem = 0; + if (_.isNumber(selectedItem)) { + if (selectedItem>val-1) selectedItem = val-1; + this.rangeList.selectByIndex(selectedItem); + setTimeout(function() { + me.rangeList.scrollToRecord(store.at(selectedItem)); + }, 50); + + } else if (selectedItem){ // object + var rec = store.findWhere({name: selectedItem.asc_getName(true), scope: selectedItem.asc_getScope()}); + if (rec) { + this.rangeList.selectRecord(rec); + setTimeout(function() { + me.rangeList.scrollToRecord(rec); + }, 50); + } + } + + if (this.userTooltip===true && this.rangeList.cmpEl.find('.lock-user').length>0) + this.rangeList.cmpEl.on('mouseover', _.bind(me.onMouseOverLock, me)).on('mouseout', _.bind(me.onMouseOutLock, me)); + } + _.delay(function () { + me.rangeList.scroller.update({alwaysVisibleY: true}); + }, 100, this); + }, + + onEditRange: function (isEdit) { + if (this._isWarningVisible) return; + + if (this.locked) { + Common.NotificationCenter.trigger('namedrange:locked'); + return; + } + var me = this, + xy = me.$window.offset(), + rec = this.rangeList.getSelectedRec(), + idx = _.indexOf(this.rangeList.store.models, rec), + oldname = (isEdit && rec) ? new Asc.asc_CDefName(rec.get('name'), rec.get('range'), rec.get('scope'), rec.get('type'), undefined, undefined, undefined, true) : null; + + var win = new SSE.Views.NamedRangeEditDlg({ + api: me.api, + sheets : this.sheets, + props : (isEdit) ? oldname : this.props, + isEdit : isEdit, + handler : function(result, settings) { + if (result == 'ok' && settings) { + if (isEdit) { + me.currentNamedRange = settings; + me.api.asc_editDefinedNames(oldname, settings); + } else { + me.cmbFilter.setValue(0); + me.currentNamedRange = settings; + me.api.asc_setDefinedNames(settings); + } + } + } + }).on('close', function() { + me.show(); + setTimeout(function(){ me.getDefaultFocusableComponent().focus(); }, 100); + }); + + me.hide(); + win.show(xy.left + 65, xy.top + 77); + }, + + onDeleteRange: function () { + var rec = this.rangeList.getSelectedRec(); + if (rec) { + var me = this; + me._isWarningVisible = true; + Common.UI.warning({ + msg: Common.Utils.String.format(me.warnDelete, rec.get('name')), + buttons: ['ok', 'cancel'], + callback: function(btn) { + if (btn == 'ok') { + me.currentNamedRange = _.indexOf(me.rangeList.store.models, rec); + me.api.asc_delDefinedNames(new Asc.asc_CDefName(rec.get('name'), rec.get('range'), rec.get('scope'), rec.get('type'), undefined, undefined, undefined, true)); + } + setTimeout(function(){ me.getDefaultFocusableComponent().focus(); }, 100); + me._isWarningVisible = false; + } + }); + } + }, + + getSettings: function() { + return this.sort; + }, + + onPrimary: function() { + return true; + }, + + onDlgBtnClick: function(event) { + this.handler && this.handler.call(this, event.currentTarget.attributes['result'].value); + this.close(); + }, + + onSelectRoleItem: function(lisvView, itemView, record) { + if (!record) return; + + this.userTipHide(); + var rawData = {}, + isViewSelect = _.isFunction(record.toJSON); + + if (isViewSelect){ + if (record.get('selected')) { + rawData = record.toJSON(); + } else {// record deselected + return; + } + this.currentNamedRange = _.indexOf(this.rangeList.store.models, record); + this.btnEditRange.setDisabled(rawData.lock); + this.btnDeleteRange.setDisabled(rawData.lock || rawData.isTable || rawData.isSlicer); + } + }, + + hide: function () { + this.userTipHide(); + Common.UI.Window.prototype.hide.call(this); + }, + + close: function () { + this.userTipHide(); + this.api.asc_unregisterCallback('asc_onRefreshRolesList', this.wrapEvents.onRefreshRolesList); + + Common.UI.Window.prototype.close.call(this); + }, + + onKeyDown: function (lisvView, record, e) { + if (e.keyCode==Common.UI.Keys.DELETE && !this.btnDeleteRange.isDisabled()) + this.onDeleteRange(); + }, + + onDblClickItem: function (lisvView, record, e) { + if (!this.btnEditRole.isDisabled()) + this.onEditRole(true); + }, + + txtTitle: 'Manage Roles', + closeButtonText : 'Close', + textNew: 'New', + textEdit: 'Edit', + textDelete: 'Delete', + textEmpty: 'No named ranges have been created yet.
Create at least one named range and it will appear in this field.', + warnDelete: 'Are you sure you want to delete the role {0}?' + + }, DE.Views.RolesManagerDlg || {})); +}); \ No newline at end of file From 726c0fe6ef6b93e0bfb45e32304db43f66a28c65 Mon Sep 17 00:00:00 2001 From: Julia Radzhabova Date: Wed, 13 Apr 2022 22:35:41 +0300 Subject: [PATCH 002/188] [DE] Change Forms tab and Roles manager according to layout --- .../less/advanced-settings-window.less | 37 ++++ .../main/app/controller/FormsTab.js | 27 ++- .../app/template/RolesManagerDlg.template | 27 +++ apps/documenteditor/main/app/view/FormsTab.js | 160 +++++++++--------- .../main/app/view/RolesManagerDlg.js | 151 +++++++++-------- .../resources/less/advanced-settings.less | 36 ---- 6 files changed, 255 insertions(+), 183 deletions(-) create mode 100644 apps/documenteditor/main/app/template/RolesManagerDlg.template diff --git a/apps/common/main/resources/less/advanced-settings-window.less b/apps/common/main/resources/less/advanced-settings-window.less index 49085e69c..bd448746e 100644 --- a/apps/common/main/resources/less/advanced-settings-window.less +++ b/apps/common/main/resources/less/advanced-settings-window.less @@ -52,4 +52,41 @@ padding-right: 30px; } } + + .range-tableview { + .list-item > div{ + vertical-align: middle; + display: inline-block; + text-overflow: ellipsis; + overflow: hidden; + white-space: pre; + } + + .listitem-icon { + width: 20px; + height: 20px; + vertical-align: middle; + margin-right: 5px; + } + + .selected { + .listitem-icon { + background-position-x: -20px; + background-position-x: @button-small-active-icon-offset-x; + } + } + + .lock-user { + position: absolute; + right: 2px; + min-width: 100px; + max-width: 150px; + height: 20px; + padding: 2px 10px; + background-color: #EE3525; + color: #fff; + text-align: center; + } + } + } \ No newline at end of file diff --git a/apps/documenteditor/main/app/controller/FormsTab.js b/apps/documenteditor/main/app/controller/FormsTab.js index 49e71d3ae..adfed2b58 100644 --- a/apps/documenteditor/main/app/controller/FormsTab.js +++ b/apps/documenteditor/main/app/controller/FormsTab.js @@ -41,7 +41,8 @@ define([ 'core', - 'documenteditor/main/app/view/FormsTab' + 'documenteditor/main/app/view/FormsTab', + 'documenteditor/main/app/view/RolesManagerDlg' ], function () { 'use strict'; @@ -66,7 +67,7 @@ define([ this.api.asc_registerCallback('asc_onFocusObject', this.onApiFocusObject.bind(this)); this.api.asc_registerCallback('asc_onCoAuthoringDisconnect',_.bind(this.onCoAuthoringDisconnect, this)); Common.NotificationCenter.on('api:disconnect', _.bind(this.onCoAuthoringDisconnect, this)); - this.api.asc_registerCallback('asc_onChangeSpecialFormsGlobalSettings', _.bind(this.onChangeSpecialFormsGlobalSettings, this)); + // this.api.asc_registerCallback('asc_onChangeSpecialFormsGlobalSettings', _.bind(this.onChangeSpecialFormsGlobalSettings, this)); Common.NotificationCenter.on('app:ready', this.onAppReady.bind(this)); this.api.asc_registerCallback('asc_onStartAction', _.bind(this.onLongActionBegin, this)); this.api.asc_registerCallback('asc_onEndAction', _.bind(this.onLongActionEnd, this)); @@ -90,12 +91,13 @@ define([ 'FormsTab': { 'forms:insert': this.onControlsSelect, 'forms:clear': this.onClearClick, - 'forms:no-color': this.onNoControlsColor, - 'forms:select-color': this.onSelectControlsColor, + // 'forms:no-color': this.onNoControlsColor, + // 'forms:select-color': this.onSelectControlsColor, 'forms:mode': this.onModeClick, 'forms:goto': this.onGoTo, 'forms:submit': this.onSubmitClick, - 'forms:save': this.onSaveFormClick + 'forms:save': this.onSaveFormClick, + 'forms:manager': this.onManagerClick }, 'Toolbar': { 'tab:active': this.onActiveTab @@ -195,6 +197,7 @@ define([ onModeClick: function(state) { if (this.api) { this.disableEditing(state); + this.view && this.view.setPreviewMode(state); this.api.asc_setRestriction(state ? Asc.c_oAscRestrictionType.OnlyForms : Asc.c_oAscRestrictionType.None); this.api.asc_SetPerformContentControlActionByClick(state); this.api.asc_SetHighlightRequiredFields(state); @@ -412,6 +415,20 @@ define([ } }, + onManagerClick: function() { + var me = this; + (new DE.Views.RolesManagerDlg({ + api: me.api, + handler: function(result) { + Common.component.Analytics.trackEvent('ToolBar', 'Roles Manager'); + Common.NotificationCenter.trigger('edit:complete', me.toolbar); + }, + roles: [], + props : undefined + })).on('close', function(win){ + }).show(); + }, + onActiveTab: function(tab) { if (tab !== 'forms') { this.tipSaveForm && this.tipSaveForm.close(); diff --git a/apps/documenteditor/main/app/template/RolesManagerDlg.template b/apps/documenteditor/main/app/template/RolesManagerDlg.template new file mode 100644 index 000000000..345fc1bb1 --- /dev/null +++ b/apps/documenteditor/main/app/template/RolesManagerDlg.template @@ -0,0 +1,27 @@ +
+
+ + + + + + + + + + + +
+ + +
+
+
+
+
+ + + +
+
+
\ No newline at end of file diff --git a/apps/documenteditor/main/app/view/FormsTab.js b/apps/documenteditor/main/app/view/FormsTab.js index 9498a7b43..c611cd109 100644 --- a/apps/documenteditor/main/app/view/FormsTab.js +++ b/apps/documenteditor/main/app/view/FormsTab.js @@ -49,7 +49,7 @@ define([ DE.Views.FormsTab = Common.UI.BaseView.extend(_.extend((function(){ var template = '
' + - '