ScriptSelector.js 9.8 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251
  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 = MWF.Actions.get("x_organization_assemble_control");
  105. //if (!this.restActions) this.restActions = new MWF.xApplication.process.ProcessManager.Actions.RestActions();
  106. this.scriptConfigurator = new MWF.xApplication.process.ProcessDesigner.widget.ScriptSelector.ScriptExplorer(this.windowContentNode, this.app.actions);
  107. this.scriptConfigurator.app = this.app;
  108. this.scriptConfigurator.window = this;
  109. this.scriptConfigurator.load();
  110. //}.bind(this));
  111. //this.scriptListNode = new Element("div", {"styles": this.css.scriptListNode}).inject(this.windowContentNode);
  112. //this.scriptContentNode = new Element("div", {"styles": this.css.scriptContentNode}).inject(this.windowContentNode);
  113. },
  114. selected: function(script){
  115. this.scriptData = script.data;
  116. this.createScriptNode(script);
  117. this.fireEvent("selected", [script.data]);
  118. //this.node.set("text", script.data.name);
  119. this.close();
  120. },
  121. createScriptNode: function(){
  122. this.node.empty();
  123. var _self = this;
  124. this.scriptNode = new Element("div", {
  125. "styles": {"cursor": "pointer","color": "#0000FF"},
  126. "text": this.scriptData.name
  127. }).inject(this.node);
  128. this.scriptNode.addEvent("click", function(e){this.openScript(e);}.bind(this));
  129. },
  130. openScript: function(e){
  131. var id = this.scriptData.id;
  132. var _self = this;
  133. var options = {
  134. "onQueryLoad": function(){
  135. this.actions = _self.app.actions;
  136. this.options.id = id;
  137. this.application = _self.app.application;
  138. }
  139. };
  140. this.app.desktop.openApplication(e, "process.ScriptDesigner", options);
  141. },
  142. close: function(){
  143. this.windowNode.destroy();
  144. this.options.maskNode.unmask();
  145. },
  146. });
  147. MWF.xDesktop.requireApp("process.ProcessManager", "ScriptExplorer", null, false);
  148. MWF.xApplication.process.ProcessDesigner.widget.ScriptSelector.ScriptExplorer = new Class({
  149. Extends: MWF.xApplication.process.ProcessManager.ScriptExplorer,
  150. loadToolbar: function(){
  151. this.toolbarNode = new Element("div", {"styles": this.css.toolbarNode});
  152. this.toolbarNode.setStyle("height", "40px");
  153. this.createCreateElementNode();
  154. this.createElementNode.setStyles({"height": "40px", "width": "40px"});
  155. this.toolbarNode.inject(this.node);
  156. },
  157. loadContentNode: function(){
  158. this.elementContentNode = new Element("div", {
  159. "styles": this.css.elementContentNode
  160. }).inject(this.node);
  161. this.elementContentListNode = new Element("div", {
  162. "styles": this.css.elementContentListNode
  163. }).inject(this.elementContentNode);
  164. this.setContentSize();
  165. //this.app.addEvent("resize", function(){this.setContentSize();}.bind(this));
  166. },
  167. _getItemObject: function(item){
  168. return new MWF.xApplication.process.ProcessDesigner.widget.ScriptSelector.ScriptExplorer.Script(this, item)
  169. },
  170. });
  171. MWF.xApplication.process.ProcessDesigner.widget.ScriptSelector.ScriptExplorer.Script = new Class({
  172. Extends: MWF.xApplication.process.ProcessManager.ScriptExplorer.Script,
  173. _open: function(e){
  174. var _self = this;
  175. var options = {
  176. "onQueryLoad": function(){
  177. this.actions = _self.explorer.actions;
  178. this.category = _self;
  179. this.options.id = _self.data.id;
  180. this.application = _self.explorer.app.application;
  181. this.explorer = _self.explorer
  182. }
  183. };
  184. this.explorer.app.desktop.openApplication(e, "process.ScriptDesigner", options);
  185. },
  186. _getLnkPar: function(){
  187. return {
  188. "icon": this.explorer.path+this.explorer.options.style+"/scriptIcon/lnk.png",
  189. "title": this.data.name,
  190. "par": "process.ScriptDesigner#{\"id\": \""+this.data.id+"\", \"applicationId\": \""+this.explorer.app.application.id+"\"}"
  191. };
  192. },
  193. _customNodes: function(){
  194. if (!this.data.validated){
  195. new Element("div", {"styles": this.explorer.css.itemErrorNode}).inject(this.node);
  196. this.node.setStyle("background-color", "#f9e8e8");
  197. }
  198. this.node.setStyle("cursor", "pointer");
  199. this.nodeColor = this.node.getStyle("background-color");
  200. var _self = this;
  201. this.node.removeEvents("mouseover");
  202. this.node.removeEvents("mouseout");
  203. this.node.addEvents({
  204. "mouseover": function(){this.setStyle("background-color", "#dcdcdc");},
  205. "mouseout": function(){this.setStyle("background-color", _self.nodeColor);},
  206. "click": function(){this.selected();}.bind(this)
  207. });
  208. var inforNode = new Element("div", {"styles": {
  209. "font-size": "14px"
  210. }, "text": this.explorer.app.lp.selectScript+this.data.name+" ("+this.data.alias+") "});
  211. new mBox.Tooltip({
  212. theme: 'BlackGradient',
  213. content: inforNode,
  214. offset: {x: 0, y:0},
  215. setStyles: {content: {padding: 10, lineHeight: 20}},
  216. attach: this.node,
  217. transition: 'flyin'
  218. });
  219. },
  220. selected: function(){
  221. this.explorer.window.selected(this);
  222. }
  223. });