From 1c2bd5bd6e64e6fa048b36d4b467f897ad1ac133 Mon Sep 17 00:00:00 2001 From: KirillovIlya Date: Sun, 25 Dec 2022 12:14:28 +0300 Subject: [PATCH] [oform] Implement writing of default user master to xml Also fix writing to xml of duplicates in relationship table --- oform/format/Document.js | 31 +++++++++++++++++++++++++------ oform/xml/XmlContext.js | 14 +++++++++++++- 2 files changed, 38 insertions(+), 7 deletions(-) diff --git a/oform/format/Document.js b/oform/format/Document.js index 5733cdb..9271b6d 100644 --- a/oform/format/Document.js +++ b/oform/format/Document.js @@ -220,10 +220,9 @@ }; CDocument.prototype.toPkg = function(xmlPkg) { - // TODO: default.xml - let xmlContext = xmlPkg.getContext(); let xmlWriter = xmlPkg.getXmlWriter(); + let main = xmlPkg.addPart(AscCommon.openXml.Types.oformMain).part; xmlWriter.Seek(0); @@ -324,10 +323,30 @@ // TODO: Author, Date - writer.WriteXmlNodeWithText("description", this.getDescription()); - writer.WriteXmlNodeWithText("type", this.getType()); - writer.WriteXmlNodeWithText("application", this.getApplication()); - writer.WriteXmlNodeWithText("id", this.getDocumentId()); + let description = this.getDescription(); + if (description) + writer.WriteXmlNodeWithText("description", description); + + let type = this.getType(); + if (type) + writer.WriteXmlNodeWithText("type", type); + + let application = this.getApplication(); + if (application) + writer.WriteXmlNodeWithText("application", application); + + let documentId = this.getDocumentId(); + if (documentId) + writer.WriteXmlNodeWithText("id", documentId); + + let xmlContext = writer.context; + let defaultUserPart = xmlContext.getDefaultUserMasterPart(this.DefaultUser); + if (defaultUserPart) + { + writer.WriteXmlNodeStart("defaultUser"); + writer.WriteXmlNullableAttributeString("r:id", xmlContext.getRId(defaultUserPart)); + writer.WriteXmlAttributesEnd(true); + } for (let fgIndex = 0, fgCount = this.FieldGroups.length; fgIndex < fgCount; ++fgIndex) { diff --git a/oform/xml/XmlContext.js b/oform/xml/XmlContext.js index 2b89a01..0228e0b 100644 --- a/oform/xml/XmlContext.js +++ b/oform/xml/XmlContext.js @@ -186,12 +186,18 @@ this.userMasterToPart = {}; this.fieldToPart = {}; this.fieldMasterToPart = {}; + + this.partToRId = {}; } XmlWriterContext.prototype.clearCurrentPartDataMaps = function() { + this.partToRId = {}; }; XmlWriterContext.prototype.getRId = function(part) { + if (this.partToRId[part.uri]) + return this.partToRId[part.uri]; + if (!this.part) return ""; @@ -220,7 +226,9 @@ relative += targetSplit.join('/'); - return this.part.addRelationship(null, relative); + let rId = this.part.addRelationship(null, relative); + this.partToRId[part.uri] = rId; + return rId; }; XmlWriterContext.prototype.getUserPart = function(user) { @@ -234,6 +242,10 @@ { return this.getPartFromPkg(this.userMasterToPart, userMaster, AscCommon.openXml.Types.oformUserMaster); }; + XmlWriterContext.prototype.getDefaultUserMasterPart = function(userMaster) + { + return this.getPartFromPkg(this.userMasterToPart, userMaster, AscCommon.openXml.Types.oformDefaultUserMaster); + }; XmlWriterContext.prototype.haveUserMasterPart = function(userMaster) { return !!this.userMasterToPart[userMaster.GetId()];