Explorer.js 20 KB

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