Explorer.js 17 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251252253254255256257258259260261262263264265266267268269270271272273274275276277278279280281282283284285286287288289290291292293294295296297298299300301302303304305306307308309310311312313314315316317318319320321322323324325326327328329330331332333334335336337338339340341342343344345346347348349350351352353354355356357358359360361362363364365366367368369370371372373374375376377378379380381382383384385386387388389390391392393394395396397398399400401402403404405406407408409410411412413414415416417418419420421422423424425426427428429430431432433434435436437438439440441442443444445446447448449450451452453454455456457458459460461462463464465
  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", {
  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. });
  227. MWF.xApplication.process.ProcessManager.Explorer.Item = new Class({
  228. initialize: function(explorer, item){
  229. this.explorer = explorer;
  230. this.data = item;
  231. this.container = this.explorer.elementContentListNode;
  232. this.css = this.explorer.css;
  233. this.icon = this._getIcon();
  234. },
  235. load: function(){
  236. this.createNode();
  237. this.createIconNode();
  238. //this.createDeleteNode();
  239. this.createActionNode();
  240. this.createTextNodes();
  241. this._isNew();
  242. },
  243. createNode: function(){
  244. this.node = new Element("div", {
  245. "styles": this.css.itemNode,
  246. "events": {
  247. "mouseover": function(){
  248. this.deleteActionNode.fade("in");
  249. if (this.saveasActionNode) this.saveasActionNode.fade("in");
  250. }.bind(this),
  251. "mouseout": function(){
  252. this.deleteActionNode.fade("out");
  253. if (this.saveasActionNode) this.saveasActionNode.fade("out");
  254. }.bind(this)
  255. }
  256. }).inject(this.container);
  257. },
  258. createIconNode: function(){
  259. if (this.data.icon) this.icon = this.data.icon.substr(this.data.icon.lastIndexOf("/")+1, this.data.icon.length);
  260. //if (this.data.name.icon) this.icon = this.data.name.icon;
  261. var iconUrl = this.explorer.path+""+this.explorer.options.style+"/processIcon/"+this.icon;
  262. var itemIconNode = new Element("div", {
  263. "styles": this.css.itemIconNode
  264. }).inject(this.node);
  265. itemIconNode.setStyle("background", "url("+iconUrl+") center center no-repeat");
  266. itemIconNode.addEvent("click", function(e){
  267. this.toggleSelected();
  268. e.stopPropagation();
  269. }.bind(this));
  270. itemIconNode.makeLnk({
  271. "par": this._getLnkPar()
  272. });
  273. },
  274. toggleSelected: function(){
  275. if (this.isSelected){
  276. this.unSelected();
  277. }else{
  278. this.selected();
  279. }
  280. },
  281. checkShowCopyInfor: function(){
  282. if (this.explorer.selectMarkItems.length===1){
  283. this.explorer.app.notice(this.explorer.app.lp.copyInfor, "infor");
  284. }
  285. },
  286. selected: function(){
  287. if (this.deleteMode) this.deleteItem();
  288. this.isSelected = true;
  289. this.node.setStyles(this.css.itemNode_selected);
  290. this.explorer.selectMarkItems.push(this);
  291. this.checkShowCopyInfor();
  292. },
  293. unSelected: function(){
  294. this.isSelected = false;
  295. this.node.setStyles(this.css.itemNode);
  296. this.explorer.selectMarkItems.erase(this);
  297. },
  298. createActionNode: function(){
  299. debugger;
  300. this.deleteActionNode = new Element("div", {
  301. "styles": this.css.deleteActionNode
  302. }).inject(this.node);
  303. this.deleteActionNode.addEvent("click", function(e){
  304. this.deleteItem(e);
  305. }.bind(this));
  306. this.saveasActionNode = new Element("div", {
  307. "styles": this.css.saveasActionNode,
  308. "title": this.explorer.app.lp.copy
  309. }).inject(this.node);
  310. this.saveasActionNode.addEvent("click", function(e){
  311. this.saveas(e);
  312. }.bind(this));
  313. },
  314. // createDeleteNode: function(){
  315. // this.deleteActionNode = new Element("div", {
  316. // "styles": this.css.deleteActionNode
  317. // }).inject(this.node);
  318. // this.deleteActionNode.addEvent("click", function(e){
  319. // this.deleteItem(e);
  320. // }.bind(this));
  321. // },
  322. createTextNodes: function(){
  323. new Element("div", {
  324. "styles": this.css.itemTextTitleNode,
  325. "text": this.data.name,
  326. "title": this.data.name,
  327. "events": {
  328. "click": function(e){this._open(e);}.bind(this)
  329. }
  330. }).inject(this.node);
  331. new Element("div", {
  332. "styles": this.css.itemTextDescriptionNode,
  333. "text": this.data.description || "",
  334. "title": this.data.description || ""
  335. }).inject(this.node);
  336. new Element("div", {
  337. "styles": this.css.itemTextDateNode,
  338. "text": (this.data.updateTime || "")
  339. }).inject(this.node);
  340. },
  341. saveas: function(){
  342. MWF.xDesktop.requireApp("Selector", "package", function(){
  343. var selector = new MWF.O2Selector(this.explorer.app.content, {
  344. "title": this.explorer.app.lp.copyto,
  345. "type": "Application",
  346. "values": [this.explorer.app.options.application],
  347. "onComplete": function(items){
  348. items.each(function(item){
  349. this.saveItemAs(item.data);
  350. }.bind(this));
  351. }.bind(this),
  352. });
  353. }.bind(this));
  354. },
  355. // saveItemAs: function(item){
  356. //
  357. // },
  358. deleteItem: function(){
  359. if (this.isSelected) this.unSelected();
  360. if (!this.deleteMode){
  361. this.deleteMode = true;
  362. this.node.setStyle("background-color", "#ffb7b7");
  363. this.deleteActionNode.setStyle("background-image", "url("+"/x_component_process_ProcessManager/$Explorer/default/processIcon/deleteProcess_red1.png)");
  364. this.node.removeEvents("mouseover");
  365. this.node.removeEvents("mouseout");
  366. if (this.saveasActionNode) this.saveasActionNode.fade("out");
  367. this.explorer.deleteMarkItems.push(this);
  368. }else{
  369. this.deleteMode = false;
  370. this.node.setStyle("background", "#FFF");
  371. this.deleteActionNode.setStyle("background-image", "url("+"/x_component_process_ProcessManager/$Explorer/default/processIcon/deleteProcess.png)");
  372. if (this.saveasActionNode) this.saveasActionNode.fade("in");
  373. this.node.addEvents({
  374. "mouseover": function(){
  375. this.deleteActionNode.fade("in");
  376. if (this.saveasActionNode) this.saveasActionNode.fade("in");
  377. }.bind(this),
  378. "mouseout": function(){
  379. this.deleteActionNode.fade("out");
  380. if (this.saveasActionNode) this.saveasActionNode.fade("out");
  381. }.bind(this)
  382. });
  383. this.explorer.deleteMarkItems.erase(this);
  384. }
  385. if (this.explorer.deleteMarkItems.length){
  386. this.explorer.showDeleteAction();
  387. }else{
  388. this.explorer.hideDeleteAction();
  389. }
  390. },
  391. deleteItems: function(){},
  392. _open: function(e){
  393. var _self = this;
  394. var options = {
  395. "onQueryLoad": function(){
  396. this.actions = _self.explorer.actions;
  397. this.category = _self;
  398. this.options.id = _self.data.id;
  399. this.application = _self.explorer.app.options.application;
  400. }
  401. };
  402. this.explorer.app.desktop.openApplication(e, "process.ProcessDesigner", options);
  403. },
  404. _getIcon: function(){
  405. var x = (Math.random()*49).toInt();
  406. return "process_icon_"+x+".png";
  407. },
  408. _getLnkPar: function(){
  409. return {
  410. "icon": this.explorer.path+this.explorer.options.style+"/processIcon/lnk.png",
  411. "title": this.data.name,
  412. "par": "ProcessDesigner#{\"id\": \""+this.data.id+"\"}"
  413. };
  414. },
  415. _isNew: function(){
  416. if (this.data.updateTime){
  417. var createDate = Date.parse(this.data.updateTime);
  418. var currentDate = new Date();
  419. if (createDate.diff(currentDate, "hour")<12) {
  420. this.newNode = new Element("div", {
  421. "styles": this.css.itemNewNode
  422. }).inject(this.node);
  423. this.newNode.addEvent("click", function(e){
  424. this.toggleSelected();
  425. e.stopPropagation();
  426. }.bind(this));
  427. }
  428. }
  429. }
  430. });