Main.js 18 KB

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