ProjectionEditor.js 11 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251252253254255256257258259260261262263264265266267268269270
  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.ProjectionEditor = new Class({
  4. Implements: [Options, Events],
  5. Extends: MWF.widget.Common,
  6. options: {
  7. "style": "default",
  8. "maxTypeCount": {
  9. "string": 10,
  10. "long": 5,
  11. "double": 5,
  12. "boolean": 2,
  13. "date":2,
  14. "time": 2,
  15. "dateTime": 5
  16. }
  17. },
  18. initialize: function(node, text, options){
  19. this.setOptions(options);
  20. this.node = $(node);
  21. this.data = (text) ? JSON.decode(text) : [];
  22. this.name = node.get("name");
  23. this.path = "../x_component_process_ProcessDesigner/widget/$ProjectionEditor/";
  24. this.cssPath = "../x_component_process_ProcessDesigner/widget/$ProjectionEditor/"+this.options.style+"/css.wcss";
  25. this._loadCss();
  26. this.selectedItems = [];
  27. this.items = {};
  28. },
  29. getData: function(){
  30. return this.data;
  31. },
  32. load: function(){
  33. this.titleNode = this.node.getFirst("div").setStyles(this.css.titleNode).set("text", MWF.xApplication.process.ProcessDesigner.LP.projectionTitle);
  34. // this.titleNode = new Element("div", {"styles": this.css.titleNode}).inject(this.node);
  35. // this.titleNode.set("text", MWF.xApplication.process.ProcessDesigner.LP.projectionTitle);
  36. this.tableArea = this.node.getLast("div");
  37. this.actionNode = this.tableArea.getPrevious().setStyles(this.css.actionNode).set("text", MWF.xApplication.process.ProcessDesigner.LP.projectionActionNode_add);
  38. var inputs = this.node.getElements("input");
  39. this.nameInput = inputs[0];
  40. this.pathInput = inputs[1];
  41. this.typeSelect = this.node.getElement("select");
  42. // this.tableArea = new Element("div", {"styles": {"overflow": "hidden"}}).inject(this.node);
  43. var html = "<table cellspacing='0' cellpadding='3px' width='100%' border='0'><tr>" +
  44. "<th>"+MWF.xApplication.process.ProcessDesigner.LP.projectionDataName+"</th>" +
  45. "<th>"+MWF.xApplication.process.ProcessDesigner.LP.projectionPath+"</th>" +
  46. "<th>"+MWF.xApplication.process.ProcessDesigner.LP.projectionType+"</th>" +
  47. "<th>"+MWF.xApplication.process.ProcessDesigner.LP.projectionName+"</th>" +
  48. "<th></th>" +
  49. "</tr></table>";
  50. this.tableArea.set("html", html);
  51. this.table = this.tableArea.getElement("table").setStyles(this.css.projectionTable);
  52. this.tableArea.getElements("th").setStyles(this.css.projectionTableTitle);
  53. this.runAction = new Element("div.mainColor_bg", {"styles": this.css.actionNode, "text": MWF.xApplication.process.ProcessDesigner.LP.projectionRunActionNode}).inject(this.node);
  54. this.loadProjectionList();
  55. // //this.loadProjectionCreate();
  56. //
  57. //
  58. // this.actionNode = new Element("div", {"styles": this.css.actionNode, "text": MWF.xApplication.process.ProcessDesigner.LP.projectionActionNode}).inject(this.node);
  59. this.actionNode.addEvent("click", this.changeProjectionItem.bind(this));
  60. this.runAction.addEvent("click", function(e){
  61. var _self = this;
  62. MWF.xDesktop.confirm("infor", e, MWF.xApplication.process.ProcessDesigner.LP.projectionRunTitle, MWF.xApplication.process.ProcessDesigner.LP.projectionRunText, 300, 120, function(){
  63. _self.runProjection();
  64. this.close();
  65. }, function(){
  66. this.close();
  67. }, null, null, "o2");
  68. }.bind(this));
  69. //
  70. // this.selectNode = new Element("div", {"styles": this.css.selectNode}).inject(this.node);
  71. //
  72. // this.downNode = new Element("div", {"styles": this.css.downNode}).inject(this.node);
  73. //
  74. // this.previewNode = new Element("div", {"styles": this.css.previewNode}).inject(this.node);
  75. // this.showNode = new Element("div", {"styles": this.css.showNode}).inject(this.node);
  76. //
  77. // this.propertyNode = new Element("div", {"styles": this.css.propertyNode}).inject(this.node);
  78. //
  79. // this.loadSelectNode();
  80. // this.loadSerialActivity();
  81. },
  82. runProjection: function(){
  83. o2.Actions.get("x_processplatform_assemble_designer").executeProjection(this.options.process, null, function(json){
  84. if (json.data.value){
  85. o2.xDesktop.notice("success", {x: "right", y:"top"}, MWF.xApplication.process.ProcessDesigner.LP.projectionRunSuccess, this.node);
  86. }else{
  87. o2.xDesktop.notice("error", {x: "right", y:"top"}, MWF.xApplication.process.ProcessDesigner.LP.projectionRunError, this.node);
  88. }
  89. });
  90. },
  91. changeProjectionItem: function(){
  92. if (this.currentItem) {
  93. this.modifyProjectionItem();
  94. }else{
  95. this.addProjectionItem();
  96. }
  97. },
  98. checkItemData: function(name, path, type){
  99. if (!name || !path){
  100. o2.xDesktop.notice("error", {x: "right", y:"top"}, MWF.xApplication.process.ProcessDesigner.LP.projectionInputError, this.node);
  101. return false;
  102. }
  103. var count = 0;
  104. for (var i=0; i<this.data.length; i++){
  105. if (this.data[i].type===type) count++;
  106. if (count>=this.options.maxTypeCount[type]){
  107. var txt = MWF.xApplication.process.ProcessDesigner.LP.projectionTypeCountError;
  108. txt = txt.replace(/{type}/g, type);
  109. txt = txt.replace(/{count}/g, this.options.maxTypeCount[type]);
  110. o2.xDesktop.notice("error", {x: "right", y:"top"}, txt, this.node);
  111. return false;
  112. }
  113. if (this.data[i].name===name && (!this.currentItem || this.data[i]!=this.currentItem.data)) {
  114. o2.xDesktop.notice("error", {x: "right", y:"top"}, MWF.xApplication.process.ProcessDesigner.LP.projectionSameNameError, this.node);
  115. return false;
  116. }
  117. }
  118. return true;
  119. },
  120. checkItemColumn: function(){
  121. var columnNames = {
  122. "string": 0,
  123. "long": 0,
  124. "double": 0,
  125. "boolean": 0,
  126. "date":0,
  127. "time": 0,
  128. "dateTime": 0
  129. };
  130. var rows = this.table.rows;
  131. for (var i=0; i<this.data.length; i++){
  132. columnNames[this.data[i].type]++;
  133. var n = columnNames[this.data[i].type] || 1;
  134. var c = this.data[i].type+"Value"+(n>=10 ? n : "0"+n);
  135. rows[i+1].cells[3].set("text", c);
  136. }
  137. },
  138. modifyProjectionItem: function(){
  139. var name = this.nameInput.get("value");
  140. var path = this.pathInput.get("value");
  141. var type = this.typeSelect.options[this.typeSelect.selectedIndex].value;
  142. if (this.checkItemData(name, path, type)){
  143. this.currentItem.data.name = name;
  144. this.currentItem.data.path = path;
  145. this.currentItem.data.type = type;
  146. this.currentItem.refresh();
  147. this.currentItem.unSelected();
  148. this.checkItemColumn();
  149. this.fireEvent("change");
  150. this.fireEvent("modifyItem");
  151. }
  152. },
  153. addProjectionItem: function(){
  154. var name = this.nameInput.get("value");
  155. var path = this.pathInput.get("value");
  156. var type = this.typeSelect.options[this.typeSelect.selectedIndex].value;
  157. if (this.checkItemData(name, path, type)){
  158. var o = { "name": name, "path": path, "type": type };
  159. this.data.push(o);
  160. new MWF.xApplication.process.ProcessDesigner.widget.ProjectionEditor.Item(o, this);
  161. this.checkItemColumn();
  162. this.fireEvent("change");
  163. this.fireEvent("addItem");
  164. }
  165. },
  166. loadProjectionList: function(){
  167. this.data.each(function(d){
  168. new MWF.xApplication.process.ProcessDesigner.widget.ProjectionEditor.Item(d, this);
  169. }.bind(this));
  170. this.checkItemColumn();
  171. }
  172. });
  173. MWF.xApplication.process.ProcessDesigner.widget.ProjectionEditor.Item = new Class({
  174. initialize: function(data, editor){
  175. this.editor = editor;
  176. this.data = data;
  177. this.table = this.editor.table;
  178. this.css = this.editor.css;
  179. this.load();
  180. },
  181. load: function(){
  182. this.tr = new Element('tr').inject(this.table);
  183. var td = this.tr.insertCell().setStyles(this.css.projectionTableTd).set("text", this.data.name);
  184. td = this.tr.insertCell().setStyles(this.css.projectionTableTd).set("text", this.data.path);
  185. td = this.tr.insertCell().setStyles(this.css.projectionTableTd).set("text", this.data.type);
  186. td = this.tr.insertCell().setStyles(this.css.projectionTableTd).set("text", this.data.type);
  187. td = this.tr.insertCell().setStyles(this.css.projectionTableTd);
  188. this.delAction = new Element("div", {"styles": this.css.projectionItemAction}).inject(td);
  189. this.setEvent();
  190. },
  191. setEvent: function(){
  192. this.delAction.addEvent("click", function(e){
  193. var txt = MWF.xApplication.process.ProcessDesigner.LP.projectionDeleteItem;
  194. txt = txt.replace(/{name}/g, this.data.name);
  195. txt = txt.replace(/{path}/g, this.data.path);
  196. var _self = this;
  197. MWF.xDesktop.confirm("infor", e, MWF.xApplication.process.ProcessDesigner.LP.projectionDeleteItemTitle, txt, 300, 120, function(){
  198. _self.destroy();
  199. this.close();
  200. }, function(){
  201. this.close();
  202. }, null, null, "o2");
  203. }.bind(this));
  204. this.tr.addEvents({
  205. "click": function(){
  206. var item = this.editor.currentItem;
  207. if (item) item.unSelected();
  208. if (item!==this) this.selected();
  209. }.bind(this)
  210. })
  211. },
  212. selected: function(){
  213. this.editor.currentItem = this;
  214. this.tr.setStyles(this.css.projectionTableTr_selected);
  215. this.editor.nameInput.set("value", this.data.name);
  216. this.editor.pathInput.set("value", this.data.path);
  217. var ops = this.editor.typeSelect.options;
  218. for (var i=0; i<ops.length; i++){
  219. if (ops[i].value===this.data.type){
  220. ops[i].set("selected", true);
  221. break;
  222. }
  223. }
  224. this.editor.actionNode.set("text", MWF.xApplication.process.ProcessDesigner.LP.projectionActionNode_modify);
  225. },
  226. unSelected: function(){
  227. this.editor.currentItem = null;
  228. this.tr.setStyles(this.css.projectionTableTr);
  229. this.editor.actionNode.set("text", MWF.xApplication.process.ProcessDesigner.LP.projectionActionNode_add);
  230. },
  231. refresh: function(){
  232. var tds = this.tr.getElements("td");
  233. tds[0].set("text", this.data.name);
  234. tds[1].set("text", this.data.path);
  235. tds[2].set("text", this.data.type);
  236. },
  237. destroy: function(){
  238. this.unSelected();
  239. this.tr.destroy();
  240. this.editor.data.erase(this.data);
  241. this.editor.checkItemColumn();
  242. this.editor.fireEvent("change");
  243. this.editor.fireEvent("deleteItem");
  244. o2.release(this);
  245. }
  246. });