DictionaryExplorer.js 17 KB

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