DictionaryExplorer.js 11 KB

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