From f88a486b13c74a6b7bc622a29ea4eeb36a06ed58 Mon Sep 17 00:00:00 2001 From: KirillovIlya Date: Tue, 29 Nov 2022 14:32:03 +0300 Subject: [PATCH] [oform] Add event about changing user master --- oform/Document.js | 16 ++++++++++++++++ oform/FieldGroup.js | 2 +- oform/UserMaster.js | 16 ++++++++++++++++ oform/changes/DocumentChanges.js | 16 +++++++++++----- oform/changes/UserMasterChanges.js | 3 +++ 5 files changed, 47 insertions(+), 6 deletions(-) diff --git a/oform/Document.js b/oform/Document.js index ce96489..fdc10da 100644 --- a/oform/Document.js +++ b/oform/Document.js @@ -315,6 +315,7 @@ AscCommon.History.Add(new AscDFH.CChangesOFormDocumentUserMaster(this, userMaster.GetId(), true)); this.UserMasters.push(userMaster); + userMaster.setParent(this); }; CDocument.prototype.removeUserMaster = function(userMaster) { @@ -322,6 +323,7 @@ if (-1 === index) return; + userMaster.setParent(null); AscCommon.History.Add(new AscDFH.CChangesOFormDocumentUserMaster(this, userMaster.GetId(), false)); this.UserMasters.splice(index, 1); }; @@ -399,6 +401,20 @@ this.OForm.onChangeRoles(); }; + CDocument.prototype.onChangeFieldGroup = function(fieldGroup) + { + if (!this.OForm) + return; + + this.OForm.onChangeRoles(); + }; + CDocument.prototype.onChangeUserMaster = function(userMaster) + { + if (!this.OForm) + return; + + this.OForm.onChangeRoles(); + }; //--------------------------------------------------------export---------------------------------------------------- AscOForm.CDocument = CDocument; diff --git a/oform/FieldGroup.js b/oform/FieldGroup.js index 97764c4..eecd339 100644 --- a/oform/FieldGroup.js +++ b/oform/FieldGroup.js @@ -114,7 +114,7 @@ if (!this.Parent) return; - this.Parent.onChangeFieldGroups(); + this.Parent.onChangeFieldGroup(this); }; CFieldGroup.prototype.getFirstUser = function() { diff --git a/oform/UserMaster.js b/oform/UserMaster.js index 9d08a4e..4cc0d67 100644 --- a/oform/UserMaster.js +++ b/oform/UserMaster.js @@ -50,8 +50,14 @@ if (true === generateId) this.setUserId(AscCommon.CreateGUID()); + + this.Parent = null; } AscFormat.InitClass(CUserMaster, AscFormat.CBaseFormatObject, AscDFH.historyitem_type_OForm_UserMaster); + CUserMaster.prototype.setParent = function(parent) + { + this.Parent = parent; + }; CUserMaster.prototype.setUserId = function(userId) { if (userId === this.UserId) @@ -59,6 +65,7 @@ AscCommon.History.Add(new AscDFH.CChangesOFormUserMasterUserId(this, this.UserId, userId)); this.UserId = userId; + this.onChange(); }; CUserMaster.prototype.getUserId = function() { @@ -73,6 +80,7 @@ AscCommon.History.Add(new AscDFH.CChangesOFormUserMasterRole(this, this.Role, role)); this.Role = role; + this.onChange(); }; CUserMaster.prototype.getRole = function() { @@ -87,6 +95,7 @@ AscCommon.History.Add(new AscDFH.CChangesOFormUserMasterColor(this, oldColor, newColor)); this.Color = newColor; + this.onChange(); }; CUserMaster.prototype.getColor = function() { @@ -135,6 +144,13 @@ return 0; }; + CUserMaster.prototype.onChange = function() + { + if (!this.Parent) + return; + + this.Parent.onChangeUserMaster(this); + }; CUserMaster.prototype.readChildXml = function(name, reader) { let bRead = false; diff --git a/oform/changes/DocumentChanges.js b/oform/changes/DocumentChanges.js index b4506ce..e232300 100644 --- a/oform/changes/DocumentChanges.js +++ b/oform/changes/DocumentChanges.js @@ -252,16 +252,22 @@ window['AscDFH'].historyitem_OForm_Document_UserMaster, function() { - let user = AscCommon.g_oTableId.GetById(this.Key); - if (-1 === this.Class.UserMasters.indexOf(user)) - this.Class.UserMasters.push(user); + let userMaster = AscCommon.g_oTableId.GetById(this.Key); + if (-1 === this.Class.UserMasters.indexOf(userMaster)) + { + userMaster.setParent(this.Class); + this.Class.UserMasters.push(userMaster); + } }, function() { - let user = AscCommon.g_oTableId.GetById(this.Key); - let index = this.Class.UserMasters.indexOf(user); + let userMaster = AscCommon.g_oTableId.GetById(this.Key); + let index = this.Class.UserMasters.indexOf(userMaster); if (-1 !== index) + { + userMaster.setParent(null); this.Class.UserMasters.splice(index, 1); + } } ); window['AscDFH'].CChangesOFormDocumentUserMaster = CChangesOFormDocumentUserMaster; diff --git a/oform/changes/UserMasterChanges.js b/oform/changes/UserMasterChanges.js index 7089956..290ec2f 100644 --- a/oform/changes/UserMasterChanges.js +++ b/oform/changes/UserMasterChanges.js @@ -53,6 +53,7 @@ function(Value) { this.Class.UserId = Value; + this.Class.onChange(); }, false ); @@ -73,6 +74,7 @@ function(Value) { this.Class.Role = Value; + this.Class.onChange(); }, false ); @@ -93,6 +95,7 @@ function(value) { this.Class.Color = value; + this.Class.onChange(); }, false );