mirror of
https://github.com/ONLYOFFICE/sdkjs-forms.git
synced 2026-02-10 18:05:42 +08:00
[oform] Add correction of a field master array
Also, return the number of role fields that are used in the document
This commit is contained in:
@ -369,6 +369,15 @@
|
||||
AscCommon.History.Add(new AscDFH.CChangesOFormDocumentFieldMaster(this, fieldMaster.GetId(), false));
|
||||
this.FieldMasters.splice(index, 1);
|
||||
};
|
||||
CDocument.prototype.removeFieldMasterByIndex = function(index)
|
||||
{
|
||||
if (index < 0 || index >= this.FieldMasters.length)
|
||||
return;
|
||||
|
||||
let fieldMaster = this.FieldMasters[index];
|
||||
AscCommon.History.Add(new AscDFH.CChangesOFormDocumentFieldMaster(this, fieldMaster.GetId(), false));
|
||||
this.FieldMasters.splice(index, 1);
|
||||
};
|
||||
CDocument.prototype.getFieldMasterCount = function()
|
||||
{
|
||||
return this.FieldMasters.length;
|
||||
@ -437,6 +446,39 @@
|
||||
|
||||
this.OForm.onChangeRoles();
|
||||
};
|
||||
CDocument.prototype.correctFieldMasters = function(logicDocument)
|
||||
{
|
||||
if (!logicDocument)
|
||||
return;
|
||||
|
||||
let formManager = logicDocument.GetFormsManager();
|
||||
let allForms = formManager.GetAllForms();
|
||||
|
||||
for (let index = 0, count = allForms.length; index < count; ++index)
|
||||
{
|
||||
let form = allForms[index];
|
||||
let fieldMaster = form.GetFieldMaster();
|
||||
if (!fieldMaster)
|
||||
{
|
||||
// TODO: Мы не можем здесь генерировать id, т.к. данная функция вызывается на открытии
|
||||
// и тогда у разных клиентов будут разные id. Поэтому, пока лучше вообще такие поля будут без id
|
||||
fieldMaster = new AscOForm.CFieldMaster(false);
|
||||
this.addFieldMaster(fieldMaster);
|
||||
fieldMaster.addUser(this.getDefaultUserMaster());
|
||||
form.SetFieldMaster(fieldMaster);
|
||||
}
|
||||
fieldMaster.setLogicField(form);
|
||||
}
|
||||
|
||||
for (let fieldIndex = this.FieldMasters.length - 1; fieldIndex >= 0; --fieldIndex)
|
||||
{
|
||||
let fieldMaster = this.FieldMasters[fieldIndex];
|
||||
|
||||
let form = fieldMaster.getLogicField();
|
||||
if (!form || form.GetFieldMaster() !== fieldMaster)
|
||||
this.removeFieldMasterByIndex(fieldIndex);
|
||||
}
|
||||
};
|
||||
|
||||
//--------------------------------------------------------export----------------------------------------------------
|
||||
AscOForm.CDocument = CDocument;
|
||||
|
||||
@ -130,7 +130,13 @@
|
||||
};
|
||||
CFieldGroup.prototype.getAllFields = function()
|
||||
{
|
||||
let fields = this.Fields.slice();
|
||||
let fields = [];
|
||||
for (let fieldIndex = 0, fieldCount = this.Fields.length; fieldIndex < fieldCount; ++fieldIndex)
|
||||
{
|
||||
if (this.Fields[index].isUseInDocument())
|
||||
fields.push(this.Fields[index]);
|
||||
}
|
||||
|
||||
if (this.Users.length && this.Parent)
|
||||
{
|
||||
for (let index = 0, count = this.Users.length; index < count; ++index)
|
||||
@ -138,7 +144,7 @@
|
||||
let userFields = this.Parent.getAllFieldsByUserMaster(this.Users[index]);
|
||||
for (let fieldIndex = 0, fieldCount = userFields.length; fieldIndex < fieldCount; ++fieldIndex)
|
||||
{
|
||||
if (-1 === fields.indexOf(userFields[fieldIndex]))
|
||||
if (-1 === fields.indexOf(userFields[fieldIndex]) && userFields[fieldIndex].isUseInDocument())
|
||||
fields.push(userFields[fieldIndex]);
|
||||
}
|
||||
}
|
||||
|
||||
@ -55,6 +55,10 @@
|
||||
{
|
||||
this.Field = logicField;
|
||||
};
|
||||
CFieldMaster.prototype.getLogicField = function()
|
||||
{
|
||||
return this.Field;
|
||||
};
|
||||
CFieldMaster.prototype.clone = function()
|
||||
{
|
||||
let fm = new CFieldMaster(true);
|
||||
@ -138,6 +142,13 @@
|
||||
|
||||
return false;
|
||||
};
|
||||
CFieldMaster.prototype.isUseInDocument = function()
|
||||
{
|
||||
return true;
|
||||
return (this.Field
|
||||
&& this.Field.IsUseInDocument()
|
||||
&& this === this.Field.GetFieldMaster());
|
||||
};
|
||||
CFieldMaster.prototype.readAttrXml = function(name, reader)
|
||||
{
|
||||
switch (name)
|
||||
|
||||
@ -462,6 +462,7 @@
|
||||
OForm.prototype.onEndLoad = function()
|
||||
{
|
||||
this.NeedUpdateRoles = true;
|
||||
this.Format.correctFieldMasters(this.getDocument());
|
||||
this.correctFieldGroups();
|
||||
this.updateRoles();
|
||||
};
|
||||
@ -495,6 +496,7 @@
|
||||
if (!logicDocument)
|
||||
return;
|
||||
|
||||
this.Format.correctFieldMasters(this.getDocument());
|
||||
this.correctFieldGroups();
|
||||
this.updateRoles();
|
||||
|
||||
|
||||
Reference in New Issue
Block a user