ScriptSelector.js 9.7 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250
  1. MWF.xApplication.process.ProcessDesigner.widget = MWF.xApplication.process.ProcessDesigner.widget || {};
  2. MWF.xApplication.process.ProcessDesigner.widget.ScriptSelector = new Class({
  3. Implements: [Options, Events],
  4. Extends: MWF.widget.Common,
  5. options: {
  6. "style": "default",
  7. "maskNode": $(document.body)
  8. },
  9. initialize: function(node, script, app, options){
  10. this.setOptions(options);
  11. this.node = $(node);
  12. this.app = app;
  13. this.script = script;
  14. this.path = "/x_component_process_ProcessDesigner/widget/$ScriptSelector/";
  15. this.cssPath = "/x_component_process_ProcessDesigner/widget/$ScriptSelector/"+this.options.style+"/css.wcss";
  16. this._loadCss();
  17. this.selNode = new Element("div", {"styles": this.css.selScriptNode}).inject(this.node, "before");
  18. this.delNode = new Element("div", {"styles": this.css.delScriptNode}).inject(this.node, "before");
  19. //this.selNode = new Element("div", {"styles": this.css.selScriptNode, "text": "选择"}).inject(this.node, "before");
  20. this.node.setStyles(this.css.contentNode);
  21. //this.node.set("text", script||"");
  22. this.loadValue(script);
  23. //this.createEditor();
  24. //this.addNode.addEvent("click", function(e){
  25. // this.addScript();
  26. //}.bind(this));
  27. this.selNode.addEvent("click", function(e){
  28. this.editScript();
  29. }.bind(this));
  30. this.delNode.addEvent("click", function(e){
  31. this.delScript();
  32. }.bind(this));
  33. },
  34. loadValue: function(script){
  35. if (script && script.toString()){
  36. this.app.actions.getScriptByName(script, this.app.application.id, function(json){
  37. this.scriptData = json.data;
  38. this.createScriptNode(script);
  39. }.bind(this));
  40. }
  41. },
  42. //createEditor: function(){
  43. // this.editorNode = new Element("div", {"styles": this.css.editorNode}).inject(this.node, "after");
  44. // MWF.require("MWF.widget.JavascriptEditor", function(){
  45. // this.editor = new MWF.widget.JavascriptEditor(this.editorNode);
  46. // this.editor.load();
  47. // }.bind(this));
  48. //},
  49. delScript: function(){
  50. this.fireEvent("delete");
  51. },
  52. editScript: function(){
  53. this.loadWindow();
  54. this.loadContent();
  55. },
  56. loadWindow: function(){
  57. this.options.maskNode.mask({
  58. "destroyOnHide": true,
  59. "style": this.css.maskNode
  60. });
  61. this.windowNode = new Element("div", {"styles": this.css.containerNode});
  62. this.titleNode = new Element("div", {"styles": this.css.titleNode,}).inject(this.windowNode);
  63. this.titleActionNode = new Element("div", {"styles": this.css.titleActionNode}).inject(this.titleNode);
  64. this.titleTextNode = new Element("div", {"styles": this.css.titleTextNode,"text": "Select Script"}).inject(this.titleNode);
  65. this.titleActionNode.addEvent("click", function(){
  66. this.close();
  67. }.bind(this));
  68. this.windowContentNode = new Element("div", {"styles": this.css.windowContentNode}).inject(this.windowNode);
  69. //this.actionNode = new Element("div", {"styles": this.css.actionNode}).inject(this.windowNode);
  70. //this.loadAction();
  71. this.windowNode.inject(this.options.maskNode);
  72. this.windowNode.position({
  73. relativeTo: this.options.maskNode,
  74. position: "center",
  75. edge: "center"
  76. });
  77. var size = this.options.maskNode.getSize();
  78. var nodeSize = this.windowNode.getSize();
  79. this.windowNode.makeDraggable({
  80. "handle": this.titleNode,
  81. "limit": {
  82. "x": [0, size.x-nodeSize.x],
  83. "y": [0, size.y-nodeSize.y]
  84. }
  85. });
  86. },
  87. loadAction: function(){
  88. this.okActionNode = new Element("button", {
  89. "styles": this.css.okActionNode,
  90. "text": "确 定"
  91. }).inject(this.actionNode);
  92. this.cancelActionNode = new Element("button", {
  93. "styles": this.css.cancelActionNode,
  94. "text": "取 消"
  95. }).inject(this.actionNode);
  96. this.okActionNode.addEvent("click", function(){
  97. this.fireEvent("complete", [this.selectedItems]);
  98. this.close();
  99. }.bind(this));
  100. this.cancelActionNode.addEvent("click", function(){this.close();}.bind(this));
  101. },
  102. loadContent: function(){
  103. MWF.xDesktop.requireApp("process.ProcessManager", "Actions.RestActions", function(){
  104. if (!this.restActions) this.restActions = new MWF.xApplication.process.ProcessManager.Actions.RestActions();
  105. this.scriptConfigurator = new MWF.xApplication.process.ProcessDesigner.widget.ScriptSelector.ScriptExplorer(this.windowContentNode, this.app.actions);
  106. this.scriptConfigurator.app = this.app;
  107. this.scriptConfigurator.window = this;
  108. this.scriptConfigurator.load();
  109. }.bind(this));
  110. //this.scriptListNode = new Element("div", {"styles": this.css.scriptListNode}).inject(this.windowContentNode);
  111. //this.scriptContentNode = new Element("div", {"styles": this.css.scriptContentNode}).inject(this.windowContentNode);
  112. },
  113. selected: function(script){
  114. this.scriptData = script.data;
  115. this.createScriptNode(script);
  116. this.fireEvent("selected", [script.data]);
  117. //this.node.set("text", script.data.name);
  118. this.close();
  119. },
  120. createScriptNode: function(){
  121. this.node.empty();
  122. var _self = this;
  123. this.scriptNode = new Element("div", {
  124. "styles": {"cursor": "pointer","color": "#0000FF"},
  125. "text": this.scriptData.name
  126. }).inject(this.node);
  127. this.scriptNode.addEvent("click", function(e){this.openScript(e);}.bind(this));
  128. },
  129. openScript: function(e){
  130. var id = this.scriptData.id;
  131. var _self = this;
  132. var options = {
  133. "onQueryLoad": function(){
  134. this.actions = _self.app.actions;
  135. this.options.id = id;
  136. this.application = _self.app.application;
  137. }
  138. };
  139. this.app.desktop.openApplication(e, "process.ScriptDesigner", options);
  140. },
  141. close: function(){
  142. this.windowNode.destroy();
  143. this.options.maskNode.unmask();
  144. },
  145. });
  146. MWF.xDesktop.requireApp("process.ProcessManager", "ScriptExplorer", null, false);
  147. MWF.xApplication.process.ProcessDesigner.widget.ScriptSelector.ScriptExplorer = new Class({
  148. Extends: MWF.xApplication.process.ProcessManager.ScriptExplorer,
  149. loadToolbar: function(){
  150. this.toolbarNode = new Element("div", {"styles": this.css.toolbarNode});
  151. this.toolbarNode.setStyle("height", "40px");
  152. this.createCreateElementNode();
  153. this.createElementNode.setStyles({"height": "40px", "width": "40px"});
  154. this.toolbarNode.inject(this.node);
  155. },
  156. loadContentNode: function(){
  157. this.elementContentNode = new Element("div", {
  158. "styles": this.css.elementContentNode
  159. }).inject(this.node);
  160. this.elementContentListNode = new Element("div", {
  161. "styles": this.css.elementContentListNode
  162. }).inject(this.elementContentNode);
  163. this.setContentSize();
  164. //this.app.addEvent("resize", function(){this.setContentSize();}.bind(this));
  165. },
  166. _getItemObject: function(item){
  167. return new MWF.xApplication.process.ProcessDesigner.widget.ScriptSelector.ScriptExplorer.Script(this, item)
  168. },
  169. });
  170. MWF.xApplication.process.ProcessDesigner.widget.ScriptSelector.ScriptExplorer.Script = new Class({
  171. Extends: MWF.xApplication.process.ProcessManager.ScriptExplorer.Script,
  172. _open: function(e){
  173. var _self = this;
  174. var options = {
  175. "onQueryLoad": function(){
  176. this.actions = _self.explorer.actions;
  177. this.category = _self;
  178. this.options.id = _self.data.id;
  179. this.application = _self.explorer.app.application;
  180. this.explorer = _self.explorer
  181. }
  182. };
  183. this.explorer.app.desktop.openApplication(e, "process.ScriptDesigner", options);
  184. },
  185. _getLnkPar: function(){
  186. return {
  187. "icon": this.explorer.path+this.explorer.options.style+"/scriptIcon/lnk.png",
  188. "title": this.data.name,
  189. "par": "process.ScriptDesigner#{\"id\": \""+this.data.id+"\", \"applicationId\": \""+this.explorer.app.application.id+"\"}"
  190. };
  191. },
  192. _customNodes: function(){
  193. if (!this.data.validated){
  194. new Element("div", {"styles": this.explorer.css.itemErrorNode}).inject(this.node);
  195. this.node.setStyle("background-color", "#f9e8e8");
  196. }
  197. this.node.setStyle("cursor", "pointer");
  198. this.nodeColor = this.node.getStyle("background-color");
  199. var _self = this;
  200. this.node.removeEvents("mouseover");
  201. this.node.removeEvents("mouseout");
  202. this.node.addEvents({
  203. "mouseover": function(){this.setStyle("background-color", "#dcdcdc");},
  204. "mouseout": function(){this.setStyle("background-color", _self.nodeColor);},
  205. "click": function(){this.selected();}.bind(this)
  206. });
  207. var inforNode = new Element("div", {"styles": {
  208. "font-size": "14px"
  209. }, "text": this.explorer.app.lp.selectScript+this.data.name+" ("+this.data.alias+") "});
  210. new mBox.Tooltip({
  211. theme: 'BlackGradient',
  212. content: inforNode,
  213. offset: {x: 0, y:0},
  214. setStyles: {content: {padding: 10, lineHeight: 20}},
  215. attach: this.node,
  216. transition: 'flyin'
  217. });
  218. },
  219. selected: function(){
  220. this.explorer.window.selected(this);
  221. }
  222. });