mirror of
https://github.com/ONLYOFFICE/sdkjs-forms.git
synced 2026-03-31 10:23:35 +08:00
[oform] Work on reading FieldGroup rels
This commit is contained in:
@ -8,9 +8,8 @@
|
||||
"apiBuilder.js",
|
||||
"oform/OForm.js",
|
||||
"oform/Role.js",
|
||||
"oform/XmlFile.js",
|
||||
"oform/XmlFormat.js",
|
||||
"oform/xml/XmlPackage.js",
|
||||
"oform/xml/XmlContext.js",
|
||||
"oform/format/Document.js",
|
||||
"oform/format/FieldGroup.js",
|
||||
"oform/format/FieldMaster.js",
|
||||
|
||||
@ -64,6 +64,13 @@
|
||||
this.FieldMasters = [];
|
||||
}
|
||||
AscFormat.InitClass(CDocument, AscFormat.CBaseFormatObject, AscDFH.historyitem_type_OForm_Document);
|
||||
CDocument.prototype.clear = function()
|
||||
{
|
||||
// TODO: fields?
|
||||
this.clearUsers();
|
||||
this.clearUserMasters();
|
||||
this.clearFieldGroups();
|
||||
};
|
||||
CDocument.prototype.setAuthor = function(author)
|
||||
{
|
||||
if (this.Author === author)
|
||||
@ -160,6 +167,13 @@
|
||||
this.FieldGroups.splice(index, 1);
|
||||
this.onChangeFieldGroups();
|
||||
};
|
||||
CDocument.prototype.clearFieldGroups = function()
|
||||
{
|
||||
while (this.FieldGroups.length)
|
||||
{
|
||||
this.removeFieldGroup(this.FieldGroups[0]);
|
||||
}
|
||||
};
|
||||
CDocument.prototype.getFieldGroupsCount = function()
|
||||
{
|
||||
return this.FieldGroups.length;
|
||||
@ -173,10 +187,18 @@
|
||||
};
|
||||
CDocument.prototype.fromPkg = function(xmlPkg)
|
||||
{
|
||||
|
||||
let mainPart = xmlPkg.getMainPart();
|
||||
let mainContent = mainPart ? mainPart.getDocumentContent() : null;
|
||||
if (mainContent)
|
||||
{
|
||||
let reader = new AscCommon.StaxParser(mainContent, mainPart, xmlPkg.getContext());
|
||||
this.fromXml(reader);
|
||||
}
|
||||
};
|
||||
CDocument.prototype.fromXml = function()
|
||||
CDocument.prototype.fromXml = function(reader)
|
||||
{
|
||||
this.clear();
|
||||
|
||||
// TODO: Author, Date
|
||||
if (!reader.ReadNextNode() || "document" !== reader.GetNameNoNS())
|
||||
return false;
|
||||
@ -191,19 +213,19 @@
|
||||
case "date":
|
||||
break;
|
||||
case "description":
|
||||
this.setDescription(reader.GetValueDecodeXml());
|
||||
this.setDescription(reader.GetTextDecodeXml());
|
||||
break;
|
||||
case "type":
|
||||
this.setType(reader.GetValueDecodeXml());
|
||||
this.setType(reader.GetTextDecodeXml());
|
||||
break;
|
||||
case "application":
|
||||
this.setApplication(reader.GetValueDecodeXml());
|
||||
this.setApplication(reader.GetTextDecodeXml());
|
||||
break;
|
||||
case "id":
|
||||
this.setDocumentId(reader.GetValueDecodeXml());
|
||||
this.setDocumentId(reader.GetTextDecodeXml());
|
||||
break;
|
||||
case "fieldGroup":
|
||||
this.addFieldMaster(AscOForm.CFieldGroup.fromXml(reader));
|
||||
this.addFieldGroup(AscOForm.CFieldGroup.fromXml(reader));
|
||||
break;
|
||||
}
|
||||
}
|
||||
@ -270,6 +292,13 @@
|
||||
|
||||
return this.Users[index];
|
||||
};
|
||||
CDocument.prototype.clearUsers = function()
|
||||
{
|
||||
while (this.Users.length)
|
||||
{
|
||||
this.removeUser(this.Users[0]);
|
||||
}
|
||||
};
|
||||
CDocument.prototype.addUserMaster = function(userMaster)
|
||||
{
|
||||
if (-1 !== this.UserMasters.indexOf(userMaster))
|
||||
@ -304,6 +333,13 @@
|
||||
{
|
||||
return this.UserMasters;
|
||||
};
|
||||
CDocument.prototype.clearUserMasters = function()
|
||||
{
|
||||
while (this.UserMasters.length)
|
||||
{
|
||||
this.removeUserMaster(this.UserMasters[0]);
|
||||
}
|
||||
};
|
||||
CDocument.prototype.createFieldMaster = function(id)
|
||||
{
|
||||
let fieldMaster = new AscOForm.CFieldMaster(!id);
|
||||
|
||||
@ -217,14 +217,41 @@
|
||||
fG.setWeight(reader.GetValueInt());
|
||||
}
|
||||
|
||||
let xmlContext = reader.GetContext();
|
||||
let depth = reader.GetDepth();
|
||||
while (reader.ReadNextSiblingNode(depth))
|
||||
{
|
||||
switch(reader.GetNameNoNS())
|
||||
{
|
||||
case "user":
|
||||
|
||||
while (reader.MoveToNextAttribute())
|
||||
{
|
||||
if ("r:id" === reader.GetName())
|
||||
{
|
||||
let rId = reader.GetValueDecodeXml();
|
||||
let rel = reader.rels.getRelationship(rId);
|
||||
let userMaster = xmlContext.getUserMaster(rel.getFullPath());
|
||||
if (userMaster)
|
||||
this.addUserMaster(userMaster);
|
||||
}
|
||||
}
|
||||
|
||||
break;
|
||||
case "field":
|
||||
|
||||
while (reader.MoveToNextAttribute())
|
||||
{
|
||||
if ("r:id" === reader.GetName())
|
||||
{
|
||||
let rId = reader.GetValueDecodeXml();
|
||||
let rel = reader.rels.getRelationship(rId);
|
||||
let userMaster = xmlContext.getUserMaster(rel.getFullPath());
|
||||
if (userMaster)
|
||||
this.addUserMaster(userMaster);
|
||||
}
|
||||
}
|
||||
|
||||
break;
|
||||
}
|
||||
}
|
||||
|
||||
89
oform/xml/XmlContext.js
Normal file
89
oform/xml/XmlContext.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)
|
||||
{
|
||||
/**
|
||||
* Класс для работы с ссылками внутри xml структуры
|
||||
* @constructor
|
||||
*/
|
||||
function XmlContext(pkg)
|
||||
{
|
||||
this.pkg = pkg;
|
||||
|
||||
this.pathToUser = {};
|
||||
this.pathToUserMaster = {};
|
||||
this.pathToFieldMaster = {};
|
||||
}
|
||||
XmlContext.prototype.getUser = function(path)
|
||||
{
|
||||
let rel = reader.rels.getRelationship(context.InitOpenManager.legacyDrawingId);
|
||||
let oRelPart = reader.rels.pkg.getPartByUri(oRel.getFullPath());
|
||||
|
||||
path = this.getFullPath(path, part);
|
||||
let user = this.pathToUser[path];
|
||||
if (!user)
|
||||
{
|
||||
this.pkg.getPartByUri(path);
|
||||
}
|
||||
|
||||
return user;
|
||||
};
|
||||
XmlContext.prototype.getUserMaster = function(path)
|
||||
{
|
||||
let userMaster = this.pathToUserMaster[path];
|
||||
if (userMaster)
|
||||
return userMaster;
|
||||
|
||||
let part = this.pkg.getPartByUri(path);
|
||||
let partContent = part ? part.getDocumentContent() : null;
|
||||
if (!partContent)
|
||||
return null;
|
||||
|
||||
let reader = new AscCommon.StaxParser(partContent, part, this);
|
||||
return AscOForm.CUserMaster.fromXml(reader);
|
||||
};
|
||||
XmlContext.prototype.getFieldMaster = function(path)
|
||||
{
|
||||
|
||||
};
|
||||
////////////////////////////////////////////////////////////////////////////////////////////////////////////////////
|
||||
// Private area
|
||||
////////////////////////////////////////////////////////////////////////////////////////////////////////////////////
|
||||
|
||||
|
||||
//--------------------------------------------------------export----------------------------------------------------
|
||||
AscOForm.XmlContext = XmlContext;
|
||||
|
||||
})(window);
|
||||
File diff suppressed because one or more lines are too long
Reference in New Issue
Block a user