ApplicationSelector.js 8.9 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236
  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. if (!this.restActions) this.restActions = MWF.Actions.get("x_processplatform_assemble_designer");
  82. this.restActions.listApplication("", function(json){
  83. json.data.each(function(app){
  84. var application = new MWF.xApplication.process.ProcessManager.widget.ApplicationSelector.Application(this.app, this, app);
  85. application.load();
  86. this.applications.push(application);
  87. //this.windowContentNode
  88. //var check = new Element("input", {"type": "checkbox", "value": app.id}).inject(content);
  89. //var span = new Element("span", {"text": app.name}).inject(content);
  90. }.bind(this));
  91. }.bind(this));
  92. //}.bind(this));
  93. },
  94. //selected: function(script){
  95. // this.scriptData = script.data;
  96. // this.createScriptNode(script);
  97. //
  98. // this.fireEvent("selected", [script.data]);
  99. // //this.node.set("text", script.data.name);
  100. // this.close();
  101. //},
  102. //createScriptNode: function(){
  103. // this.node.empty();
  104. //
  105. // var _self = this;
  106. // this.scriptNode = new Element("div", {
  107. // "styles": {"cursor": "pointer","color": "#0000FF"},
  108. // "text": this.scriptData.name
  109. // }).inject(this.node);
  110. // this.scriptNode.addEvent("click", function(e){this.openScript(e);}.bind(this));
  111. //},
  112. //
  113. //openScript: function(e){
  114. // var id = this.scriptData.id;
  115. // var _self = this;
  116. // var options = {
  117. // "onQueryLoad": function(){
  118. // this.actions = _self.app.actions;
  119. // this.options.id = id;
  120. // this.application = _self.app.application;
  121. // }
  122. // };
  123. // this.app.desktop.openApplication(e, "process.ScriptDesigner", options);
  124. //},
  125. clearSelected: function(){
  126. this.applications.each(function(app){
  127. if (app.selected) app.unSelectedItem();
  128. }.bind(this));
  129. },
  130. close: function(){
  131. //if (this.callback) this.callback();
  132. this.selectedItems = [];
  133. this.windowNode.destroy();
  134. this.options.maskNode.unmask();
  135. }
  136. });
  137. MWF.xApplication.process.ProcessManager.widget.ApplicationSelector.Application = new Class({
  138. Extends: MWF.xApplication.process.ApplicationExplorer.Application,
  139. Implements: [Options, Events],
  140. initialize: function(app, selector, data, options){
  141. this.setOptions(options);
  142. this.app = app;
  143. this.selector = selector;
  144. this.container = selector.windowContentNode;
  145. this.css = selector.css;
  146. this.data = data;
  147. },
  148. load: function(){
  149. this.node = new Element("div", {
  150. "styles": this.css.applicationItemNode
  151. });
  152. this.loadTopNode();
  153. this.loadIconNode();
  154. this.loadSelectIcon();
  155. //this.loadExportAction();
  156. this.loadTitleNode();
  157. this.loadNewNode();
  158. //this.loadInforNode();
  159. //this.loadProcessNode();
  160. //this.loadFormNode();
  161. // this.loadDateNode();
  162. this.node.inject(this.container, this.options.where);
  163. },
  164. openApplication: function(){
  165. if (!this.selected){
  166. if (!this.selector.options.multi) this.selector.clearSelected();
  167. this.selectedItem();
  168. }else{
  169. //var bgcolor = this.topNode.retrieve("bgcolor");
  170. //this.topNode.setStyle("background-color", bgcolor);
  171. //this.selectIconNode.setStyles(this.css.applicationItemSelectIcon);
  172. //this.node.setStyles(this.css.applicationItemNode);
  173. //this.topNode.setStyles(this.css.applicationItemTopNode);
  174. //this.selector.selectedItems.erase(this.data);
  175. //this.selected = false;
  176. this.unSelectedItem();
  177. }
  178. },
  179. selectedItem: function(){
  180. this.selectIconNode.setStyles(this.css.applicationItemSelectIcon_selected);
  181. this.topNode.store("bgcolor", this.topNode.getStyle("background-color"));
  182. this.node.setStyles(this.css.applicationItemNode_select);
  183. this.topNode.setStyles(this.css.applicationItemTopNode_select);
  184. this.selector.selectedItems.push(this.data);
  185. this.selected = true;
  186. },
  187. unSelectedItem: function(){
  188. var bgcolor = this.topNode.retrieve("bgcolor");
  189. this.topNode.setStyle("background-color", bgcolor);
  190. this.selectIconNode.setStyles(this.css.applicationItemSelectIcon);
  191. this.node.setStyles(this.css.applicationItemNode);
  192. this.topNode.setStyles(this.css.applicationItemTopNode);
  193. this.selector.selectedItems.erase(this.data);
  194. this.selected = false;
  195. },
  196. loadSelectIcon: function(){
  197. //this.topNode.setStyle("background-color", "#666");
  198. this.selectIconNode = new Element("div", {
  199. "styles": this.css.applicationItemSelectIcon
  200. }).inject(this.topNode);
  201. //this.topNode.addEvents({
  202. // "mouseover": function(){if (!this.readyDelete) this.delAdctionNode.fade("in"); }.bind(this),
  203. // "mouseout": function(){if (!this.readyDelete) this.delAdctionNode.fade("out"); }.bind(this)
  204. //});
  205. this.selectIconNode.addEvent("click", function(e){
  206. this.checkDeleteApplication(e);
  207. e.stopPropagation();
  208. }.bind(this));
  209. },
  210. });