[oform] Implement reading all users,user masters, field masters

This commit is contained in:
KirillovIlya
2022-12-22 14:18:11 +03:00
parent e412f3095d
commit 923eed266f
4 changed files with 69 additions and 5 deletions

View File

@ -195,13 +195,28 @@
}; };
CDocument.prototype.fromPkg = function(xmlPkg) CDocument.prototype.fromPkg = function(xmlPkg)
{ {
let xmlContext = xmlPkg.getContext();
let mainPart = xmlPkg.getMainPart(); let mainPart = xmlPkg.getMainPart();
let mainContent = mainPart ? mainPart.getDocumentContent() : null; let mainContent = mainPart ? mainPart.getDocumentContent() : null;
if (mainContent) if (mainContent)
{ {
let reader = new AscCommon.StaxParser(mainContent, mainPart, xmlPkg.getContext()); let reader = new AscCommon.StaxParser(mainContent, mainPart, xmlContext);
this.fromXml(reader); this.fromXml(reader);
} }
let document = this;
xmlContext.getAllUsers().forEach(function(user)
{
document.addUser(user)
});
xmlContext.getAllUserMasters().forEach(function(userMaster)
{
document.addUserMaster(userMaster);
});
xmlContext.getAllFieldMasters().forEach(function(fieldMaster)
{
document.addFieldMaster(fieldMaster);
});
}; };
CDocument.prototype.fromXml = function(reader) CDocument.prototype.fromXml = function(reader)
{ {
@ -294,7 +309,7 @@
}; };
CDocument.prototype.removeUser = function(user) CDocument.prototype.removeUser = function(user)
{ {
let index = this.User.indexOf(user); let index = this.Users.indexOf(user);
if (-1 === index) if (-1 === index)
return; return;

View File

@ -149,8 +149,8 @@
let fields = []; let fields = [];
for (let fieldIndex = 0, fieldCount = this.Fields.length; fieldIndex < fieldCount; ++fieldIndex) for (let fieldIndex = 0, fieldCount = this.Fields.length; fieldIndex < fieldCount; ++fieldIndex)
{ {
if (this.Fields[index].isUseInDocument()) if (this.Fields[fieldIndex].isUseInDocument())
fields.push(this.Fields[index]); fields.push(this.Fields[fieldIndex]);
} }
if (this.Users.length && this.Parent) if (this.Users.length && this.Parent)

View File

@ -34,6 +34,11 @@
(function(window) (function(window)
{ {
const PATH_USERS = "/users/";
const PATH_USER_MASTERS = "/userMasters/";
const PATH_FIELDS = "/fields/";
const PATH_FIELD_MASTERS = "/fieldMasters/";
/** /**
* Класс для работы с ссылками внутри xml структуры * Класс для работы с ссылками внутри xml структуры
* @constructor * @constructor
@ -106,6 +111,24 @@
this.pathToFieldMaster[path] = fieldMaster; this.pathToFieldMaster[path] = fieldMaster;
return fieldMaster; return fieldMaster;
}; };
XmlContext.prototype.getAllUsers = function()
{
return this.getAllByMapAndPath(this.pathToUser, PATH_USERS, AscOForm.CUser.fromXml);
};
XmlContext.prototype.getAllUserMasters = function()
{
return this.getAllByMapAndPath(this.pathToUserMaster, PATH_USER_MASTERS, AscOForm.CUserMaster.fromXml);
};
XmlContext.prototype.getAllFields = function()
{
// TODO: Implement
return [];
//return this.getAllByMapAndPath(this.pathToField, PATH_FIELDS, AscOForm.CField.fromXml);
};
XmlContext.prototype.getAllFieldMasters = function()
{
return this.getAllByMapAndPath(this.pathToFieldMaster, PATH_FIELD_MASTERS, AscOForm.CFieldMaster.fromXml);
};
//////////////////////////////////////////////////////////////////////////////////////////////////////////////////// ////////////////////////////////////////////////////////////////////////////////////////////////////////////////////
// Private area // Private area
//////////////////////////////////////////////////////////////////////////////////////////////////////////////////// ////////////////////////////////////////////////////////////////////////////////////////////////////////////////////
@ -121,6 +144,32 @@
return new AscCommon.StaxParser(partContent, part, this); return new AscCommon.StaxParser(partContent, part, this);
}; };
XmlContext.prototype.getAllByMapAndPath = function(map, path, fromXml)
{
let result = [];
for (let key in map)
{
result.push(map[key]);
}
for (let uri in this.pkg.parts)
{
if (uri.startsWith(path)
&& uri.endsWith(".xml")
&& !map[uri])
{
let reader = this.getXmlReader(uri);
if (!reader)
return;
let element = fromXml(reader);
if (element)
result.push(element);
}
}
return result;
}
//--------------------------------------------------------export---------------------------------------------------- //--------------------------------------------------------export----------------------------------------------------
AscOForm.XmlContext = XmlContext; AscOForm.XmlContext = XmlContext;

File diff suppressed because one or more lines are too long