Main.js 18 KB

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