]> git.argeo.org Git - gpl/argeo-slc.git/blob - server/org.argeo.slc.ria/src/argeo-ria-lib/slc/class/org/argeo/slc/ria/execution/Value.js
New icons for the tree
[gpl/argeo-slc.git] / server / org.argeo.slc.ria / src / argeo-ria-lib / slc / class / org / argeo / slc / ria / execution / Value.js
1 /**
2 * Wrapper for SlcValue object
3 */
4 qx.Class.define("org.argeo.slc.ria.execution.Value", {
5
6 extend : qx.core.Object,
7
8 properties : {
9 /**
10 * Name of this Execution Flow
11 */
12 key : {
13 check : "String",
14 init : ""
15 },
16 /**
17 * The type of this value, for the moment "primitive" and "ref" are supported
18 */
19 specType : {
20 check : "String",
21 init : ""
22 },
23 /**
24 * Subtype, depending on the "type".
25 */
26 specSubType : {
27 check : "String"
28 },
29 /**
30 * Whether it is a parameter or not
31 */
32 parameter : {
33 check : "Boolean"
34 },
35 /**
36 * Whether it is frozen on the server, i.e. disabled in the form
37 */
38 frozen : {
39 check : "Boolean"
40 },
41 /**
42 * Should not be editable nor seeable, thus hidden
43 */
44 hidden : {
45 check : "Boolean"
46 },
47 /**
48 * The real value
49 */
50 value : {
51 nullable : true
52 },
53 /**
54 * Castor representation of the object
55 */
56 xmlSpecNode : {
57 apply : "_applyXmlSpecNode"
58 }
59 },
60
61 statics : {
62 XPATH_KEY : "@key"
63 },
64
65 construct : function(){
66 this.base(arguments);
67 },
68
69 members : {
70 /**
71 * Init the object from an XML representation
72 * @param xmlNode {Node} Castor representation of this object
73 */
74 _applyXmlSpecNode : function(xmlNode){
75 this.setKey(org.argeo.ria.util.Element.getSingleNodeText(xmlNode, "@key"));
76 var childs = xmlNode.childNodes;
77 for(var i=0;i<childs.length;i++){
78 var child = childs[i];
79 if(child.nodeType != 1) continue;
80 if(child.nodeName == "slc:primitive-spec-attribute"){
81 this.setSpecType("primitive");
82 this.setSpecSubType(org.argeo.ria.util.Element.getSingleNodeText(child, "@type")||"");
83 if(org.argeo.ria.util.Element.getSingleNodeText(child, ".")){
84 this.setValue(org.argeo.ria.util.Element.getSingleNodeText(child, "."));
85 }
86 }else if(child.nodeName == "slc:ref-spec-attribute"){
87 this.setSpecType("ref");
88 this.setSpecSubType(org.argeo.ria.util.Element.getSingleNodeText(child, "@targetClassName")||"");
89 }
90 this.set({
91 parameter : (org.argeo.ria.util.Element.getSingleNodeText(child, "@isParameter")=="true"?true:false),
92 frozen : (org.argeo.ria.util.Element.getSingleNodeText(child, "@isFrozen")=="true"?true:false),
93 hidden : (org.argeo.ria.util.Element.getSingleNodeText(child, "@isHidden")=="true"?true:false)
94 });
95 }
96 },
97
98 /**
99 * Create an XML Representation of this value
100 * @return {String} The XML String
101 */
102 toAttributeXml : function(){
103 var valueTag = '';
104 var specAttribute = '';
105 if(this.getSpecType() == "primitive"){
106 valueTag = (this.getValue()?this.getValue():'');
107 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>';
108 }else if(this.getSpecType() == "ref"){
109 valueTag = (this.getValue()?'<slc:label>'+this.getValue()+'</slc:label>':'');
110 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>';
111 }
112 return '<slc:value key="'+this.getKey()+'">'+specAttribute+'</slc:value>';
113 },
114
115 toValueXml : function(){
116 var valueTag = '';
117 var specAttribute = '';
118 if(this.getSpecType() == "primitive"){
119 valueTag = this.getValue();
120 specAttribute = '<slc:primitive-value type="'+this.getSpecSubType()+'">'+valueTag+'</slc:primitive-value>';
121 }else if(this.getSpecType() == "ref"){
122 valueTag = '<slc:label>'+this.getValue()+'</slc:label>';
123 specAttribute = '<slc:ref-value >'+valueTag+'</slc:ref-value>';
124 }
125 return '<slc:value key="'+this.getKey()+'">'+specAttribute+'</slc:value>';
126 }
127 }
128
129 });