Explorer.js 17 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251252253254255256257258259260261262263264265266267268269270271272273274275276277278279280281282283284285286287288289290291292293294295296297298299300301302303304305306307308309310311312313314315316317318319320321322323324325326327328329330331332333334335336337338339340341342343344345346347348349350351352353354355356357358359360361362363364365366367368369370371372373374375376377378379380381382383384385386387388389390391392393394395396397398399400401402403404405406407408409410411412413414415416417418419420421422423424425426427428429430431432433434435436437438439440441442443444445446447448449450451452453454455456457458459460461462463464
  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. });
  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. this.deleteActionNode = new Element("div", {
  300. "styles": this.css.deleteActionNode
  301. }).inject(this.node);
  302. this.deleteActionNode.addEvent("click", function(e){
  303. this.deleteItem(e);
  304. }.bind(this));
  305. this.saveasActionNode = new Element("div", {
  306. "styles": this.css.saveasActionNode,
  307. "title": this.explorer.app.lp.copy
  308. }).inject(this.node);
  309. this.saveasActionNode.addEvent("click", function(e){
  310. this.saveas(e);
  311. }.bind(this));
  312. },
  313. // createDeleteNode: function(){
  314. // this.deleteActionNode = new Element("div", {
  315. // "styles": this.css.deleteActionNode
  316. // }).inject(this.node);
  317. // this.deleteActionNode.addEvent("click", function(e){
  318. // this.deleteItem(e);
  319. // }.bind(this));
  320. // },
  321. createTextNodes: function(){
  322. new Element("div", {
  323. "styles": this.css.itemTextTitleNode,
  324. "text": this.data.name,
  325. "title": this.data.name,
  326. "events": {
  327. "click": function(e){this._open(e);}.bind(this)
  328. }
  329. }).inject(this.node);
  330. new Element("div", {
  331. "styles": this.css.itemTextDescriptionNode,
  332. "text": this.data.description || "",
  333. "title": this.data.description || ""
  334. }).inject(this.node);
  335. new Element("div", {
  336. "styles": this.css.itemTextDateNode,
  337. "text": (this.data.updateTime || "")
  338. }).inject(this.node);
  339. },
  340. saveas: function(){
  341. MWF.xDesktop.requireApp("Selector", "package", function(){
  342. var selector = new MWF.O2Selector(this.explorer.app.content, {
  343. "title": this.explorer.app.lp.copyto,
  344. "type": "Application",
  345. "values": [this.explorer.app.options.application],
  346. "onComplete": function(items){
  347. items.each(function(item){
  348. this.saveItemAs(item.data);
  349. }.bind(this));
  350. }.bind(this),
  351. });
  352. }.bind(this));
  353. },
  354. // saveItemAs: function(item){
  355. //
  356. // },
  357. deleteItem: function(){
  358. if (this.isSelected) this.unSelected();
  359. if (!this.deleteMode){
  360. this.deleteMode = true;
  361. this.node.setStyle("background-color", "#ffb7b7");
  362. this.deleteActionNode.setStyle("background-image", "url("+"/x_component_process_ProcessManager/$Explorer/default/processIcon/deleteProcess_red1.png)");
  363. this.node.removeEvents("mouseover");
  364. this.node.removeEvents("mouseout");
  365. if (this.saveasActionNode) this.saveasActionNode.fade("out");
  366. this.explorer.deleteMarkItems.push(this);
  367. }else{
  368. this.deleteMode = false;
  369. this.node.setStyle("background", "#FFF");
  370. this.deleteActionNode.setStyle("background-image", "url("+"/x_component_process_ProcessManager/$Explorer/default/processIcon/deleteProcess.png)");
  371. if (this.saveasActionNode) this.saveasActionNode.fade("in");
  372. this.node.addEvents({
  373. "mouseover": function(){
  374. this.deleteActionNode.fade("in");
  375. if (this.saveasActionNode) this.saveasActionNode.fade("in");
  376. }.bind(this),
  377. "mouseout": function(){
  378. this.deleteActionNode.fade("out");
  379. if (this.saveasActionNode) this.saveasActionNode.fade("out");
  380. }.bind(this)
  381. });
  382. this.explorer.deleteMarkItems.erase(this);
  383. }
  384. if (this.explorer.deleteMarkItems.length){
  385. this.explorer.showDeleteAction();
  386. }else{
  387. this.explorer.hideDeleteAction();
  388. }
  389. },
  390. deleteItems: function(){},
  391. _open: function(e){
  392. var _self = this;
  393. var options = {
  394. "onQueryLoad": function(){
  395. this.actions = _self.explorer.actions;
  396. this.category = _self;
  397. this.options.id = _self.data.id;
  398. this.application = _self.explorer.app.options.application;
  399. }
  400. };
  401. this.explorer.app.desktop.openApplication(e, "process.ProcessDesigner", options);
  402. },
  403. _getIcon: function(){
  404. var x = (Math.random()*49).toInt();
  405. return "process_icon_"+x+".png";
  406. },
  407. _getLnkPar: function(){
  408. return {
  409. "icon": this.explorer.path+this.explorer.options.style+"/processIcon/lnk.png",
  410. "title": this.data.name,
  411. "par": "ProcessDesigner#{\"id\": \""+this.data.id+"\"}"
  412. };
  413. },
  414. _isNew: function(){
  415. if (this.data.updateTime){
  416. var createDate = Date.parse(this.data.updateTime);
  417. var currentDate = new Date();
  418. if (createDate.diff(currentDate, "hour")<12) {
  419. this.newNode = new Element("div", {
  420. "styles": this.css.itemNewNode
  421. }).inject(this.node);
  422. this.newNode.addEvent("click", function(e){
  423. this.toggleSelected();
  424. e.stopPropagation();
  425. }.bind(this));
  426. }
  427. }
  428. }
  429. });