From a58534687a2990282bd533ffeda1042f40cbc05f Mon Sep 17 00:00:00 2001 From: Julia Radzhabova Date: Thu, 1 Dec 2022 18:38:42 +0300 Subject: [PATCH] [DE] Add new form with last selected role or the last role in list --- .../main/app/controller/FormsTab.js | 25 ++++++++----------- .../main/app/view/FormSettings.js | 1 + apps/documenteditor/main/app/view/FormsTab.js | 10 ++++---- 3 files changed, 16 insertions(+), 20 deletions(-) diff --git a/apps/documenteditor/main/app/controller/FormsTab.js b/apps/documenteditor/main/app/controller/FormsTab.js index 9b0c72e3b..2cfc2aa77 100644 --- a/apps/documenteditor/main/app/controller/FormsTab.js +++ b/apps/documenteditor/main/app/controller/FormsTab.js @@ -59,7 +59,10 @@ define([ initialize: function () { }, onLaunch: function () { - this._state = {}; + this._state = { + lastViewRole: undefined, // last selected role in the preview mode + lastRoleInList: undefined // last role in the roles list + }; }, setApi: function (api) { @@ -177,6 +180,7 @@ define([ var oPr, oFormPr = new AscCommon.CSdtFormPr(); + oFormPr.put_Role(Common.Utils.InternalSettings.get('de-last-form-role') || this._state.lastRoleInList); this.toolbar.toolbar.fireEvent('insertcontrol', this.toolbar.toolbar); if (type == 'picture') this.api.asc_AddContentControlPicture(oFormPr); @@ -213,14 +217,14 @@ define([ Common.NotificationCenter.trigger('edit:complete', this.toolbar); }, - onModeClick: function(state, lastRole) { + onModeClick: function(state, lastViewRole) { if (this.api) { this.disableEditing(state); - this.view && this.view.setPreviewMode(state); // sent role name - lastRole + this.view && this.view.setPreviewMode(state); // send role name - lastViewRole this.api.asc_setRestriction(state ? Asc.c_oAscRestrictionType.OnlyForms : Asc.c_oAscRestrictionType.None); this.api.asc_SetPerformContentControlActionByClick(state); this.api.asc_SetHighlightRequiredFields(state); - state && (this._state.lastRole = lastRole); + state && (this._state.lastViewRole = lastViewRole); } Common.NotificationCenter.trigger('edit:complete', this.toolbar); }, @@ -395,13 +399,7 @@ define([ // me.view.btnHighlight.currentColor = clr; // } config.isEdit && config.canFeatureContentControl && config.isFormCreator && me.showCreateFormTip(); // show tip only when create form in docxf - // change to event asc_onRefreshRolesList me.onRefreshRolesList(); - // me.onRefreshRolesList([ - // {name: 'employee 1', color: Common.Utils.ThemeColor.getRgbColor('ff0000'), fields: 5}, - // {name: 'employee 2', color: Common.Utils.ThemeColor.getRgbColor('00ff00'), fields: 1}, - // {name: 'manager', color: null, fields: 10} - // ]); me.onChangeProtectDocument(); }); }, @@ -457,7 +455,8 @@ define([ var oform = this.api.asc_GetOForm(); oform && (roles = oform.asc_getAllRoles()); } - this.view && this.view.fillRolesMenu(roles, this._state.lastRole); + this._state.lastRoleInList = (roles && roles.length>0) ? roles[roles.length-1].asc_getSettings().asc_getName() : undefined; + this.view && this.view.fillRolesMenu(roles, this._state.lastViewRole); }, onManagerClick: function() { @@ -465,12 +464,8 @@ define([ this.api.asc_GetOForm() && (new DE.Views.RolesManagerDlg({ api: me.api, handler: function(result, settings) { - // me.roles = settings; - // me.onRefreshRolesList(me.roles); - // Common.component.Analytics.trackEvent('ToolBar', 'Roles Manager'); Common.NotificationCenter.trigger('edit:complete', me.toolbar); }, - // roles: me.roles, props : undefined })).on('close', function(win){ }).show(); diff --git a/apps/documenteditor/main/app/view/FormSettings.js b/apps/documenteditor/main/app/view/FormSettings.js index 4179fd679..d3140a4e5 100644 --- a/apps/documenteditor/main/app/view/FormSettings.js +++ b/apps/documenteditor/main/app/view/FormSettings.js @@ -1620,6 +1620,7 @@ define([ formPr.put_Role(record.value); props.put_FormPr(formPr); this.api.asc_SetContentControlProperties(props, this.internalId); + Common.Utils.InternalSettings.set('de-last-form-role', record.value) this.fireEvent('editcomplete', this); } }, diff --git a/apps/documenteditor/main/app/view/FormsTab.js b/apps/documenteditor/main/app/view/FormsTab.js index ea1259238..49c31f943 100644 --- a/apps/documenteditor/main/app/view/FormsTab.js +++ b/apps/documenteditor/main/app/view/FormsTab.js @@ -510,15 +510,15 @@ define([ return this.$el; }, - fillRolesMenu: function(roles, lastRole) { + fillRolesMenu: function(roles, lastViewRole) { if (!(this.btnViewFormRoles && this.btnViewFormRoles.menu && this.btnViewFormRoles.menu.isVisible())) { this._state.roles = roles; - this._state.lastRole = lastRole; + this._state.lastViewRole = lastViewRole; return; } roles = roles || this._state.roles; - lastRole = lastRole || this._state.lastRole; - this._state.roles = this._state.lastRole = undefined; + lastViewRole = lastViewRole || this._state.lastViewRole; + this._state.roles = this._state.lastViewRole = undefined; if (!roles) return; @@ -530,7 +530,7 @@ define([ roles && roles.forEach(function(item, index) { var role = item.asc_getSettings(), color = role.asc_getColor(); - if (role.asc_getName()===lastRole) + if (role.asc_getName()===lastViewRole) checkedIndex = index; me.btnViewFormRoles.menu.addItem(new Common.UI.MenuItem({ caption: role.asc_getName() || me.textAnyone,