[DE] Add/edit roles

This commit is contained in:
Julia Radzhabova 2022-04-14 20:55:11 +03:00
parent 726c0fe6ef
commit 87ad3134b9
8 changed files with 347 additions and 103 deletions

View file

@ -52,41 +52,4 @@
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;
}
}
}

View file

@ -423,7 +423,11 @@ define([
Common.component.Analytics.trackEvent('ToolBar', 'Roles Manager');
Common.NotificationCenter.trigger('edit:complete', me.toolbar);
},
roles: [],
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}
],
props : undefined
})).on('close', function(win){
}).show();

View file

@ -12,7 +12,7 @@
</tr>
<tr>
<td colspan=2 class="padding-small">
<div id="roles-manager-roles-list" class="range-tableview" style="width:100%; height: 170px;"></div>
<div id="roles-manager-roles-list" class="roles-tableview" style="width:100%; height: 170px;"></div>
</td>
</tr>
<tr>

View file

@ -211,7 +211,6 @@ define([
iconCls: 'toolbar__icon btn-ic-sharing',
lock: [ _set.previewReviewMode, _set.viewFormMode, _set.lostConnect, _set.disableOnStart],
caption: this.capBtnManager,
enableToggle: true,
dataHint: '1',
dataHintDirection: 'bottom',
dataHintOffset: 'small'

View file

@ -0,0 +1,206 @@
/*
*
* (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
*
*/
/**
* RoleEditDlg.js
*
* Created by Julia Radzhabova on 13/04/22
* Copyright (c) 2022 Ascensio System SIA. All rights reserved.
*
*/
define([
'common/main/lib/component/Window',
'common/main/lib/component/InputField'
], function () { 'use strict';
DE.Views.RoleEditDlg = Common.UI.Window.extend(_.extend({
options: {
width: 330,
cls: 'modal-dlg',
buttons: ['ok', 'cancel']
},
initialize : function(options) {
_.extend(this.options, options || {});
this.template = [
'<div class="box">',
'<table cols="2" style="width: 100%;">',
'<tr>',
'<td style="width: 50px; padding-right: 10px;">',
'<label></label>',
'<div id="id-dlg-role-color" style="margin-bottom: 10px;"></div>',
'</td>',
'<td>',
'<label>' + this.textName + '</label>',
'<div id="id-dlg-role-name" class="input-row" style="margin-bottom: 10px; "></div>',
'</td>',
'</tr>',
'</table>',
'</div>'
].join('');
this.options.tpl = _.template(this.template)(this.options);
this.props = this.options.props;
this.lastColor = 'C9C8FF';
Common.UI.Window.prototype.initialize.call(this, this.options);
},
render: function() {
Common.UI.Window.prototype.render.call(this);
var me = this;
var $window = this.getChild();
$window.find('.dlg-btn').on('click', _.bind(this.onBtnClick, this));
me.inputName = new Common.UI.InputField({
el : $window.find('#id-dlg-role-name'),
allowBlank : false,
blankError : me.textEmptyError,
style : 'width: 100%;',
validateOnBlur: false,
validation : function(value) {
return value ? true : '';
}
});
this.btnColor = new Common.UI.ColorButton({
parentEl: $window.find('#id-dlg-role-color'),
additionalItems: [ this.mnuNoFormsColor = new Common.UI.MenuItem({
id: 'id-dlg-role-menu-no-highlight',
caption: this.textNoHighlight,
checkable: true,
style: 'padding-left: 20px;'
}),
{caption: '--'}],
additionalAlign: this.menuAddAlign,
colors: ['000000', '993300', '333300', '003300', '003366', '000080', '333399', '333333', '800000', 'FF6600',
'808000', '00FF00', '008080', '0000FF', '666699', '808080', 'FF0000', 'FF9900', '99CC00', '339966',
'33CCCC', '3366FF', '800080', '999999', 'FF00FF', 'FFCC00', 'FFFF00', '00FF00', '00FFFF', '00CCFF',
'993366', 'C0C0C0', 'FF99CC', 'FFCC99', 'FFFF99', 'CCFFCC', 'CCFFFF', 'C9C8FF', 'CC99FF', 'FFFFFF'
],
color: this.lastColor,
paletteHeight: 94,
cls: 'move-focus',
takeFocusOnClose: true
});
this.btnColor.on('color:select', _.bind(this.onColorsSelect, this));
this.mnuNoFormsColor.on('click', _.bind(this.onNoColorClick, this));
this.mnuColorPicker = this.btnColor.getPicker();
this.afterRender();
},
afterRender: function() {
this.setSettings(this.props);
this.setTitle((this.isEdit) ? this.txtTitleEdit : this.txtTitleNew);
},
show: function() {
Common.UI.Window.prototype.show.apply(this, arguments);
},
setSettings: function (props) {
if (props) {
var clr = props.color,
show = !!clr;
this.mnuNoFormsColor.setChecked(!show, true);
this.mnuColorPicker.clearSelection();
if (clr) {
clr = Common.Utils.ThemeColor.getHexColor(clr.get_r(), clr.get_g(), clr.get_b());
this.mnuColorPicker.selectByRGB(clr, true);
this.lastColor = clr;
}
this.btnColor.setColor(clr || 'transparent');
this.inputName.setValue(props.name || '');
}
},
getSettings: function() {
return {name: this.inputName.getValue(), color: this.mnuNoFormsColor.isChecked() ? null : Common.Utils.ThemeColor.getRgbColor(this.lastColor)};
},
onColorsSelect: function(btn, color) {
this.lastColor = color;
this.mnuNoFormsColor.setChecked(false, true);
},
onNoColorClick: function(item) {
if (!item.isChecked()) {
this.btnColor.setColor(this.lastColor);
this.mnuColorPicker.selectByRGB(this.lastColor, true);
} else {
this.mnuColorPicker.clearSelection();
}
},
onPrimary: function(event) {
this._handleInput('ok');
return false;
},
onBtnClick: function(event) {
this._handleInput(event.currentTarget.attributes['result'].value);
},
getFocusedComponents: function() {
return [this.btnColor, this.inputName];
},
getDefaultFocusableComponent: function () {
return this.inputName;
},
_handleInput: function(state) {
if (this.options.handler) {
if (state == 'ok') {
if (this.inputName.checkValidate() !== true) {
this.inputName.cmpEl.find('input').focus();
return;
}
}
this.options.handler.call(this, state, (state == 'ok') ? this.getSettings() : undefined);
}
this.close();
},
txtTitleEdit: 'Edit Role',
txtTitleNew: 'Create New Role',
textName: 'Role name',
textEmptyError: 'Role name must not be empty.',
textNoHighlight: 'No highlighting'
}, DE.Views.RoleEditDlg || {}));
});

View file

@ -42,7 +42,7 @@
define([ 'text!documenteditor/main/app/template/RolesManagerDlg.template',
'common/main/lib/view/AdvancedSettingsWindow',
'common/main/lib/component/ListView',
// 'documenteditor/main/app/view/RoleEditDlg'
'documenteditor/main/app/view/RoleEditDlg'
], function (contentTemplate) {
'use strict';
@ -51,7 +51,7 @@ define([ 'text!documenteditor/main/app/template/RolesManagerDlg.template',
DE.Views.RolesManagerDlg = Common.Views.AdvancedSettingsWindow.extend(_.extend({
options: {
alias: 'RolesManagerDlg',
contentWidth: 525,
contentWidth: 500,
height: 353,
buttons: null
},
@ -76,8 +76,6 @@ define([ 'text!documenteditor/main/app/template/RolesManagerDlg.template',
this.props = options.props;
this.roles = options.roles;
this.rolesStore = new Common.UI.DataViewStore();
this.wrapEvents = {
onRefreshRolesList: _.bind(this.onRefreshRolesList, this)
};
@ -93,24 +91,18 @@ define([ 'text!documenteditor/main/app/template/RolesManagerDlg.template',
store: new Common.UI.DataViewStore(),
emptyText: this.textEmpty,
itemTemplate: _.template([
'<div id="<%= id %>" class="list-item" style="width: 100%;display:inline-block;<% if (!lock) { %>pointer-events:none;<% } %>">',
'<div class="listitem-icon toolbar__icon <% print(isTable?"btn-menu-table":(isSlicer ? "btn-slicer" : "btn-named-range")) %>"></div>',
'<div style="width:141px;padding-right: 5px;"><%= Common.Utils.String.htmlEncode(name) %></div>',
'<div style="width:117px;padding-right: 5px;"><%= scopeName %></div>',
'<div style="width:204px;"><%= range %></div>',
'<% if (lock) { %>',
'<div class="lock-user"><%=lockuser%></div>',
'<% } %>',
'<div id="<%= id %>" class="list-item" style="">',
'<div class="listitem-icon toolbar__icon <%= scope.getIconCls(index) %>"></div>',
'<div style="min-width: 25px;text-align:center; padding-right: 5px;"><%= index+1 %></div>',
'<div style="min-width: 25px;">',
'<span class="color" style="background: <% if (color) { %>#<%= Common.Utils.ThemeColor.getHexColor(color.get_r(), color.get_g(), color.get_b()) %><% } else { %> transparent <% } %>;"></span>',
'</div>',
'<div style="flex-grow: 1;padding-right: 5px;"><%= Common.Utils.String.htmlEncode(name) %></div>',
'<div style="min-width: 25px;text-align: right;opacity: 0.8;"><%= fields %></div>',
'</div>'
].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 (n1<n2) ? -me.sort.direction : me.sort.direction;
};
this.rolesList.on('item:select', _.bind(this.onSelectRoleItem, this))
.on('item:keydown', _.bind(this.onKeyDown, this))
.on('item:dblclick', _.bind(this.onDblClickItem, this))
@ -176,57 +168,40 @@ define([ 'text!documenteditor/main/app/template/RolesManagerDlg.template',
this.roles = roles;
var arr = [];
for (var i=0; i<this.roles.length; i++) {
var scope = this.roles[i].asc_getScope(),
id = this.roles[i].asc_getIsLock(),
type = this.roles[i].asc_getType();
var role = this.roles[i];
arr.push({
name: this.roles[i].asc_getName(true),
type: type,
isTable: type===Asc.c_oAscDefNameType.table,
isSlicer: type===Asc.c_oAscDefNameType.slicer
name: role.name,//role.asc_getName(),
color: role.color,//role.asc_getColor(),
fields: role.fields,//role.asc_getFields(),
index: i,
scope: this
});
}
this.rolesStore.reset(arr);
this.rolesList.store.reset(arr);
}
var me = this,
store = this.rolesList.store,
models = this.rolesStore.models,
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.rolesList.selectByIndex(selectedItem);
setTimeout(function() {
me.rolesList.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.rolesList.selectRecord(rec);
setTimeout(function() {
me.rolesList.scrollToRecord(rec);
}, 50);
}
}
if (this.rolesList.store.length>0) {
var me = this;
this.rolesList.selectByIndex(0);
setTimeout(function() {
me.rolesList.scrollToRecord(me.rolesList.store.at(0));
}, 50);
}
_.delay(function () {
me.rolesList.scroller.update({alwaysVisibleY: true});
}, 100, this);
this.updateButtons();
},
refreshRolesIndexes: function() {
this.rolesList.store.each(function(item, index) {
item.set('index', index);
});
},
getIconCls: function(index) {
return (index===0) ? 'btn-arrow-up' : (index===this.rolesList.store.length-1 ? 'btn-arrow-down' : 'btn-border-insidevert');
},
onEditRole: function (isEdit) {
if (this._isWarningVisible) return;
if (this.locked) {
Common.NotificationCenter.trigger('namedrange:locked');
return;
}
var me = this,
xy = me.$window.offset(),
rec = this.rolesList.getSelectedRec(),
@ -238,10 +213,26 @@ define([ 'text!documenteditor/main/app/template/RolesManagerDlg.template',
isEdit : isEdit,
handler : function(result, settings) {
if (result == 'ok' && settings) {
var color = settings.color,
name = settings.name,
store = me.rolesList.store;
if (isEdit) {
me.api.asc_editRole(settings);
// me.api.asc_editRole(settings);
rec.set('name', name);
rec.set('color', color);
} else {
me.api.asc_addRole(settings);
// 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);
me.rolesList.scrollToRecord(rec);
}
}
}
}
@ -258,21 +249,27 @@ define([ 'text!documenteditor/main/app/template/RolesManagerDlg.template',
onDeleteRole: function () {
var rec = this.rolesList.getSelectedRec();
if (rec) {
var me = this;
var me = this,
store = this.rolesList.store;
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.api.asc_delRole(rec.get('name'));
var index = store.indexOf(rec);
// me.api.asc_delRole(rec.get('name'));
store.remove(rec);
me.refreshRolesIndexes();
(store.length>0) && me.rolesList.selectByIndex(index<store.length ? index : store.length-1);
me.rolesList.scrollToRecord(me.rolesList.getSelectedRec());
me.updateButtons();
}
setTimeout(function(){ me.getDefaultFocusableComponent().focus(); }, 100);
me._isWarningVisible = false;
}
});
}
this.updateButtons();
},
getSettings: function() {
@ -314,6 +311,7 @@ define([ 'text!documenteditor/main/app/template/RolesManagerDlg.template',
this.rolesList.selectRecord(rec);
this.rolesList.scrollToRecord(rec);
}
this.refreshRolesIndexes();
this.updateMoveButtons();
},

View file

@ -94,4 +94,42 @@
#id-text-table-spn-fixed, #bookmarks-radio-location {
display: inline-block;
vertical-align: middle;
}
.advanced-settings-dlg {
.roles-tableview {
.list-item {
display: flex;
align-items: center;
span.color {
display: block;
width: 12px;
height: 12px;
border: @scaled-one-px-value-ie solid @border-color-shading-ie;
border: @scaled-one-px-value solid @border-color-shading;
}
}
.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;
}
}
}
}

View file

@ -59,6 +59,42 @@
}
}
}
.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;
}
}
}
#sort-dialog-btn-down {