StatementExplorer.js 13 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251252253254255256257258259260261262263264265266267268269270271272273274275276277278279280281282283284285286287288289290291292293294295296297298299300301302303304305306307308309310311312313314315316317318319320321322323324325326
  1. MWF.xDesktop.requireApp("query.QueryManager", "StatExplorer", null, false);
  2. MWF.xApplication.query.QueryManager.StatementExplorer = 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.statement.create,
  9. "search": MWF.xApplication.query.QueryManager.LP.statement.search,
  10. "searchText": MWF.xApplication.query.QueryManager.LP.statement.searchText,
  11. "noElement": MWF.xApplication.query.QueryManager.LP.statement.noStatNoticeText
  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.getStatement(item.data.id, function(json){
  53. json.data.elementType = "statement";
  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==="statement"){
  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. o2.Actions.load("x_query_assemble_designer").StatementAction.manageList(function(dJson){
  95. var i=1;
  96. var someItems = dJson.data.filter(function(d){ return (d.id && d.id===data.id) || (d.name && d.name===data.name) || (d.alias && d.alias===data.alias) });
  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_server+"</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.isNewStatement = false;
  142. data.application = id;
  143. data.applicationName = name;
  144. this.app.restActions.saveStatement(data, function(){
  145. if (success) success();
  146. }.bind(this), function(){
  147. if (failure) failure();
  148. }.bind(this));
  149. },
  150. saveItemAsNew: function(dJson, data, success, failure){
  151. var item = this.app.options.application;
  152. var id = item.id;
  153. var name = item.name;
  154. var oldName = data.name;
  155. var i=1;
  156. while (dJson.data.some(function(d){ return d.name==data.name || d.alias==data.name })){
  157. data.name = oldName+"_copy"+i;
  158. data.alias = oldName+"_copy"+i;
  159. i++;
  160. }
  161. data.id = "";
  162. data.isNewStatement = true;
  163. data.application = id;
  164. data.applicationName = name;
  165. this.app.restActions.saveStatement(data, function(){
  166. if (success) success();
  167. }.bind(this), function(){
  168. if (failure) failure();
  169. }.bind(this));
  170. },
  171. _createElement: function(e){
  172. var _self = this;
  173. var options = {
  174. "application":{
  175. "name": _self.app.options.application.name,
  176. "id": _self.app.options.application.id
  177. },
  178. "onQueryLoad": function(){
  179. this.actions = _self.app.restActions;
  180. this.application = _self.app.options.application;
  181. this.explorer = _self;
  182. }
  183. };
  184. this.app.desktop.openApplication(e, "query.StatementDesigner", options);
  185. },
  186. _loadItemDataList: function(callback){
  187. this.app.restActions.listStatement(this.app.options.application.id, {}, function(json){
  188. (json.data || []).sort(function(a, b){
  189. return (a.orderNumber || 999999999) - (b.orderNumber || 999999999 );
  190. });
  191. if(callback)callback(json)
  192. });
  193. },
  194. _getItemObject: function(item){
  195. return new MWF.xApplication.query.QueryManager.StatementExplorer.Statement(this, item);
  196. },
  197. deleteItems: function(){
  198. this.hideDeleteAction();
  199. while (this.deleteMarkItems.length){
  200. var item = this.deleteMarkItems.shift();
  201. if (this.deleteMarkItems.length){
  202. item.deleteStatement();
  203. }else{
  204. item.deleteStatement(function(){
  205. //this.reloadItems();
  206. //this.hideDeleteAction();
  207. }.bind(this));
  208. }
  209. }
  210. }
  211. });
  212. MWF.xApplication.query.QueryManager.StatementExplorer.Statement= new Class({
  213. Extends: MWF.xApplication.query.QueryManager.StatExplorer.Stat,
  214. createIconNode: function(){
  215. if (this.data.icon) this.icon = this.data.icon.substr(this.data.icon.lastIndexOf("/")+1, this.data.icon.length);
  216. //if (this.data.name.icon) this.icon = this.data.name.icon;
  217. var iconUrl = this.explorer.path+""+this.explorer.options.style+"/processIcon/"+this.icon;
  218. var itemIconNode = new Element("div", {
  219. "styles": this.css.itemIconNode
  220. }).inject(this.node);
  221. itemIconNode.setStyle("background", "url("+iconUrl+") center center no-repeat");
  222. if( o2.AC.isQueryManager() ){
  223. itemIconNode.addEvent("click", function(e){
  224. this.toggleSelected();
  225. e.stopPropagation();
  226. }.bind(this));
  227. }
  228. itemIconNode.makeLnk({
  229. "par": this._getLnkPar()
  230. });
  231. },
  232. _open: function(e){
  233. var _self = this;
  234. var options = {
  235. "appId": "query.StatementDesigner"+_self.data.id,
  236. "id": _self.data.id,
  237. // "application":_self.explorer.app.options.application.id,
  238. "application":{
  239. "name": _self.explorer.app.options.application.name,
  240. "id": _self.explorer.app.options.application.id
  241. },
  242. "onQueryLoad": function(){
  243. this.actions = _self.explorer.actions;
  244. this.category = _self;
  245. this.options.id = _self.data.id;
  246. this.application = _self.explorer.app.options.application;
  247. }
  248. };
  249. this.explorer.app.desktop.openApplication(e, "query.StatementDesigner", options);
  250. },
  251. _getIcon: function(){
  252. var x = (Math.random()*49).toInt();
  253. return "process_icon_"+x+".png";
  254. },
  255. _getLnkPar: function(){
  256. return {
  257. "icon": this.explorer.path+this.explorer.options.style+"/statementIcon/lnk.png",
  258. "title": this.data.name,
  259. "par": "query.StatementDesigner#{\"id\": \""+this.data.id+"\", \"applicationId\": \""+this.data.query+"\"}"
  260. };
  261. },
  262. deleteStatement: function(callback){
  263. this.explorer.actions.deleteStatement(this.data.id, function(){
  264. this.node.destroy();
  265. if (callback) callback();
  266. }.bind(this));
  267. },
  268. saveas: function(){
  269. MWF.xDesktop.requireApp("Selector", "package", function(){
  270. var selector = new MWF.O2Selector(this.explorer.app.content, {
  271. "title": this.explorer.app.lp.copyto,
  272. "type": "Query",
  273. "values": [this.explorer.app.options.application],
  274. "onComplete": function(items){
  275. items.each(function(item){
  276. this.saveItemAs(item.data);
  277. }.bind(this));
  278. }.bind(this),
  279. });
  280. }.bind(this));
  281. },
  282. saveItemAs: function(item){
  283. var id = item.id;
  284. var name = item.name;
  285. this.explorer.app.restActions.getStatement(this.data.id, function(json){
  286. var data = json.data;
  287. data.id = "";
  288. var oldName = data.name;
  289. o2.Actions.load("x_query_assemble_designer").StatementAction.manageList(function(dJson){
  290. var i=1;
  291. while (dJson.data.some(function(d){ return (d.name && d.name==data.name) || (d.alias && d.alias==data.name) })){
  292. data.name = oldName+"_copy"+i;
  293. data.alias = oldName+"_copy"+i;
  294. i++;
  295. }
  296. data.id = "";
  297. data.isNewStatement = true;
  298. data.application = id;
  299. data.applicationName = name;
  300. this.explorer.app.restActions.saveStatement(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. });