ScriptSelector.js 9.9 KB

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