Explorer.js 19 KB

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