DictionaryExplorer.js 18 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251252253254255256257258259260261262263264265266267268269270271272273274275276277278279280281282283284285286287288289290291292293294295296297298299300301302303304305306307308309310311312313314315316317318319320321322323324325326327328329330331332333334335336337338339340341342343344345346347348349350351352353354355356357358359360361362363364365366367368369370371372373374375376377378379380381382383384385386387388389390391392393394395396397398399400401402403404405406407408409410411412413414415416417418419420421422423424425426427428429430431432433434435436437438439440441442443444445446447448449450451452453454455456457458459460461462463464
  1. MWF.xDesktop.requireApp("process.ProcessManager", "Explorer", null, false);
  2. MWF.xApplication.process.ProcessManager.DictionaryExplorer = new Class({
  3. Extends: MWF.xApplication.process.ProcessManager.Explorer,
  4. Implements: [Options, Events],
  5. options: {
  6. "create": MWF.APPPM.LP.dictionary.create,
  7. "search": MWF.APPPM.LP.dictionary.search,
  8. "searchText": MWF.APPPM.LP.dictionary.searchText,
  9. "noElement": MWF.APPPM.LP.dictionary.noDictionaryNoticeText,
  10. "name": 'process.DictionaryExplorer',
  11. "categoryEnable": false,
  12. "itemStyle": "line"
  13. },
  14. initialize: function(node, actions, options){
  15. this.setOptions(options);
  16. this.setTooltip();
  17. this.path = "../x_component_process_ProcessManager/$DictionaryExplorer/";
  18. this.cssPath = "../x_component_process_ProcessManager/$Explorer/"+this.options.style+"/css.wcss";
  19. this._loadCss();
  20. this.actions = actions;
  21. this.node = $(node);
  22. this.initData();
  23. },
  24. setContentSize: function(){
  25. if (this.toolbarNode){
  26. var toolbarSize = this.toolbarNode.getSize();
  27. var nodeSize = this.node.getSize();
  28. var categorySize = this.categoryElementNode ? this.categoryElementNode.getSize() : {"x": 0, "y": 0};
  29. var pt = this.elementContentNode.getStyle("padding-top").toFloat();
  30. var pb = this.elementContentNode.getStyle("padding-bottom").toFloat();
  31. var height = nodeSize.y-toolbarSize.y-categorySize.y-pt-pb;
  32. this.elementContentNode.setStyle("height", ""+height+"px");
  33. }
  34. if (this.options.noCreate) if (this.createElementNode) this.createElementNode.destroy();
  35. },
  36. showDeleteAction: function(){
  37. if (!this.deleteItemsAction){
  38. this.deleteItemsAction = new Element("div", {
  39. "styles": this.css.deleteItemsAction,
  40. "text": this.app.lp.deleteItems
  41. }).inject(this.node);
  42. this.deleteItemsAction.fade("in");
  43. this.deleteItemsAction.position({
  44. relativeTo: this.elementContentListNode,
  45. position: 'centerTop',
  46. edge: 'centerTop',
  47. "offset": {"y": this.elementContentNode.getScroll().y}
  48. });
  49. this.deleteItemsAction.addEvent("click", function(){
  50. var _self = this;
  51. this.app.confirm("warn", this.deleteItemsAction, MWF.APPPM.LP.deleteElementTitle, MWF.APPPM.LP.deleteElement, 300, 120, function(){
  52. _self.deleteItems();
  53. this.close();
  54. }, function(){
  55. this.close();
  56. });
  57. }.bind(this));
  58. }
  59. },
  60. keyCopy: function(e){
  61. if (this.selectMarkItems.length){
  62. var items = [];
  63. var i = 0;
  64. var checkItems = function(e){
  65. if (i>=this.selectMarkItems.length){
  66. if (items.length){
  67. var str = JSON.encode(items);
  68. if (e){
  69. e.clipboardData.setData('text/plain', str);
  70. }else {
  71. window.clipboardData.setData("Text", str);
  72. }
  73. this.app.notice(this.app.lp.copyed, "success");
  74. }
  75. }
  76. }.bind(this);
  77. this.selectMarkItems.each(function(item){
  78. this.app.restActions.getDictionary(item.data.id, function(json){
  79. json.data.elementType = "dictionary";
  80. items.push(json.data);
  81. i++;
  82. checkItems(e);
  83. }.bind(this), null, false)
  84. }.bind(this));
  85. if (e) e.preventDefault();
  86. }
  87. },
  88. keyPaste: function(e){
  89. var dataStr = "";
  90. if (e){
  91. dataStr = e.clipboardData.getData('text/plain');
  92. }else{
  93. dataStr = window.clipboardData.getData("Text");
  94. }
  95. var data = JSON.decode(dataStr);
  96. this.pasteItem(data, 0);
  97. // data.each(function(item){
  98. // if (item.elementType==="dictionary"){
  99. // this.saveItemAs(this.app.options.application, item);
  100. // }
  101. // }.bind(this));
  102. },
  103. pasteItem: function(data, i){
  104. if (i<data.length){
  105. var item = data[i];
  106. if (item.elementType==="dictionary"){
  107. this.saveItemAs(item, function(){
  108. i++;
  109. this.pasteItem(data, i);
  110. }.bind(this), function(){
  111. i++;
  112. this.pasteItem(data, i);
  113. }.bind(this), function(){
  114. this.reload();
  115. }.bind(this));
  116. }else{
  117. i++;
  118. this.pasteItem(data, i);
  119. }
  120. }else{
  121. this.reload();
  122. }
  123. },
  124. saveItemAs: function(data, success, failure, cancel){
  125. this.app.restActions.listDictionary(this.app.options.application.id, function(dJson){
  126. var i=1;
  127. var someItems = dJson.data.filter(function(d){ return d.id===data.id });
  128. if (someItems.length){
  129. var someItem = someItems[0];
  130. var lp = this.app.lp;
  131. var _self = this;
  132. var d1 = new Date().parse(data.updateTime);
  133. var d2 = new Date().parse(someItem.updateTime);
  134. var html = "<div>"+lp.copyConfirmInfor+"</div>";
  135. html += "<div style='overflow: hidden; margin: 10px 0px; padding: 5px 10px; background-color: #ffffff; border-radius: 6px;'><div style='font-weight: bold; font-size:14px;'>"+lp.copySource+" "+someItem.name+"</div>";
  136. html += "<div style='font-size:12px; color: #666666; float: left'>"+someItem.updateTime+"</div>" +
  137. "<div style='font-size:12px; color: #666666; float: left; margin-left: 20px;'></div>" +
  138. "<div style='color: red; float: right;'>"+((d1>=d2) ? "": lp.copynew)+"</div></div>";
  139. html += "<div style='overflow: hidden; margin: 10px 0px; padding: 5px 10px; background-color: #ffffff; border-radius: 6px;'><div style='clear: both;font-weight: bold; font-size:14px;'>"+lp.copyTarget+" "+data.name+"</div>";
  140. html += "<div style='font-size:12px; color: #666666; float: left;'>"+data.updateTime+"</div>" +
  141. "<div style='font-size:12px; color: #666666; float: left; margin-left: 20px;'></div>" +
  142. "<div style='color: red; float: right;'>"+((d1<=d2) ? "": lp.copynew)+"</div></div>";
  143. // html += "<>"
  144. this.app.dlg("inofr", null, this.app.lp.copyConfirmTitle, {"html": html}, 500, 290, [
  145. {
  146. "text": lp.copyConfirm_overwrite,
  147. "action": function(){_self.saveItemAsUpdate(someItem, data, success, failure);this.close();}
  148. },
  149. {
  150. "text": lp.copyConfirm_new,
  151. "action": function(){_self.saveItemAsNew(dJson, data, success, failure);this.close();}
  152. },
  153. {
  154. "text": lp.copyConfirm_skip,
  155. "action": function(){/*nothing*/ this.close(); if (success) success();}
  156. },
  157. {
  158. "text": lp.copyConfirm_cancel,
  159. "action": function(){this.close(); if (cancel) cancel();}
  160. }
  161. ]);
  162. }else{
  163. this.saveItemAsNew(dJson, data, success, failure)
  164. }
  165. }.bind(this), function(){if (failure) failure();}.bind(this));
  166. },
  167. saveItemAsUpdate: function(someItem, data, success, failure){
  168. data.id = someItem.id;
  169. data.application = someItem.application;
  170. data.applicationName = someItem.applicationName;
  171. data.name = someItem.name;
  172. data.alias = someItem.alias;
  173. this.app.restActions.saveDictionary(data, function(){
  174. if (success) success();
  175. }.bind(this), function(){
  176. if (failure) failure();
  177. }.bind(this));
  178. },
  179. saveItemAsNew: function(dJson, data, success, failure){
  180. var item = this.app.options.application;
  181. var id = item.id;
  182. var name = item.name;
  183. var oldName = data.name;
  184. var i=1;
  185. while (dJson.data.some(function(d){ return d.name==data.name || d.alias==data.name })){
  186. data.name = oldName+"_copy"+i;
  187. data.alias = oldName+"_copy"+i;
  188. i++;
  189. }
  190. data.id = "";
  191. data.application = id;
  192. data.applicationName = name;
  193. this.app.restActions.saveDictionary(data, function(){
  194. if (success) success();
  195. }.bind(this), function(){
  196. if (failure) failure();
  197. }.bind(this));
  198. },
  199. _createElement: function(e){
  200. var _self = this;
  201. var options = {
  202. "application":{
  203. "name": _self.app.options.application.name,
  204. "id": _self.app.options.application.id
  205. },
  206. "onQueryLoad": function(){
  207. this.actions = _self.app.restActions;
  208. this.application = _self.app.options.application;
  209. this.explorer = _self;
  210. }
  211. };
  212. this.app.desktop.openApplication(e, "process.DictionaryDesigner", options);
  213. },
  214. _loadItemDataList: function(callback){
  215. this.actions.listDictionary(this.app.options.application.id,callback, function () {
  216. }.bind(this));
  217. },
  218. _getItemObject: function(item){
  219. return new MWF.xApplication.process.ProcessManager.DictionaryExplorer.Dictionary(this, item)
  220. },
  221. setTooltip: function(){
  222. this.options.tooltip = {
  223. "create": MWF.APPPM.LP.dictionary.create,
  224. "search": MWF.APPPM.LP.dictionary.search,
  225. "searchText": MWF.APPPM.LP.dictionary.searchText,
  226. "noElement": MWF.APPPM.LP.dictionary.noDictionaryNoticeText
  227. };
  228. },
  229. loadElementList: function(){
  230. this.itemList = [];
  231. this._loadItemDataList(function(json){
  232. if (json.data.length){
  233. this.checkSort(json.data);
  234. json.data.each(function(item){
  235. var itemObj = this._getItemObject(item);
  236. itemObj.load();
  237. this.checkShow(itemObj);
  238. this.itemList.push(itemObj);
  239. }.bind(this));
  240. }else{
  241. var noElementNode = new Element("div.noElementNode", {
  242. "styles": this.css.noElementNode,
  243. "text": (this.options.noCreate) ? MWF.APPPM.LP.dictionary.noDictionaryNoCreateNoticeText : this.options.noElement
  244. }).inject(this.elementContentListNode);
  245. if (!this.options.noCreate){
  246. noElementNode.addEvent("click", function(e){
  247. this._createElement(e);
  248. }.bind(this));
  249. }
  250. }
  251. if(this.options.topEnable)this.loadTopNode();
  252. if( !this.isSetContentSize ){
  253. this.setContentSize();
  254. this.isSetContentSize = true;
  255. }
  256. }.bind(this));
  257. },
  258. deleteItems: function(){
  259. this.hideDeleteAction();
  260. while (this.deleteMarkItems.length){
  261. var item = this.deleteMarkItems.shift();
  262. if (this.deleteMarkItems.length){
  263. item.deleteDictionary();
  264. }else{
  265. item.deleteDictionary(function(){
  266. // this.reloadItems();
  267. // this.hideDeleteAction();
  268. }.bind(this));
  269. }
  270. }
  271. }
  272. });
  273. MWF.xApplication.process.ProcessManager.DictionaryExplorer.Dictionary = new Class({
  274. Extends: MWF.xApplication.process.ProcessManager.Explorer.Item,
  275. // load: function(){
  276. // this.node = new Element("div", {
  277. // "styles": this.explorer.css.itemNode,
  278. // "events": {
  279. // "mouseover": function(){
  280. // if (this.deleteActionNode) this.deleteActionNode.fade("in");
  281. // if (this.saveasActionNode) this.saveasActionNode.fade("in");
  282. // }.bind(this),
  283. // "mouseout": function(){
  284. // if (this.deleteActionNode) this.deleteActionNode.fade("out");
  285. // if (this.saveasActionNode) this.saveasActionNode.fade("out");
  286. // }.bind(this)
  287. // }
  288. // }).inject(this.container);
  289. //
  290. // if (this.data.name.icon) this.icon = this.data.name.icon;
  291. // var iconUrl = this.explorer.path+""+this.explorer.options.style+"/processIcon/"+this.icon;
  292. //
  293. // var itemIconNode = new Element("div", {
  294. // "styles": this.explorer.css.itemIconNode
  295. // }).inject(this.node);
  296. // itemIconNode.setStyle("background", "url("+iconUrl+") center center no-repeat");
  297. // //new Element("img", {
  298. // // "src": iconUrl, "border": "0"
  299. // //}).inject(itemIconNode);
  300. //
  301. // itemIconNode.addEvent("click", function(e){
  302. // this.toggleSelected();
  303. // e.stopPropagation();
  304. // }.bind(this));
  305. //
  306. // itemIconNode.makeLnk({
  307. // "par": this._getLnkPar()
  308. // });
  309. //
  310. // if (!this.explorer.options.noDelete){
  311. // this._createActions();
  312. // }
  313. //
  314. // var inforNode = new Element("div", {
  315. // "styles": this.explorer.css.itemInforNode
  316. // }).inject(this.node);
  317. // var inforBaseNode = new Element("div", {
  318. // "styles": this.explorer.css.itemInforBaseNode
  319. // }).inject(inforNode);
  320. //
  321. // new Element("div", {
  322. // "styles": this.explorer.css.itemTextTitleNode,
  323. // "text": this.data.name,
  324. // "title": this.data.name,
  325. // "events": {
  326. // "click": function(e){this._open(e);e.stopPropagation();}.bind(this)
  327. // }
  328. // }).inject(inforBaseNode);
  329. //
  330. // new Element("div", {
  331. // "styles": this.explorer.css.itemTextAliasNode,
  332. // "text": this.data.alias,
  333. // "title": this.data.alias
  334. // }).inject(inforBaseNode);
  335. // new Element("div", {
  336. // "styles": this.explorer.css.itemTextDateNode,
  337. // "text": (this.data.updateTime || "")
  338. // }).inject(inforBaseNode);
  339. //
  340. // new Element("div", {
  341. // "styles": this.explorer.css.itemTextDescriptionNode,
  342. // "text": this.data.description || "",
  343. // "title": this.data.description || ""
  344. // }).inject(inforNode);
  345. //
  346. // this._customNodes();
  347. //
  348. // this._isNew();
  349. // },
  350. _createActions: function(){
  351. this.deleteActionNode = new Element("div", {
  352. "styles": this.explorer.css.deleteActionNode
  353. }).inject(this.node);
  354. this.deleteActionNode.addEvent("click", function(e){
  355. this.deleteItem(e);
  356. }.bind(this));
  357. this.saveasActionNode = new Element("div", {
  358. "styles": this.css.saveasActionNode,
  359. "title": this.explorer.app.lp.copy
  360. }).inject(this.node);
  361. this.saveasActionNode.addEvent("click", function(e){
  362. this.saveas(e);
  363. }.bind(this));
  364. },
  365. _customNodes: function(){},
  366. _open: function(e){
  367. var _self = this;
  368. var options = {
  369. "appId": "process.DictionaryDesigner"+_self.data.id,
  370. "id": _self.data.id,
  371. // "application": _self.explorer.app.options.application.id,
  372. "application":{
  373. "name": _self.explorer.app.options.application.name,
  374. "id": _self.explorer.app.options.application.id
  375. },
  376. "noModifyName": _self.explorer.options.noModifyName,
  377. "readMode": _self.explorer.options.readMode,
  378. "onQueryLoad": function(){
  379. this.actions = _self.explorer.actions;
  380. this.category = _self;
  381. this.options.id = _self.data.id;
  382. this.application = _self.explorer.app.options.application;
  383. this.options.noModifyName = _self.explorer.options.noModifyName;
  384. this.options.readMode = _self.explorer.options.readMode;
  385. this.explorer = _self.explorer;
  386. }
  387. };
  388. this.explorer.app.desktop.openApplication(e, "process.DictionaryDesigner", options);
  389. },
  390. _getIcon: function(){
  391. //var x = (Math.random()*33).toInt();
  392. //return "process_icon_"+x+".png";
  393. return "dictionary.png";
  394. },
  395. _getLnkPar: function(){
  396. return {
  397. "icon": this.explorer.path+this.explorer.options.style+"/dictionaryIcon/lnk.png",
  398. "title": this.data.name,
  399. "par": "process.DictionaryDesigner#{\"id\": \""+this.data.id+"\", \"applicationId\": \""+this.explorer.app.options.application.id+"\"}"
  400. };
  401. },
  402. // deleteItem: function(e){
  403. // var _self = this;
  404. // this.explorer.app.confirm("info", e, this.explorer.app.lp.form.deleteFormTitle, this.explorer.app.lp.form.deleteForm, 320, 110, function(){
  405. // _self.deleteForm();
  406. // this.close();
  407. // },function(){
  408. // this.close();
  409. // });
  410. // },
  411. deleteDictionary: function(callback){
  412. this.explorer.app.restActions.deleteDictionary(this.data.id, function(){
  413. this.node.destroy();
  414. if (callback) callback();
  415. }.bind(this));
  416. },
  417. saveItemAs: function(item){
  418. var id = item.id;
  419. var name = item.name;
  420. this.explorer.app.restActions.getDictionary(this.data.id, function(json){
  421. var data = json.data;
  422. var oldName = data.name;
  423. this.explorer.app.restActions.listDictionary(id, function(dJson){
  424. var i=1;
  425. while (dJson.data.some(function(d){ return d.name==data.name || d.alias==data.name })){
  426. data.name = oldName+"_copy"+i;
  427. data.alias = oldName+"_copy"+i;
  428. i++;
  429. }
  430. data.id = "";
  431. data.application = id;
  432. data.applicationName = name;
  433. this.explorer.app.restActions.saveDictionary(data, function(){
  434. if (id == this.explorer.app.options.application.id) this.explorer.reload();
  435. }.bind(this));
  436. }.bind(this));
  437. }.bind(this));
  438. }
  439. });