ApplicationSelector.js 9.0 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237
  1. MWF.xDesktop.requireApp("process.ApplicationExplorer", "",null,false);
  2. MWF.xApplication.process.ProcessManager.widget = MWF.xApplication.process.ProcessManager.widget || {};
  3. MWF.xApplication.process.ProcessManager.widget.ApplicationSelector = new Class({
  4. Implements: [Options, Events],
  5. Extends: MWF.widget.Common,
  6. options: {
  7. "style": "default",
  8. "multi": true,
  9. "maskNode": $(document.body)
  10. },
  11. initialize: function(app, options){
  12. this.setOptions(options);
  13. //this.node = $(node);
  14. this.app = app;
  15. this.applications = [];
  16. this.path = "../x_component_process_ProcessManager/widget/$ApplicationSelector/";
  17. this.cssPath = "../x_component_process_ProcessManager/widget/$ApplicationSelector/"+this.options.style+"/css.wcss";
  18. this._loadCss();
  19. this.selectedItems = [];
  20. },
  21. load: function(callback){
  22. this.callback = callback || null;
  23. this.loadWindow();
  24. this.loadContent();
  25. },
  26. loadWindow: function(){
  27. this.options.maskNode.mask({
  28. "destroyOnHide": true,
  29. "style": this.css.maskNode
  30. });
  31. this.windowNode = new Element("div", {"styles": this.css.containerNode});
  32. this.titleNode = new Element("div", {"styles": this.css.titleNode,}).inject(this.windowNode);
  33. this.titleActionNode = new Element("div", {"styles": this.css.titleActionNode}).inject(this.titleNode);
  34. this.titleTextNode = new Element("div", {"styles": this.css.titleTextNode,"text": "Select Application"}).inject(this.titleNode);
  35. this.titleActionNode.addEvent("click", function(){
  36. this.close();
  37. }.bind(this));
  38. this.windowContentScrollNode = new Element("div", {"styles": this.css.windowContentScrollNode}).inject(this.windowNode);
  39. this.windowContentNode = new Element("div", {"styles": this.css.windowContentNode}).inject(this.windowContentScrollNode);
  40. MWF.require("MWF.widget.DragScroll", function(){
  41. new MWF.widget.DragScroll(this.windowContentScrollNode);
  42. }.bind(this));
  43. MWF.require("MWF.widget.ScrollBar", function(){
  44. new MWF.widget.ScrollBar(this.windowContentScrollNode);
  45. }.bind(this));
  46. this.actionNode = new Element("div", {"styles": this.css.actionNode}).inject(this.windowNode);
  47. this.loadAction();
  48. this.windowNode.inject(this.options.maskNode);
  49. this.windowNode.position({
  50. relativeTo: this.options.maskNode,
  51. position: "center",
  52. edge: "center"
  53. });
  54. var size = this.options.maskNode.getSize();
  55. var nodeSize = this.windowNode.getSize();
  56. this.windowNode.makeDraggable({
  57. "handle": this.titleNode,
  58. "limit": {
  59. "x": [0, size.x-nodeSize.x],
  60. "y": [0, size.y-nodeSize.y]
  61. }
  62. });
  63. },
  64. loadAction: function(){
  65. this.cancelActionNode = new Element("button", {
  66. "styles": this.css.cancelActionNode,
  67. "text": this.app.lp.selectorButton.cancel
  68. }).inject(this.actionNode);
  69. this.okActionNode = new Element("button", {
  70. "styles": this.css.okActionNode,
  71. "text": this.app.lp.selectorButton.ok
  72. }).inject(this.actionNode);
  73. this.okActionNode.addEvent("click", function(){
  74. if (this.callback) this.callback(this.selectedItems);
  75. this.close();
  76. }.bind(this));
  77. this.cancelActionNode.addEvent("click", function(){this.close();}.bind(this));
  78. },
  79. loadContent: function(){
  80. //MWF.xDesktop.requireApp("process.ProcessManager", "Actions.RestActions", function(){
  81. this.restActions = MWF.Actions.get("x_processplatform_assemble_designer");
  82. //if (!this.restActions) this.restActions = new MWF.xApplication.process.ProcessManager.Actions.RestActions();
  83. this.restActions.listApplication("", function(json){
  84. json.data.each(function(app){
  85. var application = new MWF.xApplication.process.ProcessManager.widget.ApplicationSelector.Application(this.app, this, app);
  86. application.load();
  87. this.applications.push(application);
  88. //this.windowContentNode
  89. //var check = new Element("input", {"type": "checkbox", "value": app.id}).inject(content);
  90. //var span = new Element("span", {"text": app.name}).inject(content);
  91. }.bind(this));
  92. }.bind(this));
  93. //}.bind(this));
  94. },
  95. //selected: function(script){
  96. // this.scriptData = script.data;
  97. // this.createScriptNode(script);
  98. //
  99. // this.fireEvent("selected", [script.data]);
  100. // //this.node.set("text", script.data.name);
  101. // this.close();
  102. //},
  103. //createScriptNode: function(){
  104. // this.node.empty();
  105. //
  106. // var _self = this;
  107. // this.scriptNode = new Element("div", {
  108. // "styles": {"cursor": "pointer","color": "#0000FF"},
  109. // "text": this.scriptData.name
  110. // }).inject(this.node);
  111. // this.scriptNode.addEvent("click", function(e){this.openScript(e);}.bind(this));
  112. //},
  113. //
  114. //openScript: function(e){
  115. // var id = this.scriptData.id;
  116. // var _self = this;
  117. // var options = {
  118. // "onQueryLoad": function(){
  119. // this.actions = _self.app.actions;
  120. // this.options.id = id;
  121. // this.application = _self.app.application;
  122. // }
  123. // };
  124. // this.app.desktop.openApplication(e, "process.ScriptDesigner", options);
  125. //},
  126. clearSelected: function(){
  127. this.applications.each(function(app){
  128. if (app.selected) app.unSelectedItem();
  129. }.bind(this));
  130. },
  131. close: function(){
  132. //if (this.callback) this.callback();
  133. this.selectedItems = [];
  134. this.windowNode.destroy();
  135. this.options.maskNode.unmask();
  136. }
  137. });
  138. MWF.xApplication.process.ProcessManager.widget.ApplicationSelector.Application = new Class({
  139. Extends: MWF.xApplication.process.ApplicationExplorer.Application,
  140. Implements: [Options, Events],
  141. initialize: function(app, selector, data, options){
  142. this.setOptions(options);
  143. this.app = app;
  144. this.selector = selector;
  145. this.container = selector.windowContentNode;
  146. this.css = selector.css;
  147. this.data = data;
  148. },
  149. load: function(){
  150. this.node = new Element("div", {
  151. "styles": this.css.applicationItemNode
  152. });
  153. //this.loadTopNode();
  154. this.loadIconNode();
  155. this.loadSelectIcon();
  156. //this.loadExportAction();
  157. this.loadTitleNode();
  158. this.loadNewNode();
  159. //this.loadInforNode();
  160. //this.loadProcessNode();
  161. //this.loadFormNode();
  162. // this.loadDateNode();
  163. this.node.inject(this.container, this.options.where);
  164. },
  165. openApplication: function(){
  166. if (!this.selected){
  167. if (!this.selector.options.multi) this.selector.clearSelected();
  168. this.selectedItem();
  169. }else{
  170. //var bgcolor = this.topNode.retrieve("bgcolor");
  171. //this.topNode.setStyle("background-color", bgcolor);
  172. //this.selectIconNode.setStyles(this.css.applicationItemSelectIcon);
  173. //this.node.setStyles(this.css.applicationItemNode);
  174. //this.topNode.setStyles(this.css.applicationItemTopNode);
  175. //this.selector.selectedItems.erase(this.data);
  176. //this.selected = false;
  177. this.unSelectedItem();
  178. }
  179. },
  180. selectedItem: function(){
  181. this.selectIconNode.setStyles(this.css.applicationItemSelectIcon_selected);
  182. this.topNode.store("bgcolor", this.topNode.getStyle("background-color"));
  183. this.node.setStyles(this.css.applicationItemNode_select);
  184. this.topNode.setStyles(this.css.applicationItemTopNode_select);
  185. this.selector.selectedItems.push(this.data);
  186. this.selected = true;
  187. },
  188. unSelectedItem: function(){
  189. var bgcolor = this.topNode.retrieve("bgcolor");
  190. this.topNode.setStyle("background-color", bgcolor);
  191. this.selectIconNode.setStyles(this.css.applicationItemSelectIcon);
  192. this.node.setStyles(this.css.applicationItemNode);
  193. this.topNode.setStyles(this.css.applicationItemTopNode);
  194. this.selector.selectedItems.erase(this.data);
  195. this.selected = false;
  196. },
  197. loadSelectIcon: function(){
  198. //this.topNode.setStyle("background-color", "#666");
  199. this.selectIconNode = new Element("div", {
  200. "styles": this.css.applicationItemSelectIcon
  201. }).inject(this.topNode);
  202. //this.topNode.addEvents({
  203. // "mouseover": function(){if (!this.readyDelete) this.delAdctionNode.fade("in"); }.bind(this),
  204. // "mouseout": function(){if (!this.readyDelete) this.delAdctionNode.fade("out"); }.bind(this)
  205. //});
  206. this.selectIconNode.addEvent("click", function(e){
  207. this.checkDeleteApplication(e);
  208. e.stopPropagation();
  209. }.bind(this));
  210. },
  211. });