ScriptExplorer.js 13 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251252253254255256257258259260261262263264265266267268269270271272273274275276277278279280281282283284285286287288289290291292293294295296297298299300301302303304305306307308309310311312313314315316317318319320321322323324325326327328329330331332333334335336337338339
  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. },
  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 application = _self.app.options.application || _self.app.application;
  163. var options = {
  164. "application":{
  165. "name": application.name,
  166. "id": application.id
  167. },
  168. "onQueryLoad": function(){
  169. this.actions = _self.app.restActions;
  170. this.application = application;
  171. this.explorer = _self;
  172. }
  173. };
  174. this.app.desktop.openApplication(e, "portal.ScriptDesigner", options);
  175. },
  176. _loadItemDataList: function(callback){
  177. var id = "";
  178. if (this.app.application) id = this.app.application.id;
  179. if (this.app.options.application) id = this.app.options.application.id;
  180. this.actions.listScript(id,callback);
  181. },
  182. _getItemObject: function(item){
  183. return new MWF.xApplication.portal.PortalManager.ScriptExplorer.Script(this, item)
  184. },
  185. setTooltip: function(){
  186. this.options.tooltip = {
  187. "create": MWF.xApplication.portal.PortalManager.LP.script.create,
  188. "search": MWF.xApplication.portal.PortalManager.LP.script.search,
  189. "searchText": MWF.xApplication.portal.PortalManager.LP.script.searchText,
  190. "noElement": MWF.xApplication.portal.PortalManager.LP.script.noScriptNoticeText
  191. };
  192. },
  193. loadElementList: function(){
  194. debugger;
  195. this._loadItemDataList(function(json){
  196. if (json.data.length){
  197. json.data.each(function(item){
  198. var itemObj = this._getItemObject(item);
  199. itemObj.load()
  200. }.bind(this));
  201. }else{
  202. var noElementNode = new Element("div.noElementNode", {
  203. "styles": this.css.noElementNode,
  204. "text": (this.options.noCreate) ? this.options.tooltip.noElement : this.options.tooltip.noElement
  205. }).inject(this.elementContentListNode);
  206. if (!this.options.noCreate){
  207. noElementNode.addEvent("click", function(e){
  208. this._createElement(e);
  209. }.bind(this));
  210. }
  211. }
  212. if( !this.isSetContentSize ){
  213. this.setContentSize();
  214. this.isSetContentSize = true;
  215. }
  216. }.bind(this));
  217. },
  218. deleteItems: function(){
  219. this.hideDeleteAction();
  220. while (this.deleteMarkItems.length){
  221. var item = this.deleteMarkItems.shift();
  222. if (this.deleteMarkItems.length){
  223. item.deleteScript();
  224. }else{
  225. item.deleteScript(function(){
  226. // this.reloadItems();
  227. // this.hideDeleteAction();
  228. }.bind(this));
  229. }
  230. }
  231. }
  232. });
  233. MWF.xApplication.portal.PortalManager.ScriptExplorer.Script = new Class({
  234. Extends: MWF.xApplication.process.ProcessManager.DictionaryExplorer.Dictionary,
  235. _customNodes: function(){
  236. if (!this.data.validated){
  237. new Element("div", {"styles": this.explorer.css.itemErrorNode}).inject(this.node);
  238. this.node.setStyle("background-color", "#f9e8e8");
  239. }
  240. },
  241. _open: function(e){
  242. var _self = this;
  243. var options = {
  244. "appId": "portal.ScriptDesigner"+_self.data.id,
  245. "id": _self.data.id,
  246. // "application": _self.explorer.app.options.application.id,
  247. "application":{
  248. "name": _self.explorer.app.options.application.name,
  249. "id": _self.explorer.app.options.application.id
  250. },
  251. "onQueryLoad": function(){
  252. this.actions = _self.explorer.actions;
  253. this.category = _self;
  254. this.options.id = _self.data.id;
  255. this.application = _self.explorer.app.options.application;
  256. this.explorer = _self.explorer
  257. }
  258. };
  259. this.explorer.app.desktop.openApplication(e, "portal.ScriptDesigner", options);
  260. },
  261. _getIcon: function(){
  262. //var x = (Math.random()*33).toInt();
  263. //return "process_icon_"+x+".png";
  264. return "script.png";
  265. },
  266. _getLnkPar: function(){
  267. return {
  268. "icon": this.explorer.path+this.explorer.options.style+"/scriptIcon/lnk.png",
  269. "title": this.data.name,
  270. "par": "portal.ScriptDesigner#{\"id\": \""+this.data.id+"\", \"applicationId\": \""+this.explorer.app.options.application.id+"\"}"
  271. };
  272. },
  273. // deleteItem: function(e){
  274. // var _self = this;
  275. // this.explorer.app.confirm("info", e, this.explorer.app.lp.form.deleteFormTitle, this.explorer.app.lp.form.deleteForm, 320, 110, function(){
  276. // _self.deleteForm();
  277. // this.close();
  278. // },function(){
  279. // this.close();
  280. // });
  281. // },
  282. deleteScript: function(callback){
  283. this.explorer.app.restActions.deleteScript(this.data.id, function(){
  284. this.node.destroy();
  285. if (callback) callback();
  286. }.bind(this));
  287. },
  288. saveas: function(){
  289. MWF.xDesktop.requireApp("Selector", "package", function(){
  290. var selector = new MWF.O2Selector(this.explorer.app.content, {
  291. "title": this.explorer.app.lp.copyto,
  292. "type": "Portal",
  293. "values": [this.explorer.app.options.application],
  294. "onComplete": function(items){
  295. items.each(function(item){
  296. this.saveItemAs(item.data);
  297. }.bind(this));
  298. }.bind(this),
  299. });
  300. }.bind(this));
  301. },
  302. saveItemAs: function(item){
  303. var id = item.id;
  304. var name = item.name;
  305. this.explorer.app.restActions.getScript(this.data.id, function(json){
  306. var data = json.data;
  307. var oldName = data.name;
  308. this.explorer.app.restActions.listScript(id, function(dJson){
  309. var i=1;
  310. while (dJson.data.some(function(d){ return d.name==data.name || d.alias==data.name })){
  311. data.name = oldName+"_copy"+i;
  312. data.alias = oldName+"_copy"+i;
  313. i++;
  314. }
  315. data.id = "";
  316. data.isNewScript = true;
  317. data.application = id;
  318. data.applicationName = name;
  319. this.explorer.app.restActions.saveScript(data, function(){
  320. if (id == this.explorer.app.options.application.id) this.explorer.reload();
  321. }.bind(this));
  322. }.bind(this));
  323. }.bind(this));
  324. }
  325. });