[DE] Use sdk methods

This commit is contained in:
Julia Radzhabova 2022-11-28 18:25:02 +03:00
parent 5251f9f5e3
commit fa29dd9a48
5 changed files with 135 additions and 84 deletions

View file

@ -60,7 +60,6 @@ define([
}, },
onLaunch: function () { onLaunch: function () {
this._state = {}; this._state = {};
this.roles = [];
}, },
setApi: function (api) { setApi: function (api) {
@ -75,7 +74,7 @@ define([
this.api.asc_registerCallback('asc_onEndAction', _.bind(this.onLongActionEnd, this)); 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_onError', _.bind(this.onError, this));
this.api.asc_registerCallback('asc_onDownloadUrl', _.bind(this.onDownloadUrl, 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_onShowContentControlsActions',_.bind(this.onShowContentControlsActions, this));
// this.api.asc_registerCallback('asc_onHideContentControlsActions',_.bind(this.onHideContentControlsActions, 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 config.isEdit && config.canFeatureContentControl && config.isFormCreator && me.showCreateFormTip(); // show tip only when create form in docxf
// change to event asc_onRefreshRolesList // change to event asc_onRefreshRolesList
me.onRefreshRolesList([ me.onRefreshRolesList();
{name: 'employee 1', color: Common.Utils.ThemeColor.getRgbColor('ff0000'), fields: 5}, // me.onRefreshRolesList([
{name: 'employee 2', color: Common.Utils.ThemeColor.getRgbColor('00ff00'), fields: 1}, // {name: 'employee 1', color: Common.Utils.ThemeColor.getRgbColor('ff0000'), fields: 5},
{name: 'manager', color: null, fields: 10} // {name: 'employee 2', color: Common.Utils.ThemeColor.getRgbColor('00ff00'), fields: 1},
]); // {name: 'manager', color: null, fields: 10}
// ]);
me.onChangeProtectDocument(); me.onChangeProtectDocument();
}); });
}, },
@ -451,36 +451,40 @@ define([
}, },
onRefreshRolesList: function(roles) { 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); this.view && this.view.fillRolesMenu(roles, this._state.lastRole);
}, },
onManagerClick: function() { onManagerClick: function() {
var me = this; var me = this;
(new DE.Views.RolesManagerDlg({ this.api.asc_GetOForm() && (new DE.Views.RolesManagerDlg({
api: me.api, api: me.api,
handler: function(result, settings) { handler: function(result, settings) {
me.roles = settings; // me.roles = settings;
me.onRefreshRolesList(me.roles); // me.onRefreshRolesList(me.roles);
Common.component.Analytics.trackEvent('ToolBar', 'Roles Manager'); // Common.component.Analytics.trackEvent('ToolBar', 'Roles Manager');
Common.NotificationCenter.trigger('edit:complete', me.toolbar); Common.NotificationCenter.trigger('edit:complete', me.toolbar);
}, },
roles: me.roles, // roles: me.roles,
props : undefined props : undefined
})).on('close', function(win){ })).on('close', function(win){
}).show(); }).show();
}, },
showRolesList: function(callback) { showRolesList: function(callback) {
var me = this; var me = this,
(new DE.Views.SaveFormDlg({ oform = this.api.asc_GetOForm();
oform && (new DE.Views.SaveFormDlg({
handler: function(result, settings) { handler: function(result, settings) {
if (result=='ok') if (result=='ok')
callback.call(me); callback.call(me);
else else
Common.NotificationCenter.trigger('edit:complete', me.toolbar); Common.NotificationCenter.trigger('edit:complete', me.toolbar);
}, },
roles: me.roles roles: oform.asc_getAllRoles()
})).show(); })).show();
}, },

View file

