Main.js 19 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251252253254255256257258259260261262263264265266267268269270271272273274275276277278279280281282283284285286287288289290291292293294295296297298299300301302303304305306307308309310311312313314315316317318319320321322323324325326327328329330331332333334335336337338339340341342343344345346347348349350351352353354355356357358359360361362363364365366367368369370371372373374375376377378379380381382383384385386387388389390391392393394395396397398399400401402403404405406407408409410411412413414415416417418419420421422423424425426427428429430431432433434435436437438439440441442
  1. MWF.xDesktop.requireApp("portal.PortalManager", "package", null, false);
  2. //MWF.xDesktop.requireApp("portal.PortalManager", "Actions.RestActions", null, false);
  3. MWF.require("MWF.xAction.org.express.RestActions", null,false);
  4. MWF.require("MWF.widget.Identity", null,false);
  5. MWF.xDesktop.requireApp("process.ProcessManager", "", null, false);
  6. MWF.xApplication.portal = MWF.xApplication.portal || {};
  7. MWF.xApplication.portal.PortalManager.Main = new Class({
  8. Extends: MWF.xApplication.process.ProcessManager.Main,
  9. Implements: [Options, Events],
  10. options: {
  11. "application": null,
  12. "style": "default",
  13. "name": "portal.PortalManager",
  14. "icon": "icon.png",
  15. "width": "1100",
  16. "height": "700",
  17. "title": MWF.xApplication.portal.PortalManager.LP.title
  18. },
  19. onQueryLoad: function(){
  20. this.lp = MWF.xApplication.portal.PortalManager.LP;
  21. this.currentContentNode = null;
  22. this.restActions = MWF.Actions.get("x_portal_assemble_designer");
  23. //new MWF.xApplication.portal.PortalManager.Actions.RestActions();
  24. },
  25. keyCopyItems: function(e){
  26. if (layout.desktop.currentApp && layout.desktop.currentApp.appId===this.appId){
  27. if (this.pageConfigurator){
  28. this.pageConfigurator.keyCopy(e);
  29. }
  30. if (this.scriptConfigurator){
  31. this.scriptConfigurator.keyCopy(e);
  32. }
  33. if (this.widgetConfigurator){
  34. this.widgetConfigurator.keyCopy(e);
  35. }
  36. }
  37. },
  38. keyPasteItems: function(e){
  39. if (layout.desktop.currentApp && layout.desktop.currentApp.appId===this.appId) {
  40. if (this.pageConfigurator){
  41. this.pageConfigurator.keyPaste(e);
  42. }
  43. if (this.scriptConfigurator){
  44. this.scriptConfigurator.keyPaste(e);
  45. }
  46. if (this.widgetConfigurator){
  47. this.widgetConfigurator.keyPaste(e);
  48. }
  49. }
  50. },
  51. loadStartMenu: function(callback){
  52. this.startMenuNode = new Element("div", {
  53. "styles": this.css.startMenuNode
  54. }).inject(this.node);
  55. this.menu = new MWF.xApplication.portal.PortalManager.Menu(this, this.startMenuNode, {
  56. "onPostLoad": function(){
  57. if (this.status){
  58. if (this.status.navi!=null){
  59. this.menu.doAction(this.menu.startNavis[this.status.navi]);
  60. }else{
  61. this.menu.doAction(this.menu.startNavis[0]);
  62. }
  63. }else{
  64. this.menu.doAction(this.menu.startNavis[0]);
  65. }
  66. }.bind(this)
  67. });
  68. this.addEvent("resize", function(){
  69. if (this.menu) this.menu.onResize();
  70. }.bind(this));
  71. },
  72. clearContent: function(){
  73. if (this.pageConfiguratorContent){
  74. if (this.pageConfigurator) delete this.pageConfigurator;
  75. this.pageConfiguratorContent.destroy();
  76. this.pageConfiguratorContent = null;
  77. }
  78. if (this.menuConfiguratorContent){
  79. if (this.menuConfigurator) delete this.menuConfigurator;
  80. this.menuConfiguratorContent.destroy();
  81. this.menuConfiguratorContent = null;
  82. }
  83. if (this.propertyConfiguratorContent){
  84. if (this.property) delete this.property;
  85. this.propertyConfiguratorContent.destroy();
  86. this.propertyConfiguratorContent = null;
  87. }
  88. if (this.widgetConfiguratorContent){
  89. if (this.widgetConfigurator) delete this.widgetConfigurator;
  90. this.widgetConfiguratorContent.destroy();
  91. this.widgetConfiguratorContent = null;
  92. }
  93. if (this.scriptConfiguratorContent){
  94. if (this.scriptConfigurator) delete this.scriptConfigurator;
  95. this.scriptConfiguratorContent.destroy();
  96. this.scriptConfiguratorContent = null;
  97. }
  98. if (this.fileConfiguratorContent){
  99. if (this.fileConfigurator) delete this.fileConfigurator;
  100. this.fileConfiguratorContent.destroy();
  101. this.fileConfiguratorContent = null;
  102. }
  103. },
  104. applicationProperty: function(){
  105. this.clearContent();
  106. this.propertyConfiguratorContent = new Element("div", {
  107. "styles": this.css.rightContentNode
  108. }).inject(this.node);
  109. this.property = new MWF.xApplication.portal.PortalManager.ApplicationProperty(this, this.propertyConfiguratorContent);
  110. this.property.load();
  111. },
  112. pageConfig: function(){
  113. this.clearContent();
  114. this.pageConfiguratorContent = new Element("div", {
  115. "styles": this.css.rightContentNode
  116. }).inject(this.node);
  117. this.loadPageConfig();
  118. },
  119. loadPageConfig: function(){
  120. MWF.xDesktop.requireApp("portal.PortalManager", "PageExplorer", function(){
  121. this.pageConfigurator = new MWF.xApplication.portal.PortalManager.PageExplorer(this.pageConfiguratorContent, this.restActions);
  122. this.pageConfigurator.app = this;
  123. this.pageConfigurator.load();
  124. }.bind(this));
  125. },
  126. menuConfig: function(){
  127. this.clearContent();
  128. this.menuConfiguratorContent = new Element("div", {
  129. "styles": this.css.rightContentNode
  130. }).inject(this.node);
  131. this.loadMenuConfig();
  132. },
  133. loadMenuConfig: function(){
  134. MWF.xDesktop.requireApp("portal.PortalManager", "MenuExplorer", function(){
  135. //MWF.xDesktop.requireApp("portal.PortalManager", "Actions.RestActions", function(){
  136. //if (!this.restActions) this.restActions = new MWF.xApplication.portal.PortalManager.Actions.RestActions();
  137. if (!this.restActions) this.restActions = MWF.Actions.get("x_portal_assemble_designer");
  138. this.menuConfigurator = new MWF.xApplication.portal.PortalManager.MenuExplorer(this.menuConfiguratorContent, this.restActions);
  139. this.menuConfigurator.app = this;
  140. this.menuConfigurator.load();
  141. //}.bind(this));
  142. }.bind(this));
  143. },
  144. widgetConfig: function(){
  145. this.clearContent();
  146. this.widgetConfiguratorContent = new Element("div", {
  147. "styles": this.css.rightContentNode
  148. }).inject(this.node);
  149. this.loadWidgetConfig();
  150. },
  151. loadWidgetConfig: function(){
  152. MWF.xDesktop.requireApp("portal.PortalManager", "WidgetExplorer", function(){
  153. this.widgetConfigurator = new MWF.xApplication.portal.PortalManager.WidgetExplorer(this.widgetConfiguratorContent, this.restActions);
  154. this.widgetConfigurator.app = this;
  155. this.widgetConfigurator.load();
  156. }.bind(this));
  157. },
  158. scriptConfig: function(){
  159. this.clearContent();
  160. this.scriptConfiguratorContent = new Element("div", {
  161. "styles": this.css.rightContentNode
  162. }).inject(this.node);
  163. this.loadScriptConfig();
  164. },
  165. loadScriptConfig: function(){
  166. MWF.xDesktop.requireApp("portal.PortalManager", "ScriptExplorer", function(){
  167. //MWF.xDesktop.requireApp("portal.PortalManager", "Actions.RestActions", function(){
  168. //if (!this.restActions) this.restActions = new MWF.xApplication.portal.PortalManager.Actions.RestActions();
  169. if (!this.restActions) this.restActions = MWF.Actions.get("x_portal_assemble_designer");
  170. this.scriptConfigurator = new MWF.xApplication.portal.PortalManager.ScriptExplorer(this.scriptConfiguratorContent, this.restActions);
  171. this.scriptConfigurator.app = this;
  172. this.scriptConfigurator.load();
  173. //}.bind(this));
  174. }.bind(this));
  175. },
  176. fileConfig: function(){
  177. this.clearContent();
  178. this.fileConfiguratorContent = new Element("div", {
  179. "styles": this.css.rightContentNode
  180. }).inject(this.node);
  181. this.loadFileConfig();
  182. },
  183. loadFileConfig: function(){
  184. MWF.xDesktop.requireApp("portal.PortalManager", "FileExplorer", function(){
  185. //MWF.xDesktop.requireApp("process.ProcessManager", "Actions.RestActions", function(){
  186. // if (!this.restActions) this.restActions = new MWF.xApplication.process.ProcessManager.Actions.RestActions();
  187. this.restActions = MWF.Actions.get("x_portal_assemble_designer");
  188. this.fileConfigurator = new MWF.xApplication.portal.PortalManager.FileExplorer(this.fileConfiguratorContent, this.restActions);
  189. this.fileConfigurator.app = this;
  190. this.fileConfigurator.load();
  191. //}.bind(this));
  192. }.bind(this));
  193. }
  194. });
  195. MWF.xApplication.portal.PortalManager.Menu = new Class({
  196. Extends: MWF.xApplication.process.ProcessManager.Menu,
  197. Implements: [Options, Events]
  198. });
  199. MWF.xApplication.portal.PortalManager.ApplicationProperty = new Class({
  200. Extends: MWF.xApplication.process.ProcessManager.ApplicationProperty,
  201. createPropertyContentNode: function(){
  202. this.propertyContentNode = new Element("div", {"styles": {
  203. "overflow": "hidden",
  204. "-webkit-user-select": "text",
  205. "-moz-user-select": "text"
  206. }}).inject(this.contentAreaNode);
  207. var html = "<table cellspacing='0' cellpadding='0' border='0' width='95%' align='center' style='margin-top: 20px'>";
  208. html += "<tr><td class='formTitle'>"+this.app.lp.application.name+"</td><td id='formApplicationName'></td></tr>";
  209. html += "<tr><td class='formTitle'>"+this.app.lp.application.alias+"</td><td id='formApplicationAlias'></td></tr>";
  210. html += "<tr><td class='formTitle'>"+this.app.lp.application.description+"</td><td id='formApplicationDescription'></td></tr>";
  211. html += "<tr><td class='formTitle'>"+this.app.lp.application.type+"</td><td id='formApplicationType'></td></tr>";
  212. html += "<tr><td class='formTitle'>"+this.app.lp.application.firstPage+"</td><td id='formApplicationFirstPage'></td></tr>";
  213. html += "<tr><td class='formTitle'>"+this.app.lp.application.pcClient+"</td><td id='formApplicationPcClient'></td></tr>";
  214. html += "<tr><td class='formTitle'>"+this.app.lp.application.mobileClient+"</td><td id='formApplicationMobileClient'></td></tr>";
  215. // html += "<tr><td class='formTitle'>"+this.app.lp.application.anonymousAccess+"</td><td id='formApplicationAnonymousAccess'></td></tr>";
  216. html += "<tr><td class='formTitle'>"+this.app.lp.application.id+"</td><td id='formApplicationId'></td></tr>";
  217. html += "<tr><td class='formTitle'>"+this.app.lp.application.url+"</td><td id='formApplicationUrl'></td></tr>";
  218. // html += "<tr><td class='formTitle'>"+this.app.lp.application.icon+"</td><td id='formApplicationIcon'></td></tr>";
  219. html += "</table>";
  220. this.propertyContentNode.set("html", html);
  221. this.propertyContentNode.getElements("td.formTitle").setStyles(this.app.css.propertyBaseContentTdTitle);
  222. this.nameInput = new MWF.xApplication.portal.PortalManager.Input(this.propertyContentNode.getElement("#formApplicationName"), this.data.name, this.app.css.formInput);
  223. this.aliasInput = new MWF.xApplication.portal.PortalManager.Input(this.propertyContentNode.getElement("#formApplicationAlias"), this.data.alias, this.app.css.formInput);
  224. this.descriptionInput = new MWF.xApplication.portal.PortalManager.Input(this.propertyContentNode.getElement("#formApplicationDescription"), this.data.description, this.app.css.formInput);
  225. this.typeInput = new MWF.xApplication.portal.PortalManager.Input(this.propertyContentNode.getElement("#formApplicationType"), this.data.portalCategory, this.app.css.formInput);
  226. this.firstPageInput = new MWF.xApplication.portal.PortalManager.Select(this.propertyContentNode.getElement("#formApplicationFirstPage"), this.data.firstPage, this.app.css.formInput, function(){
  227. var pages = {};
  228. this.app.restActions.listPage(this.app.options.application.id, function(json){
  229. json.data.each(function(page) {
  230. pages[page.id] = page.name;
  231. }.bind(this));
  232. }.bind(this), null, false);
  233. return pages;
  234. }.bind(this));
  235. this.pcClientInput = new MWF.xApplication.portal.PortalManager.Radio(this.propertyContentNode.getElement("#formApplicationPcClient"), (this.data.pcClient!=undefined) ? this.data.pcClient.toString() : "true", this.app.css.formInput, function(){
  236. return {
  237. "true": this.app.lp.application.true,
  238. "false": this.app.lp.application.false
  239. };
  240. }.bind(this));
  241. this.mobileClientInput = new MWF.xApplication.portal.PortalManager.Radio(this.propertyContentNode.getElement("#formApplicationMobileClient"), (this.data.mobileClient!=undefined) ? this.data.mobileClient.toString():"true", this.app.css.formInput, function(){
  242. return {
  243. "true": this.app.lp.application.true,
  244. "false": this.app.lp.application.false
  245. };
  246. }.bind(this));
  247. // this.anonymousAccessInput = new MWF.xApplication.portal.PortalManager.Radio(
  248. // this.propertyContentNode.getElement("#formApplicationAnonymousAccess"),
  249. // (this.data.anonymousAccess!=undefined) ? this.data.anonymousAccess.toString():"false",
  250. // this.app.css.formInput,
  251. // function(){
  252. // return {
  253. // "true": this.app.lp.application.true,
  254. // "false": this.app.lp.application.false
  255. // };
  256. // }.bind(this))
  257. // ;
  258. this.idInput = new MWF.xApplication.portal.PortalManager.Input(this.propertyContentNode.getElement("#formApplicationId"), this.data.id, this.app.css.formInput);
  259. var host = window.location.host;
  260. //var port = window.location.port;
  261. var par = '?id='+this.data.id;
  262. //var url = "http://"+host+(((!port || port==80) ? "" : ":"+port))+"../x_desktop/portal.html"+par;
  263. var url = "http://"+host+"/x_desktop/portal.html"+par;
  264. this.urlInput = new MWF.xApplication.portal.PortalManager.Input(this.propertyContentNode.getElement("#formApplicationUrl"), url, this.app.css.formInput);
  265. },
  266. editMode: function(){
  267. this.nameInput.editMode();
  268. this.aliasInput.editMode();
  269. this.descriptionInput.editMode();
  270. this.typeInput.editMode();
  271. this.firstPageInput.editMode();
  272. this.pcClientInput.editMode();
  273. this.mobileClientInput.editMode();
  274. // this.anonymousAccessInput.editMode();
  275. this.isEdit = true;
  276. },
  277. readMode: function(){
  278. this.nameInput.readMode();
  279. this.aliasInput.readMode();
  280. this.descriptionInput.readMode();
  281. this.typeInput.readMode();
  282. this.firstPageInput.readMode();
  283. this.pcClientInput.readMode();
  284. this.mobileClientInput.readMode();
  285. // this.anonymousAccessInput.readMode();
  286. this.isEdit = false;
  287. },
  288. save: function(callback, cancel) {
  289. this.data.name = this.nameInput.input.get("value");
  290. this.data.alias = this.aliasInput.input.get("value");
  291. this.data.description = this.descriptionInput.input.get("value");
  292. this.data.portalCategory = this.typeInput.input.get("value") || "";
  293. this.data.firstPage = this.firstPageInput.input.get("value");
  294. this.data.pcClient = this.pcClientInput.getValue()==="true";
  295. this.data.mobileClient = this.mobileClientInput.getValue()==="true";
  296. // this.data.anonymousAccess = this.anonymousAccessInput.getValue()==="true";
  297. this.app.restActions.saveApplication(this.data, function (json) {
  298. this.propertyTitleBar.set("text", this.data.name);
  299. this.data.id = json.data.id;
  300. this.nameInput.save();
  301. this.aliasInput.save();
  302. this.descriptionInput.save();
  303. this.typeInput.save();
  304. this.firstPageInput.save();
  305. this.pcClientInput.save();
  306. this.mobileClientInput.save();
  307. // this.anonymousAccessInput.save();
  308. if (callback) callback();
  309. }.bind(this), function (xhr, text, error) {
  310. if (cancel) cancel(xhr, text, error);
  311. }.bind(this));
  312. }
  313. });
  314. MWF.xApplication.portal.PortalManager.Input = new Class({
  315. Extends: MWF.xApplication.process.ProcessManager.Input,
  316. Implements: [Events]
  317. });
  318. MWF.xApplication.portal.PortalManager.Select = new Class({
  319. Extends: MWF.xApplication.portal.PortalManager.Input,
  320. Implements: [Events],
  321. initialize: function(node, value, style, select){
  322. this.node = $(node);
  323. this.value = (value) ? value: "";
  324. this.style = style;
  325. this.select = select;
  326. this.selectList = null;
  327. this.load();
  328. },
  329. getSelectList: function(){
  330. if (this.select){
  331. return this.select();
  332. }
  333. return [];
  334. },
  335. getText: function(value){
  336. if (value){
  337. if (this.selectList){
  338. return this.selectList[value] || "";
  339. }
  340. }
  341. return "";
  342. },
  343. load: function(){
  344. this.selectList = this.getSelectList();
  345. this.content = new Element("div", {
  346. "styles": this.style.content,
  347. "text": this.getText(this.value)
  348. }).inject(this.node);
  349. },
  350. editMode: function(){
  351. this.content.empty();
  352. this.input = new Element("select",{
  353. //"styles": this.style.input,
  354. //"value": this.value
  355. }).inject(this.content);
  356. Object.each(this.selectList, function(v, k){
  357. new Element("option", {
  358. "value": k,
  359. "text": v,
  360. "selected": (this.value==k)
  361. }).inject(this.input);
  362. }.bind(this));
  363. //this.input.addEvents({
  364. // //"focus": function(){
  365. // // this.input.setStyles(this.style.input_focus);
  366. // //}.bind(this),
  367. // //"blur": function(){
  368. // // this.input.setStyles(this.style.input);
  369. // //}.bind(this),
  370. // //"change": function(){
  371. // // this.input.setStyles(this.style.input);
  372. // //}.bind(this)
  373. //});
  374. },
  375. readMode: function(){
  376. this.content.empty();
  377. this.input = null;
  378. this.content.set("text", this.getText(this.value));
  379. },
  380. save: function(){
  381. if (this.input) this.value = this.input.options[this.input.selectedIndex].get("value");
  382. return this.value;
  383. }
  384. });
  385. MWF.xApplication.portal.PortalManager.Radio = new Class({
  386. Extends: MWF.xApplication.portal.PortalManager.Select,
  387. editMode: function(){
  388. this.content.empty();
  389. var name = Math.random();
  390. Object.each(this.selectList, function(v, k){
  391. var input = new Element("input", {
  392. "type": "radio",
  393. "name": "rd"+name,
  394. "value": k,
  395. "checked": (this.value===k)
  396. }).inject(this.content);
  397. input.appendHTML(v, "after");
  398. }.bind(this));
  399. },
  400. getValue: function(){
  401. var radios = this.content.getElements("input");
  402. for (var i=0; i<radios.length; i++){
  403. if (radios[i].checked){
  404. this.value = radios[i].value;
  405. break;
  406. }
  407. }
  408. return this.value;
  409. },
  410. save: function(){
  411. var radios = this.content.getElements("input");
  412. for (var i=0; i<radios.length; i++){
  413. if (radios[i].checked){
  414. this.value = radios[i].value;
  415. break;
  416. }
  417. }
  418. return this.value;
  419. }
  420. });