ScriptExplorer.js 14 KB

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