ScriptExplorer.js 12 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251252253254255256257258259260261262263264265266267268269270271272273274275276277278279280281282283284285286287288289290291292293294295296297298299300301302303
  1. MWF.xDesktop.requireApp("process.ProcessManager", "DictionaryExplorer", null, false);
  2. MWF.xApplication.portal.PortalManager.ScriptExplorer = new Class({
  3. Extends: MWF.xApplication.process.ProcessManager.DictionaryExplorer,
  4. Implements: [Options, Events],
  5. options: {
  6. "style": "default",
  7. "tooltip": {
  8. "create": MWF.xApplication.portal.PortalManager.LP.script.create,
  9. "search": MWF.xApplication.portal.PortalManager.LP.script.search,
  10. "searchText": MWF.xApplication.portal.PortalManager.LP.script.searchText,
  11. "noElement": MWF.xApplication.portal.PortalManager.LP.script.noProcessNoticeText
  12. }
  13. },
  14. openFindDesigner: function(){
  15. this.app.options.application.moduleType = "portal";
  16. var options = {
  17. "filter": {
  18. "moduleList": ["portal"],
  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.getScript(item.data.id, function(json){
  43. json.data.elementType = "script";
  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==="script"){
  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.listScript(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);
  92. var d2 = new Date().parse(someItem.lastUpdateTime);
  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+"</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+"</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. data.id = someItem.id;
  128. data.name = someItem.name;
  129. data.alias = someItem.alias;
  130. data.isNewScript = false;
  131. data.application = someItem.application;
  132. data.applicationName = someItem.applicationName;
  133. this.app.restActions.saveScript(data, function(){
  134. if (success) success();
  135. }.bind(this), function(){
  136. if (failure) failure();
  137. }.bind(this));
  138. },
  139. saveItemAsNew: function(dJson, data, success, failure){
  140. var item = this.app.options.application;
  141. var id = item.id;
  142. var name = item.name;
  143. var oldName = data.name;
  144. var i=1;
  145. while (dJson.data.some(function(d){ return d.name==data.name || d.alias==data.name })){
  146. data.name = oldName+"_copy"+i;
  147. data.alias = oldName+"_copy"+i;
  148. i++;
  149. }
  150. data.id = "";
  151. data.isNewScript = true;
  152. data.application = id;
  153. data.applicationName = name;
  154. this.app.restActions.saveScript(data, function(){
  155. if (success) success();
  156. }.bind(this), function(){
  157. if (failure) failure();
  158. }.bind(this));
  159. },
  160. _createElement: function(e){
  161. var _self = this;
  162. var options = {
  163. "onQueryLoad": function(){
  164. this.actions = _self.app.restActions;
  165. this.application = _self.app.options.application || _self.app.application;
  166. this.explorer = _self;
  167. }
  168. };
  169. this.app.desktop.openApplication(e, "portal.ScriptDesigner", options);
  170. },
  171. _loadItemDataList: function(callback){
  172. var id = "";
  173. if (this.app.application) id = this.app.application.id;
  174. if (this.app.options.application) id = this.app.options.application.id;
  175. this.actions.listScript(id,callback);
  176. },
  177. _getItemObject: function(item){
  178. return new MWF.xApplication.portal.PortalManager.ScriptExplorer.Script(this, item)
  179. },
  180. setTooltip: function(){
  181. this.options.tooltip = {
  182. "create": MWF.APPPM.LP.script.create,
  183. "search": MWF.APPPM.LP.script.search,
  184. "searchText": MWF.APPPM.LP.script.searchText,
  185. "noElement": MWF.APPPM.LP.script.noScriptNoticeText
  186. };
  187. },
  188. deleteItems: function(){
  189. this.hideDeleteAction();
  190. while (this.deleteMarkItems.length){
  191. var item = this.deleteMarkItems.shift();
  192. if (this.deleteMarkItems.length){
  193. item.deleteScript();
  194. }else{
  195. item.deleteScript(function(){
  196. // this.reloadItems();
  197. // this.hideDeleteAction();
  198. }.bind(this));
  199. }
  200. }
  201. }
  202. });
  203. MWF.xApplication.portal.PortalManager.ScriptExplorer.Script = new Class({
  204. Extends: MWF.xApplication.process.ProcessManager.DictionaryExplorer.Dictionary,
  205. _customNodes: function(){
  206. if (!this.data.validated){
  207. new Element("div", {"styles": this.explorer.css.itemErrorNode}).inject(this.node);
  208. this.node.setStyle("background-color", "#f9e8e8");
  209. }
  210. },
  211. _open: function(e){
  212. var _self = this;
  213. var options = {
  214. "appId": "portal.ScriptDesigner"+_self.data.id,
  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, "portal.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": "portal.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. saveas: function(){
  253. MWF.xDesktop.requireApp("Selector", "package", function(){
  254. var selector = new MWF.O2Selector(this.explorer.app.content, {
  255. "title": this.explorer.app.lp.copyto,
  256. "type": "Portal",
  257. "values": [this.explorer.app.options.application],
  258. "onComplete": function(items){
  259. items.each(function(item){
  260. this.saveItemAs(item.data);
  261. }.bind(this));
  262. }.bind(this),
  263. });
  264. }.bind(this));
  265. },
  266. saveItemAs: function(item){
  267. var id = item.id;
  268. var name = item.name;
  269. this.explorer.app.restActions.getScript(this.data.id, function(json){
  270. var data = json.data;
  271. var oldName = data.name;
  272. this.explorer.app.restActions.listScript(id, function(dJson){
  273. var i=1;
  274. while (dJson.data.some(function(d){ return d.name==data.name || d.alias==data.name })){
  275. data.name = oldName+"_copy"+i;
  276. data.alias = oldName+"_copy"+i;
  277. i++;
  278. }
  279. data.id = "";
  280. data.isNewScript = true;
  281. data.application = id;
  282. data.applicationName = name;
  283. this.explorer.app.restActions.saveScript(data, function(){
  284. if (id == this.explorer.app.options.application.id) this.explorer.reload();
  285. }.bind(this));
  286. }.bind(this));
  287. }.bind(this));
  288. }
  289. });