]> git.argeo.org Git - gpl/argeo-slc.git/blobdiff - server/org.argeo.slc.ria/src/argeo-ria-lib/slc/class/org/argeo/slc/ria/execution/Value.js
Move to src
[gpl/argeo-slc.git] / server / org.argeo.slc.ria / src / argeo-ria-lib / slc / class / org / argeo / slc / ria / execution / Value.js
diff --git a/server/org.argeo.slc.ria/src/argeo-ria-lib/slc/class/org/argeo/slc/ria/execution/Value.js b/server/org.argeo.slc.ria/src/argeo-ria-lib/slc/class/org/argeo/slc/ria/execution/Value.js
new file mode 100644 (file)
index 0000000..b5944a0
--- /dev/null
@@ -0,0 +1,129 @@
+/**\r
+ * Wrapper for SlcValue object\r
+ */\r
+qx.Class.define("org.argeo.slc.ria.execution.Value", {\r
+       \r
+       extend : qx.core.Object,\r
+       \r
+       properties : {\r
+               /**\r
+                * Name of this Execution Flow \r
+                */\r
+               key : {\r
+                       check : "String",\r
+                       init : ""\r
+               },\r
+               /**\r
+                * The type of this value, for the moment "primitive" and "ref" are supported \r
+                */\r
+               specType : {\r
+                       check : "String",\r
+                       init : ""                       \r
+               },\r
+               /**\r
+                * Subtype, depending on the "type". \r
+                */\r
+               specSubType : {\r
+                       check : "String"\r
+               },\r
+               /**\r
+                * Whether it is a parameter or not \r
+                */\r
+               parameter : {\r
+                       check : "Boolean"\r
+               },\r
+               /**\r
+                * Whether it is frozen on the server, i.e. disabled in the form \r
+                */\r
+               frozen : {\r
+                       check : "Boolean"\r
+               },\r
+               /**\r
+                * Should not be editable nor seeable, thus hidden \r
+                */\r
+               hidden : {\r
+                       check : "Boolean"\r
+               },\r
+               /**\r
+                * The real value \r
+                */\r
+               value : {\r
+                       nullable : true\r
+               },\r
+               /**\r
+                * Castor representation of the object \r
+                */\r
+               xmlSpecNode : {\r
+                       apply : "_applyXmlSpecNode"\r
+               }\r
+       },\r
+       \r
+       statics : {\r
+               XPATH_KEY : "@key"\r
+       },\r
+       \r
+       construct : function(){\r
+               this.base(arguments);\r
+       },\r
+       \r
+       members : {             \r
+               /**\r
+                * Init the object from an XML representation\r
+                * @param xmlNode {Node} Castor representation of this object\r
+                */\r
+               _applyXmlSpecNode : function(xmlNode){\r
+                       this.setKey(org.argeo.ria.util.Element.getSingleNodeText(xmlNode, "@key"));\r
+                       var childs = xmlNode.childNodes;\r
+                       for(var i=0;i<childs.length;i++){\r
+                               var child = childs[i];\r
+                               if(child.nodeType != 1) continue;\r
+                               if(child.nodeName == "slc:primitive-spec-attribute"){\r
+                                       this.setSpecType("primitive");\r
+                                       this.setSpecSubType(org.argeo.ria.util.Element.getSingleNodeText(child, "@type"));\r
+                                       if(org.argeo.ria.util.Element.getSingleNodeText(child, ".")){\r
+                                               this.setValue(org.argeo.ria.util.Element.getSingleNodeText(child, "."));\r
+                                       }\r
+                               }else if(child.nodeName == "slc:ref-spec-attribute"){\r
+                                       this.setSpecType("ref");\r
+                                       this.setSpecSubType(org.argeo.ria.util.Element.getSingleNodeText(child, "@targetClassName"));\r
+                               }\r
+                               this.set({\r
+                                       parameter : (org.argeo.ria.util.Element.getSingleNodeText(child, "@isParameter")=="true"?true:false),\r
+                                       frozen : (org.argeo.ria.util.Element.getSingleNodeText(child, "@isFrozen")=="true"?true:false),\r
+                                       hidden : (org.argeo.ria.util.Element.getSingleNodeText(child, "@isHidden")=="true"?true:false)\r
+                               });                             \r
+                       }\r
+               },\r
+                               \r
+               /**\r
+                * Create an XML Representation of this value\r
+                * @return {String} The XML String\r
+                */\r
+               toAttributeXml : function(){\r
+                       var valueTag = '';\r
+                       var specAttribute = '';\r
+                       if(this.getSpecType() == "primitive"){\r
+                               valueTag =  (this.getValue()?this.getValue():'');\r
+                               specAttribute = '<slc:primitive-spec-attribute isParameter="'+(this.getParameter()?"true":"false")+'" isFrozen="'+(this.getFrozen()?"true":"false")+'" isHidden="'+(this.getHidden()?"true":"false")+'" type="'+this.getSpecSubType()+'">'+valueTag+'</slc:primitive-spec-attribute>';\r
+                       }else if(this.getSpecType() == "ref"){\r
+                               valueTag = (this.getValue()?'<slc:label>'+this.getValue()+'</slc:label>':'');\r
+                               specAttribute = '<slc:ref-spec-attribute isParameter="'+(this.getParameter()?"true":"false")+'" isFrozen="'+(this.getFrozen()?"true":"false")+'" isHidden="'+(this.getHidden()?"true":"false")+'" targetClassName="'+this.getSpecSubType()+'">'+valueTag+'</slc:ref-spec-attribute>';\r
+                       }\r
+                       return '<slc:value key="'+this.getKey()+'">'+specAttribute+'</slc:value>';\r
+               },\r
+               \r
+               toValueXml : function(){\r
+                       var valueTag = '';\r
+                       var specAttribute = '';\r
+                       if(this.getSpecType() == "primitive"){\r
+                               valueTag =  this.getValue();\r
+                               specAttribute = '<slc:primitive-value type="'+this.getSpecSubType()+'">'+valueTag+'</slc:primitive-value>';\r
+                       }else if(this.getSpecType() == "ref"){\r
+                               valueTag = '<slc:label>'+this.getValue()+'</slc:label>';\r
+                               specAttribute = '<slc:ref-value >'+valueTag+'</slc:ref-value>';\r
+                       }\r
+                       return '<slc:value key="'+this.getKey()+'">'+specAttribute+'</slc:value>';                      \r
+               }\r
+       }       \r
+       \r
+});
\ No newline at end of file