Main.js 11 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251252253254255256257258259260261262263264265266267268269270271272273274275276277278279280281282283284285286287288289290291292293294295296297298299300301302303304305306307308309310311312313314315316317318319320321322323324325326327328329
  1. //MWF.xDesktop.requireApp("Organization", "Selector.package", null, false);
  2. MWF.xApplication.Org.Main = new Class({
  3. Extends: MWF.xApplication.Common.Main,
  4. Implements: [Options, Events],
  5. options: {
  6. "style": "default",
  7. "name": "Org",
  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.Org.LP.title
  12. },
  13. onQueryLoad: function(){
  14. this.lp = MWF.xApplication.Org.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(){
  32. this.startMenuNode = new Element("div", {
  33. "styles": this.css.startMenuNode
  34. }).inject(this.node);
  35. this.menu = new MWF.xApplication.Org.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){
  60. this.groupConfigurator.destroy();
  61. this.groupConfigurator = null;
  62. }
  63. this.groupConfiguratorContentNode.destroy();
  64. }
  65. if (this.roleConfiguratorContentNode){
  66. if (this.roleConfigurator){
  67. this.roleConfigurator.destroy();
  68. this.roleConfigurator = null;
  69. }
  70. this.roleConfiguratorContentNode.destroy();
  71. }
  72. if (this.personConfiguratorContentNode){
  73. if (this.personConfigurator){
  74. this.personConfigurator.destroy();
  75. this.personConfigurator = null;
  76. }
  77. this.personConfiguratorContentNode.destroy();
  78. }
  79. if (this.pingyinArea) this.pingyinArea.empty();
  80. },
  81. orgConfig: function(){
  82. this.clearContent();
  83. this.orgConfiguratorContentNode = new Element("div", {
  84. "styles": this.css.rightContentNode
  85. }).inject(this.node);
  86. this.loadOrgConfig();
  87. },
  88. loadOrgConfig: function(){
  89. MWF.xDesktop.requireApp("Organization", "OrgExplorer", function(){
  90. MWF.xDesktop.requireApp("Organization", "Actions.RestActions", function(){
  91. if (!this.restActions) this.restActions = new MWF.xApplication.Organization.Actions.RestActions();
  92. this.orgConfigurator = new MWF.xApplication.Organization.OrgExplorer(this.orgConfiguratorContentNode, this.restActions);
  93. this.orgConfigurator.app = this;
  94. this.orgConfigurator.load();
  95. }.bind(this));
  96. }.bind(this));
  97. },
  98. groupConfig: function(){
  99. this.clearContent();
  100. this.groupConfiguratorContentNode = new Element("div", {
  101. "styles": this.css.rightContentNode
  102. }).inject(this.node);
  103. this.loadGroupConfig();
  104. },
  105. loadGroupConfig: function(){
  106. MWF.xDesktop.requireApp("Org", "GroupExplorer", function(){
  107. MWF.xDesktop.requireApp("Org", "Actions.RestActions", function(){
  108. if (!this.restActions) this.restActions = new MWF.xApplication.Org.Actions.RestActions();
  109. this.groupConfigurator = new MWF.xApplication.Org.GroupExplorer(this.groupConfiguratorContentNode, this.restActions);
  110. this.groupConfigurator.app = this;
  111. this.groupConfigurator.load();
  112. }.bind(this));
  113. }.bind(this));
  114. },
  115. roleConfig: function(){
  116. this.clearContent();
  117. this.roleConfiguratorContentNode = new Element("div", {
  118. "styles": this.css.rightContentNode
  119. }).inject(this.node);
  120. this.loadRoleConfig();
  121. },
  122. loadRoleConfig: function(){
  123. MWF.xDesktop.requireApp("Org", "RoleExplorer", function(){
  124. MWF.xDesktop.requireApp("Org", "Actions.RestActions", function(){
  125. if (!this.restActions) this.restActions = new MWF.xApplication.Org.Actions.RestActions();
  126. this.roleConfigurator = new MWF.xApplication.Org.RoleExplorer(this.roleConfiguratorContentNode, this.restActions);
  127. this.roleConfigurator.app = this;
  128. this.roleConfigurator.load();
  129. }.bind(this));
  130. }.bind(this));
  131. },
  132. personConfig: function(){
  133. this.clearContent();
  134. this.personConfiguratorContentNode = new Element("div", {
  135. "styles": this.css.rightContentNode
  136. }).inject(this.node);
  137. this.loadPersonConfig();
  138. },
  139. loadPersonConfig: function(){
  140. MWF.xDesktop.requireApp("Org", "PersonExplorer", function(){
  141. MWF.xDesktop.requireApp("Org", "Actions.RestActions", function(){
  142. if (!this.restActions) this.restActions = new MWF.xApplication.Org.Actions.RestActions();
  143. this.personConfigurator = new MWF.xApplication.Org.PersonExplorer(this.personConfiguratorContentNode, this.restActions);
  144. this.personConfigurator.app = this;
  145. this.personConfigurator.load();
  146. }.bind(this));
  147. }.bind(this));
  148. },
  149. recordStatus: function(){
  150. var idx = null;
  151. if (this.menu.currentNavi){
  152. idx = this.menu.startNavis.indexOf(this.menu.currentNavi);
  153. }
  154. return {"navi": idx};
  155. }
  156. });
  157. MWF.xApplication.Org.Menu = new Class({
  158. Implements: [Options, Events],
  159. initialize: function(app, node, options){
  160. this.setOptions(options);
  161. this.app = app;
  162. this.node = $(node);
  163. this.currentNavi = null;
  164. this.status = "start";
  165. this.startNavis = [];
  166. this.load();
  167. },
  168. load: function(){
  169. var menuUrl = (MWF.AC.isAdministrator()) ? this.app.path+"startMenu_admin.json" : this.app.path+"startMenu.json";
  170. MWF.getJSON(menuUrl, function(json){
  171. json.each(function(navi){
  172. var naviNode = new Element("div", {
  173. "styles": this.app.css.startMenuNaviNode,
  174. "title": navi.title
  175. });
  176. naviNode.store("naviData", navi);
  177. var iconNode = new Element("div", {
  178. "styles": this.app.css.startMenuIconNode
  179. }).inject(naviNode);
  180. iconNode.setStyle("background-image", "url("+this.app.path+this.app.options.style+"/icon/"+navi.icon+"60.png)");
  181. var textNode = new Element("div", {
  182. "styles": this.app.css.startMenuTextNode,
  183. "text": navi.title
  184. });
  185. textNode.inject(naviNode);
  186. naviNode.inject(this.node);
  187. this.startNavis.push(naviNode);
  188. this.setStartNaviEvent(naviNode, navi);
  189. this.setNodeCenter(this.node);
  190. }.bind(this));
  191. this.setStartMenuWidth();
  192. this.fireEvent("postLoad");
  193. }.bind(this));
  194. },
  195. setStartNaviEvent: function(naviNode){
  196. var _self = this;
  197. naviNode.addEvents({
  198. "mouseover": function(){
  199. //debugger;
  200. if (_self.currentNavi!==this){
  201. var iconNode = this.getFirst();
  202. this.setStyles(_self.app.css.startMenuNaviNode_over);
  203. var navi = this.retrieve("naviData");
  204. iconNode.setStyle("background-image", "url("+_self.app.path+_self.app.options.style+"/icon/"+navi.icon+".png)");
  205. iconNode.setStyles(_self.app.css.startMenuIconNode_over);
  206. }
  207. },
  208. "mouseout": function(){
  209. var iconNode = this.getFirst();
  210. if (_self.currentNavi!==this) this.setStyles(_self.app.css.startMenuNaviNode);
  211. var navi = this.retrieve("naviData");
  212. iconNode.setStyle("background-image", "url("+_self.app.path+_self.app.options.style+"/icon/"+navi.icon+"60.png)");
  213. iconNode.setStyles(_self.app.css.startMenuIconNode);
  214. },
  215. "mousedown": function(){
  216. if (_self.currentNavi!==this) this.setStyles(_self.app.css.startMenuNaviNode_down);
  217. },
  218. "mouseup": function(){if (_self.currentNavi!==this) this.setStyles(_self.app.css.startMenuNaviNode_over);},
  219. "click": function(){
  220. _self.doAction.apply(_self, [this]);
  221. }
  222. });
  223. },
  224. doAction: function(naviNode){
  225. var navi = naviNode.retrieve("naviData");
  226. var action = navi.action;
  227. this.startNavis.each(function(node){
  228. node.removeEvents("mouseover");
  229. node.removeEvents("mouseout");
  230. node.removeEvents("mousedown");
  231. node.removeEvents("mouseup");
  232. node.setStyles(this.app.css.startMenuNaviLeftNode);
  233. var iconNode = node.getFirst();
  234. var textNode = node.getLast();
  235. var tmpnavi = node.retrieve("naviData");
  236. iconNode.setStyle("background-image", "url("+this.app.path+this.app.options.style+"/icon/"+tmpnavi.icon+"32.png)");
  237. iconNode.setStyles(this.app.css.startMenuIconLeftNode);
  238. textNode.setStyles(this.app.css.startMenuTextLeftNode);
  239. }.bind(this));
  240. naviNode.setStyles(this.app.css.startMenuNaviLeftNode_current);
  241. this.currentNavi = naviNode;
  242. if (this.app[action]) this.app[action].apply(this.app);
  243. if (this.status === "start"){
  244. this.toNormal();
  245. this.status = "normal";
  246. }
  247. },
  248. toNormal: function(){
  249. var css = this.app.css.normalStartMenuNode;
  250. if (!this.morph){
  251. this.morph = new Fx.Morph(this.node, {duration: 50, link: "chain"});
  252. }
  253. this.app.pingyinArea = new Element("div", {"styles": this.app.css.startMenuNaviLeftPingyinNode}).inject(this.node, "top");
  254. this.morph.start(css).chain(function(){
  255. this.node.setStyles(css);
  256. // MWF.require("MWF.widget.ScrollBar", function(){
  257. // new MWF.widget.ScrollBar(this.node, {
  258. // "style":"xApp_ProcessManager_StartMenu", "distance": 100, "friction": 4, "axis": {"x": false, "y": true}
  259. // });
  260. // }.bind(this));
  261. }.bind(this));
  262. },
  263. setNodeCenter: function(node){
  264. var size = node.getSize();
  265. var contentSize = this.app.node.getSize();
  266. var top = contentSize.y/2 - size.y/2;
  267. var left = contentSize.x/2 - size.x/2;
  268. if (left<0) left = 0;
  269. if (top<0) top = 0;
  270. node.setStyles({"left": left, "top": top});
  271. },
  272. getStartMenuNormalSize: function(){
  273. var naviItemNode = this.node.getFirst();
  274. var size = naviItemNode.getComputedSize();
  275. var mt = naviItemNode.getStyle("margin-top").toFloat();
  276. var mb = naviItemNode.getStyle("margin-bottom").toFloat();
  277. var height = size.totalWidth+mt+mb;
  278. var ml = naviItemNode.getStyle("margin-left").toFloat();
  279. var mr = naviItemNode.getStyle("margin-right").toFloat();
  280. var width = size.totalWidth+ml+mr;
  281. return {"width": width, "height": height*this.startNavis.length};
  282. },
  283. setStartMenuWidth: function(){
  284. var naviItemNode = this.node.getFirst();
  285. var size = naviItemNode.getComputedSize();
  286. var ml = naviItemNode.getStyle("margin-left").toFloat();
  287. var mr = naviItemNode.getStyle("margin-right").toFloat();
  288. var width = size.totalWidth+ml+mr;
  289. this.node.setStyle("width", (width*this.startNavis.length)+"px");
  290. },
  291. onResize: function(){
  292. if (this.status === "start"){
  293. this.setNodeCenter(this.node);
  294. }
  295. }
  296. });