Main.js 11 KB

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