SerialExplorer.js 12 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251252253254255256257258259260261262263264265266267268269270271272273274275276277278279280281282283284285286287288
  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), function () {
  95. if(this.mask)this.mask.hide();
  96. }.bind(this));
  97. },
  98. _createItem: function(data){
  99. return new MWF.xApplication.process.Application.SerialExplorer.Item(data, this);
  100. },
  101. removeSerial: function(serial, all){
  102. this.actions.deleteSerialNumber(serial.data.id, function(json){
  103. this.items.erase(serial);
  104. serial.destroy();
  105. MWF.release(serial);
  106. }.bind(this));
  107. }
  108. });
  109. MWF.xApplication.process.Application.SerialExplorer.Item = new Class({
  110. initialize: function(data, explorer){
  111. this.explorer = explorer;
  112. this.data = data;
  113. this.container = this.explorer.elementContentListNode;
  114. this.css = this.explorer.css;
  115. this.load();
  116. },
  117. load: function(){
  118. this.node = new Element("div", {"styles": this.css.workItemNode});
  119. this.node.inject(this.container);
  120. this.workAreaNode = new Element("div", {"styles": this.css.workItemWorkNode}).inject(this.node);
  121. //this.otherWorkAreaNode = new Element("div", {"styles": this.css.workItemWorkNode}).inject(this.node);
  122. var html = "<div class='emptyAreaNode'></div><div class='processAreaNode'>"+this.data.processName+"</div>" +
  123. "<div class='keyAreaNode'>"+this.data.name+"</div><div class='numberAreaNode'>"+this.data.serial+"</div><div class='actionAreaNode'></div>";
  124. this.workAreaNode.set("html", html);
  125. this.workAreaNode.getElement(".processAreaNode").setStyles(this.css.processAreaNode);
  126. this.workAreaNode.getElement(".keyAreaNode").setStyles(this.css.keyAreaNode);
  127. this.numberAreaNode = this.workAreaNode.getElement(".numberAreaNode");
  128. this.numberAreaNode.setStyles(this.css.numberAreaNode);
  129. this.workAreaNode.getElement(".emptyAreaNode").setStyles(this.css.emptyAreaNode);
  130. this.actionAreaNode = this.workAreaNode.getElement(".actionAreaNode");
  131. this.actionAreaNode.setStyles(this.css.emptyAreaNode);
  132. //if (!this.data.control.allowRead){
  133. // this.node.setStyles(this.css.workItemNode_noread)
  134. // this.checkAreaNode.setStyles(this.css.actionStopWorkNode);
  135. // this.actionAreaNode.setStyles(this.css.actionStopWorkActionNode);
  136. //}
  137. //
  138. //this.iconAreaNode.setStyles(this.css.iconWorkNode);
  139. //this.titleAreaNode.setStyles(this.css.titleWorkNode);
  140. //this.setPersonData();
  141. //this.setStatusData();
  142. //
  143. this.setActions();
  144. //
  145. this.setEvents();
  146. //
  147. //if (!this.relative) this.listRelatives();
  148. },
  149. setActions: function(){
  150. if (this.explorer.app.options.application.allowControl){
  151. this.editNode = new Element("div", {"styles": this.css.actionEditNode, "title": this.explorer.app.lp.edit}).inject(this.actionAreaNode);
  152. this.deleteNode = new Element("div", {"styles": this.css.actionDeleteNode, "title": this.explorer.app.lp.delete}).inject(this.actionAreaNode);
  153. }
  154. },
  155. setEvents: function(){
  156. if (this.deleteNode){
  157. this.deleteNode.addEvents({
  158. "mouseover": function(){this.deleteNode.setStyles(this.css.actionDeleteNode_over);}.bind(this),
  159. "mouseout": function(){this.deleteNode.setStyles(this.css.actionDeleteNode);}.bind(this),
  160. "mousedown": function(){this.deleteNode.setStyles(this.css.actionDeleteNode_down);}.bind(this),
  161. "mouseup": function(){this.deleteNode.setStyles(this.css.actionDeleteNode_over);}.bind(this),
  162. "click": function(e){
  163. this.remove(e);
  164. }.bind(this)
  165. });
  166. }
  167. if (this.editNode){
  168. this.editNode.addEvents({
  169. "mouseover": function(){this.editNode.setStyles(this.css.actionEditNode_over);}.bind(this),
  170. "mouseout": function(){this.editNode.setStyles(this.css.actionEditNode);}.bind(this),
  171. "mousedown": function(){this.editNode.setStyles(this.css.actionEditNode_down);}.bind(this),
  172. "mouseup": function(){this.editNode.setStyles(this.css.actionEditNode_over);}.bind(this),
  173. "click": function(e){
  174. this.editNumber(e);
  175. }.bind(this)
  176. });
  177. }
  178. },
  179. editNumber: function(){
  180. //this.numberAreaNode
  181. this.editAreaNode = new Element("div", {"styles": this.css.editAreaNode}).inject(this.node);
  182. this.editNumberInputNode = new Element("input", {"type": "number", "styles": this.css.editNumberInputNode}).inject(this.editAreaNode);
  183. this.editOkActionNode = new Element("div", {"styles": this.css.editOkActionNode, "text": this.explorer.app.lp.ok}).inject(this.editAreaNode);
  184. this.editCancelActionNode = new Element("div", {"styles": this.css.editCancelActionNode, "text": this.explorer.app.lp.cancel}).inject(this.editAreaNode);
  185. this.editNumberInputNode.set("value", this.data.serial);
  186. this.editNumberInputNode.focus();
  187. this.editCancelActionNode.addEvent("click", function(){
  188. this.cancelEdit();
  189. }.bind(this));
  190. this.editOkActionNode.addEvent("click", function(){
  191. this.okEdit();
  192. }.bind(this));
  193. this.setEditAreaSize();
  194. this.explorer.app.addEvent("resize", function(){
  195. this.setEditAreaSize();
  196. }.bind(this));
  197. },
  198. setEditAreaSize: function(){
  199. if (this.editAreaNode){
  200. var width = this.numberAreaNode.getSize().x + this.actionAreaNode.getSize().x-2;
  201. this.editAreaNode.setStyle("width", ""+width+"px");
  202. var inputWidth = width - 26 - 50 - 50;
  203. this.editNumberInputNode.setStyle("width", ""+inputWidth+"px");
  204. this.editAreaNode.position({
  205. relativeTo: this.numberAreaNode,
  206. position: 'topLeft',
  207. edge: 'topLeft'
  208. });
  209. }
  210. },
  211. okEdit: function(){
  212. var serial = this.editNumberInputNode.get("value");
  213. if (!serial) serial = 0;
  214. this.data.serial = serial;
  215. this.explorer.actions.updateSerialNumber(this.data.id, this.data, function(json){
  216. this.cancelEdit();
  217. this.numberAreaNode.set("text", this.data.serial);
  218. }.bind(this));
  219. },
  220. cancelEdit: function(){
  221. if (this.editAreaNode){
  222. this.editCancelActionNode.destroy();
  223. this.editOkActionNode.destroy();
  224. this.editNumberInputNode.destroy();
  225. this.editAreaNode.destroy();
  226. this.editCancelActionNode = null;
  227. this.editOkActionNode = null;
  228. this.editNumberInputNode = null;
  229. this.editAreaNode = null;
  230. }
  231. },
  232. remove: function(e){
  233. var lp = this.explorer.app.lp;
  234. var text = lp.deleteSerial.replace(/{key}/g, this.data.name);
  235. var _self = this;
  236. this.workAreaNode.setStyles(this.css.workItemWorkNode_remove);
  237. this.readyRemove = true;
  238. this.explorer.app.confirm("warn", e, lp.deleteSerialTitle, text, 350, 120, function(){
  239. _self.explorer.removeSerial(_self, true);
  240. this.close();
  241. }, function(){
  242. _self.workAreaNode.setStyles(_self.css.workItemWorkNode);
  243. _self.readyRemove = false;
  244. this.close();
  245. });
  246. },
  247. destroy: function(){
  248. this.node.destroy();
  249. },
  250. });