ScriptIncluder.js 10 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251252253254255256257258259260261262263264265
  1. MWF.xApplication.process.FormDesigner.widget = MWF.xApplication.process.FormDesigner.widget || {};
  2. MWF.require("MWF.widget.UUID", null, false);
  3. MWF.xApplication.process.FormDesigner.widget.ScriptIncluder = new Class({
  4. Implements: [Options, Events],
  5. Extends: MWF.widget.Common,
  6. options: {
  7. "style": "default",
  8. "maxObj": document.body
  9. },
  10. initialize: function(node, designer, options){
  11. this.setOptions(options);
  12. this.node = $(node);
  13. this.designer = designer;
  14. this.path = "../x_component_process_FormDesigner/widget/$ScriptIncluder/";
  15. this.cssPath = "../x_component_process_FormDesigner/widget/$ScriptIncluder/"+this.options.style+"/css.wcss";
  16. this._loadCss();
  17. this.items = [];
  18. },
  19. load: function(data){
  20. this.titleNode = new Element("div", {"styles": this.css.titleNode, "text": this.designer.lp.validation.validation}).inject(this.node);
  21. this.editorNode = new Element("div", {"styles": this.css.editorNode}).inject(this.node);
  22. this.actionNode = new Element("div", {"styles": this.css.actionNode}).inject(this.node);
  23. this.listNode = new Element("div", {"styles": this.css.listNode}).inject(this.node);
  24. this.loadEditorNode();
  25. this.loadActionNode();
  26. this.loadListNode(data);
  27. },
  28. loadEditorNode: function(){
  29. var html = "<table width='100%' border='0' cellpadding='5' cellspacing='0' class='editTable'>" +
  30. "<tr><td></td><td></td></tr><tr><td></td><td></td></tr></table>";
  31. this.editorNode.set("html", html);
  32. var tds = this.editorNode.getElements("td").setStyles(this.css.editTableTdValue);
  33. },
  34. loadActionNode: function(){
  35. this.actionAreaNode = new Element("div", {"styles": this.css.actionAreaNode}).inject(this.actionNode);
  36. this.addAction = new Element("div", {"styles": this.css.addAction, "text": this.designer.lp.validation.add}).inject(this.actionAreaNode);
  37. this.modifyAction = new Element("div", {"styles": this.css.modifyAction_disabled, "text": this.designer.lp.validation.modify}).inject(this.actionAreaNode);
  38. this.addAction.addEvent("click", function(){
  39. this.addValidation();
  40. }.bind(this));
  41. this.modifyAction.addEvent("click", function(){
  42. this.modifyValidation();
  43. }.bind(this));
  44. },
  45. getData: function(){
  46. var status = this.getStatusValue();
  47. var decision = this.decisionInputNode.get("value");
  48. var valueType = this.valueTypeSelectNode.options[this.valueTypeSelectNode.selectedIndex].value;
  49. var operateor = this.operateorSelectNode.options[this.operateorSelectNode.selectedIndex].value;
  50. var value = this.valueInputNode.get("value");
  51. var prompt = this.promptInputNode.get("value");
  52. if (decision == this.designer.lp.validation.decisionName) decision = "";
  53. if (value == this.designer.lp.validation.valueInput) value = "";
  54. return {
  55. "status": status,
  56. "decision": decision,
  57. "valueType": valueType,
  58. "operateor": operateor,
  59. "value": value,
  60. "prompt": prompt
  61. };
  62. },
  63. addValidation: function(){
  64. this.hideErrorNode();
  65. var data = this.getData();
  66. if (data.status!="all"){
  67. if (!data.decision || data.decision==this.designer.lp.validation.decisionName){
  68. this.showErrorNode(this.designer.lp.validation.inputDecisionName);
  69. return false;
  70. }
  71. }
  72. if (data.operateor!="isnull" && data.operateor!="notnull"){
  73. if (!data.value || data.value==this.designer.lp.validation.valueInput){
  74. this.showErrorNode(this.designer.lp.validation.inputValue);
  75. return false;
  76. }
  77. }
  78. if (!data.prompt){
  79. this.showErrorNode(this.designer.lp.validation.inputPrompt);
  80. return false;
  81. }
  82. var item = new MWF.xApplication.process.FormDesigner.widget.ScriptIncluder.Item(data, this);
  83. this.items.push(item);
  84. item.selected();
  85. this.fireEvent("change");
  86. },
  87. showErrorNode: function(text){
  88. this.errorNode = new Element("div", {"styles": this.css.errorNode}).inject(this.actionNode, "before");
  89. this.errorTextNode = new Element("div", {"styles": this.css.errorTextNode}).inject(this.errorNode);
  90. this.errorTextNode.set("text", text);
  91. this.errorNode.addEvent("click", function(){this.hideErrorNode();}.bind(this));
  92. },
  93. hideErrorNode: function(){
  94. if (this.errorNode) this.errorNode.destroy();
  95. },
  96. getStatusValue: function(){
  97. for (var i=0; i<this.statusRadioNodes.length; i++){
  98. var item = this.statusRadioNodes[i];
  99. if (item.checked) return item.value;
  100. }
  101. return "";
  102. },
  103. modifyValidation: function(){
  104. if (this.currentItem){
  105. this.hideErrorNode();
  106. var data = this.getData();
  107. if (data.status!="all"){
  108. if (!data.decision || data.decision==this.designer.lp.validation.decisionName){
  109. this.showErrorNode(this.designer.lp.validation.inputDecisionName);
  110. return false;
  111. }
  112. }
  113. if (data.operateor!="isnull" && data.operateor!="notnull"){
  114. if (!data.value || data.value==this.designer.lp.validation.valueInput){
  115. this.showErrorNode(this.designer.lp.validation.inputValue);
  116. return false;
  117. }
  118. }
  119. if (!data.prompt){
  120. this.showErrorNode(this.designer.lp.validation.inputPrompt);
  121. return false;
  122. }
  123. this.currentItem.reload(data);
  124. this.currentItem.unSelected();
  125. this.disabledModify();
  126. this.fireEvent("change");
  127. }
  128. },
  129. loadListNode: function(data){
  130. if (data){
  131. if (data.length){
  132. data.each(function(itemData){
  133. var item = new MWF.xApplication.process.FormDesigner.widget.ScriptIncluder.Item(itemData, this);
  134. this.items.push(item);
  135. }.bind(this));
  136. }
  137. }
  138. },
  139. enabledModify: function(){
  140. this.modifyAction.setStyles(this.css.modifyAction);
  141. },
  142. disabledModify: function(){
  143. this.modifyAction.setStyles(this.css.modifyAction_disabled);
  144. },
  145. setData: function(data){
  146. if (data.decision) this.decisionInputNode.set("value", data.decision);
  147. if (data.status){
  148. for (var i=0; i<this.statusRadioNodes.length; i++){
  149. if (data.status == this.statusRadioNodes[i].get("value")){
  150. this.statusRadioNodes[i].set("checked", true);
  151. break;
  152. }
  153. }
  154. }else{
  155. this.statusRadioNodes[0].set("checked", true);
  156. }
  157. for (var i=0; i<this.valueTypeSelectNode.options.length; i++){
  158. if (data.valueType == this.valueTypeSelectNode.options[i].get("value")){
  159. this.valueTypeSelectNode.options[i].set("selected", true);
  160. break;
  161. }
  162. }
  163. for (var i=0; i<this.operateorSelectNode.options.length; i++){
  164. if (data.operateor == this.operateorSelectNode.options[i].get("value")){
  165. this.operateorSelectNode.options[i].set("selected", true);
  166. break;
  167. }
  168. }
  169. if (data.value) this.valueInputNode.set("value", data.value);
  170. if (data.prompt) this.promptInputNode.set("value", data.prompt);
  171. },
  172. deleteItem: function(item){
  173. if (this.currentItem == item) item.unSelected();
  174. this.items.erase(item);
  175. item.node.destroy();
  176. MWF.release(item);
  177. this.fireEvent("change");
  178. },
  179. getValidationData: function(){
  180. var data = [];
  181. this.items.each(function(item){
  182. data.push(item.data);
  183. });
  184. return data;
  185. }
  186. });
  187. MWF.xApplication.process.FormDesigner.widget.ScriptIncluder.Item = new Class({
  188. initialize: function(data, editor){
  189. this.data = data;
  190. this.editor = editor;
  191. this.container = this.editor.listNode;
  192. this.css = this.editor.css;
  193. this.lp = this.editor.designer.lp;
  194. this.load();
  195. },
  196. load: function(){
  197. this.node = new Element("div", {"styles": this.css.itemNode}).inject(this.container);
  198. this.deleteNode = new Element("div", {"styles": this.css.itemDeleteNode}).inject(this.node);
  199. this.contentNode = new Element("div", {"styles": this.css.itemContentNode}).inject(this.node);
  200. this.contentNode.set("text", this.getText());
  201. this.contentNode.addEvent("click", function(){
  202. this.selected();
  203. }.bind(this));
  204. this.deleteNode.addEvent("click", function(e){
  205. this.deleteItem(e);
  206. }.bind(this));
  207. },
  208. reload: function(data){
  209. this.data = data;
  210. this.contentNode.set("text", this.getText());
  211. },
  212. getText: function(){
  213. var text = "";
  214. if (this.data.status=="all"){
  215. text = this.lp.validation.anytime+" ";
  216. }else{
  217. text = this.lp.validation.when+this.lp.validation.decision+" \""+this.data.decision+"\" "+this.lp.validation.as+" ";
  218. }
  219. text += this.lp.validation[this.data.valueType]+" ";
  220. text += this.lp.validation[this.data.operateor]+" ";
  221. text += " \""+this.data.value+"\" ";
  222. text += this.lp.validation.prompt+": \""+this.data.prompt+"\"";
  223. return text;
  224. },
  225. selected: function(){
  226. if (this.editor.currentItem) this.editor.currentItem.unSelected();
  227. this.node.setStyles(this.css.itemNode_current);
  228. this.editor.currentItem = this;
  229. this.editor.setData(this.data);
  230. this.editor.enabledModify();
  231. },
  232. unSelected: function(){
  233. this.node.setStyles(this.css.itemNode);
  234. this.editor.currentItem = this;
  235. //this.editor.modifyValidation();
  236. this.editor.disabledModify();
  237. },
  238. deleteItem: function(e){
  239. var _self = this;
  240. this.editor.designer.confirm("warn", e, this.lp.validation.delete_title, this.lp.validation.delete_text, 300, 120, function(){
  241. _self.destroy();
  242. this.close();
  243. }, function(){
  244. this.close();
  245. });
  246. },
  247. destroy: function(){
  248. this.editor.deleteItem(this);
  249. }
  250. });