PageExplorer.js 13 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251252253254255256257258259260261262263264265266267268269270271272273274275276277278279280281282283284285286287288289290291292293294295296297298299300301302303304305306307308309310311312313314315316317318319320321322323
  1. MWF.xDesktop.requireApp("process.ProcessManager", "Explorer", null, false);
  2. MWF.xApplication.portal.PortalManager.PageExplorer = new Class({
  3. Extends: MWF.xApplication.process.ProcessManager.Explorer,
  4. Implements: [Options, Events],
  5. options: {
  6. "style": "default",
  7. "tooltip": {
  8. "create": MWF.xApplication.portal.PortalManager.LP.page.create,
  9. "search": MWF.xApplication.portal.PortalManager.LP.page.search,
  10. "searchText": MWF.xApplication.portal.PortalManager.LP.page.searchText,
  11. "noElement": MWF.xApplication.portal.PortalManager.LP.page.noPageNoticeText
  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.getPage(item.data.id, function(json){
  43. json.data.elementType = "page";
  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==="page"){
  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.listPage(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 || data.updateTime);
  92. var d2 = new Date().parse(someItem.lastUpdateTime || someItem.updateTime);
  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 || someItem.updateTime)+"</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 || data.updateTime)+"</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, form, success, failure){
  127. var item = this.app.options.application;
  128. var pcdata = JSON.decode(MWF.decodeJsonString(form.data));
  129. var mobiledata = JSON.decode(MWF.decodeJsonString(form.mobileData));
  130. pcdata.id = someItem.id;
  131. pcdata.isNewPage = false;
  132. pcdata.json.id = someItem.id;
  133. pcdata.json.application = item.id;
  134. pcdata.json.applicationName = item.name;
  135. pcdata.json.name = someItem.name;
  136. pcdata.json.alias = someItem.alias;
  137. mobiledata.json.id = someItem.id;
  138. mobiledata.json.application = item.id;
  139. mobiledata.applicationName = item.name;
  140. mobiledata.json.name = someItem.name;
  141. mobiledata.json.alias = someItem.alias;
  142. this.app.restActions.savePage(pcdata, mobiledata, null, function(){
  143. if (success) success();
  144. }.bind(this), function(){
  145. if (failure) failure();
  146. }.bind(this));
  147. },
  148. saveItemAsNew: function(formsJson, form, success, failure){
  149. var item = this.app.options.application;
  150. var id = item.id;
  151. var name = item.name;
  152. var pcdata = JSON.decode(MWF.decodeJsonString(form.data));
  153. var mobiledata = JSON.decode(MWF.decodeJsonString(form.mobileData));
  154. var oldName = pcdata.json.name;
  155. var i=1;
  156. while (formsJson.data.some(function(d){ return d.name==pcdata.json.name })){
  157. pcdata.json.name = oldName+"_copy"+i;
  158. mobiledata.json.name = oldName+"_copy"+i;
  159. i++;
  160. }
  161. pcdata.id = "";
  162. pcdata.isNewPage = true;
  163. pcdata.json.id = "";
  164. pcdata.json.application = id;
  165. pcdata.json.applicationName = name;
  166. pcdata.json.alias = "";
  167. mobiledata.json.id = "";
  168. mobiledata.json.application = id;
  169. mobiledata.applicationName = name;
  170. mobiledata.json.alias = "";
  171. this.app.restActions.savePage(pcdata, mobiledata, null, function(){
  172. if (success) success();
  173. }.bind(this), function(){
  174. if (failure) failure();
  175. }.bind(this));
  176. },
  177. _createElement: function(e){
  178. if( layout.desktop && layout.desktop.getPageDesignerStyle ){
  179. layout.desktop.getPageDesignerStyle(function(){
  180. this.__createElement(e, layout.desktop.pageDesignerStyle )
  181. }.bind(this));
  182. }else{
  183. this.__createElement( e,"default" );
  184. }
  185. },
  186. __createElement: function( e, style ){
  187. var _self = this;
  188. var options = {
  189. "style": style,
  190. "template": "page.json",
  191. "application":{
  192. "name": _self.app.options.application.name,
  193. "id": _self.app.options.application.id
  194. },
  195. "onQueryLoad": function(){
  196. this.actions = _self.app.restActions;
  197. this.application = _self.app.options.application;
  198. }
  199. };
  200. layout.desktop.openApplication(e, "portal.PageDesigner", options);
  201. },
  202. _loadItemDataList: function(callback){
  203. this.app.restActions.listPage(this.app.options.application.id,callback);
  204. },
  205. _getItemObject: function(item){
  206. return new MWF.xApplication.portal.PortalManager.PageExplorer.Page(this, item)
  207. },
  208. deleteItems: function(){
  209. this.hideDeleteAction();
  210. while (this.deleteMarkItems.length){
  211. var item = this.deleteMarkItems.shift();
  212. if (this.deleteMarkItems.length){
  213. item.deletePage();
  214. }else{
  215. item.deletePage(function(){
  216. // this.reloadItems();
  217. //this.hideDeleteAction();
  218. }.bind(this));
  219. }
  220. }
  221. }
  222. });
  223. MWF.xApplication.portal.PortalManager.PageExplorer.Page= new Class({
  224. Extends: MWF.xApplication.process.ProcessManager.Explorer.Item,
  225. _open: function(e){
  226. var _self = this;
  227. var options = {
  228. "appId": "portal.PageDesigner"+_self.data.id,
  229. "id": _self.data.id,
  230. // "application": _self.explorer.app.options.application.id,
  231. "application":{
  232. "name": _self.explorer.app.options.application.name,
  233. "id": _self.explorer.app.options.application.id
  234. },
  235. "onQueryLoad": function(){
  236. this.actions = _self.explorer.actions;
  237. this.category = _self;
  238. this.options.id = _self.data.id;
  239. this.application = _self.explorer.app.options.application;
  240. }
  241. };
  242. this.explorer.app.desktop.openApplication(e, "portal.PageDesigner", options);
  243. },
  244. _getIcon: function(){
  245. var x = (Math.random()*49).toInt();
  246. return "process_icon_"+x+".png";
  247. },
  248. _getLnkPar: function(){
  249. return {
  250. "icon": this.explorer.path+this.explorer.options.style+"/formIcon/lnk.png",
  251. "title": this.data.name,
  252. "par": "portal.PageDesigner#{\"id\": \""+this.data.id+"\"}"
  253. };
  254. },
  255. deletePage: function(callback){
  256. this.explorer.actions.deletePage(this.data.id, function(){
  257. this.node.destroy();
  258. if (callback) callback();
  259. }.bind(this));
  260. },
  261. saveas: function(){
  262. MWF.xDesktop.requireApp("Selector", "package", function(){
  263. var selector = new MWF.O2Selector(this.explorer.app.content, {
  264. "title": this.explorer.app.lp.copyto,
  265. "type": "Portal",
  266. "values": [this.explorer.app.options.application],
  267. "onComplete": function(items){
  268. items.each(function(item){
  269. this.saveItemAs(item.data);
  270. }.bind(this));
  271. }.bind(this),
  272. });
  273. }.bind(this));
  274. },
  275. saveItemAs: function(item){
  276. var id = item.id;
  277. var name = item.name;
  278. this.explorer.app.restActions.getPage(this.data.id, function(json){
  279. var pcdata = JSON.decode(MWF.decodeJsonString(json.data.data));
  280. var mobiledata = JSON.decode(MWF.decodeJsonString(json.data.mobileData));
  281. pcdata.json.alias = "";
  282. mobiledata.json.alias = "";
  283. var oldName = pcdata.json.name;
  284. this.explorer.app.restActions.listPage(id, function(formsJson){
  285. var i=1;
  286. while (formsJson.data.some(function(d){ return d.name==pcdata.json.name })){
  287. pcdata.json.name = oldName+"_copy"+i;
  288. mobiledata.json.name = oldName+"_copy"+i;
  289. i++;
  290. }
  291. pcdata.id = "";
  292. pcdata.isNewPage = true;
  293. pcdata.json.id = "";
  294. pcdata.json.application = id;
  295. pcdata.json.applicationName = name;
  296. mobiledata.json.id = "";
  297. mobiledata.json.application = id;
  298. mobiledata.applicationName = name;
  299. this.explorer.app.restActions.savePage(pcdata, mobiledata, null, function(){
  300. if (id == this.explorer.app.options.application.id) this.explorer.reload();
  301. }.bind(this));
  302. }.bind(this));
  303. }.bind(this));
  304. }
  305. });