ProjectionEditor.js 10 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237
  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></th>" +
  48. "</tr></table>";
  49. this.tableArea.set("html", html);
  50. this.table = this.tableArea.getElement("table").setStyles(this.css.projectionTable);
  51. this.tableArea.getElements("th").setStyles(this.css.projectionTableTitle);
  52. this.runAction = new Element("div", {"styles": this.css.actionNode, "text": MWF.xApplication.process.ProcessDesigner.LP.projectionRunActionNode}).inject(this.node);
  53. this.loadProjectionList();
  54. // //this.loadProjectionCreate();
  55. //
  56. //
  57. // this.actionNode = new Element("div", {"styles": this.css.actionNode, "text": MWF.xApplication.process.ProcessDesigner.LP.projectionActionNode}).inject(this.node);
  58. this.actionNode.addEvent("click", this.changeProjectionItem.bind(this));
  59. this.runAction.addEvent("click", function(e){
  60. var _self = this;
  61. MWF.xDesktop.confirm("infor", e, MWF.xApplication.process.ProcessDesigner.LP.projectionRunTitle, MWF.xApplication.process.ProcessDesigner.LP.projectionRunText, 300, 120, function(){
  62. _self.runProjection();
  63. this.close();
  64. }, function(){
  65. this.close();
  66. }, null, null, "o2");
  67. }.bind(this));
  68. //
  69. // this.selectNode = new Element("div", {"styles": this.css.selectNode}).inject(this.node);
  70. //
  71. // this.downNode = new Element("div", {"styles": this.css.downNode}).inject(this.node);
  72. //
  73. // this.previewNode = new Element("div", {"styles": this.css.previewNode}).inject(this.node);
  74. // this.showNode = new Element("div", {"styles": this.css.showNode}).inject(this.node);
  75. //
  76. // this.propertyNode = new Element("div", {"styles": this.css.propertyNode}).inject(this.node);
  77. //
  78. // this.loadSelectNode();
  79. // this.loadSerialActivity();
  80. },
  81. runProjection: function(){
  82. o2.Actions.get("x_processplatform_assemble_designer").executeProjection(this.options.process, null, function(json){
  83. if (json.data.value){
  84. o2.xDesktop.notice("success", {x: "right", y:"top"}, MWF.xApplication.process.ProcessDesigner.LP.projectionRunSuccess, this.node);
  85. }else{
  86. o2.xDesktop.notice("error", {x: "right", y:"top"}, MWF.xApplication.process.ProcessDesigner.LP.projectionRunError, this.node);
  87. }
  88. });
  89. },
  90. changeProjectionItem: function(){
  91. if (this.currentItem) {
  92. this.modifyProjectionItem();
  93. }else{
  94. this.addProjectionItem();
  95. }
  96. },
  97. checkItemData: function(name, path, type){
  98. if (!name || !path){
  99. o2.xDesktop.notice("error", {x: "right", y:"top"}, MWF.xApplication.process.ProcessDesigner.LP.projectionInputError, this.node);
  100. return false;
  101. }
  102. var count = 0;
  103. for (var i=0; i<this.data.length; i++){
  104. if (this.data[i].type===type) count++;
  105. if (count>=this.options.maxTypeCount[type]){
  106. var txt = MWF.xApplication.process.ProcessDesigner.LP.projectionTypeCountError;
  107. txt = txt.replace(/{type}/g, type);
  108. txt = txt.replace(/{count}/g, this.options.maxTypeCount[type]);
  109. o2.xDesktop.notice("error", {x: "right", y:"top"}, txt, this.node);
  110. return false;
  111. }
  112. if (this.data[i].name===name && (!this.currentItem || this.data[i]!=this.currentItem.data)) {
  113. o2.xDesktop.notice("error", {x: "right", y:"top"}, MWF.xApplication.process.ProcessDesigner.LP.projectionSameNameError, this.node);
  114. return false;
  115. }
  116. }
  117. return true;
  118. },
  119. modifyProjectionItem: function(){
  120. var name = this.nameInput.get("value");
  121. var path = this.pathInput.get("value");
  122. var type = this.typeSelect.options[this.typeSelect.selectedIndex].value;
  123. if (this.checkItemData(name, path, type)){
  124. this.currentItem.data.name = name;
  125. this.currentItem.data.path = path;
  126. this.currentItem.data.type = type;
  127. this.currentItem.refresh();
  128. this.currentItem.unSelected();
  129. this.fireEvent("change");
  130. this.fireEvent("modifyItem");
  131. }
  132. },
  133. addProjectionItem: function(){
  134. var name = this.nameInput.get("value");
  135. var path = this.pathInput.get("value");
  136. var type = this.typeSelect.options[this.typeSelect.selectedIndex].value;
  137. if (this.checkItemData(name, path, type)){
  138. var o = { "name": name, "path": path, "type": type };
  139. this.data.push(o);
  140. new MWF.xApplication.process.ProcessDesigner.widget.ProjectionEditor.Item(o, this);
  141. this.fireEvent("change");
  142. this.fireEvent("addItem");
  143. }
  144. },
  145. loadProjectionList: function(){
  146. this.data.each(function(d){
  147. new MWF.xApplication.process.ProcessDesigner.widget.ProjectionEditor.Item(d, this);
  148. }.bind(this));
  149. }
  150. });
  151. MWF.xApplication.process.ProcessDesigner.widget.ProjectionEditor.Item = new Class({
  152. initialize: function(data, editor){
  153. this.editor = editor;
  154. this.data = data;
  155. this.table = this.editor.table;
  156. this.css = this.editor.css;
  157. this.load();
  158. },
  159. load: function(){
  160. this.tr = new Element('tr').inject(this.table);
  161. var td = this.tr.insertCell().setStyles(this.css.projectionTableTd).set("text", this.data.name);
  162. td = this.tr.insertCell().setStyles(this.css.projectionTableTd).set("text", this.data.path);
  163. td = this.tr.insertCell().setStyles(this.css.projectionTableTd).set("text", this.data.type);
  164. td = this.tr.insertCell().setStyles(this.css.projectionTableTd);
  165. this.delAction = new Element("div", {"styles": this.css.projectionItemAction}).inject(td);
  166. this.setEvent();
  167. },
  168. setEvent: function(){
  169. this.delAction.addEvent("click", function(e){
  170. var txt = MWF.xApplication.process.ProcessDesigner.LP.projectionDeleteItem;
  171. txt = txt.replace(/{name}/g, this.data.name);
  172. txt = txt.replace(/{path}/g, this.data.path);
  173. var _self = this;
  174. MWF.xDesktop.confirm("infor", e, MWF.xApplication.process.ProcessDesigner.LP.projectionDeleteItemTitle, txt, 300, 120, function(){
  175. _self.destroy();
  176. this.close();
  177. }, function(){
  178. this.close();
  179. }, null, null, "o2");
  180. }.bind(this));
  181. this.tr.addEvents({
  182. "click": function(){
  183. if (this.editor.currentItem) this.editor.currentItem.unSelected();
  184. this.selected();
  185. }.bind(this)
  186. })
  187. },
  188. selected: function(){
  189. this.editor.currentItem = this;
  190. this.tr.setStyles(this.css.projectionTableTr_selected);
  191. this.editor.nameInput.set("value", this.data.name);
  192. this.editor.pathInput.set("value", this.data.path);
  193. var ops = this.editor.typeSelect.options;
  194. for (var i=0; i<ops.length; i++){
  195. if (ops[i].value===this.data.type){
  196. ops[i].set("selected", true);
  197. break;
  198. }
  199. }
  200. this.editor.actionNode.set("text", MWF.xApplication.process.ProcessDesigner.LP.projectionActionNode_modify);
  201. },
  202. unSelected: function(){
  203. this.editor.currentItem = null;
  204. this.tr.setStyles(this.css.projectionTableTr);
  205. this.editor.actionNode.set("text", MWF.xApplication.process.ProcessDesigner.LP.projectionActionNode_add);
  206. },
  207. refresh: function(){
  208. var tds = this.tr.getElements("td");
  209. tds[0].set("text", this.data.name);
  210. tds[1].set("text", this.data.path);
  211. tds[2].set("text", this.data.type);
  212. },
  213. destroy: function(){
  214. this.tr.destroy();
  215. this.editor.data.erase(this.data);
  216. this.editor.fireEvent("change");
  217. this.editor.fireEvent("deleteItem");
  218. o2.release(this);
  219. }
  220. });