ScriptExplorer.js 11 KB

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