Explorer.js 20 KB

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