@ -611,7 +611,7 @@ define([
this.api = api; this.api = api;
if (this.api) { if (this.api) {
// this.api.asc_registerCallback('asc_onParaSpacingLine', _.bind(this._onLineSpacing, this)); // 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)); Common.NotificationCenter.on('storage:image-insert', _.bind(this.insertImageFromStorage, this));
return this; return this;
@ -1585,23 +1585,28 @@ define([
} }
if (!roles) { if (!roles) {
roles = this.api.asc_GetOForm().asc_getAllRoles();
// change to event asc_onRefreshRolesList // change to event asc_onRefreshRolesList
roles = [ // roles = [
{name: 'employee 1', color: Common.Utils.ThemeColor.getRgbColor('ff0000'), fields: 5}, // {name: 'employee 1', color: Common.Utils.ThemeColor.getRgbColor('ff0000'), fields: 5},
{name: 'employee 2', color: Common.Utils.ThemeColor.getRgbColor('00ff00'), fields: 1}, // {name: 'employee 2', color: Common.Utils.ThemeColor.getRgbColor('00ff00'), fields: 1},
{name: 'manager', color: null, fields: 10} // {name: 'manager', color: null, fields: 10}
]; // ];
} }
var lastrole = this.cmbRoles.getSelectedRecord(); var lastrole = this.cmbRoles.getSelectedRecord();
lastrole = lastrole ? lastrole.get('value') : ''; lastrole = lastrole ? lastrole.value : '';
var arr = []; var arr = [];
var me = this;
roles && roles.forEach(function(item) { roles && roles.forEach(function(item) {
var role = item.asc_getSettings(),
color = role.asc_getColor();
arr.push({ arr.push({
displayValue: item.name, displayValue: role.asc_getName() || me.textAnyone,
value: item.name, value: role.asc_getName(),
color: item.color ? '#' + Common.Utils.ThemeColor.getHexColor(item.color.get_r(), item.color.get_g(), item.color.get_b()) : 'transparent' color: color ? '#' + Common.Utils.ThemeColor.getHexColor(color.get_r(), color.get_g(), color.get_b()) : 'transparent'
}); });
}); });
this.cmbRoles.setData(arr); this.cmbRoles.setData(arr);
@ -1671,7 +1676,8 @@ define([
textLetters: 'Letters', textLetters: 'Letters',
textDigits: 'Digits', textDigits: 'Digits',
textNone: 'None', textNone: 'None',
textComplex: 'Complex Field' textComplex: 'Complex Field',
textAnyone: 'Anyone'
}, DE.Views.FormSettings || {})); }, DE.Views.FormSettings || {}));
}); });

View file

