DictionaryExplorer.js 13 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251252253254255256257258259260261262263264265266267268269270271272273274275276277278279280281282283284285286287288289290291292293294295296297298299300301302303304305306307308309310311312313314315316317318319
  1. MWF.xApplication.process = MWF.xApplication.process || {};
  2. MWF.xApplication.process.ProcessManager = MWF.xApplication.process.ProcessManager || {};
  3. MWF.xDesktop.requireApp("process.ProcessManager", "lp."+MWF.language, null, false);
  4. MWF.xDesktop.requireApp("process.ProcessManager", "DictionaryExplorer", null, false);
  5. MWF.xApplication.portal.PortalManager.DictionaryExplorer = new Class({
  6. Extends: MWF.xApplication.process.ProcessManager.DictionaryExplorer,
  7. Implements: [Options, Events],
  8. options: {
  9. "create": MWF.xApplication.portal.PortalManager.LP.dictionary.create,
  10. "search": MWF.xApplication.portal.PortalManager.LP.dictionary.search,
  11. "searchText": MWF.xApplication.portal.PortalManager.LP.dictionary.searchText,
  12. "noElement": MWF.xApplication.portal.PortalManager.LP.dictionary.noDictionaryNoticeText
  13. },
  14. openFindDesigner: function(){
  15. this.app.options.application.moduleType = "portal";
  16. var options = {
  17. "filter": {
  18. "moduleList": ["portal"],
  19. "appList": [this.app.options.application]
  20. }
  21. };
  22. layout.openApplication(null, "FindDesigner", options);
  23. },
  24. keyCopy: function(e){
  25. if (this.selectMarkItems.length){
  26. var items = [];
  27. var i = 0;
  28. var checkItems = function(e){
  29. if (i>=this.selectMarkItems.length){
  30. if (items.length){
  31. var str = JSON.encode(items);
  32. if (e){
  33. e.clipboardData.setData('text/plain', str);
  34. }else {
  35. window.clipboardData.setData("Text", str);
  36. }
  37. this.app.notice(this.app.lp.copyed, "success");
  38. }
  39. }
  40. }.bind(this);
  41. this.selectMarkItems.each(function(item){
  42. this.app.restActions.getDictionary(item.data.id, function(json){
  43. json.data.elementType = "dictionary";
  44. items.push(json.data);
  45. i++;
  46. checkItems(e);
  47. }.bind(this), null, false)
  48. }.bind(this));
  49. if (e) e.preventDefault();
  50. }
  51. },
  52. keyPaste: function(e){
  53. var dataStr = "";
  54. if (e){
  55. dataStr = e.clipboardData.getData('text/plain');
  56. }else{
  57. dataStr = window.clipboardData.getData("Text");
  58. }
  59. var data = JSON.decode(dataStr);
  60. this.pasteItem(data, 0);
  61. },
  62. pasteItem: function(data, i){
  63. if (i<data.length){
  64. var item = data[i];
  65. if (item.elementType==="dictionary"){
  66. this.saveItemAs(item, function(){
  67. i++;
  68. this.pasteItem(data, i);
  69. }.bind(this), function(){
  70. i++;
  71. this.pasteItem(data, i);
  72. }.bind(this), function(){
  73. this.reload();
  74. }.bind(this));
  75. }else{
  76. i++;
  77. this.pasteItem(data, i);
  78. }
  79. }else{
  80. this.reload();
  81. }
  82. },
  83. saveItemAs: function(data, success, failure, cancel){
  84. this.app.restActions.listDictionary(this.app.options.application.id, function(dJson){
  85. var i=1;
  86. var someItems = dJson.data.filter(function(d){ return d.id===data.id });
  87. if (someItems.length){
  88. var someItem = someItems[0];
  89. var lp = this.app.lp;
  90. var _self = this;
  91. var d1 = new Date().parse(data.updateTime);
  92. var d2 = new Date().parse(someItem.updateTime);
  93. var html = "<div>"+lp.copyConfirmInfor+"</div>";
  94. 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>";
  95. html += "<div style='font-size:12px; color: #666666; float: left'>"+someItem.updateTime+"</div>" +
  96. "<div style='font-size:12px; color: #666666; float: left; margin-left: 20px;'></div>" +
  97. "<div style='color: red; float: right;'>"+((d1>=d2) ? "": lp.copynew)+"</div></div>";
  98. 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>";
  99. html += "<div style='font-size:12px; color: #666666; float: left;'>"+data.updateTime+"</div>" +
  100. "<div style='font-size:12px; color: #666666; float: left; margin-left: 20px;'></div>" +
  101. "<div style='color: red; float: right;'>"+((d1<=d2) ? "": lp.copynew)+"</div></div>";
  102. // html += "<>"
  103. this.app.dlg("inofr", null, this.app.lp.copyConfirmTitle, {"html": html}, 500, 290, [
  104. {
  105. "text": lp.copyConfirm_overwrite,
  106. "action": function(){_self.saveItemAsUpdate(someItem, data, success, failure);this.close();}
  107. },
  108. {
  109. "text": lp.copyConfirm_new,
  110. "action": function(){_self.saveItemAsNew(dJson, data, success, failure);this.close();}
  111. },
  112. {
  113. "text": lp.copyConfirm_skip,
  114. "action": function(){/*nothing*/ this.close(); if (success) success();}
  115. },
  116. {
  117. "text": lp.copyConfirm_cancel,
  118. "action": function(){this.close(); if (cancel) cancel();}
  119. }
  120. ]);
  121. }else{
  122. this.saveItemAsNew(dJson, data, success, failure)
  123. }
  124. }.bind(this), function(){if (failure) failure();}.bind(this));
  125. },
  126. saveItemAsUpdate: function(someItem, data, success, failure){
  127. data.id = someItem.id;
  128. data.application = someItem.application;
  129. data.applicationName = someItem.applicationName;
  130. data.name = someItem.name;
  131. data.alias = someItem.alias;
  132. this.app.restActions.saveDictionary(data, function(){
  133. if (success) success();
  134. }.bind(this), function(){
  135. if (failure) failure();
  136. }.bind(this));
  137. },
  138. saveItemAsNew: function(dJson, data, success, failure){
  139. var item = this.app.options.application;
  140. var id = item.id;
  141. var name = item.name;
  142. var oldName = data.name;
  143. var i=1;
  144. while (dJson.data.some(function(d){ return d.name==data.name || d.alias==data.name })){
  145. data.name = oldName+"_copy"+i;
  146. data.alias = oldName+"_copy"+i;
  147. i++;
  148. }
  149. data.id = "";
  150. data.application = id;
  151. data.applicationName = name;
  152. this.app.restActions.saveDictionary(data, function(){
  153. if (success) success();
  154. }.bind(this), function(){
  155. if (failure) failure();
  156. }.bind(this));
  157. },
  158. _createElement: function(e){
  159. var _self = this;
  160. var application = _self.app.options.application || _self.app.application;
  161. var options = {
  162. "application":{
  163. "name": application.name,
  164. "id": application.id
  165. },
  166. "onQueryLoad": function(){
  167. this.actions = _self.app.restActions;
  168. this.application = application;
  169. this.explorer = _self;
  170. }
  171. };
  172. this.app.desktop.openApplication(e, "portal.DictionaryDesigner", options);
  173. },
  174. _loadItemDataList: function(callback){
  175. var id = "";
  176. if (this.app.application) id = this.app.application.id;
  177. if (this.app.options.application) id = this.app.options.application.id;
  178. this.actions.listDictionary(id,callback, function () {
  179. }.bind(this));
  180. },
  181. _getItemObject: function(item){
  182. return new MWF.xApplication.portal.PortalManager.DictionaryExplorer.Dictionary(this, item)
  183. },
  184. // setTooltip: function(){
  185. // this.options.tooltip = {
  186. // "create": MWF.APPPM.LP.dictionary.create,
  187. // "search": MWF.APPPM.LP.dictionary.search,
  188. // "searchText": MWF.APPPM.LP.dictionary.searchText,
  189. // "noElement": MWF.APPPM.LP.dictionary.noDictionaryNoticeText
  190. // };
  191. // },
  192. // loadElementList: function(){
  193. // this._loadItemDataList(function(json){
  194. // if (json.data.length){
  195. // json.data.each(function(item){
  196. // var itemObj = this._getItemObject(item);
  197. // itemObj.load()
  198. // }.bind(this));
  199. // }else{
  200. // var noElementNode = new Element("div.noElementNode", {
  201. // "styles": this.css.noElementNode,
  202. // "text": (this.options.noCreate) ? MWF.APPPM.LP.dictionary.noDictionaryNoCreateNoticeText : this.options.noElement
  203. // }).inject(this.elementContentListNode);
  204. // if (!this.options.noCreate){
  205. // noElementNode.addEvent("click", function(e){
  206. // this._createElement(e);
  207. // }.bind(this));
  208. // }
  209. // }
  210. // if( !this.isSetContentSize ){
  211. // this.setContentSize();
  212. // this.isSetContentSize = true;
  213. // }
  214. // }.bind(this));
  215. // },
  216. // deleteItems: function(){
  217. // this.hideDeleteAction();
  218. // while (this.deleteMarkItems.length){
  219. // var item = this.deleteMarkItems.shift();
  220. // if (this.deleteMarkItems.length){
  221. // item.deleteDictionary();
  222. // }else{
  223. // item.deleteDictionary(function(){
  224. // // this.reloadItems();
  225. // // this.hideDeleteAction();
  226. // }.bind(this));
  227. // }
  228. // }
  229. // }
  230. });
  231. MWF.xApplication.portal.PortalManager.DictionaryExplorer.Dictionary = new Class({
  232. Extends: MWF.xApplication.process.ProcessManager.DictionaryExplorer.Dictionary,
  233. _open: function(e){
  234. var _self = this;
  235. var options = {
  236. "appId": "portal.DictionaryDesigner"+_self.data.id,
  237. "id": _self.data.id,
  238. // "application": _self.explorer.app.options.application.id,
  239. "application":{
  240. "name": _self.explorer.app.options.application.name,
  241. "id": _self.explorer.app.options.application.id
  242. },
  243. "noModifyName": _self.explorer.options.noModifyName,
  244. "readMode": _self.explorer.options.readMode,
  245. "onQueryLoad": function(){
  246. // this.actions = _self.explorer.actions;
  247. this.category = _self;
  248. this.options.id = _self.data.id;
  249. this.application = _self.explorer.app.options.application;
  250. this.options.noModifyName = _self.explorer.options.noModifyName;
  251. this.options.readMode = _self.explorer.options.readMode;
  252. this.explorer = _self.explorer;
  253. }
  254. };
  255. this.explorer.app.desktop.openApplication(e, "portal.DictionaryDesigner", options);
  256. },
  257. _getLnkPar: function(){
  258. return {
  259. "icon": this.explorer.path+this.explorer.options.style+"/dictionaryIcon/lnk.png",
  260. "title": this.data.name,
  261. "par": "portal.DictionaryDesigner#{\"id\": \""+this.data.id+"\", \"applicationId\": \""+this.explorer.app.options.application.id+"\"}"
  262. };
  263. },
  264. deleteDictionary: function(callback){
  265. this.explorer.app.restActions.deleteDictionary(this.data.id, function(){
  266. this.node.destroy();
  267. if (callback) callback();
  268. }.bind(this));
  269. },
  270. saveas: function(){
  271. MWF.xDesktop.requireApp("Selector", "package", function(){
  272. var selector = new MWF.O2Selector(this.explorer.app.content, {
  273. "title": this.explorer.app.lp.copyto,
  274. "type": "Portal",
  275. "values": [this.explorer.app.options.application],
  276. "onComplete": function(items){
  277. items.each(function(item){
  278. this.saveItemAs(item.data);
  279. }.bind(this));
  280. }.bind(this),
  281. });
  282. }.bind(this));
  283. },
  284. saveItemAs: function(item){
  285. var id = item.id;
  286. var name = item.name;
  287. this.explorer.app.restActions.getDictionary(this.data.id, function(json){
  288. var data = json.data;
  289. var oldName = data.name;
  290. this.explorer.app.restActions.listDictionary(id, function(dJson){
  291. var i=1;
  292. while (dJson.data.some(function(d){ return d.name==data.name || d.alias==data.name })){
  293. data.name = oldName+"_copy"+i;
  294. data.alias = oldName+"_copy"+i;
  295. i++;
  296. }
  297. data.id = "";
  298. data.application = id;
  299. data.applicationName = name;
  300. this.explorer.app.restActions.saveDictionary(data, function(){
  301. if (id == this.explorer.app.options.application.id) this.explorer.reload();
  302. }.bind(this));
  303. }.bind(this));
  304. }.bind(this));
  305. }
  306. });