mirror of
https://github.com/ONLYOFFICE/sdkjs-forms.git
synced 2026-02-10 18:05:42 +08:00
[oform] Add class for roles
Also add blank functions for managing roles
This commit is contained in:
101
oform/OForm.js
101
oform/OForm.js
@ -46,6 +46,7 @@
|
||||
this.Document = document;
|
||||
|
||||
// Сейчас у нас роль - это ровно один userMaster и ровно одна группа полей
|
||||
this.Roles = [];
|
||||
}
|
||||
/**
|
||||
* @returns {AscWord.CDocument}
|
||||
@ -63,17 +64,107 @@
|
||||
};
|
||||
OForm.prototype.getAllRoles = function()
|
||||
{
|
||||
let userMasters = this.Format.getAllUserMasters();
|
||||
userMasters.unshift(this.Format.getDefaultUser());
|
||||
return userMasters;
|
||||
return this.Roles;
|
||||
};
|
||||
OForm.prototype.addRole = function(name, ascColor)
|
||||
/**
|
||||
* @param roleSettings {AscOForm.CRoleSettings}
|
||||
*/
|
||||
OForm.prototype.addRole = function(roleSettings)
|
||||
{
|
||||
|
||||
if (!this.startAction(AscDFH.historydescription_OForm_AddRole))
|
||||
return false;
|
||||
|
||||
// TODO: fix me
|
||||
let role;
|
||||
if (roleSettings instanceof AscOForm.CRoleSettings)
|
||||
role = AscOForm.create(roleSettings);
|
||||
else
|
||||
role = new AscOForm.CRole();
|
||||
|
||||
this.updateRoles();
|
||||
this.endAction();
|
||||
return true;
|
||||
};
|
||||
OForm.prototype.removeRole = function(name)
|
||||
{
|
||||
let roleIndex = this.getRoleIndex(name);
|
||||
if (-1 === roleIndex)
|
||||
return false;
|
||||
|
||||
if (!this.startAction(AscDFH.historydescription_OForm_RemoveRole))
|
||||
return false;
|
||||
|
||||
|
||||
this.updateRoles();
|
||||
this.endAction();
|
||||
return true;
|
||||
};
|
||||
OForm.prototype.getRole = function(name)
|
||||
{
|
||||
let roleIndex = this.getRoleIndex(name);
|
||||
if (-1 === roleIndex)
|
||||
return null;
|
||||
|
||||
return this.Roles[roleIndex];
|
||||
};
|
||||
OForm.prototype.getRoleIndex = function(name)
|
||||
{
|
||||
for (let index = 0, count = this.Roles.length; index < count; ++index)
|
||||
{
|
||||
if (name === this.Roles[index].getName())
|
||||
return index;
|
||||
}
|
||||
|
||||
return -1;
|
||||
};
|
||||
OForm.prototype.haveRole = function(name)
|
||||
{
|
||||
return !!(this.getRole(name));
|
||||
};
|
||||
OForm.prototype.getRoleSettings = function(name)
|
||||
{
|
||||
let role = this.getRole(name);
|
||||
if (!role)
|
||||
return null;
|
||||
|
||||
return role.getSettings();
|
||||
};
|
||||
OForm.prototype.updateRoles = function()
|
||||
{
|
||||
// TODO: Обновить состояние ролей в соответствии с форматом
|
||||
|
||||
};
|
||||
////////////////////////////////////////////////////////////////////////////////////////////////////////////////////
|
||||
// Private area
|
||||
////////////////////////////////////////////////////////////////////////////////////////////////////////////////////
|
||||
OForm.prototype.startAction = function(description)
|
||||
{
|
||||
let logicDocument = this.getDocument();
|
||||
if (!logicDocument)
|
||||
return false;
|
||||
|
||||
if (logicDocument.IsSelectionLocked(AscCommon.changestype_Document_Settings, null, false, false, null))
|
||||
return false;
|
||||
|
||||
logicDocument.StartAction(description);
|
||||
return true;
|
||||
};
|
||||
OForm.prototype.endAction = function()
|
||||
{
|
||||
let logicDocument = this.getDocument();
|
||||
if (!logicDocument)
|
||||
return;
|
||||
|
||||
logicDocument.UpdateInterface();
|
||||
logicDocument.FinalizeAction();
|
||||
};
|
||||
//--------------------------------------------------------export----------------------------------------------------
|
||||
AscOForm.OForm = OForm;
|
||||
//---------------------------------------------interface export-----------------------------------------------------
|
||||
OForm.prototype['asc_getAllRoles'] = OForm.prototype.getAllRoles;
|
||||
OForm.prototype['asc_addRole'] = OForm.prototype.addRole;
|
||||
OForm.prototype['asc_removeRole'] = OForm.prototype.removeRole;
|
||||
OForm.prototype['asc_haveRole'] = OForm.prototype.haveRole;
|
||||
OForm.prototype['asc_getRole'] = OForm.prototype.getRoleSettings;
|
||||
|
||||
})(window);
|
||||
|
||||
89
oform/Role.js
Normal file
89
oform/Role.js
Normal file
@ -0,0 +1,89 @@
|
||||
/*
|
||||
* (c) Copyright Ascensio System SIA 2010-2019
|
||||
*
|
||||
* 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
|
||||
*
|
||||
*/
|
||||
|
||||
"use strict";
|
||||
|
||||
(function(window)
|
||||
{
|
||||
/**
|
||||
* Класс представляющий роль при заполнении формы. В данный момент роль - это ровно один userMaster
|
||||
* и группа полей связанные с данным userMaster
|
||||
* @param fieldGroup
|
||||
* @param userMaster
|
||||
* @constructor
|
||||
*/
|
||||
function CRole(fieldGroup, userMaster)
|
||||
{
|
||||
this.FieldGroup = fieldGroup;
|
||||
this.UserMaster = userMaster;
|
||||
}
|
||||
CRole.create = function(name, weight)
|
||||
{
|
||||
let userMaster = new AscOForm.CUserMaster(true);
|
||||
userMaster.setRole(name);
|
||||
|
||||
let fieldGroup = new AscOForm.CFieldGroup();
|
||||
fieldGroup.setWeight(weight);
|
||||
|
||||
return new CRole(fieldGroup, userMaster);
|
||||
};
|
||||
CRole.prototype.getSettings = function()
|
||||
{
|
||||
// TODO: Fix me
|
||||
return new CRoleSettings();
|
||||
};
|
||||
|
||||
/**
|
||||
* Класс для задания настроек роли из интерфейса
|
||||
* @constructor
|
||||
*/
|
||||
function CRoleSettings()
|
||||
{
|
||||
this.Name = "";
|
||||
this.Color = null;
|
||||
this.Index = 0;
|
||||
}
|
||||
CRoleSettings.prototype.getName = function()
|
||||
{
|
||||
return this.Name;
|
||||
};
|
||||
|
||||
|
||||
|
||||
|
||||
//--------------------------------------------------------export----------------------------------------------------
|
||||
AscOForm.CRole = CRole;
|
||||
AscOForm.CRoleSettings = CRoleSettings;
|
||||
//---------------------------------------------interface export-----------------------------------------------------
|
||||
window['AscCommon']["CRoleSettings"] = CRoleSettings;
|
||||
|
||||
})(window);
|
||||
Reference in New Issue
Block a user