Main.js 15 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251252253254255256257258259260261262263264265266267268269270271272273274275276277278279280281282283284285286287288289290291292293294295296297298299300301302303304305306307308309310311312313314315316317318319320321322323324325326327328329330331332333334335336337338339340341342343344345346347348349350351352353354355356357358359360361362363364365366367368369370371372373374375376377378379380381382383384385386387388389390391392393394395396397398399400401402403404405406407408409410411412413414415416417418419420421422423424425426427428429430431432433434435436437438439440441442443444445446447448449450451452453454455456457458459460461462463
  1. MWF.xApplication.cms = MWF.xApplication.cms || {};
  2. MWF.CMSE = MWF.xApplication.cms.Explorer = MWF.xApplication.cms.Explorer ||{};
  3. MWF.require("MWF.widget.Identity", null,false);
  4. MWF.xDesktop.requireApp("cms.Explorer", "Actions.RestActions", null, false);
  5. MWF.xApplication.cms.Explorer.options = {
  6. multitask: false,
  7. executable: true
  8. }
  9. MWF.xApplication.cms.Explorer.Main = new Class({
  10. Extends: MWF.xApplication.Common.Main,
  11. Implements: [Options, Events],
  12. options: {
  13. "style": "default",
  14. "name": "cms.Explorer",
  15. "icon": "icon.png",
  16. "width": "1200",
  17. "height": "700",
  18. "isResize": false,
  19. "isMax": true,
  20. "title": MWF.CMSE.LP.title
  21. },
  22. onQueryLoad: function(){
  23. this.lp = MWF.CMSE.LP;
  24. },
  25. loadApplication: function(callback){
  26. this.restActions = new MWF.xApplication.cms.Explorer.Actions.RestActions();
  27. this.createNode();
  28. this.loadApplicationContent();
  29. },
  30. createNode: function(){
  31. this.content.setStyle("overflow", "hidden");
  32. this.node = new Element("div", {
  33. "styles": {"width": "100%", "height": "100%", "overflow": "hidden"}
  34. }).inject(this.content);
  35. },
  36. loadApplicationContent: function(){
  37. this.loadDefaultMenu();
  38. //this.loadApplicationLayout();
  39. },
  40. loadDefaultMenu: function(callback){
  41. this.defaultMenuNode = new Element("div", {
  42. "styles": this.css.defaultMenuNode
  43. }).inject(this.node);
  44. this.menu = new MWF.xApplication.cms.Explorer.Menu(this, this.defaultMenuNode, {
  45. "onPostLoad": function(){
  46. if (this.status){
  47. if (this.status.navi!=null){
  48. if( this.status.navi.type == "default" ) {
  49. this.menu.doAction(this.menu.items[this.status.navi.id]);
  50. }else if(this.status.navi.type == "column" ) {
  51. this.menu.doColumnAction(this.menu.items[this.status.navi.id]);
  52. }else{
  53. this.menu.doColumnAction(this.menu.items[this.status.navi.columnId], function(){
  54. this.menu.doCategoryAction(this.menu.items[this.status.navi.id], this.status.view );
  55. }.bind(this));
  56. }
  57. }else{
  58. if (this.menu.status == "start"){
  59. this.menu.toNormal();
  60. this.menu.status = "normal";
  61. }
  62. //this.menu.doAction(this.menu.navis[0]);
  63. }
  64. }else{
  65. if (this.menu.status == "start"){
  66. this.menu.toNormal();
  67. this.menu.status = "normal";
  68. }
  69. //this.menu.doAction(this.menu.navis[0]);
  70. }
  71. }.bind(this)
  72. });
  73. this.addEvent("resize", function(){
  74. if (this.menu) this.menu.onResize();
  75. }.bind(this));
  76. },
  77. clearContent: function(){
  78. //debugger;
  79. if (this.draftContent){
  80. if (this.draftExplorer) delete this.draftExplorer;
  81. this.draftContent.destroy();
  82. this.draftContent = null;
  83. }
  84. if (this.explorerContent){
  85. if (this.explorer) delete this.explorer;
  86. this.explorerContent.destroy();
  87. this.explorerContent = null;
  88. }
  89. },
  90. openDraft : function(){
  91. this.clearContent();
  92. this.draftContent = new Element("div", {
  93. "styles": this.css.rightContentNode
  94. }).inject(this.node);
  95. MWF.xDesktop.requireApp("cms.Explorer", "DraftExplorer", function(){
  96. //MWF.xDesktop.requireApp("cms.Explorer", "Actions.RestActions", function(){
  97. if (!this.restActions) this.restActions = new MWF.xApplication.cms.Explorer.Actions.RestActions();
  98. this.draftExplorer = new MWF.xApplication.cms.Explorer.DraftExplorer(this.draftContent, this.restActions);
  99. this.draftExplorer.app = this;
  100. this.draftExplorer.load();
  101. //}.bind(this));
  102. }.bind(this));
  103. },
  104. openRecycleBin : function(){
  105. alert("openRecycleBin")
  106. },
  107. openManager : function(){
  108. var appId = "cms.Column";
  109. if (this.desktop.apps[appId]){
  110. this.desktop.apps[appId].setCurrent();
  111. }else {
  112. this.desktop.openApplication(null, "cms.Column", {
  113. "appId": appId,
  114. "onQueryLoad": function(){
  115. }
  116. });
  117. }
  118. },
  119. openCategory : function(columnData, categoryData, view){
  120. MWF.xDesktop.requireApp("cms.Explorer", "ViewExplorer", function(){
  121. this.clearContent();
  122. this.explorerContent = new Element("div", {
  123. "styles": this.css.rightContentNode
  124. }).inject(this.node);
  125. if (!this.restActions) this.restActions = new MWF.xApplication.cms.Explorer.Actions.RestActions();
  126. this.explorer = new MWF.xApplication.cms.Explorer.ViewExplorer(this.explorerContent, this.restActions, columnData, categoryData, view ? {"viewId":view } : null );
  127. this.explorer.app = this;
  128. this.explorer.load();
  129. }.bind(this));
  130. },
  131. recordStatus: function(){
  132. if (this.menu.currentNavi){
  133. var naviType = this.menu.currentNavi.retrieve("type");
  134. var naviData = this.menu.currentNavi.retrieve("naviData");
  135. return {
  136. "navi" :{ "type": naviType, "id": naviData.id, "columnId":naviData.appId},
  137. "view" : this.explorer.currentViewData.id ? this.explorer.currentViewData.id : "default"
  138. };
  139. }
  140. }
  141. });
  142. MWF.xApplication.cms.Explorer.Menu = new Class({
  143. Implements: [Options, Events],
  144. initialize: function(app, node, options){
  145. this.setOptions(options);
  146. this.app = app;
  147. this.node = $(node);
  148. this.currentNavi = null;
  149. this.status = "start";
  150. this.navis = [];
  151. this.columns = {};
  152. this.items = {};
  153. this.load();
  154. },
  155. load: function(){
  156. var menuUrl = this.app.path+"defaultMenu.json";
  157. MWF.getJSON(menuUrl, function(json){
  158. json.each(function(navi){
  159. if( navi.access && navi.access == "admin" ){
  160. if( MWF.AC.isAdministrator() )this.createDefaultNaviNode(navi);
  161. }else{
  162. this.createDefaultNaviNode(navi);
  163. }
  164. }.bind(this));
  165. this.app.restActions.listColumn( function( columns ){
  166. if( columns.data ){
  167. columns.data.each(function(column){
  168. if(!column.name)column.name = column.appName;
  169. this.createColumnNaviNode(column);
  170. }.bind(this))
  171. }
  172. this.setDefaultMenuWidth();
  173. this.fireEvent("postLoad");
  174. }.bind(this),function(){
  175. this.setDefaultMenuWidth();
  176. this.fireEvent("postLoad");
  177. }.bind(this), true)
  178. //this.setDefaultMenuWidth();
  179. //this.fireEvent("postLoad");
  180. }.bind(this));
  181. },
  182. createDefaultNaviNode :function(navi){
  183. var naviNode = new Element("div", {
  184. "styles": this.app.css.defaultMenuNaviNode
  185. });
  186. naviNode.store("naviData", navi);
  187. naviNode.store("type", "default");
  188. var iconNode = new Element("div", {
  189. "styles": this.app.css.defaultMenuIconNode
  190. }).inject(naviNode);
  191. iconNode.setStyle("background-image", "url("+this.app.path+this.app.options.style+"/icon/"+navi.icon+")");
  192. var textNode = new Element("div", {
  193. "styles": this.app.css.defaultMenuTextNode,
  194. "text": navi.title
  195. });
  196. textNode.inject(naviNode);
  197. naviNode.inject(this.node);
  198. this.navis.push(naviNode);
  199. this.items[navi.id] = naviNode;
  200. this.setDefaultNaviEvent(naviNode, navi);
  201. this.setNodeCenter(this.node);
  202. },
  203. createColumnNaviNode:function(column){
  204. var columnObj = this.columns[column.id] = this.columns[column.id] || {};
  205. var naviNode = columnObj.node = new Element("div", {
  206. "styles": this.app.css.columnMenuNaviNode
  207. });
  208. naviNode.store("naviData", column);
  209. naviNode.store("type", "column");
  210. var iconNode = new Element("div", {
  211. "styles": this.app.css.columnMenuIconNode
  212. }).inject(naviNode);
  213. if( column.appIcon && column.appIcon!="" ){
  214. var imgNode = new Element("img",{
  215. "src" : "data:image/png;base64,"+column.appIcon
  216. }).inject( iconNode )
  217. imgNode.setStyles(this.app.css.columnMenuImgNode);
  218. //iconNode.setStyle("background-image", "url(data:image/png;base64,"+column.appIcon+")");
  219. }else{
  220. iconNode.setStyle("background-image", "url("+this.app.path+this.app.options.style+"/icon/column24.png)");
  221. }
  222. var textNode = new Element("div", {
  223. "styles": this.app.css.columnMenuTextNode,
  224. "text": column.name
  225. });
  226. textNode.inject(naviNode);
  227. naviNode.inject(this.node);
  228. this.navis.push(naviNode);
  229. this.items[column.id] = naviNode;
  230. this.setColumnNaviEvent(naviNode);
  231. this.setNodeCenter(this.node);
  232. },
  233. createCategoryNaviNode:function(category,columnId,columnNode){
  234. var categorys = this.columns[columnId].categoryNodes = this.columns[columnId].categoryNodes || [];
  235. var naviNode = new Element("div", {
  236. "styles": this.app.css.categoryMenuNaviNode
  237. });
  238. naviNode.setStyle("display","block");
  239. categorys.push(naviNode);
  240. naviNode.store("naviData", category);
  241. naviNode.store("type", "category");
  242. var iconNode = new Element("div", {
  243. "styles": this.app.css.categoryMenuIconNode
  244. }).inject(naviNode);
  245. var textNode = new Element("div", {
  246. "styles": this.app.css.categoryMenuTextNode,
  247. "text": category.name
  248. });
  249. textNode.inject(naviNode);
  250. naviNode.inject(columnNode,'after');
  251. this.navis.push(naviNode);
  252. this.items[category.id] = naviNode;
  253. this.setCategoryNaviEvent(naviNode);
  254. this.setNodeCenter(this.node);
  255. },
  256. setDefaultNaviEvent: function(naviNode){
  257. var _self = this;
  258. naviNode.addEvents({
  259. "mouseover": function(){ if (_self.currentNavi!=this) this.setStyles(_self.app.css.defaultMenuNaviNode_over);},
  260. "mouseout": function(){if (_self.currentNavi!=this) this.setStyles(_self.app.css.defaultMenuNaviNode);},
  261. "mousedown": function(){if (_self.currentNavi!=this) this.setStyles(_self.app.css.defaultMenuNaviNode_down);},
  262. "mouseup": function(){if (_self.currentNavi!=this) this.setStyles(_self.app.css.defaultMenuNaviNode_over);},
  263. "click": function(){
  264. //if (_self.currentNavi!=this) _self.doAction.apply(_self, [this]);
  265. _self.doAction.apply(_self, [this]);
  266. }
  267. });
  268. },
  269. setColumnNaviEvent: function(naviNode){
  270. var _self = this;
  271. naviNode.addEvents({
  272. "mouseover": function(){ if (_self.currentNavi!=this) this.setStyles(_self.app.css.columnMenuNaviNode_over);},
  273. "mouseout": function(){if (_self.currentNavi!=this) this.setStyles(_self.app.css.columnMenuNaviNode);},
  274. "mousedown": function(){if (_self.currentNavi!=this) this.setStyles(_self.app.css.columnMenuNaviNode_down);},
  275. "mouseup": function(){if (_self.currentNavi!=this) this.setStyles(_self.app.css.columnMenuNaviNode_over);},
  276. "click": function(){
  277. //if (_self.currentNavi!=this) _self.doAction.apply(_self, [this]);
  278. _self.doColumnAction.apply(_self, [this]);
  279. }
  280. });
  281. },
  282. setCategoryNaviEvent: function(naviNode){
  283. var _self = this;
  284. naviNode.addEvents({
  285. "mouseover": function(){ if (_self.currentNavi!=this) this.setStyles(_self.app.css.categoryMenuNaviNode_over);},
  286. "mouseout": function(){if (_self.currentNavi!=this) this.setStyles(_self.app.css.categoryMenuNaviNode);},
  287. "mousedown": function(){if (_self.currentNavi!=this) this.setStyles(_self.app.css.categoryMenuNaviNode_down);},
  288. "mouseup": function(){if (_self.currentNavi!=this) this.setStyles(_self.app.css.categoryMenuNaviNode_over);},
  289. "click": function(){
  290. //if (_self.currentNavi!=this) _self.doAction.apply(_self, [this]);
  291. _self.doCategoryAction.apply(_self, [this]);
  292. }
  293. });
  294. },
  295. doAction: function(naviNode) {
  296. this.closeCurrentColumn();
  297. var navi = naviNode.retrieve("naviData");
  298. var action = navi.action;
  299. var type = naviNode.retrieve("type");
  300. if (!navi.target || navi.target != "_blank") {
  301. if (this.currentNavi) this.currentNavi.setStyles((this.currentNavi.retrieve("type") != "column") ? this.app.css.defaultMenuNaviNode : this.app.css.columnMenuNaviNode);
  302. naviNode.setStyles((type != "column") ? this.app.css.defaultMenuNaviNode_current : this.app.css.columnMenuNaviNode_current);
  303. this.currentNavi = naviNode;
  304. }
  305. if (this.app[action]) this.app[action].apply(this.app);
  306. if (this.status == "start"){
  307. this.toNormal();
  308. this.status = "normal";
  309. }
  310. },
  311. doColumnAction: function(naviNode, callback ) {
  312. var navi = naviNode.retrieve("naviData");
  313. var action = navi.action;
  314. this.closeCurrentColumn();
  315. if( this.columns[navi.id].categoryNodes ) {
  316. this.columns[navi.id].categoryNodes.each( function(categoryNod){
  317. categoryNod.setStyle("display","block");
  318. })
  319. }else{
  320. this.app.restActions.listCategory( navi.id, function( categorys ){
  321. categorys.data.reverse().each(function(category){
  322. this.createCategoryNaviNode( category, navi.id , naviNode );
  323. }.bind(this))
  324. if( callback )callback();
  325. }.bind(this))
  326. }
  327. this.currentColumn = naviNode;
  328. var type = naviNode.retrieve("type");
  329. if (!navi.target || navi.target != "_blank") {
  330. if (this.currentNavi) this.currentNavi.setStyles((this.currentNavi.retrieve("type") != "column") ? this.app.css.defaultMenuNaviNode : this.app.css.columnMenuNaviNode);
  331. naviNode.setStyles((type != "column") ? this.app.css.defaultMenuNaviNode_current : this.app.css.columnMenuNaviNode_current);
  332. this.currentNavi = naviNode;
  333. }
  334. if (this.status == "start"){
  335. this.toNormal();
  336. this.status = "normal";
  337. }
  338. },
  339. doCategoryAction: function(naviNode, view ) {
  340. var navi = naviNode.retrieve("naviData");
  341. var action = navi.action;
  342. var type = naviNode.retrieve("type");
  343. if (!navi.target || navi.target != "_blank") {
  344. if (this.currentNavi) this.currentNavi.setStyles((this.currentNavi.retrieve("type") != "column") ? this.app.css.defaultMenuNaviNode : this.app.css.columnMenuNaviNode);
  345. naviNode.setStyles((type != "column") ? this.app.css.defaultMenuNaviNode_current : this.app.css.columnMenuNaviNode_current);
  346. this.currentNavi = naviNode;
  347. }
  348. this.app.openCategory.call(this.app, this.currentColumn.retrieve("naviData"), navi, view );
  349. if (this.status == "start"){
  350. this.toNormal();
  351. this.status = "normal";
  352. }
  353. },
  354. closeCurrentColumn:function(){
  355. if( this.currentColumn ) {
  356. var curNavi = this.currentColumn.retrieve("naviData");
  357. if (this.columns[curNavi.id].categoryNodes) {
  358. this.columns[curNavi.id].categoryNodes.each(function (categoryNod) {
  359. categoryNod.setStyle("display", "none");
  360. })
  361. }
  362. this.currentColumn = null;
  363. }
  364. },
  365. toNormal: function(){
  366. var css = this.app.css.normalDefaultMenuNode;
  367. //if (!this.morph){
  368. // this.morph = new Fx.Morph(this.node, {duration: 50, link: "chain"});
  369. //}
  370. //this.morph.start(css).chain(function(){
  371. this.node.setStyles(css);
  372. MWF.require("MWF.widget.ScrollBar", function(){
  373. new MWF.widget.ScrollBar(this.node, {
  374. "style":"xApp_CMSExplorer_StartMenu", "distance": 100, "friction": 4, "axis": {"x": false, "y": true}
  375. });
  376. }.bind(this));
  377. //}.bind(this));
  378. },
  379. setNodeCenter: function(node){
  380. var size = node.getSize();
  381. var contentSize = this.app.node.getSize();
  382. var top = contentSize.y/2 - size.y/2;
  383. var left = contentSize.x/2 - size.x/2;
  384. if (left<0) left = 0;
  385. if (top<0) top = 0;
  386. node.setStyles({"left": left, "top": top});
  387. },
  388. getDefaultMenuNormalSize: function(){
  389. var naviItemNode = this.node.getFirst();
  390. var size = naviItemNode.getComputedSize();
  391. var mt = naviItemNode.getStyle("margin-top").toFloat();
  392. var mb = naviItemNode.getStyle("margin-bottom").toFloat();
  393. var height = size.totalWidth+mt+mb;
  394. var ml = naviItemNode.getStyle("margin-left").toFloat();
  395. var mr = naviItemNode.getStyle("margin-right").toFloat();
  396. var width = size.totalWidth+ml+mr;
  397. return {"width": width, "height": height*this.navis.length};
  398. },
  399. setDefaultMenuWidth: function(){
  400. var naviItemNode = this.node.getFirst();
  401. var size = naviItemNode.getComputedSize();
  402. var ml = naviItemNode.getStyle("margin-left").toFloat();
  403. var mr = naviItemNode.getStyle("margin-right").toFloat();
  404. var width = size.totalWidth+ml+mr;
  405. this.node.setStyle("width", (width*this.navis.length)+"px");
  406. },
  407. onResize: function(){
  408. if (this.status == "start"){
  409. this.setNodeCenter(this.node);
  410. }
  411. }
  412. });