ImporterExplorer.js 12 KB

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