SerialExplorer.js 12 KB

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