@ -117,6 +117,10 @@ define([
me.fireEvent('forms:mode', [true, item.caption]); me.fireEvent('forms:mode', [true, item.caption]);
} }
}, me)); }, me));
this.btnViewFormRoles.menu.on('show:after', function (menu) {
me.fillRolesMenu();
});
this.btnManager && this.btnManager.on('click', function (b, e) { this.btnManager && this.btnManager.on('click', function (b, e) {
me.fireEvent('forms:manager'); me.fireEvent('forms:manager');
}); });
@ -155,6 +159,7 @@ define([
this.appConfig = options.config; this.appConfig = options.config;
this.paragraphControls = []; this.paragraphControls = [];
this._state = {};
var me = this; var me = this;
var _set = Common.enumLock; var _set = Common.enumLock;
@ -457,17 +462,30 @@ define([
}, },
fillRolesMenu: function(roles, lastRole) { 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, var checkedIndex = 0,
me = this; me = this;
this.btnViewFormRoles.menu.removeAll(); this.btnViewFormRoles.menu.removeAll();
roles && roles.forEach(function(item, index) { 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; checkedIndex = index;
me.btnViewFormRoles.menu.addItem(new Common.UI.MenuItem({ me.btnViewFormRoles.menu.addItem(new Common.UI.MenuItem({
caption: item.name, caption: role.asc_getName() || me.textAnyone,
color: item.color ? '#' + Common.Utils.ThemeColor.getHexColor(item.color.get_r(), item.color.get_g(), item.color.get_b()) : 'transparent', color: color ? '#' + Common.Utils.ThemeColor.getHexColor(color.get_r(), color.get_g(), color.get_b()) : 'transparent',
checkable: true, checkable: true,
toggleGroup: 'formtab-view-role', toggleGroup: 'formtab-view-role',
template: _.template([ template: _.template([
@ -550,7 +568,8 @@ define([
capBtnComplex: 'Complex Field', capBtnComplex: 'Complex Field',
tipEmailField: 'Insert email address', tipEmailField: 'Insert email address',
tipPhoneField: 'Insert phone number', tipPhoneField: 'Insert phone number',
tipComplexField: 'Insert complex field' tipComplexField: 'Insert complex field',
textAnyone: 'Anyone'
} }
}()), DE.Views.FormsTab || {})); }()), DE.Views.FormsTab || {}));
}); });

View file

@ -75,7 +75,6 @@ define([ 'text!documenteditor/main/app/template/RolesManagerDlg.template',
this.api = options.api; this.api = options.api;
this.handler = options.handler; this.handler = options.handler;
this.props = options.props; this.props = options.props;
this.roles = options.roles;
this.wrapEvents = { this.wrapEvents = {
onRefreshRolesList: _.bind(this.onRefreshRolesList, this) onRefreshRolesList: _.bind(this.onRefreshRolesList, this)
@ -156,24 +155,29 @@ define([ 'text!documenteditor/main/app/template/RolesManagerDlg.template',
}, },
_setDefaults: function (props) { _setDefaults: function (props) {
this.refreshRolesList(this.roles, 0); this.refreshRolesList(this.api.asc_GetOForm().asc_getAllRoles(), 0);
this.api.asc_registerCallback('asc_onRefreshRolesList', this.wrapEvents.onRefreshRolesList); this.api.asc_registerCallback('asc_onUpdateOFormRoles', this.wrapEvents.onRefreshRolesList);
}, },
onRefreshRolesList: function(roles) { onRefreshRolesList: function(roles) {
this.refreshRolesList(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) { if (roles) {
this.roles = roles;
var arr = []; var arr = [];
for (var i=0; i<this.roles.length; i++) { for (var i=0; i<roles.length; i++) {
var role = this.roles[i]; var role = roles[i].asc_getSettings();
arr.push({ arr.push({
name: role.name,//role.asc_getName(), name: role.asc_getName() || this.textAnyone,
color: role.color,//role.asc_getColor(), color: role.asc_getColor(),
fields: role.fields,//role.asc_getFields(), fields: role.fields || 0,//role.asc_getFields(),
index: i, index: i,
scope: this scope: this
}); });
@ -181,10 +185,18 @@ define([ 'text!documenteditor/main/app/template/RolesManagerDlg.template',
this.rolesList.store.reset(arr); this.rolesList.store.reset(arr);
} }
if (this.rolesList.store.length>0) { if (this.rolesList.store.length>0) {
var me = this; var me = this,
this.rolesList.selectByIndex(0); 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() { setTimeout(function() {
me.rolesList.scrollToRecord(me.rolesList.store.at(0)); me.rolesList.scrollToRecord(rec || me.rolesList.store.at(0));
}, 50); }, 50);
} }
this.updateButtons(); this.updateButtons();
@ -219,25 +231,29 @@ define([ 'text!documenteditor/main/app/template/RolesManagerDlg.template',
var color = settings.color, var color = settings.color,
name = settings.name, name = settings.name,
store = me.rolesList.store; store = me.rolesList.store;
this.lastSelectedRole = name;
if (isEdit) { if (isEdit) {
// me.api.asc_editRole(settings); // me.api.asc_editRole(settings);
rec.set('name', name); rec.set('name', name);
rec.set('color', color); rec.set('color', color);
} else { } else {
// me.api.asc_addRole(settings); var role = new AscCommon.CRoleSettings();
rec = store.push({ role.asc_putName(name);
name: name, role.asc_putColor(color);
color: color, me.api.asc_GetOForm().asc_addRole(role);
fields: 0, // rec = store.push({
index: store.length, // name: name,
scope: me // color: color,
}); // fields: 0,
if (rec) { // index: store.length,
me.rolesList.selectRecord(rec); // scope: me
setTimeout(function() { // });
me.rolesList.scrollToRecord(rec); // if (rec) {
}, 50); // me.rolesList.selectRecord(rec);
} // setTimeout(function() {
// me.rolesList.scrollToRecord(rec);
// }, 50);
// }
} }
me.updateButtons(); me.updateButtons();
} }
@ -268,17 +284,20 @@ define([ 'text!documenteditor/main/app/template/RolesManagerDlg.template',
var callback = function(toRole) { var callback = function(toRole) {
var index = store.indexOf(rec); var index = store.indexOf(rec);
if (toRole) { this.lastSelectedRole = index;
var item = store.findWhere({name: toRole}); me.api.asc_delRole(rec.get('name'), toRole); // remove role and move it's fields
item && item.set('fields', item.get('fields') + rec.get('fields'));
// me.api.asc_moveFieldsToRole(rec.get('name'), toRole); // from - to // if (toRole) {
} // var item = store.findWhere({name: toRole});
// me.api.asc_delRole(rec.get('name')); // item && item.set('fields', item.get('fields') + rec.get('fields'));
store.remove(rec); // // me.api.asc_moveFieldsToRole(rec.get('name'), toRole); // from - to
me.refreshRolesIndexes(); // }
(store.length>0) && me.rolesList.selectByIndex(index<store.length ? index : store.length-1); // me.api.asc_delRole(rec.get('name'), toRole); // remove role and move it's fields
me.rolesList.scrollToRecord(me.rolesList.getSelectedRec()); // store.remove(rec);
me.updateButtons(); // me.refreshRolesIndexes();
// (store.length>0) && me.rolesList.selectByIndex(index<store.length ? index : store.length-1);
// me.rolesList.scrollToRecord(me.rolesList.getSelectedRec());
// me.updateButtons();
}; };
if (rec.get('fields')<1) { if (rec.get('fields')<1) {
@ -314,15 +333,15 @@ define([ 'text!documenteditor/main/app/template/RolesManagerDlg.template',
}, },
getSettings: function() { getSettings: function() {
var arr = []; // var arr = [];
this.rolesList.store.each(function(item, index) { // this.rolesList.store.each(function(item, index) {
arr.push({ // arr.push({
name: item.get('name'), // name: item.get('name'),
color: item.get('color'), // color: item.get('color'),
fields: item.get('fields') // fields: item.get('fields')
}); // });
}); // });
return arr; // return arr;
}, },
onPrimary: function() { onPrimary: function() {
@ -383,7 +402,7 @@ define([ 'text!documenteditor/main/app/template/RolesManagerDlg.template',
}, },
close: function () { close: function () {
this.api.asc_unregisterCallback('asc_onRefreshRolesList', this.wrapEvents.onRefreshRolesList); this.api.asc_unregisterCallback('asc_onUpdateOFormRoles', this.wrapEvents.onRefreshRolesList);
Common.UI.Window.prototype.close.call(this); Common.UI.Window.prototype.close.call(this);
}, },
@ -408,7 +427,8 @@ define([ 'text!documenteditor/main/app/template/RolesManagerDlg.template',
warnCantDelete: 'You cannot delete this role because it has associated fields.', warnCantDelete: 'You cannot delete this role because it has associated fields.',
textUp: 'Move role up', textUp: 'Move role up',
textDown: 'Move role down', textDown: 'Move role down',
textDescription: 'Add roles and set the order in which the fillers receive and sign the document' textDescription: 'Add roles and set the order in which the fillers receive and sign the document',
textAnyone: 'Anyone'
}, DE.Views.RolesManagerDlg || {})); }, DE.Views.RolesManagerDlg || {}));
}); });

View file

@ -129,11 +129,12 @@ define([ 'common/main/lib/view/AdvancedSettingsWindow',
if (roles) { if (roles) {
this.roles = roles; this.roles = roles;
var arr = []; var arr = [];
var me = this;
for (var i=0; i<this.roles.length; i++) { for (var i=0; i<this.roles.length; i++) {
var role = this.roles[i]; var role = roles[i].asc_getSettings();
(role.fields>0) && arr.push({ (role.fields>0) && arr.push({
name: role.name,//role.asc_getName(), name: role.asc_getName() || me.textAnyone,
color: role.color,//role.asc_getColor(), color: role.asc_getColor(),
fields: role.fields,//role.asc_getFields(), fields: role.fields,//role.asc_getFields(),
index: i, index: i,
scope: this scope: this
@ -153,7 +154,8 @@ define([ 'common/main/lib/view/AdvancedSettingsWindow',
saveButtonText : 'Save', saveButtonText : 'Save',
textEmpty: 'There are no roles associated with fields.', textEmpty: 'There are no roles associated with fields.',
textDescription: 'When saving to the oform, only roles with fields are added to the filling list', 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 || {})); }, DE.Views.SaveFormDlg || {}));
}); });