mirror of
https://github.com/ONLYOFFICE/sdkjs-forms.git
synced 2026-03-31 10:23:35 +08:00
[oform] Write users/userMasters/fieldMaster to zip package
Serialize all of these classes to xml if no other classes are related to them
This commit is contained in:
@ -220,11 +220,47 @@
|
||||
};
|
||||
CDocument.prototype.toPkg = function(xmlPkg)
|
||||
{
|
||||
let xmlWriter = xmlPkg.getXmlWriter();
|
||||
let main = xmlPkg.addPart(AscCommon.openXml.Types.oformMain);
|
||||
// TODO: default.xml
|
||||
|
||||
let xmlContext = xmlPkg.getContext();
|
||||
let xmlWriter = xmlPkg.getXmlWriter();
|
||||
let main = xmlPkg.addPart(AscCommon.openXml.Types.oformMain).part;
|
||||
|
||||
xmlWriter.Seek(0);
|
||||
main.part.setDataXml(this, xmlWriter);
|
||||
main.setDataXml(this, xmlWriter);
|
||||
|
||||
this.Users.forEach(function(user)
|
||||
{
|
||||
if (!xmlContext.haveUserPart(user))
|
||||
{
|
||||
xmlWriter.Seek(0);
|
||||
let part = main.addPartWithoutRels(AscCommon.openXml.Types.oformUser);
|
||||
if (part)
|
||||
part.setDataXml(user, xmlWriter);
|
||||
}
|
||||
});
|
||||
|
||||
this.UserMasters.forEach(function(userMaster)
|
||||
{
|
||||
if (!xmlContext.haveUserMasterPart(userMaster))
|
||||
{
|
||||
xmlWriter.Seek(0);
|
||||
let part = main.addPartWithoutRels(AscCommon.openXml.Types.oformUserMaster);
|
||||
if (part)
|
||||
part.setDataXml(userMaster, xmlWriter);
|
||||
}
|
||||
});
|
||||
|
||||
this.FieldMasters.forEach(function(fieldMaster)
|
||||
{
|
||||
if (!xmlContext.haveFieldMasterPart(fieldMaster))
|
||||
{
|
||||
xmlWriter.Seek(0);
|
||||
let part = main.addPartWithoutRels(AscCommon.openXml.Types.oformFieldMaster);
|
||||
if (part)
|
||||
part.setDataXml(fieldMaster, xmlWriter);
|
||||
}
|
||||
});
|
||||
};
|
||||
CDocument.prototype.fromXml = function(reader)
|
||||
{
|
||||
|
||||
@ -189,20 +189,34 @@
|
||||
}
|
||||
return user;
|
||||
};
|
||||
CFieldGroup.prototype.toXml = function(writer, xmlFormat)
|
||||
CFieldGroup.prototype.toXml = function(writer)
|
||||
{
|
||||
let context = writer.context;
|
||||
|
||||
writer.WriteXmlNodeStart("fieldGroup");
|
||||
writer.WriteXmlNullableAttributeInt("weight", this.getWeight());
|
||||
writer.WriteXmlAttributesEnd();
|
||||
|
||||
for (let userIndex = 0, userCount = this.Users.length; userIndex < userCount; ++userIndex)
|
||||
{
|
||||
|
||||
let part = context.getUserMasterPart(this.Users[userIndex]);
|
||||
if (!part)
|
||||
continue;
|
||||
|
||||
writer.WriteXmlNodeStart("user");
|
||||
writer.WriteXmlNullableAttributeString("r:id", part.rId);
|
||||
writer.WriteXmlAttributesEnd(true);
|
||||
}
|
||||
|
||||
for (let fieldIndex = 0, fieldCount = this.Fields.length; fieldIndex < fieldCount; ++fieldIndex)
|
||||
{
|
||||
|
||||
// let part = context.getFieldMasterPart(this.Fields[fieldIndex]);
|
||||
// if (!part)
|
||||
// continue;
|
||||
//
|
||||
// writer.WriteXmlNodeStart("field");
|
||||
// writer.WriteXmlNullableAttributeString("r:id", part.rId);
|
||||
// writer.WriteXmlAttributesEnd(true);
|
||||
}
|
||||
|
||||
writer.WriteXmlNodeEnd("fieldGroup");
|
||||
|
||||
@ -180,6 +180,7 @@
|
||||
};
|
||||
CFieldMaster.prototype.toXml = function(writer)
|
||||
{
|
||||
return;
|
||||
writer.WriteXmlString(AscCommonWord.g_sXmlHeader);
|
||||
writer.WriteXmlNodeStart("FieldMaster");
|
||||
writer.WriteXmlAttributeString("xmlns:r", "http://schemas.openxmlformats.org/officeDocument/2006/relationships");
|
||||
|
||||
@ -182,11 +182,65 @@
|
||||
{
|
||||
this.pkg = pkg;
|
||||
|
||||
this.userToPath = {};
|
||||
this.userMasterToPath = {};
|
||||
this.fieldToPath = {};
|
||||
this.fieldMasterToPath = {};
|
||||
this.userToPart = {};
|
||||
this.userMasterToPart = {};
|
||||
this.fieldToPart = {};
|
||||
this.fieldMasterToPart = {};
|
||||
}
|
||||
XmlWriterContext.prototype.clearCurrentPartDataMaps = function()
|
||||
{
|
||||
};
|
||||
XmlWriterContext.prototype.getUserPart = function(user, part)
|
||||
{
|
||||
return this.getPart(this.userToPart, user, AscCommon.openXml.Types.oformUser);
|
||||
};
|
||||
XmlWriterContext.prototype.haveUserPart = function(user)
|
||||
{
|
||||
return !!this.userToPart[user.GetId()];
|
||||
};
|
||||
XmlWriterContext.prototype.getUserMasterPart = function(userMaster)
|
||||
{
|
||||
return this.getPart(this.userMasterToPart, userMaster, AscCommon.openXml.Types.oformUserMaster);
|
||||
};
|
||||
XmlWriterContext.prototype.haveUserMasterPart = function(userMaster)
|
||||
{
|
||||
return !!this.userMasterToPart[userMaster.GetId()];
|
||||
};
|
||||
XmlWriterContext.prototype.getFieldPart = function(field)
|
||||
{
|
||||
return this.getPart(this.fieldToPart, field, AscCommon.openXml.Types.oformField);
|
||||
};
|
||||
XmlWriterContext.prototype.haveFieldPart = function(field)
|
||||
{
|
||||
return !!this.fieldToPart[field.GetId()];
|
||||
};
|
||||
XmlWriterContext.prototype.getFieldMasterPart = function(fieldMaster)
|
||||
{
|
||||
return this.getPart(this.fieldMasterToPart, fieldMaster, AscCommon.openXml.Types.oformFieldMaster);
|
||||
};
|
||||
XmlWriterContext.prototype.haveFieldMasterPart = function(fieldMaster)
|
||||
{
|
||||
return !!this.fieldMasterToPart[fieldMaster];
|
||||
};
|
||||
////////////////////////////////////////////////////////////////////////////////////////////////////////////////////
|
||||
// Private area
|
||||
////////////////////////////////////////////////////////////////////////////////////////////////////////////////////
|
||||
XmlWriterContext.prototype.getPart = function(map, object, contentType, curPart)
|
||||
{
|
||||
let objectId = object.GetId();
|
||||
if (map[objectId])
|
||||
return map[objectId];
|
||||
|
||||
let part = curPart.addPart(contentType);
|
||||
|
||||
let xmlWriter = new AscCommon.CMemory();
|
||||
xmlWriter.context = this;
|
||||
|
||||
part.part.setDataXml(object, xmlWriter);
|
||||
|
||||
map[objectId] = part;
|
||||
return part;
|
||||
};
|
||||
//--------------------------------------------------------export----------------------------------------------------
|
||||
AscOForm.XmlWriterContext = XmlWriterContext;
|
||||
|
||||
|
||||
Reference in New Issue
Block a user