123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101 |
- /*******************************************************************************
- * IBM Confidential
- *
- * OCO Source Materials
- *
- * A and PM: PD
- *
- * (c) Copyright IBM Corp. 2014
- *
- * The source code for this program is not published or otherwise divested of
- * its trade secrets, irrespective of what has been deposited with the U.S.
- * Copyright Office.
- ******************************************************************************/
- define([
- "dojo/_base/declare",
- "dojo/store/Memory",
- "dojox/xml/parser",
- "dojo/_base/array",
- "dojo/query",
- "pd/model/pdSpec"
- ],function(declare, store, xmlParser, array, query, model){
-
- return declare("pd/data/PdSpecStore", [store], {
- constructor: function(args) {
- if (!args.xmlInput){
- throw new Error(PDMSG.ERR.IDS_ERR_MISSING_XMLDOC_PARAM);
- }
-
- if (typeof(args.xmlInput) == "string"){
- this.xmlDoc = xmlParser.parse(dojo.trim(args.xmlInput));
- } else {
- this.xmlDoc = args.xmlInput;
- }
-
- this.data = this.generateDataFromXml();
- this.inherited(arguments);
- },
-
- generateDataFromXml: function() {
- var data = {
- identifier: 'id',
- items: []
- };
- var dataList = [];
- var xmlDoc = this.xmlDoc.selectSingleNode("/pdSpec/personalData");
-
- if (xmlDoc){
- array.forEach(
- query("item", xmlDoc), function(node, index, arr){
- var dataItem = {};
- array.forEach(model, function(item, idx){
- var value;
- if (node.getAttribute(item.itemName) != null){
- value = node.getAttribute(item.itemName);
- } else {
- value = item.defaultValue;
- node.setAttribute(item.itemName, value);
- }
- dataItem[item.itemName] = value;
- });
- dataList.push(dataItem);
- }
- );
-
- for(var i=0; i<dataList.length; i++){
- data.items.push(dojo.mixin({ id: i }, dataList[i]));
- }
- }
- return data;
- },
-
- generateXmlFromData: function(selected) {
- var xmlDoc = this.xmlDoc.selectSingleNode("/pdSpec/personalData");
- for (var i=0; i<selected.length; i++){
- //since "hidden" is from indirection-selector, it doesn't affect isDirty attribute.
- xmlDoc.childNodes[i].setAttribute("hidden", this.data[i].hidden);
- if (this.data[i].__isDirty){
- xmlDoc.childNodes[i].setAttribute("name", this.data[i].name);
- xmlDoc.childNodes[i].setAttribute("regularAggregate", this.data[i].regularAggregate);
- xmlDoc.childNodes[i].setAttribute("semiAggregate", this.data[i].regularAggregate);
- if (this.data[i].regularAggregate == "unsupported"){
- xmlDoc.childNodes[i].setAttribute("usage", "attribute");
- } else {
- xmlDoc.childNodes[i].setAttribute("usage", "fact");
- }
- }
- }
- // Trim out the preview data blob.
- var dataNode = this.xmlDoc.selectSingleNode("/pdSpec/personalPreview");
- if (dataNode){
- dataNode.parentNode.removeChild(dataNode);
- }
-
- return xmlParser.parse("<addLOBData><input><pdCollection>"
- + xmlParser.innerXML(this.xmlDoc)
- + "</pdCollection></input></addLOBData>");
- }
- });
- });
|