ViewExplorer.js 12 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251252253254255256257258259260261262263264265266267268269270271272273274275276277278279280281282283284285286287288289290291292293294295296297298299300301302303304305306307308309310311
  1. MWF.xDesktop.requireApp("process.ProcessManager", "Explorer", null, false);
  2. MWF.xApplication.query.QueryManager.ViewExplorer = new Class({
  3. Extends: MWF.xApplication.process.ProcessManager.Explorer,
  4. Implements: [Options, Events],
  5. options: {
  6. "style": "default",
  7. "tooltip": {
  8. "create": MWF.xApplication.query.QueryManager.LP.view.create,
  9. "search": MWF.xApplication.query.QueryManager.LP.view.search,
  10. "searchText": MWF.xApplication.query.QueryManager.LP.view.searchText,
  11. "noElement": MWF.xApplication.query.QueryManager.LP.view.noViewNoticeText
  12. }
  13. },
  14. openFindDesigner: function(){
  15. this.app.options.application.moduleType = "query";
  16. var options = {
  17. "filter": {
  18. "moduleList": ["query"],
  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.getView(item.data.id, function(json){
  43. json.data.elementType = "view";
  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==="view"){
  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.listView(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.lastUpdateTime || data.updateTime);
  92. var d2 = new Date().parse(someItem.lastUpdateTime || 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.lastUpdateTime || someItem.updateTime)+"</div>" +
  96. "<div style='font-size:12px; color: #666666; float: left; margin-left: 20px;'>"+MWF.name.cn(someItem.lastUpdatePerson || "")+"</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.lastUpdateTime || data.updateTime)+"</div>" +
  100. "<div style='font-size:12px; color: #666666; float: left; margin-left: 20px;'>"+MWF.name.cn(data.lastUpdatePerson || "")+"</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. var item = this.app.options.application;
  128. var id = item.id;
  129. var name = item.name;
  130. var dataJson = (data.data) ? JSON.decode(data.data): "";
  131. data.data = dataJson;
  132. data.data.id = someItem.id;
  133. data.id = someItem.id;
  134. data.isNewView = false;
  135. data.application = id;
  136. data.applicationName = name;
  137. this.app.restActions.saveView(data, function(){
  138. if (success) success();
  139. }.bind(this), function(){
  140. if (failure) failure();
  141. }.bind(this));
  142. },
  143. saveItemAsNew: function(dJson, data, success, failure){
  144. var item = this.app.options.application;
  145. var id = item.id;
  146. var name = item.name;
  147. var oldName = data.name;
  148. var i=1;
  149. while (dJson.data.some(function(d){ return d.name==data.name || d.alias==data.name })){
  150. data.name = oldName+"_copy"+i;
  151. data.alias = oldName+"_copy"+i;
  152. i++;
  153. }
  154. var dataJson = (data.data) ? JSON.decode(data.data): "";
  155. data.data = dataJson;
  156. data.data.id = "";
  157. data.id = "";
  158. data.isNewView = true;
  159. data.application = id;
  160. data.applicationName = name;
  161. this.app.restActions.saveView(data, function(){
  162. if (success) success();
  163. }.bind(this), function(){
  164. if (failure) failure();
  165. }.bind(this));
  166. },
  167. _createElement: function(e){
  168. var _self = this;
  169. var options = {
  170. "application":{
  171. "name": _self.app.options.application.name,
  172. "id": _self.app.options.application.id
  173. },
  174. "onQueryLoad": function(){
  175. this.actions = _self.app.restActions;
  176. this.application = _self.app.options.application;
  177. this.explorer = _self;
  178. }
  179. };
  180. this.app.desktop.openApplication(e, "query.ViewDesigner", options);
  181. },
  182. _loadItemDataList: function(callback){
  183. this.app.restActions.listView(this.app.options.application.id,function(json){
  184. (json.data || []).sort(function(a, b){
  185. return (a.orderNumber || 999999999) - (b.orderNumber || 999999999 );
  186. });
  187. if(callback)callback(json)
  188. });
  189. },
  190. _getItemObject: function(item){
  191. return new MWF.xApplication.query.QueryManager.ViewExplorer.View(this, item)
  192. },
  193. deleteItems: function(){
  194. this.hideDeleteAction();
  195. while (this.deleteMarkItems.length){
  196. var item = this.deleteMarkItems.shift();
  197. if (this.deleteMarkItems.length){
  198. item.deleteView();
  199. }else{
  200. item.deleteView(function(){
  201. // this.reloadItems();
  202. //this.hideDeleteAction();
  203. }.bind(this));
  204. }
  205. }
  206. }
  207. });
  208. MWF.xApplication.query.QueryManager.ViewExplorer.View= new Class({
  209. Extends: MWF.xApplication.process.ProcessManager.Explorer.Item,
  210. _open: function(e){
  211. var _self = this;
  212. var options = {
  213. "appId": "query.ViewDesigner"+_self.data.id,
  214. "id": _self.data.id,
  215. // "application":_self.explorer.app.options.application.id,
  216. "application":{
  217. "name": _self.explorer.app.options.application.name,
  218. "id": _self.explorer.app.options.application.id
  219. },
  220. "onQueryLoad": function(){
  221. this.actions = _self.explorer.actions;
  222. this.category = _self;
  223. this.options.id = _self.data.id;
  224. this.application = _self.explorer.app.options.application;
  225. }
  226. };
  227. this.explorer.app.desktop.openApplication(e, "query.ViewDesigner", options);
  228. },
  229. _getIcon: function(){
  230. var x = (Math.random()*49).toInt();
  231. return "process_icon_"+x+".png";
  232. },
  233. _getLnkPar: function(){
  234. return {
  235. "icon": this.explorer.path+this.explorer.options.style+"/viewIcon/lnk.png",
  236. "title": this.data.name,
  237. "par": "query.ViewDesigner#{\"id\": \""+this.data.id+"\", \"applicationId\": \""+this.data.query+"\"}"
  238. };
  239. },
  240. // deleteItem: function(e){
  241. // var _self = this;
  242. // this.explorer.app.confirm("info", e, this.explorer.app.lp.process.deleteProcessTitle, this.explorer.app.lp.process.deleteProcess, 320, 110, function(){
  243. // _self.deleteProcess();
  244. // this.close();
  245. // },function(){
  246. // this.close();
  247. // });
  248. // },
  249. deleteView: function(callback){
  250. this.explorer.actions.deleteView(this.data.id, function(){
  251. this.node.destroy();
  252. if (callback) callback();
  253. }.bind(this));
  254. },
  255. saveas: function(){
  256. MWF.xDesktop.requireApp("Selector", "package", function(){
  257. var selector = new MWF.O2Selector(this.explorer.app.content, {
  258. "title": this.explorer.app.lp.copyto,
  259. "type": "Query",
  260. "values": [this.explorer.app.options.application],
  261. "onComplete": function(items){
  262. items.each(function(item){
  263. this.saveItemAs(item.data);
  264. }.bind(this));
  265. }.bind(this),
  266. });
  267. }.bind(this));
  268. },
  269. saveItemAs: function(item){
  270. var id = item.id;
  271. var name = item.name;
  272. this.explorer.app.restActions.getView(this.data.id, function(json){
  273. var data = json.data;
  274. var dataJson = (data.data) ? JSON.decode(data.data): "";
  275. data.data = dataJson;
  276. data.data.id = "";
  277. var oldName = data.name;
  278. this.explorer.app.restActions.listView(id, function(dJson){
  279. var i=1;
  280. while (dJson.data.some(function(d){ return d.name==data.name || d.alias==data.name })){
  281. data.name = oldName+"_copy"+i;
  282. data.alias = oldName+"_copy"+i;
  283. i++;
  284. }
  285. data.id = "";
  286. data.isNewView = true;
  287. data.application = id;
  288. data.applicationName = name;
  289. this.explorer.app.restActions.saveView(data, function(){
  290. if (id == this.explorer.app.options.application.id) this.explorer.reload();
  291. }.bind(this));
  292. }.bind(this));
  293. }.bind(this));
  294. }
  295. });