diff --git a/apps/documenteditor/main/app/controller/FormsTab.js b/apps/documenteditor/main/app/controller/FormsTab.js index 53d3d4d39..3b7263d8a 100644 --- a/apps/documenteditor/main/app/controller/FormsTab.js +++ b/apps/documenteditor/main/app/controller/FormsTab.js @@ -60,7 +60,6 @@ define([ }, onLaunch: function () { this._state = {}; - this.roles = []; }, setApi: function (api) { @@ -75,7 +74,7 @@ define([ this.api.asc_registerCallback('asc_onEndAction', _.bind(this.onLongActionEnd, this)); this.api.asc_registerCallback('asc_onError', _.bind(this.onError, this)); this.api.asc_registerCallback('asc_onDownloadUrl', _.bind(this.onDownloadUrl, this)); - this.api.asc_registerCallback('asc_onRefreshRolesList', _.bind(this.onRefreshRolesList, this)); + this.api.asc_registerCallback('asc_onUpdateOFormRoles', _.bind(this.onRefreshRolesList, this)); // this.api.asc_registerCallback('asc_onShowContentControlsActions',_.bind(this.onShowContentControlsActions, this)); // this.api.asc_registerCallback('asc_onHideContentControlsActions',_.bind(this.onHideContentControlsActions, this)); @@ -395,11 +394,12 @@ define([ // } config.isEdit && config.canFeatureContentControl && config.isFormCreator && me.showCreateFormTip(); // show tip only when create form in docxf // change to event asc_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.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(); }); }, @@ -451,36 +451,40 @@ define([ }, onRefreshRolesList: function(roles) { - this.roles = roles; + if (!roles) { + var oform = this.api.asc_GetOForm(); + oform && (roles = oform.asc_getAllRoles()); + } this.view && this.view.fillRolesMenu(roles, this._state.lastRole); }, onManagerClick: function() { var me = this; - (new DE.Views.RolesManagerDlg({ + 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'); + // me.roles = settings; + // me.onRefreshRolesList(me.roles); + // Common.component.Analytics.trackEvent('ToolBar', 'Roles Manager'); Common.NotificationCenter.trigger('edit:complete', me.toolbar); }, - roles: me.roles, + // roles: me.roles, props : undefined })).on('close', function(win){ }).show(); }, showRolesList: function(callback) { - var me = this; - (new DE.Views.SaveFormDlg({ + var me = this, + oform = this.api.asc_GetOForm(); + oform && (new DE.Views.SaveFormDlg({ handler: function(result, settings) { if (result=='ok') callback.call(me); else Common.NotificationCenter.trigger('edit:complete', me.toolbar); }, - roles: me.roles + roles: oform.asc_getAllRoles() })).show(); }, diff --git a/apps/documenteditor/main/app/view/FormSettings.js b/apps/documenteditor/main/app/view/FormSettings.js index 4a6d3511b..ca1e1b6c3 100644 --- a/apps/documenteditor/main/app/view/FormSettings.js +++ b/apps/documenteditor/main/app/view/FormSettings.js @@ -611,7 +611,7 @@ define([ this.api = api; if (this.api) { // this.api.asc_registerCallback('asc_onParaSpacingLine', _.bind(this._onLineSpacing, this)); - this.api.asc_registerCallback('asc_onRefreshRolesList', _.bind(this.onRefreshRolesList, this)); + this.api.asc_registerCallback('asc_onUpdateOFormRoles', _.bind(this.onRefreshRolesList, this)); } Common.NotificationCenter.on('storage:image-insert', _.bind(this.insertImageFromStorage, this)); return this; @@ -1585,23 +1585,28 @@ define([ } if (!roles) { + roles = this.api.asc_GetOForm().asc_getAllRoles(); + // change to event asc_onRefreshRolesList - roles = [ - {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} - ]; + // roles = [ + // {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} + // ]; } var lastrole = this.cmbRoles.getSelectedRecord(); - lastrole = lastrole ? lastrole.get('value') : ''; + lastrole = lastrole ? lastrole.value : ''; var arr = []; + var me = this; roles && roles.forEach(function(item) { + var role = item.asc_getSettings(), + color = role.asc_getColor(); arr.push({ - displayValue: item.name, - value: item.name, - color: item.color ? '#' + Common.Utils.ThemeColor.getHexColor(item.color.get_r(), item.color.get_g(), item.color.get_b()) : 'transparent' + displayValue: role.asc_getName() || me.textAnyone, + value: role.asc_getName(), + color: color ? '#' + Common.Utils.ThemeColor.getHexColor(color.get_r(), color.get_g(), color.get_b()) : 'transparent' }); }); this.cmbRoles.setData(arr); @@ -1671,7 +1676,8 @@ define([ textLetters: 'Letters', textDigits: 'Digits', textNone: 'None', - textComplex: 'Complex Field' + textComplex: 'Complex Field', + textAnyone: 'Anyone' }, DE.Views.FormSettings || {})); }); \ 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 0cf268afe..09d0396ed 100644 --- a/apps/documenteditor/main/app/view/FormsTab.js +++ b/apps/documenteditor/main/app/view/FormsTab.js @@ -117,6 +117,10 @@ define([ me.fireEvent('forms:mode', [true, item.caption]); } }, me)); + this.btnViewFormRoles.menu.on('show:after', function (menu) { + me.fillRolesMenu(); + }); + this.btnManager && this.btnManager.on('click', function (b, e) { me.fireEvent('forms:manager'); }); @@ -155,6 +159,7 @@ define([ this.appConfig = options.config; this.paragraphControls = []; + this._state = {}; var me = this; var _set = Common.enumLock; @@ -457,17 +462,30 @@ define([ }, fillRolesMenu: function(roles, lastRole) { + if (!(this.btnViewFormRoles && this.btnViewFormRoles.menu && this.btnViewFormRoles.menu.isVisible())) { + this._state.roles = roles; + this._state.lastRole = lastRole; + return; + } + roles = roles || this._state.roles; + lastRole = lastRole || this._state.lastRole; + this._state.roles = this._state.lastRole = undefined; + + if (!roles) return; + var checkedIndex = 0, me = this; this.btnViewFormRoles.menu.removeAll(); roles && roles.forEach(function(item, index) { - if (item.name===lastRole) + var role = item.asc_getSettings(), + color = role.asc_getColor(); + if (role.asc_getName()===lastRole) checkedIndex = index; me.btnViewFormRoles.menu.addItem(new Common.UI.MenuItem({ - caption: item.name, - color: item.color ? '#' + Common.Utils.ThemeColor.getHexColor(item.color.get_r(), item.color.get_g(), item.color.get_b()) : 'transparent', + caption: role.asc_getName() || me.textAnyone, + color: color ? '#' + Common.Utils.ThemeColor.getHexColor(color.get_r(), color.get_g(), color.get_b()) : 'transparent', checkable: true, toggleGroup: 'formtab-view-role', template: _.template([ @@ -550,7 +568,8 @@ define([ capBtnComplex: 'Complex Field', tipEmailField: 'Insert email address', tipPhoneField: 'Insert phone number', - tipComplexField: 'Insert complex field' + tipComplexField: 'Insert complex field', + textAnyone: 'Anyone' } }()), DE.Views.FormsTab || {})); }); \ No newline at end of file diff --git a/apps/documenteditor/main/app/view/RolesManagerDlg.js b/apps/documenteditor/main/app/view/RolesManagerDlg.js index 26b4cfd9e..53fb86b53 100644 --- a/apps/documenteditor/main/app/view/RolesManagerDlg.js +++ b/apps/documenteditor/main/app/view/RolesManagerDlg.js @@ -75,7 +75,6 @@ define([ 'text!documenteditor/main/app/template/RolesManagerDlg.template', this.api = options.api; this.handler = options.handler; this.props = options.props; - this.roles = options.roles; this.wrapEvents = { onRefreshRolesList: _.bind(this.onRefreshRolesList, this) @@ -156,24 +155,29 @@ define([ 'text!documenteditor/main/app/template/RolesManagerDlg.template', }, _setDefaults: function (props) { - this.refreshRolesList(this.roles, 0); - this.api.asc_registerCallback('asc_onRefreshRolesList', this.wrapEvents.onRefreshRolesList); + this.refreshRolesList(this.api.asc_GetOForm().asc_getAllRoles(), 0); + this.api.asc_registerCallback('asc_onUpdateOFormRoles', this.wrapEvents.onRefreshRolesList); }, onRefreshRolesList: function(roles) { this.refreshRolesList(roles); }, - refreshRolesList: function(roles, selectedItem) { + refreshRolesList: function(roles, selectedRole) { + (selectedRole===undefined) && (selectedRole = this.lastSelectedRole); // when add or delete roles + this.lastSelectedRole = undefined; + if (selectedRole===undefined && this.rolesList.store.length>0) { + var rec = this.rolesList.getSelectedRec(); + rec && (selectedRole = rec.get('name')); + } if (roles) { - this.roles = roles; var arr = []; - for (var i=0; i0) { - var me = this; - this.rolesList.selectByIndex(0); + var me = this, + rec; + (selectedRole===undefined) && (selectedRole = 0); + if (typeof selectedRole === 'string') { // name + rec = this.rolesList.store.findWhere({name: selectedRole}); + this.rolesList.selectRecord(rec); + } else { + selectedRole = Math.min(selectedRole, this.rolesList.store.length-1); + rec = this.rolesList.selectByIndex(selectedRole); + } setTimeout(function() { - me.rolesList.scrollToRecord(me.rolesList.store.at(0)); + me.rolesList.scrollToRecord(rec || me.rolesList.store.at(0)); }, 50); } this.updateButtons(); @@ -219,25 +231,29 @@ define([ 'text!documenteditor/main/app/template/RolesManagerDlg.template', var color = settings.color, name = settings.name, store = me.rolesList.store; + this.lastSelectedRole = name; if (isEdit) { // me.api.asc_editRole(settings); rec.set('name', name); rec.set('color', color); } else { - // me.api.asc_addRole(settings); - rec = store.push({ - name: name, - color: color, - fields: 0, - index: store.length, - scope: me - }); - if (rec) { - me.rolesList.selectRecord(rec); - setTimeout(function() { - me.rolesList.scrollToRecord(rec); - }, 50); - } + var role = new AscCommon.CRoleSettings(); + role.asc_putName(name); + role.asc_putColor(color); + me.api.asc_GetOForm().asc_addRole(role); + // rec = store.push({ + // name: name, + // color: color, + // fields: 0, + // index: store.length, + // scope: me + // }); + // if (rec) { + // me.rolesList.selectRecord(rec); + // setTimeout(function() { + // me.rolesList.scrollToRecord(rec); + // }, 50); + // } } me.updateButtons(); } @@ -268,17 +284,20 @@ define([ 'text!documenteditor/main/app/template/RolesManagerDlg.template', var callback = function(toRole) { var index = store.indexOf(rec); - if (toRole) { - var item = store.findWhere({name: toRole}); - item && item.set('fields', item.get('fields') + rec.get('fields')); - // me.api.asc_moveFieldsToRole(rec.get('name'), toRole); // from - to - } - // me.api.asc_delRole(rec.get('name')); - store.remove(rec); - me.refreshRolesIndexes(); - (store.length>0) && me.rolesList.selectByIndex(index0) && me.rolesList.selectByIndex(index0) && arr.push({ - name: role.name,//role.asc_getName(), - color: role.color,//role.asc_getColor(), + name: role.asc_getName() || me.textAnyone, + color: role.asc_getColor(), fields: role.fields,//role.asc_getFields(), index: i, scope: this @@ -153,7 +154,8 @@ define([ 'common/main/lib/view/AdvancedSettingsWindow', saveButtonText : 'Save', textEmpty: 'There are no roles associated with fields.', textDescription: 'When saving to the oform, only roles with fields are added to the filling list', - textFill: 'Filling list' + textFill: 'Filling list', + textAnyone: 'Anyone' }, DE.Views.SaveFormDlg || {})); }); \ No newline at end of file