ProjectionExplorer.js 15 KB

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