SerialExplorer.js 12 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251252253254255256257258259260261262263264265266267268269270271272273274275276277278279280281282283284285
  1. MWF.require("MWF.xAction.org.express.RestActions", null,false);
  2. MWF.require("MWF.widget.Mask", null, false);
  3. MWF.require("MWF.widget.Identity", null,false);
  4. MWF.xDesktop.requireApp("Organization", "Selector.package", null, false);
  5. MWF.xDesktop.requireApp("process.ProcessManager", "DictionaryExplorer", null, false);
  6. MWF.xApplication.process.Application.SerialExplorer = new Class({
  7. Extends: MWF.xApplication.process.ProcessManager.DictionaryExplorer,
  8. Implements: [Options, Events],
  9. initialize: function(node, actions, options){
  10. this.setOptions(options);
  11. this.setTooltip();
  12. this.path = "/x_component_process_Application/$SerialExplorer/";
  13. this.cssPath = "/x_component_process_Application/$SerialExplorer/"+this.options.style+"/css.wcss";
  14. this._loadCss();
  15. this.actions = actions;
  16. this.node = $(node);
  17. this.items=[];
  18. },
  19. load: function(){
  20. this.loadToolbar();
  21. // this.loadFilterNode();
  22. // this.loadFilterConditionNode();
  23. this.loadContentNode();
  24. this.setNodeScroll();
  25. this.mask = new MWF.widget.Mask({"style": "desktop"});
  26. this.mask.loadNode(this.node);
  27. this.loadElementList();
  28. },
  29. clearWorks: function(){
  30. MWF.release(this.items);
  31. this.works = null;
  32. this.items=[];
  33. this.elementContentListNode.empty();
  34. },
  35. reloadWorks: function(){
  36. this.clearWorks();
  37. this.createWorkListHead();
  38. this.loadElementList();
  39. },
  40. loadContentNode: function(){
  41. this.elementContentNode = new Element("div", {
  42. "styles": this.css.elementContentNode
  43. }).inject(this.node);
  44. this.elementContentListNode = new Element("div", {
  45. "styles": this.css.elementContentListNode
  46. }).inject(this.elementContentNode);
  47. this.createWorkListHead();
  48. this.setContentSize();
  49. this.app.addEvent("resize", function(){this.setContentSize();}.bind(this));
  50. },
  51. setNodeScroll: function(){
  52. //MWF.require("MWF.widget.DragScroll", function(){
  53. // new MWF.widget.DragScroll(this.elementContentNode);
  54. //}.bind(this));
  55. //MWF.require("MWF.widget.ScrollBar", function(){
  56. // new MWF.widget.ScrollBar(this.elementContentNode, {"indent": false});
  57. //}.bind(this));
  58. var _self = this;
  59. MWF.require("MWF.widget.ScrollBar", function(){
  60. new MWF.widget.ScrollBar(this.elementContentNode, {
  61. "indent": false,"style":"xApp_TaskList", "where": "before", "distance": 30, "friction": 4, "axis": {"x": false, "y": true}
  62. });
  63. }.bind(this));
  64. },
  65. createWorkListHead: function(){
  66. var headNode = new Element("div", {"styles": this.css.workItemHeadNode}).inject(this.elementContentListNode);
  67. var html = "<div class='emptyAreaHeadNode'></div><div class='processAreaHeadNode'>"+this.app.lp.process+"</div>" +
  68. "<div class='keyAreaHeadNode'>"+this.app.lp.key+"</div><div class='numberAreaHeadNode'>"+this.app.lp.serialNumber+"</div><div class='emptyAreaHeadNode'></div>";
  69. headNode.set("html", html);
  70. headNode.getElement(".processAreaHeadNode").setStyles(this.css.processAreaHeadNode);
  71. headNode.getElement(".keyAreaHeadNode").setStyles(this.css.keyAreaHeadNode);
  72. headNode.getElement(".numberAreaHeadNode").setStyles(this.css.numberAreaHeadNode);
  73. headNode.getElements(".emptyAreaHeadNode").setStyles(this.css.emptyAreaHeadNode);
  74. },
  75. createCreateElementNode: function(){},
  76. setContentSize: function(){
  77. var toolbarSize = this.toolbarNode.getSize();
  78. var nodeSize = this.node.getSize();
  79. var pt = this.elementContentNode.getStyle("padding-top").toFloat();
  80. var pb = this.elementContentNode.getStyle("padding-bottom").toFloat();
  81. var height = nodeSize.y-toolbarSize.y-pt-pb;
  82. this.elementContentNode.setStyle("height", ""+height+"px");
  83. this.pageCount = (height/40).toInt()+5;
  84. if (this.options.noCreate) this.createElementNode.destroy();
  85. },
  86. loadElementList: function(count){
  87. this.actions.listSerialNumber(this.app.options.id, function(json){
  88. json.data.each(function(data){
  89. var item = this._createItem(data);
  90. this.items.push(item);
  91. }.bind(this));
  92. this.mask.hide();
  93. }.bind(this));
  94. },
  95. _createItem: function(data){
  96. return new MWF.xApplication.process.Application.SerialExplorer.Item(data, this);
  97. },
  98. removeSerial: function(serial, all){
  99. this.actions.deleteSerialNumber(serial.data.id, function(json){
  100. this.items.erase(serial);
  101. serial.destroy();
  102. MWF.release(serial);
  103. }.bind(this));
  104. }
  105. });
  106. MWF.xApplication.process.Application.SerialExplorer.Item = new Class({
  107. initialize: function(data, explorer){
  108. this.explorer = explorer;
  109. this.data = data;
  110. this.container = this.explorer.elementContentListNode;
  111. this.css = this.explorer.css;
  112. this.load();
  113. },
  114. load: function(){
  115. this.node = new Element("div", {"styles": this.css.workItemNode});
  116. this.node.inject(this.container);
  117. this.workAreaNode = new Element("div", {"styles": this.css.workItemWorkNode}).inject(this.node);
  118. //this.otherWorkAreaNode = new Element("div", {"styles": this.css.workItemWorkNode}).inject(this.node);
  119. var html = "<div class='emptyAreaNode'></div><div class='processAreaNode'>"+this.data.processName+"</div>" +
  120. "<div class='keyAreaNode'>"+this.data.name+"</div><div class='numberAreaNode'>"+this.data.serial+"</div><div class='actionAreaNode'></div>";
  121. this.workAreaNode.set("html", html);
  122. this.workAreaNode.getElement(".processAreaNode").setStyles(this.css.processAreaNode);
  123. this.workAreaNode.getElement(".keyAreaNode").setStyles(this.css.keyAreaNode);
  124. this.numberAreaNode = this.workAreaNode.getElement(".numberAreaNode");
  125. this.numberAreaNode.setStyles(this.css.numberAreaNode);
  126. this.workAreaNode.getElement(".emptyAreaNode").setStyles(this.css.emptyAreaNode);
  127. this.actionAreaNode = this.workAreaNode.getElement(".actionAreaNode");
  128. this.actionAreaNode.setStyles(this.css.emptyAreaNode);
  129. //if (!this.data.control.allowRead){
  130. // this.node.setStyles(this.css.workItemNode_noread)
  131. // this.checkAreaNode.setStyles(this.css.actionStopWorkNode);
  132. // this.actionAreaNode.setStyles(this.css.actionStopWorkActionNode);
  133. //}
  134. //
  135. //this.iconAreaNode.setStyles(this.css.iconWorkNode);
  136. //this.titleAreaNode.setStyles(this.css.titleWorkNode);
  137. //this.setPersonData();
  138. //this.setStatusData();
  139. //
  140. this.setActions();
  141. //
  142. this.setEvents();
  143. //
  144. //if (!this.relative) this.listRelatives();
  145. },
  146. setActions: function(){
  147. if (this.explorer.app.options.application.allowControl){
  148. this.editNode = new Element("div", {"styles": this.css.actionEditNode, "title": this.explorer.app.lp.edit}).inject(this.actionAreaNode);
  149. this.deleteNode = new Element("div", {"styles": this.css.actionDeleteNode, "title": this.explorer.app.lp.delete}).inject(this.actionAreaNode);
  150. }
  151. },
  152. setEvents: function(){
  153. if (this.deleteNode){
  154. this.deleteNode.addEvents({
  155. "mouseover": function(){this.deleteNode.setStyles(this.css.actionDeleteNode_over);}.bind(this),
  156. "mouseout": function(){this.deleteNode.setStyles(this.css.actionDeleteNode);}.bind(this),
  157. "mousedown": function(){this.deleteNode.setStyles(this.css.actionDeleteNode_down);}.bind(this),
  158. "mouseup": function(){this.deleteNode.setStyles(this.css.actionDeleteNode_over);}.bind(this),
  159. "click": function(e){
  160. this.remove(e);
  161. }.bind(this)
  162. });
  163. }
  164. if (this.editNode){
  165. this.editNode.addEvents({
  166. "mouseover": function(){this.editNode.setStyles(this.css.actionEditNode_over);}.bind(this),
  167. "mouseout": function(){this.editNode.setStyles(this.css.actionEditNode);}.bind(this),
  168. "mousedown": function(){this.editNode.setStyles(this.css.actionEditNode_down);}.bind(this),
  169. "mouseup": function(){this.editNode.setStyles(this.css.actionEditNode_over);}.bind(this),
  170. "click": function(e){
  171. this.editNumber(e);
  172. }.bind(this)
  173. });
  174. }
  175. },
  176. editNumber: function(){
  177. //this.numberAreaNode
  178. this.editAreaNode = new Element("div", {"styles": this.css.editAreaNode}).inject(this.node);
  179. this.editNumberInputNode = new Element("input", {"type": "number", "styles": this.css.editNumberInputNode}).inject(this.editAreaNode);
  180. this.editOkActionNode = new Element("div", {"styles": this.css.editOkActionNode, "text": this.explorer.app.lp.ok}).inject(this.editAreaNode);
  181. this.editCancelActionNode = new Element("div", {"styles": this.css.editCancelActionNode, "text": this.explorer.app.lp.cancel}).inject(this.editAreaNode);
  182. this.editNumberInputNode.set("value", this.data.serial);
  183. this.editNumberInputNode.focus();
  184. this.editCancelActionNode.addEvent("click", function(){
  185. this.cancelEdit();
  186. }.bind(this));
  187. this.editOkActionNode.addEvent("click", function(){
  188. this.okEdit();
  189. }.bind(this));
  190. this.setEditAreaSize();
  191. this.explorer.app.addEvent("resize", function(){
  192. this.setEditAreaSize();
  193. }.bind(this));
  194. },
  195. setEditAreaSize: function(){
  196. if (this.editAreaNode){
  197. var width = this.numberAreaNode.getSize().x + this.actionAreaNode.getSize().x-2;
  198. this.editAreaNode.setStyle("width", ""+width+"px");
  199. var inputWidth = width - 26 - 50 - 50;
  200. this.editNumberInputNode.setStyle("width", ""+inputWidth+"px");
  201. this.editAreaNode.position({
  202. relativeTo: this.numberAreaNode,
  203. position: 'topLeft',
  204. edge: 'topLeft'
  205. });
  206. }
  207. },
  208. okEdit: function(){
  209. var serial = this.editNumberInputNode.get("value");
  210. if (!serial) serial = 0;
  211. this.data.serial = serial;
  212. this.explorer.actions.updateSerialNumber(this.data.id, this.data, function(json){
  213. this.cancelEdit();
  214. this.numberAreaNode.set("text", this.data.serial);
  215. }.bind(this));
  216. },
  217. cancelEdit: function(){
  218. if (this.editAreaNode){
  219. this.editCancelActionNode.destroy();
  220. this.editOkActionNode.destroy();
  221. this.editNumberInputNode.destroy();
  222. this.editAreaNode.destroy();
  223. this.editCancelActionNode = null;
  224. this.editOkActionNode = null;
  225. this.editNumberInputNode = null;
  226. this.editAreaNode = null;
  227. }
  228. },
  229. remove: function(e){
  230. var lp = this.explorer.app.lp;
  231. var text = lp.deleteSerial.replace(/{key}/g, this.data.name);
  232. var _self = this;
  233. this.workAreaNode.setStyles(this.css.workItemWorkNode_remove);
  234. this.readyRemove = true;
  235. this.explorer.app.confirm("warn", e, lp.deleteSerialTitle, text, 350, 120, function(){
  236. _self.explorer.removeSerial(_self, true);
  237. this.close();
  238. }, function(){
  239. _self.workAreaNode.setStyles(_self.css.workItemWorkNode);
  240. _self.readyRemove = false;
  241. this.close();
  242. });
  243. },
  244. destroy: function(){
  245. this.node.destroy();
  246. },
  247. });