Explorer.js 20 KB

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