Explorer.js 19 KB

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