Explorer.js 17 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251252253254255256257258259260261262263264265266267268269270271272273274275276277278279280281282283284285286287288289290291292293294295296297298299300301302303304305306307308309310311312313314315316317318319320321322323324325326327328329330331332333334335336337338339340341342343344345346347348349350351352353354355356357358359360361362363364365366367368369370371372373374375376377378379380381382383384385386387388389390391392393394395396397398399400401402403404405406407408409410411412413414415416417418419420421422423424425426427428429430431432433434435436437438439440441442443444445446447448449450451452453454455456457458459460461462463464465466467468
  1. MWF.xApplication.process = MWF.xApplication.process || {};
  2. MWF.APPPM = MWF.xApplication.process.ProcessManager = MWF.xApplication.process.ProcessManager || {};
  3. MWF.xDesktop.requireApp("process.ProcessManager", "lp."+MWF.language, null, false);
  4. MWF.xApplication.process.ProcessManager.Explorer = new Class({
  5. Extends: MWF.widget.Common,
  6. Implements: [Options, Events],
  7. options: {
  8. "style": "default",
  9. "tooltip": {
  10. "create": MWF.APPPM.LP.process.create,
  11. "search": MWF.APPPM.LP.process.search,
  12. "searchText": MWF.APPPM.LP.process.searchText,
  13. "noElement": MWF.APPPM.LP.process.noProcessNoticeText
  14. }
  15. },
  16. initialize: function(node, actions, options){
  17. this.setOptions(options);
  18. this.setTooltip();
  19. this.path = "/x_component_process_ProcessManager/$Explorer/";
  20. this.cssPath = "/x_component_process_ProcessManager/$Explorer/"+this.options.style+"/css.wcss";
  21. this._loadCss();
  22. this.actions = actions;
  23. this.node = $(node);
  24. this.initData();
  25. },
  26. setTooltip: function(tooltip){
  27. if (tooltip) this.options.tooltip = Object.merge(this.options.tooltip, tooltip);
  28. },
  29. initData: function(){
  30. //this.categoryLoadFirst = true;
  31. //this.isLoaddingCategory = false;
  32. //this.categoryLoaded = false;
  33. //this.categorys = [];
  34. //this.dragItem = false;
  35. //this.dragCategory = false;
  36. //this.currentCategory = null;
  37. //this.loadCategoryQueue = 0;
  38. this.deleteMarkItems = [];
  39. this.selectMarkItems = [];
  40. },
  41. reload: function(){
  42. this.node.empty();
  43. this.load();
  44. },
  45. load: function(){
  46. this.loadToolbar();
  47. this.loadContentNode();
  48. this.setNodeScroll();
  49. this.loadElementList();
  50. },
  51. loadToolbar: function(){
  52. this.toolbarNode = new Element("div", {"styles": this.css.toolbarNode});
  53. this.createCreateElementNode();
  54. this.createIconElementNode();
  55. this.createTitleElementNode();
  56. this.createSearchElementNode();
  57. this.toolbarNode.inject(this.node);
  58. },
  59. createIconElementNode: function(){
  60. this.iconElementNode = new Element("div", {
  61. "styles": this.css.iconElementNode
  62. }).inject(this.toolbarNode);
  63. if (this.app.options.application){
  64. if (this.app.options.application.icon){
  65. this.iconElementNode.setStyle("background-image", "url(data:image/png;base64,"+this.app.options.application.icon+")");
  66. }else{
  67. this.iconElementNode.setStyle("background-image", "url("+"/x_component_process_ApplicationExplorer/$Main/default/icon/application.png)");
  68. }
  69. }
  70. },
  71. createCreateElementNode: function(){
  72. this.createElementNode = new Element("div", {
  73. "styles": this.css.createElementNode,
  74. "title": this.options.tooltip.create
  75. }).inject(this.toolbarNode);
  76. this.createElementNode.addEvent("click", function(e){
  77. this._createElement(e);
  78. }.bind(this));
  79. },
  80. createTitleElementNode: function() {
  81. this.titleElementNode = new Element("div", {
  82. "styles": this.css.titleElementNode,
  83. "text": this.app.options.application.name
  84. }).inject(this.toolbarNode);
  85. },
  86. createSearchElementNode: function(){
  87. this.searchElementNode = new Element("div", {
  88. "styles": this.css.searchElementNode
  89. }).inject(this.toolbarNode);
  90. //@todo
  91. return false;
  92. //this.searchElementButtonNode = new Element("div", {"styles": this.css.searchElementButtonNode,"title": this.options.tooltip.search}).inject(this.searchElementNode);
  93. //
  94. //this.searchElementInputAreaNode = new Element("div", {
  95. // "styles": this.css.searchElementInputAreaNode
  96. //}).inject(this.searchElementNode);
  97. //
  98. //this.searchElementInputBoxNode = new Element("div", {
  99. // "styles": this.css.searchElementInputBoxNode
  100. //}).inject(this.searchElementInputAreaNode);
  101. //
  102. //this.searchElementInputNode = new Element("input", {
  103. // "type": "text",
  104. // "value": this.options.tooltip.searchText,
  105. // "styles": this.css.searchElementInputNode,
  106. // "x-webkit-speech": "1"
  107. //}).inject(this.searchElementInputBoxNode);
  108. //var _self = this;
  109. //this.searchElementInputNode.addEvents({
  110. // "focus": function(){
  111. // if (this.value==_self.options.tooltip.searchText) this.set("value", "");
  112. // },
  113. // "blur": function(){if (!this.value) this.set("value", _self.options.tooltip.searchText);},
  114. // "keydown": function(e){
  115. // if (e.code==13){
  116. // this.searchElement();
  117. // e.preventDefault();
  118. // }
  119. // }.bind(this),
  120. // "selectstart": function(e){
  121. // e.preventDefault();
  122. // }
  123. //});
  124. //this.searchElementButtonNode.addEvent("click", function(){this.searchElement();}.bind(this));
  125. },
  126. searchElement: function(){
  127. //-----------------------------------------
  128. //-----------------------------------------
  129. //-----search category---------------------
  130. //-----------------------------------------
  131. //-----------------------------------------
  132. alert("search Element");
  133. },
  134. loadContentNode: function(){
  135. this.elementContentNode = new Element("div", {
  136. "styles": this.css.elementContentNode
  137. }).inject(this.node);
  138. this.elementContentNode.addEvent("click", function(){
  139. while (this.selectMarkItems.length){
  140. this.selectMarkItems[0].unSelected();
  141. }
  142. }.bind(this));
  143. this.elementContentListNode = new Element("div", {
  144. "styles": this.css.elementContentListNode
  145. }).inject(this.elementContentNode);
  146. this.setContentSize();
  147. this.app.addEvent("resize", function(){this.setContentSize();}.bind(this));
  148. },
  149. setContentSize: function(){
  150. var toolbarSize = this.toolbarNode.getSize();
  151. var nodeSize = this.node.getSize();
  152. var pt = this.elementContentNode.getStyle("padding-top").toFloat();
  153. var pb = this.elementContentNode.getStyle("padding-bottom").toFloat();
  154. var height = nodeSize.y-toolbarSize.y-pt-pb;
  155. this.elementContentNode.setStyle("height", ""+height+"px");
  156. var count = (nodeSize.x/282).toInt();
  157. var x = count*282;
  158. var m = (nodeSize.x-x)/2-10;
  159. this.elementContentListNode.setStyles({
  160. "width": ""+x+"px",
  161. "margin-left": "" + m + "px"
  162. });
  163. },
  164. setNodeScroll: function(){
  165. MWF.require("MWF.widget.DragScroll", function(){
  166. new MWF.widget.DragScroll(this.elementContentNode);
  167. }.bind(this));
  168. MWF.require("MWF.widget.ScrollBar", function(){
  169. new MWF.widget.ScrollBar(this.elementContentNode, {"indent": false});
  170. }.bind(this));
  171. },
  172. loadElementList: function(){
  173. this._loadItemDataList(function(json){
  174. if (json.data.length){
  175. json.data.each(function(item){
  176. var itemObj = this._getItemObject(item);
  177. itemObj.load()
  178. }.bind(this));
  179. }else{
  180. var noElementNode = new Element("div.noElementNode", {
  181. "styles": this.css.noElementNode,
  182. "text": this.options.tooltip.noElement
  183. }).inject(this.elementContentListNode);
  184. noElementNode.addEvent("click", function(e){
  185. this._createElement(e);
  186. }.bind(this));
  187. }
  188. }.bind(this));
  189. },
  190. showDeleteAction: function(){
  191. if (!this.deleteItemsAction){
  192. this.deleteItemsAction = new Element("div", {
  193. "styles": this.css.deleteItemsAction,
  194. "text": this.app.lp.deleteItems
  195. }).inject(this.node);
  196. this.deleteItemsAction.fade("in");
  197. this.deleteItemsAction.position({
  198. relativeTo: this.elementContentListNode,
  199. position: 'centerTop',
  200. edge: 'centerTop',
  201. "offset": {"y": this.elementContentNode.getScroll().y}
  202. });
  203. this.deleteItemsAction.addEvent("click", function(){
  204. var _self = this;
  205. this.app.confirm("warn", this.deleteItemsAction, MWF.APPPM.LP.deleteElementTitle, MWF.APPPM.LP.deleteElement, 300, 120, function(){
  206. _self.deleteItems();
  207. this.close();
  208. }, function(){
  209. this.close();
  210. });
  211. }.bind(this));
  212. }
  213. },
  214. hideDeleteAction: function(){
  215. if (this.deleteItemsAction) this.deleteItemsAction.destroy();
  216. delete this.deleteItemsAction;
  217. },
  218. _createElement: function(e){
  219. },
  220. _loadItemDataList: function(callback){
  221. this.app.restActions.listProcess(this.app.options.application.id,callback);
  222. },
  223. _getItemObject: function(item){
  224. return MWF.xApplication.process.ProcessManager.Explorer.Item(this, item)
  225. },
  226. destroy: function(){
  227. this.node.destroy();
  228. o2.release(this);
  229. }
  230. });
  231. MWF.xApplication.process.ProcessManager.Explorer.Item = new Class({
  232. initialize: function(explorer, item){
  233. this.explorer = explorer;
  234. this.data = item;
  235. this.container = this.explorer.elementContentListNode;
  236. this.css = this.explorer.css;
  237. this.icon = this._getIcon();
  238. },
  239. load: function(){
  240. this.createNode();
  241. this.createIconNode();
  242. //this.createDeleteNode();
  243. this.createActionNode();
  244. this.createTextNodes();
  245. this._isNew();
  246. },
  247. createNode: function(){
  248. this.node = new Element("div", {
  249. "styles": this.css.itemNode,
  250. "events": {
  251. "mouseover": function(){
  252. this.deleteActionNode.fade("in");
  253. if (this.saveasActionNode) this.saveasActionNode.fade("in");
  254. }.bind(this),
  255. "mouseout": function(){
  256. this.deleteActionNode.fade("out");
  257. if (this.saveasActionNode) this.saveasActionNode.fade("out");
  258. }.bind(this)
  259. }
  260. }).inject(this.container);
  261. },
  262. createIconNode: function(){
  263. if (this.data.icon) this.icon = this.data.icon.substr(this.data.icon.lastIndexOf("/")+1, this.data.icon.length);
  264. //if (this.data.name.icon) this.icon = this.data.name.icon;
  265. var iconUrl = this.explorer.path+""+this.explorer.options.style+"/processIcon/"+this.icon;
  266. var itemIconNode = new Element("div", {
  267. "styles": this.css.itemIconNode
  268. }).inject(this.node);
  269. itemIconNode.setStyle("background", "url("+iconUrl+") center center no-repeat");
  270. itemIconNode.addEvent("click", function(e){
  271. this.toggleSelected();
  272. e.stopPropagation();
  273. }.bind(this));
  274. itemIconNode.makeLnk({
  275. "par": this._getLnkPar()
  276. });
  277. },
  278. toggleSelected: function(){
  279. if (this.isSelected){
  280. this.unSelected();
  281. }else{
  282. this.selected();
  283. }
  284. },
  285. checkShowCopyInfor: function(){
  286. if (this.explorer.selectMarkItems.length===1){
  287. this.explorer.app.notice(this.explorer.app.lp.copyInfor, "infor");
  288. }
  289. },
  290. selected: function(){
  291. if (this.deleteMode) this.deleteItem();
  292. this.isSelected = true;
  293. this.node.setStyles(this.css.itemNode_selected);
  294. this.explorer.selectMarkItems.push(this);
  295. this.checkShowCopyInfor();
  296. },
  297. unSelected: function(){
  298. this.isSelected = false;
  299. this.node.setStyles(this.css.itemNode);
  300. this.explorer.selectMarkItems.erase(this);
  301. },
  302. createActionNode: function(){
  303. this.deleteActionNode = new Element("div", {
  304. "styles": this.css.deleteActionNode
  305. }).inject(this.node);
  306. this.deleteActionNode.addEvent("click", function(e){
  307. this.deleteItem(e);
  308. }.bind(this));
  309. this.saveasActionNode = new Element("div", {
  310. "styles": this.css.saveasActionNode,
  311. "title": this.explorer.app.lp.copy
  312. }).inject(this.node);
  313. this.saveasActionNode.addEvent("click", function(e){
  314. this.saveas(e);
  315. }.bind(this));
  316. },
  317. // createDeleteNode: function(){
  318. // this.deleteActionNode = new Element("div", {
  319. // "styles": this.css.deleteActionNode
  320. // }).inject(this.node);
  321. // this.deleteActionNode.addEvent("click", function(e){
  322. // this.deleteItem(e);
  323. // }.bind(this));
  324. // },
  325. createTextNodes: function(){
  326. new Element("div", {
  327. "styles": this.css.itemTextTitleNode,
  328. "text": this.data.name,
  329. "title": this.data.name,
  330. "events": {
  331. "click": function(e){this._open(e);}.bind(this)
  332. }
  333. }).inject(this.node);
  334. new Element("div", {
  335. "styles": this.css.itemTextDescriptionNode,
  336. "text": this.data.description || "",
  337. "title": this.data.description || ""
  338. }).inject(this.node);
  339. new Element("div", {
  340. "styles": this.css.itemTextDateNode,
  341. "text": (this.data.updateTime || "")
  342. }).inject(this.node);
  343. },
  344. saveas: function(){
  345. MWF.xDesktop.requireApp("Selector", "package", function(){
  346. var selector = new MWF.O2Selector(this.explorer.app.content, {
  347. "title": this.explorer.app.lp.copyto,
  348. "type": "Application",
  349. "values": [this.explorer.app.options.application],
  350. "onComplete": function(items){
  351. items.each(function(item){
  352. this.saveItemAs(item.data);
  353. }.bind(this));
  354. }.bind(this),
  355. });
  356. }.bind(this));
  357. },
  358. // saveItemAs: function(item){
  359. //
  360. // },
  361. deleteItem: function(){
  362. if (this.isSelected) this.unSelected();
  363. if (!this.deleteMode){
  364. this.deleteMode = true;
  365. this.node.setStyle("background-color", "#ffb7b7");
  366. this.deleteActionNode.setStyle("background-image", "url("+"/x_component_process_ProcessManager/$Explorer/default/processIcon/deleteProcess_red1.png)");
  367. this.node.removeEvents("mouseover");
  368. this.node.removeEvents("mouseout");
  369. if (this.saveasActionNode) this.saveasActionNode.fade("out");
  370. this.explorer.deleteMarkItems.push(this);
  371. }else{
  372. this.deleteMode = false;
  373. this.node.setStyle("background", "#FFF");
  374. this.deleteActionNode.setStyle("background-image", "url("+"/x_component_process_ProcessManager/$Explorer/default/processIcon/deleteProcess.png)");
  375. if (this.saveasActionNode) this.saveasActionNode.fade("in");
  376. this.node.addEvents({
  377. "mouseover": function(){
  378. this.deleteActionNode.fade("in");
  379. if (this.saveasActionNode) this.saveasActionNode.fade("in");
  380. }.bind(this),
  381. "mouseout": function(){
  382. this.deleteActionNode.fade("out");
  383. if (this.saveasActionNode) this.saveasActionNode.fade("out");
  384. }.bind(this)
  385. });
  386. this.explorer.deleteMarkItems.erase(this);
  387. }
  388. if (this.explorer.deleteMarkItems.length){
  389. this.explorer.showDeleteAction();
  390. }else{
  391. this.explorer.hideDeleteAction();
  392. }
  393. },
  394. deleteItems: function(){},
  395. _open: function(e){
  396. var _self = this;
  397. var options = {
  398. "onQueryLoad": function(){
  399. this.actions = _self.explorer.actions;
  400. this.category = _self;
  401. this.options.id = _self.data.id;
  402. this.application = _self.explorer.app.options.application;
  403. }
  404. };
  405. this.explorer.app.desktop.openApplication(e, "process.ProcessDesigner", options);
  406. },
  407. _getIcon: function(){
  408. var x = (Math.random()*49).toInt();
  409. return "process_icon_"+x+".png";
  410. },
  411. _getLnkPar: function(){
  412. return {
  413. "icon": this.explorer.path+this.explorer.options.style+"/processIcon/lnk.png",
  414. "title": this.data.name,
  415. "par": "ProcessDesigner#{\"id\": \""+this.data.id+"\"}"
  416. };
  417. },
  418. _isNew: function(){
  419. if (this.data.updateTime){
  420. var createDate = Date.parse(this.data.updateTime);
  421. var currentDate = new Date();
  422. if (createDate.diff(currentDate, "hour")<12) {
  423. this.newNode = new Element("div", {
  424. "styles": this.css.itemNewNode
  425. }).inject(this.node);
  426. this.newNode.addEvent("click", function(e){
  427. this.toggleSelected();
  428. e.stopPropagation();
  429. }.bind(this));
  430. }
  431. }
  432. }
  433. });