Main.js 18 KB

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