[oform] Implement writing of default user master to xml

Also fix writing to xml of duplicates in relationship table
This commit is contained in:
KirillovIlya
2022-12-25 12:14:28 +03:00
parent 22b94b07f8
commit 1c2bd5bd6e
2 changed files with 38 additions and 7 deletions

View File

@ -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)
{

View File

@ -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()];