Main.js 9.4 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251252253254255256257258259260261262263264265266267268269270271272273274275276277278279280281282
  1. MWF.xDesktop.requireApp("Organization", "Selector.package", null, false);
  2. MWF.xApplication.Organization.Main = new Class({
  3. Extends: MWF.xApplication.Common.Main,
  4. Implements: [Options, Events],
  5. options: {
  6. "style": "default",
  7. "name": "Organization",
  8. "icon": "icon.png",
  9. "width": (layout.desktop.size) ? layout.desktop.size.x*0.7 : 1000,
  10. "height": (layout.desktop.size) ? layout.desktop.size.y*0.7: 700,
  11. "title": MWF.xApplication.Organization.LP.title
  12. },
  13. onQueryLoad: function(){
  14. this.lp = MWF.xApplication.Organization.LP;
  15. },
  16. loadApplication: function(callback){
  17. this.createNode();
  18. this.loadApplicationContent();
  19. if (callback) callback();
  20. },
  21. createNode: function(){
  22. this.content.setStyle("overflow", "hidden");
  23. this.node = new Element("div", {
  24. "styles": {"width": "100%", "height": "100%", "overflow": "hidden"}
  25. }).inject(this.content);
  26. },
  27. loadApplicationContent: function(){
  28. this.loadStartMenu();
  29. // this.loadApplicationLayout();
  30. },
  31. loadStartMenu: function(callback){
  32. this.startMenuNode = new Element("div", {
  33. "styles": this.css.startMenuNode
  34. }).inject(this.node);
  35. this.menu = new MWF.xApplication.Organization.Menu(this, this.startMenuNode, {
  36. "onPostLoad": function(){
  37. if (this.status){
  38. if (this.status.navi!=null){
  39. this.menu.doAction(this.menu.startNavis[this.status.navi]);
  40. }
  41. }
  42. }.bind(this)
  43. });
  44. this.addEvent("resize", function(){
  45. if (this.menu) this.menu.onResize();
  46. }.bind(this));
  47. },
  48. clearContent: function(){
  49. if (this.orgConfiguratorContentNode){
  50. if (this.orgConfigurator) MWF.release(this.orgConfigurator);
  51. this.orgConfiguratorContentNode.destroy();
  52. this.orgConfiguratorContentNode = null;
  53. }
  54. if (this.identityConfiguratorContentNode){
  55. if (this.identityConfigurator) delete this.identityConfigurator;
  56. this.identityConfiguratorContentNode.destroy();
  57. }
  58. if (this.groupConfiguratorContentNode){
  59. if (this.groupConfigurator) delete this.groupConfigurator;
  60. this.groupConfiguratorContentNode.destroy();
  61. }
  62. if (this.roleConfiguratorContentNode){
  63. if (this.roleConfigurator) delete this.roleConfigurator;
  64. this.roleConfiguratorContentNode.destroy();
  65. }
  66. if (this.personConfiguratorContentNode){
  67. if (this.personConfigurator) delete this.personConfigurator;
  68. this.personConfiguratorContentNode.destroy();
  69. }
  70. },
  71. orgConfig: function(){
  72. this.clearContent();
  73. this.orgConfiguratorContentNode = new Element("div", {
  74. "styles": this.css.rightContentNode
  75. }).inject(this.node);
  76. this.loadOrgConfig();
  77. },
  78. loadOrgConfig: function(){
  79. MWF.xDesktop.requireApp("Organization", "OrgExplorer", function(){
  80. MWF.xDesktop.requireApp("Organization", "Actions.RestActions", function(){
  81. if (!this.restActions) this.restActions = new MWF.xApplication.Organization.Actions.RestActions();
  82. this.orgConfigurator = new MWF.xApplication.Organization.OrgExplorer(this.orgConfiguratorContentNode, this.restActions);
  83. this.orgConfigurator.app = this;
  84. this.orgConfigurator.load();
  85. }.bind(this));
  86. }.bind(this));
  87. },
  88. groupConfig: function(){
  89. this.clearContent();
  90. this.groupConfiguratorContentNode = new Element("div", {
  91. "styles": this.css.rightContentNode
  92. }).inject(this.node);
  93. this.loadGroupConfig();
  94. },
  95. loadGroupConfig: function(){
  96. MWF.xDesktop.requireApp("Organization", "GroupExplorer", function(){
  97. MWF.xDesktop.requireApp("Organization", "Actions.RestActions", function(){
  98. if (!this.restActions) this.restActions = new MWF.xApplication.Organization.Actions.RestActions();
  99. this.groupConfigurator = new MWF.xApplication.Organization.GroupExplorer(this.groupConfiguratorContentNode, this.restActions);
  100. this.groupConfigurator.app = this;
  101. this.groupConfigurator.load();
  102. }.bind(this));
  103. }.bind(this));
  104. },
  105. roleConfig: function(){
  106. this.clearContent();
  107. this.roleConfiguratorContentNode = new Element("div", {
  108. "styles": this.css.rightContentNode
  109. }).inject(this.node);
  110. this.loadRoleConfig();
  111. },
  112. loadRoleConfig: function(){
  113. MWF.xDesktop.requireApp("Organization", "RoleExplorer", function(){
  114. MWF.xDesktop.requireApp("Organization", "Actions.RestActions", function(){
  115. if (!this.restActions) this.restActions = new MWF.xApplication.Organization.Actions.RestActions();
  116. this.roleConfigurator = new MWF.xApplication.Organization.RoleExplorer(this.roleConfiguratorContentNode, this.restActions);
  117. this.roleConfigurator.app = this;
  118. this.roleConfigurator.load();
  119. }.bind(this));
  120. }.bind(this));
  121. },
  122. personConfig: function(){
  123. this.clearContent();
  124. this.personConfiguratorContentNode = new Element("div", {
  125. "styles": this.css.rightContentNode
  126. }).inject(this.node);
  127. this.loadPersonConfig();
  128. },
  129. loadPersonConfig: function(){
  130. MWF.xDesktop.requireApp("Organization", "PersonExplorer", function(){
  131. MWF.xDesktop.requireApp("Organization", "Actions.RestActions", function(){
  132. if (!this.restActions) this.restActions = new MWF.xApplication.Organization.Actions.RestActions();
  133. this.personConfigurator = new MWF.xApplication.Organization.PersonExplorer(this.personConfiguratorContentNode, this.restActions);
  134. this.personConfigurator.app = this;
  135. this.personConfigurator.load();
  136. }.bind(this));
  137. }.bind(this));
  138. },
  139. recordStatus: function(){
  140. var idx = null;
  141. if (this.menu.currentNavi){
  142. idx = this.menu.startNavis.indexOf(this.menu.currentNavi);
  143. }
  144. return {"navi": idx};
  145. }
  146. });
  147. MWF.xApplication.Organization.Menu = new Class({
  148. Implements: [Options, Events],
  149. initialize: function(app, node, options){
  150. this.setOptions(options);
  151. this.app = app;
  152. this.node = $(node);
  153. this.currentNavi = null;
  154. this.status = "start";
  155. this.startNavis = [];
  156. this.load();
  157. },
  158. load: function(){
  159. var menuUrl = (MWF.AC.isAdministrator()) ? this.app.path+"startMenu_admin.json" : this.app.path+"startMenu.json";
  160. MWF.getJSON(menuUrl, function(json){
  161. json.each(function(navi){
  162. var naviNode = new Element("div", {
  163. "styles": this.app.css.startMenuNaviNode
  164. });
  165. naviNode.store("naviData", navi);
  166. var iconNode = new Element("div", {
  167. "styles": this.app.css.startMenuIconNode
  168. }).inject(naviNode);
  169. iconNode.setStyle("background-image", "url("+this.app.path+this.app.options.style+"/icon/"+navi.icon+")");
  170. var textNode = new Element("div", {
  171. "styles": this.app.css.startMenuTextNode,
  172. "text": navi.title
  173. });
  174. textNode.inject(naviNode);
  175. naviNode.inject(this.node);
  176. this.startNavis.push(naviNode);
  177. this.setStartNaviEvent(naviNode, navi);
  178. this.setNodeCenter(this.node);
  179. }.bind(this));
  180. this.setStartMenuWidth();
  181. this.fireEvent("postLoad");
  182. }.bind(this));
  183. },
  184. setStartNaviEvent: function(naviNode){
  185. var _self = this;
  186. naviNode.addEvents({
  187. "mouseover": function(){ if (_self.currentNavi!=this) this.setStyles(_self.app.css.startMenuNaviNode_over);},
  188. "mouseout": function(){if (_self.currentNavi!=this) this.setStyles(_self.app.css.startMenuNaviNode);},
  189. "mousedown": function(){if (_self.currentNavi!=this) this.setStyles(_self.app.css.startMenuNaviNode_down);},
  190. "mouseup": function(){if (_self.currentNavi!=this) this.setStyles(_self.app.css.startMenuNaviNode_over);},
  191. "click": function(){
  192. _self.doAction.apply(_self, [this]);
  193. }
  194. });
  195. },
  196. doAction: function(naviNode){
  197. var navi = naviNode.retrieve("naviData");
  198. var action = navi.action;
  199. if (this.currentNavi) this.currentNavi.setStyles(this.app.css.startMenuNaviNode);
  200. naviNode.setStyles(this.app.css.startMenuNaviNode_current);
  201. this.currentNavi = naviNode;
  202. if (this.app[action]) this.app[action].apply(this.app);
  203. if (this.status == "start"){
  204. this.toNormal();
  205. this.status = "normal";
  206. }
  207. },
  208. toNormal: function(){
  209. var css = this.app.css.normalStartMenuNode;
  210. if (!this.morph){
  211. this.morph = new Fx.Morph(this.node, {duration: 50, link: "chain"});
  212. }
  213. this.morph.start(css).chain(function(){
  214. this.node.setStyles(css);
  215. MWF.require("MWF.widget.ScrollBar", function(){
  216. new MWF.widget.ScrollBar(this.node, {
  217. "style":"xApp_ProcessManager_StartMenu", "distance": 100, "friction": 4, "axis": {"x": false, "y": true}
  218. });
  219. }.bind(this));
  220. }.bind(this));
  221. },
  222. setNodeCenter: function(node){
  223. var size = node.getSize();
  224. var contentSize = this.app.node.getSize();
  225. var top = contentSize.y/2 - size.y/2;
  226. var left = contentSize.x/2 - size.x/2;
  227. if (left<0) left = 0;
  228. if (top<0) top = 0;
  229. node.setStyles({"left": left, "top": top});
  230. },
  231. getStartMenuNormalSize: function(){
  232. var naviItemNode = this.node.getFirst();
  233. var size = naviItemNode.getComputedSize();
  234. var mt = naviItemNode.getStyle("margin-top").toFloat();
  235. var mb = naviItemNode.getStyle("margin-bottom").toFloat();
  236. var height = size.totalWidth+mt+mb;
  237. var ml = naviItemNode.getStyle("margin-left").toFloat();
  238. var mr = naviItemNode.getStyle("margin-right").toFloat();
  239. var width = size.totalWidth+ml+mr;
  240. return {"width": width, "height": height*this.startNavis.length};
  241. },
  242. setStartMenuWidth: function(){
  243. var naviItemNode = this.node.getFirst();
  244. var size = naviItemNode.getComputedSize();
  245. var ml = naviItemNode.getStyle("margin-left").toFloat();
  246. var mr = naviItemNode.getStyle("margin-right").toFloat();
  247. var width = size.totalWidth+ml+mr;
  248. this.node.setStyle("width", (width*this.startNavis.length)+"px");
  249. },
  250. onResize: function(){
  251. if (this.status == "start"){
  252. this.setNodeCenter(this.node);
  253. }
  254. }
  255. });