DictionaryExplorer.js 11 KB

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