QueryTablePublisher.js 9.9 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223
  1. MWF.xApplication.process.ProcessDesigner.widget = MWF.xApplication.process.ProcessDesigner.widget || {};
  2. //MWF.xDesktop.requireApp("process.ProcessDesigner", "widget.ScriptText",null,false);
  3. MWF.xApplication.process.ProcessDesigner.widget.QueryTablePublisher = new Class({
  4. Implements: [Options, Events],
  5. Extends: MWF.widget.Common,
  6. options: {
  7. "style": "default"
  8. },
  9. initialize: function(node, data, options, designer){
  10. this.setOptions(options);
  11. this.node = $(node);
  12. this.data = data || [];
  13. this.name = node.get("name");
  14. this.designer = designer;
  15. this.path = "../x_component_process_ProcessDesigner/widget/$QueryTablePublisher/";
  16. this.cssPath = "../x_component_process_ProcessDesigner/widget/$QueryTablePublisher/"+this.options.style+"/css.wcss";
  17. this._loadCss();
  18. this.selectedItems = [];
  19. this.items = {};
  20. },
  21. getData: function(){
  22. return this.data;
  23. },
  24. load: function(){
  25. this.tableArea = this.node.getFirst("div");
  26. this.actionNode = this.tableArea.getNext().setStyles(this.css.actionNode).set("text", MWF.xApplication.process.ProcessDesigner.LP.propertyTemplate.querytableActionNode_add);
  27. debugger;
  28. this.tableNameSelector = this.node.getElement("[name='tableName']").retrieve("selector");
  29. this.dataByRadioList = this.node.getElements("input[type='radio']");
  30. this.dataPathInput = this.node.getElement("[name='queryTableDataPath']");
  31. this.dataScriptSelector = this.node.getElement("[name='queryTableAssignDataScript']").retrieve("selector");
  32. this.dataScriptTextEditor = this.node.getElement("[name='queryTableAssignDataScriptText']").retrieve("editor");
  33. debugger;
  34. // this.tableArea = new Element("div", {"styles": {"overflow": "hidden"}}).inject(this.node);
  35. var html = "<table cellspacing='0' cellpadding='3px' width='100%' border='0'><tr>" +
  36. "<th>"+MWF.xApplication.process.ProcessDesigner.LP.propertyTemplate.querytable+"</th>" +
  37. "<th>"+MWF.xApplication.process.ProcessDesigner.LP.propertyTemplate.queryTableDataBy+"</th>" +
  38. "<th>"+MWF.xApplication.process.ProcessDesigner.LP.propertyTemplate.dataPath+"</th>" +
  39. "<th></th>" +
  40. "</tr></table>";
  41. this.tableArea.set("html", html);
  42. this.table = this.tableArea.getElement("table").setStyles(this.css.projectionTable);
  43. this.tableArea.getElements("th").setStyles(this.css.projectionTableTitle);
  44. this.loadQuerytableList();
  45. this.actionNode.addEvent("click", this.changeQuerytableItem.bind(this));
  46. },
  47. changeQuerytableItem: function(){
  48. if (this.currentItem) {
  49. this.modifyQuerytableItem();
  50. }else{
  51. this.addQuerytableItem();
  52. }
  53. this.tableNameSelector.setData( "" );
  54. this.dataByRadioList.each(function (radio) {
  55. if( radio.value === "dataPath" ){
  56. radio.checked;
  57. radio.click();
  58. }
  59. });
  60. this.dataPathInput.set("value", "");
  61. if(this.dataScriptSelector)this.dataScriptSelector.loadValue( "" );
  62. if( this.dataScriptTextEditor && this.dataScriptTextEditor.editor ){
  63. this.dataScriptTextEditor.editor.setValue( "" );
  64. }
  65. this.designer.data.tableName = "";
  66. this.designer.data.queryTableDataBy = "dataPath";
  67. this.designer.data.queryTableDataPath = "";
  68. this.designer.data.queryTableAssignDataScript = "";
  69. this.designer.data.queryTableAssignDataScriptText = "";
  70. },
  71. checkItemData: function(obj){
  72. if (!obj.tableName ){
  73. o2.xDesktop.notice("error", {x: "right", y:"top"}, MWF.xApplication.process.ProcessDesigner.LP.propertyTemplate.querytableInputError, this.node);
  74. return false;
  75. }
  76. if( obj.queryTableDataBy === "script" && !obj.targetAssignDataScriptText ){
  77. o2.xDesktop.notice("error", {x: "right", y:"top"}, MWF.xApplication.process.ProcessDesigner.LP.propertyTemplate.queryTableAssignDataScriptError, this.node);
  78. return false;
  79. }
  80. return true;
  81. },
  82. getCurrentData: function(){
  83. var obj = {
  84. tableName: this.designer.data.tableName,
  85. queryTableDataBy: this.designer.data.queryTableDataBy || "dataPath"
  86. };
  87. if( obj.queryTableDataBy === "script" ){
  88. obj.targetAssignDataScript = this.designer.data.queryTableAssignDataScript;
  89. obj.targetAssignDataScriptText = this.designer.data.queryTableAssignDataScriptText;
  90. }else{
  91. obj.queryTableDataPath = this.designer.data.queryTableDataPath || "";
  92. }
  93. return obj;
  94. },
  95. modifyQuerytableItem: function(){
  96. var obj = this.getCurrentData();
  97. if (this.checkItemData(obj)){
  98. ["tableName","queryTableDataBy", "queryTableDataPath","targetAssignDataScript","targetAssignDataScriptText"].each(function(key){
  99. if( obj.hasOwnProperty(key) ){
  100. this.currentItem.data[key] = obj[key];
  101. }else{
  102. delete this.currentItem.data[key];
  103. }
  104. }.bind(this));
  105. this.currentItem.refresh();
  106. this.currentItem.unSelected();
  107. this.fireEvent("change");
  108. this.fireEvent("modifyItem");
  109. }
  110. },
  111. addQuerytableItem: function(){
  112. var obj = this.getCurrentData();
  113. if (this.checkItemData(obj)){
  114. this.data.push(obj);
  115. new MWF.xApplication.process.ProcessDesigner.widget.QueryTablePublisher.Item(obj, this);
  116. this.fireEvent("change");
  117. this.fireEvent("addItem");
  118. }
  119. },
  120. loadQuerytableList: function(){
  121. this.data.each(function(d){
  122. new MWF.xApplication.process.ProcessDesigner.widget.QueryTablePublisher.Item(d, this);
  123. }.bind(this));
  124. }
  125. });
  126. MWF.xApplication.process.ProcessDesigner.widget.QueryTablePublisher.Item = new Class({
  127. initialize: function(data, editor){
  128. this.editor = editor;
  129. this.data = data;
  130. this.table = this.editor.table;
  131. this.css = this.editor.css;
  132. this.load();
  133. },
  134. load: function(){
  135. var lp = MWF.xApplication.process.ProcessDesigner.LP.propertyTemplate;
  136. this.tr = new Element('tr').inject(this.table);
  137. var td = this.tr.insertCell().setStyles(this.css.projectionTableTd).set("text", this.data.tableName);
  138. td = this.tr.insertCell().setStyles(this.css.projectionTableTd).set("text", this.data.queryTableDataBy === "script" ? lp.dataScript : lp.dataPath );
  139. td = this.tr.insertCell().setStyles(this.css.projectionTableTd).set("text", this.data.queryTableDataPath);
  140. td = this.tr.insertCell().setStyles(this.css.projectionTableTd);
  141. this.delAction = new Element("div", {"styles": this.css.projectionItemAction}).inject(td);
  142. this.setEvent();
  143. },
  144. setEvent: function(){
  145. this.delAction.addEvent("click", function(e){
  146. var txt = MWF.xApplication.process.ProcessDesigner.LP.propertyTemplate.querytableDeleteItem;
  147. var _self = this;
  148. MWF.xDesktop.confirm("infor", e, MWF.xApplication.process.ProcessDesigner.LP.propertyTemplate.querytableDeleteItemTitle, txt, 300, 120, function(){
  149. _self.destroy();
  150. this.close();
  151. }, function(){
  152. this.close();
  153. }, null, null, "o2");
  154. e.stopPropagation();
  155. }.bind(this));
  156. this.tr.addEvents({
  157. "click": function(){
  158. if (this.editor.currentItem) this.editor.currentItem.unSelected();
  159. this.selected();
  160. }.bind(this)
  161. });
  162. },
  163. selected: function(){
  164. this.editor.currentItem = this;
  165. this.tr.setStyles(this.css.projectionTableTr_selected);
  166. var eData = this.editor.designer.data;
  167. eData.tableName = this.data.tableName;
  168. eData.queryTableDataBy = this.data.queryTableDataBy || "dataPath";
  169. eData.queryTableDataPath = this.data.queryTableDataPath || "";
  170. eData.queryTableAssignDataScript = this.data.targetAssignDataScript;
  171. eData.queryTableAssignDataScriptText = this.data.targetAssignDataScriptText;
  172. var editor = this.editor;
  173. editor.tableNameSelector.setData( eData.tableName );
  174. editor.dataByRadioList.each(function (radio) {
  175. if( radio.value === eData.queryTableDataBy ){
  176. radio.checked = true;
  177. radio.click();
  178. }
  179. });
  180. editor.dataPathInput.set("value", eData.queryTableDataPath || "");
  181. editor.dataScriptSelector.loadValue( eData.queryTableAssignDataScript || "");
  182. if( editor.dataScriptTextEditor && editor.dataScriptTextEditor.editor ){
  183. editor.dataScriptTextEditor.editor.setValue( eData.queryTableAssignDataScriptText || "" );
  184. }
  185. this.editor.actionNode.set("text", MWF.xApplication.process.ProcessDesigner.LP.propertyTemplate.querytableActionNode_modify);
  186. },
  187. unSelected: function(){
  188. this.editor.currentItem = null;
  189. this.tr.setStyles(this.css.projectionTableTr);
  190. this.editor.actionNode.set("text", MWF.xApplication.process.ProcessDesigner.LP.propertyTemplate.querytableActionNode_add);
  191. },
  192. refresh: function(){
  193. var lp = MWF.xApplication.process.ProcessDesigner.LP.propertyTemplate;
  194. var tds = this.tr.getElements("td");
  195. tds[0].set("text", this.data.tableName || "");
  196. tds[1].set("text", this.data.queryTableDataBy === "script" ? lp.dataScript : lp.dataPath );
  197. tds[2].set("text", this.data.queryTableDataPath || "");
  198. },
  199. destroy: function(){
  200. this.tr.destroy();
  201. this.editor.data.erase(this.data);
  202. this.editor.currentItem = null;
  203. this.editor.actionNode.set("text", MWF.xApplication.process.ProcessDesigner.LP.propertyTemplate.querytableActionNode_add);
  204. this.editor.fireEvent("change");
  205. this.editor.fireEvent("deleteItem");
  206. o2.release(this);
  207. }
  208. });