Explorer.js 19 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251252253254255256257258259260261262263264265266267268269270271272273274275276277278279280281282283284285286287288289290291292293294295296297298299300301302303304305306307308309310311312313314315316317318319320321322323324325326327328329330331332333334335336337338339340341342343344345346347348349350351352353354355356357358359360361362363364365366367368369370371372373374375376377378379380381382383384385386387388389390391392393394395396397398399400401402403404405406407408409410411412413414415416417418419420421422423424425426427428429430431432433434435436437438439440441442443444445446447448449450451452453454455456457458459460461462463464465466467468469470471472473474475476477478479480481482483484485486487488489490491492493494495496497498499500501
  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", 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. if( category && category !== "null" ){
  207. node = new Element("div", {"styles": this.css.categoryElementItemNode, "text": category}).inject(this.categoryElementNode);
  208. if (this.elementCategory===category){
  209. node.setStyles(this.css.categoryElementItemNode_current);
  210. }
  211. }
  212. }.bind(this));
  213. var categoryItems = this.categoryElementNode.getChildren();
  214. categoryItems.addEvent("click", function(e){
  215. var text = e.target.get("text");
  216. this.elementCategory = (text===MWF.xApplication.process.ProcessManager.LP.all) ? "" : text;
  217. // categoryItems.setStyles(this.css.categoryElementItemNode);
  218. // this.categoryElementNode.getFirst().setStyles(this.css.categoryElementItemAllNode);
  219. // e.target.setStyles((this.elementCategory) ? this.css.categoryElementItemNode_current : this.css.categoryElementItemAllNode_current);
  220. this.reload();
  221. }.bind(this));
  222. },
  223. showDeleteAction: function(){
  224. if (!this.deleteItemsAction){
  225. this.deleteItemsAction = new Element("div", {
  226. "styles": this.css.deleteItemsAction,
  227. "text": this.app.lp.deleteItems
  228. }).inject(this.node);
  229. this.deleteItemsAction.fade("in");
  230. this.deleteItemsAction.position({
  231. relativeTo: this.elementContentListNode,
  232. position: 'centerTop',
  233. edge: 'centerTop',
  234. "offset": {"y": this.elementContentNode.getScroll().y}
  235. });
  236. this.deleteItemsAction.addEvent("click", function(){
  237. var _self = this;
  238. this.app.confirm("warn", this.deleteItemsAction, MWF.APPPM.LP.deleteElementTitle, MWF.APPPM.LP.deleteElement, 300, 120, function(){
  239. _self.deleteItems();
  240. this.close();
  241. }, function(){
  242. this.close();
  243. });
  244. }.bind(this));
  245. }
  246. },
  247. hideDeleteAction: function(){
  248. if (this.deleteItemsAction) this.deleteItemsAction.destroy();
  249. delete this.deleteItemsAction;
  250. },
  251. _createElement: function(e){
  252. },
  253. _loadItemDataList: function(callback){
  254. this.app.restActions.listProcess(this.app.options.application.id,callback);
  255. },
  256. _getItemObject: function(item){
  257. return MWF.xApplication.process.ProcessManager.Explorer.Item(this, item)
  258. },
  259. destroy: function(){
  260. this.node.destroy();
  261. o2.release(this);
  262. }
  263. });
  264. MWF.xApplication.process.ProcessManager.Explorer.Item = new Class({
  265. initialize: function(explorer, item){
  266. this.explorer = explorer;
  267. this.data = item;
  268. this.container = this.explorer.elementContentListNode;
  269. this.css = this.explorer.css;
  270. this.icon = this._getIcon();
  271. },
  272. load: function(){
  273. this.createNode();
  274. this.createIconNode();
  275. //this.createDeleteNode();
  276. this.createActionNode();
  277. this.createTextNodes();
  278. this._isNew();
  279. },
  280. createNode: function(){
  281. this.node = new Element("div", {
  282. "styles": this.css.itemNode,
  283. "events": {
  284. "mouseover": function(){
  285. this.deleteActionNode.fade("in");
  286. if (this.saveasActionNode) this.saveasActionNode.fade("in");
  287. }.bind(this),
  288. "mouseout": function(){
  289. this.deleteActionNode.fade("out");
  290. if (this.saveasActionNode) this.saveasActionNode.fade("out");
  291. }.bind(this)
  292. }
  293. }).inject(this.container);
  294. },
  295. createIconNode: function(){
  296. if (this.data.icon) this.icon = this.data.icon.substr(this.data.icon.lastIndexOf("/")+1, this.data.icon.length);
  297. //if (this.data.name.icon) this.icon = this.data.name.icon;
  298. var iconUrl = this.explorer.path+""+this.explorer.options.style+"/processIcon/"+this.icon;
  299. var itemIconNode = new Element("div", {
  300. "styles": this.css.itemIconNode
  301. }).inject(this.node);
  302. itemIconNode.setStyle("background", "url("+iconUrl+") center center no-repeat");
  303. itemIconNode.addEvent("click", function(e){
  304. this.toggleSelected();
  305. e.stopPropagation();
  306. }.bind(this));
  307. itemIconNode.makeLnk({
  308. "par": this._getLnkPar()
  309. });
  310. },
  311. toggleSelected: function(){
  312. if (this.isSelected){
  313. this.unSelected();
  314. }else{
  315. this.selected();
  316. }
  317. },
  318. checkShowCopyInfor: function(){
  319. if (this.explorer.selectMarkItems.length===1){
  320. this.explorer.app.notice(this.explorer.app.lp.copyInfor, "infor");
  321. }
  322. },
  323. selected: function(){
  324. if (this.deleteMode) this.deleteItem();
  325. this.isSelected = true;
  326. this.node.setStyles(this.css.itemNode_selected);
  327. this.explorer.selectMarkItems.push(this);
  328. this.checkShowCopyInfor();
  329. },
  330. unSelected: function(){
  331. this.isSelected = false;
  332. this.node.setStyles(this.css.itemNode);
  333. this.explorer.selectMarkItems.erase(this);
  334. },
  335. createActionNode: function(){
  336. this.deleteActionNode = new Element("div", {
  337. "styles": this.css.deleteActionNode
  338. }).inject(this.node);
  339. this.deleteActionNode.addEvent("click", function(e){
  340. this.deleteItem(e);
  341. }.bind(this));
  342. this.saveasActionNode = new Element("div", {
  343. "styles": this.css.saveasActionNode,
  344. "title": this.explorer.app.lp.copy
  345. }).inject(this.node);
  346. this.saveasActionNode.addEvent("click", function(e){
  347. this.saveas(e);
  348. }.bind(this));
  349. },
  350. // createDeleteNode: function(){
  351. // this.deleteActionNode = new Element("div", {
  352. // "styles": this.css.deleteActionNode
  353. // }).inject(this.node);
  354. // this.deleteActionNode.addEvent("click", function(e){
  355. // this.deleteItem(e);
  356. // }.bind(this));
  357. // },
  358. createTextNodes: function(){
  359. new Element("div", {
  360. "styles": this.css.itemTextTitleNode,
  361. "text": this.data.name,
  362. "title": this.data.name,
  363. "events": {
  364. "click": function(e){this._open(e);}.bind(this)
  365. }
  366. }).inject(this.node);
  367. new Element("div", {
  368. "styles": this.css.itemTextDescriptionNode,
  369. "text": this.data.description || "",
  370. "title": this.data.description || ""
  371. }).inject(this.node);
  372. new Element("div", {
  373. "styles": this.css.itemTextDateNode,
  374. "text": (this.data.updateTime || "")
  375. }).inject(this.node);
  376. },
  377. saveas: function(){
  378. MWF.xDesktop.requireApp("Selector", "package", function(){
  379. var selector = new MWF.O2Selector(this.explorer.app.content, {
  380. "title": this.explorer.app.lp.copyto,
  381. "type": "Application",
  382. "values": [this.explorer.app.options.application],
  383. "onComplete": function(items){
  384. items.each(function(item){
  385. this.saveItemAs(item.data);
  386. }.bind(this));
  387. }.bind(this),
  388. });
  389. }.bind(this));
  390. },
  391. // saveItemAs: function(item){
  392. //
  393. // },
  394. deleteItem: function(){
  395. if (this.isSelected) this.unSelected();
  396. if (!this.deleteMode){
  397. this.deleteMode = true;
  398. this.node.setStyle("background-color", "#ffb7b7");
  399. this.deleteActionNode.setStyle("background-image", "url("+"../x_component_process_ProcessManager/$Explorer/default/processIcon/deleteProcess_red1.png)");
  400. this.node.removeEvents("mouseover");
  401. this.node.removeEvents("mouseout");
  402. if (this.saveasActionNode) this.saveasActionNode.fade("out");
  403. this.explorer.deleteMarkItems.push(this);
  404. }else{
  405. this.deleteMode = false;
  406. this.node.setStyle("background", "#FFF");
  407. this.deleteActionNode.setStyle("background-image", "url("+"../x_component_process_ProcessManager/$Explorer/default/processIcon/deleteProcess.png)");
  408. if (this.saveasActionNode) this.saveasActionNode.fade("in");
  409. this.node.addEvents({
  410. "mouseover": function(){
  411. this.deleteActionNode.fade("in");
  412. if (this.saveasActionNode) this.saveasActionNode.fade("in");
  413. }.bind(this),
  414. "mouseout": function(){
  415. this.deleteActionNode.fade("out");
  416. if (this.saveasActionNode) this.saveasActionNode.fade("out");
  417. }.bind(this)
  418. });
  419. this.explorer.deleteMarkItems.erase(this);
  420. }
  421. if (this.explorer.deleteMarkItems.length){
  422. this.explorer.showDeleteAction();
  423. }else{
  424. this.explorer.hideDeleteAction();
  425. }
  426. },
  427. deleteItems: function(){},
  428. _open: function(e){
  429. var _self = this;
  430. var options = {
  431. "onQueryLoad": function(){
  432. this.actions = _self.explorer.actions;
  433. this.category = _self;
  434. this.options.id = _self.data.id;
  435. this.application = _self.explorer.app.options.application;
  436. }
  437. };
  438. this.explorer.app.desktop.openApplication(e, "process.ProcessDesigner", options);
  439. },
  440. _getIcon: function(){
  441. var x = (Math.random()*49).toInt();
  442. return "process_icon_"+x+".png";
  443. },
  444. _getLnkPar: function(){
  445. return {
  446. "icon": this.explorer.path+this.explorer.options.style+"/processIcon/lnk.png",
  447. "title": this.data.name,
  448. "par": "ProcessDesigner#{\"id\": \""+this.data.id+"\"}"
  449. };
  450. },
  451. _isNew: function(){
  452. if (this.data.updateTime){
  453. var createDate = Date.parse(this.data.updateTime);
  454. var currentDate = new Date();
  455. if (createDate.diff(currentDate, "hour")<12) {
  456. this.newNode = new Element("div", {
  457. "styles": this.css.itemNewNode
  458. }).inject(this.node);
  459. this.newNode.addEvent("click", function(e){
  460. this.toggleSelected();
  461. e.stopPropagation();
  462. }.bind(this));
  463. }
  464. }
  465. }
  466. });