Main.js 14 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251252253254255256257258259260261262263264265266267268269270271272273274275276277278279280281282283284285286287288289290291292293294295296297298299300301302303304305306307308309310311312313314315316317318319320321322323324325326327328329330331332333334335336337338339340341342343344345346347348349350351352353354355356357358359360361362363364365366367368369370371372373374375376377378
  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.importConfiguratorContentNode){
  84. this.importConfiguratorContentNode.destroy();
  85. }
  86. if (this.pingyinArea) this.pingyinArea.empty();
  87. },
  88. orgConfig: function(){
  89. this.clearContent();
  90. this.orgConfiguratorContentNode = new Element("div", {
  91. "styles": this.css.rightContentNode
  92. }).inject(this.node);
  93. this.loadOrgConfig();
  94. },
  95. loadOrgConfig: function(){
  96. MWF.xDesktop.requireApp("Org", "UnitExplorer", function(){
  97. //MWF.xDesktop.requireApp("Org", "Actions.RestActions", function(){
  98. // if (!this.restActions) this.restActions = new MWF.xApplication.Org.Actions.RestActions();
  99. this.orgConfigurator = new MWF.xApplication.Org.UnitExplorer(this.orgConfiguratorContentNode, this.restActions);
  100. this.orgConfigurator.app = this;
  101. this.orgConfigurator.load();
  102. //}.bind(this));
  103. }.bind(this));
  104. },
  105. groupConfig: function(){
  106. this.clearContent();
  107. this.groupConfiguratorContentNode = new Element("div", {
  108. "styles": this.css.rightContentNode
  109. }).inject(this.node);
  110. this.loadGroupConfig();
  111. },
  112. loadGroupConfig: function(){
  113. MWF.xDesktop.requireApp("Org", "GroupExplorer", function(){
  114. //MWF.xDesktop.requireApp("Org", "Actions.RestActions", function(){
  115. // if (!this.restActions) this.restActions = new MWF.xApplication.Org.Actions.RestActions();
  116. this.groupConfigurator = new MWF.xApplication.Org.GroupExplorer(this.groupConfiguratorContentNode, this.restActions);
  117. this.groupConfigurator.app = this;
  118. this.groupConfigurator.load();
  119. //}.bind(this));
  120. }.bind(this));
  121. },
  122. roleConfig: function(){
  123. this.clearContent();
  124. this.roleConfiguratorContentNode = new Element("div", {
  125. "styles": this.css.rightContentNode
  126. }).inject(this.node);
  127. this.loadRoleConfig();
  128. },
  129. loadRoleConfig: function(){
  130. MWF.xDesktop.requireApp("Org", "RoleExplorer", function(){
  131. //MWF.xDesktop.requireApp("Org", "Actions.RestActions", function(){
  132. // if (!this.restActions) this.restActions = new MWF.xApplication.Org.Actions.RestActions();
  133. this.roleConfigurator = new MWF.xApplication.Org.RoleExplorer(this.roleConfiguratorContentNode, this.restActions);
  134. this.roleConfigurator.app = this;
  135. this.roleConfigurator.load();
  136. //}.bind(this));
  137. }.bind(this));
  138. },
  139. personConfig: function(){
  140. this.clearContent();
  141. this.personConfiguratorContentNode = new Element("div", {
  142. "styles": this.css.rightContentNode
  143. }).inject(this.node);
  144. this.loadPersonConfig();
  145. },
  146. loadPersonConfig: function(){
  147. MWF.xDesktop.requireApp("Org", "PersonExplorer", function(){
  148. //MWF.xDesktop.requireApp("Org", "Actions.RestActions", function(){
  149. // if (!this.restActions) this.restActions = new MWF.xApplication.Org.Actions.RestActions();
  150. this.personConfigurator = new MWF.xApplication.Org.PersonExplorer(this.personConfiguratorContentNode, this.restActions);
  151. this.personConfigurator.app = this;
  152. this.personConfigurator.load();
  153. //}.bind(this));
  154. }.bind(this));
  155. },
  156. personImport: function(){
  157. debugger;
  158. this.clearContent();
  159. this.importConfiguratorContentNode = new Element("div", {
  160. "styles": this.css.rightContentNode
  161. }).inject(this.node);
  162. this.importConfiguratorContentNode.set("load", {"onSuccess": function(){
  163. this.importPersonTitleNode = this.importConfiguratorContentNode.getElement(".importPersonTitleNode");
  164. this.importPersonTemplateNode = this.importConfiguratorContentNode.getElement(".importPersonTemplateNode");
  165. this.importPersonNode = this.importConfiguratorContentNode.getElement(".importPersonNode");
  166. this.importPersonResultNode = this.importConfiguratorContentNode.getElement(".importPersonResultNode");
  167. o2.loadCss(this.path+this.options.style+"/importCss.css", this.importConfiguratorContentNode, function(){
  168. this.loadPersonImport();
  169. }.bind(this));
  170. }.bind(this)}).load(this.path+this.options.style+"/importView.html");
  171. },
  172. loadPersonImport: function(){
  173. var action = o2.Actions.get("x_organization_assemble_control");
  174. var url = action.action.address + action.action.actions.getImportPersonTemplate.uri;
  175. var infor = this.lp.importPersonInfor.replace("{url}", url);
  176. this.importPersonTitleNode.set("text", this.lp.importPersonTitle);
  177. this.importPersonTemplateNode.set("html", infor);
  178. this.importPersonNode.set("text", this.lp.importPersonAction);
  179. this.importPersonNode.addEvent("click", function(){
  180. this.importPersonResultNode.hide();
  181. o2.require("o2.widget.Upload", function(){
  182. new o2.widget.Upload(this.content, {
  183. "action": "x_organization_assemble_control",
  184. "method": "importPerson",
  185. "multiple": false,
  186. "onCompleted": function(json){
  187. var url = action.action.address + action.action.actions.getImportPersonResault.uri;
  188. url = url.replace("{flag}", json.data.flag);
  189. var result = this.lp.importPersonResult.replace("{url}", url);
  190. this.importPersonResultNode.set("html", result);
  191. this.importPersonResultNode.show();
  192. }.bind(this)
  193. }).load();
  194. }.bind(this));
  195. }.bind(this));
  196. },
  197. recordStatus: function(){
  198. var idx = null;
  199. if (this.menu.currentNavi){
  200. idx = this.menu.startNavis.indexOf(this.menu.currentNavi);
  201. }
  202. return {"navi": idx};
  203. }
  204. });
  205. MWF.xApplication.Org.Menu = new Class({
  206. Implements: [Options, Events],
  207. initialize: function(app, node, options){
  208. this.setOptions(options);
  209. this.app = app;
  210. this.node = $(node);
  211. this.currentNavi = null;
  212. this.status = "start";
  213. this.startNavis = [];
  214. this.load();
  215. },
  216. load: function(){
  217. var menuUrl = (MWF.AC.isOrganizationManager()) ? this.app.path+"startMenu_admin.json" : this.app.path+"startMenu.json";
  218. MWF.getJSON(menuUrl, function(json){
  219. json.each(function(navi){
  220. var naviNode = new Element("div", {
  221. "styles": this.app.css.startMenuNaviNode,
  222. "title": navi.title
  223. });
  224. naviNode.store("naviData", navi);
  225. var iconNode = new Element("div", {
  226. "styles": this.app.css.startMenuIconNode
  227. }).inject(naviNode);
  228. iconNode.setStyle("background-image", "url("+this.app.path+this.app.options.style+"/icon/"+navi.icon+"60.png)");
  229. var textNode = new Element("div", {
  230. "styles": this.app.css.startMenuTextNode,
  231. "text": navi.title
  232. });
  233. textNode.inject(naviNode);
  234. naviNode.inject(this.node);
  235. this.startNavis.push(naviNode);
  236. this.setStartNaviEvent(naviNode, navi);
  237. this.setNodeCenter(this.node);
  238. }.bind(this));
  239. this.setStartMenuWidth();
  240. this.fireEvent("postLoad");
  241. }.bind(this));
  242. },
  243. setStartNaviEvent: function(naviNode){
  244. var _self = this;
  245. naviNode.addEvents({
  246. "mouseover": function(){
  247. //debugger;
  248. if (_self.currentNavi!==this){
  249. var iconNode = this.getFirst();
  250. this.setStyles(_self.app.css.startMenuNaviNode_over);
  251. var navi = this.retrieve("naviData");
  252. iconNode.setStyle("background-image", "url("+_self.app.path+_self.app.options.style+"/icon/"+navi.icon+".png)");
  253. iconNode.setStyles(_self.app.css.startMenuIconNode_over);
  254. }
  255. },
  256. "mouseout": function(){
  257. var iconNode = this.getFirst();
  258. if (_self.currentNavi!==this) this.setStyles(_self.app.css.startMenuNaviNode);
  259. var navi = this.retrieve("naviData");
  260. iconNode.setStyle("background-image", "url("+_self.app.path+_self.app.options.style+"/icon/"+navi.icon+"60.png)");
  261. iconNode.setStyles(_self.app.css.startMenuIconNode);
  262. },
  263. "mousedown": function(){
  264. if (_self.currentNavi!==this) this.setStyles(_self.app.css.startMenuNaviNode_down);
  265. },
  266. "mouseup": function(){if (_self.currentNavi!==this) this.setStyles(_self.app.css.startMenuNaviNode_over);},
  267. "click": function(){
  268. _self.doAction.apply(_self, [this]);
  269. }
  270. });
  271. },
  272. doAction: function(naviNode){
  273. var navi = naviNode.retrieve("naviData");
  274. var action = navi.action;
  275. this.startNavis.each(function(node){
  276. node.removeEvents("mouseover");
  277. node.removeEvents("mouseout");
  278. node.removeEvents("mousedown");
  279. node.removeEvents("mouseup");
  280. node.setStyles(this.app.css.startMenuNaviLeftNode);
  281. var iconNode = node.getFirst();
  282. var textNode = node.getLast();
  283. var tmpnavi = node.retrieve("naviData");
  284. iconNode.setStyle("background-image", "url("+this.app.path+this.app.options.style+"/icon/"+tmpnavi.icon+"32.png)");
  285. iconNode.setStyles(this.app.css.startMenuIconLeftNode);
  286. textNode.setStyles(this.app.css.startMenuTextLeftNode);
  287. }.bind(this));
  288. naviNode.setStyles(this.app.css.startMenuNaviLeftNode_current);
  289. this.currentNavi = naviNode;
  290. if (this.status === "start"){
  291. this.toNormal();
  292. this.status = "normal";
  293. }
  294. if (this.app[action]) this.app[action].apply(this.app);
  295. },
  296. toNormal: function(){
  297. var css = this.app.css.normalStartMenuNode;
  298. if (!this.morph){
  299. this.morph = new Fx.Morph(this.node, {duration: 50, link: "chain"});
  300. }
  301. this.app.pingyinArea = new Element("div", {"styles": this.app.css.startMenuNaviLeftPingyinNode}).inject(this.node, "top");
  302. this.morph.start(css).chain(function(){
  303. this.node.setStyles(css);
  304. // MWF.require("MWF.widget.ScrollBar", function(){
  305. // new MWF.widget.ScrollBar(this.node, {
  306. // "style":"xApp_ProcessManager_StartMenu", "distance": 100, "friction": 4, "axis": {"x": false, "y": true}
  307. // });
  308. // }.bind(this));
  309. }.bind(this));
  310. },
  311. setNodeCenter: function(node){
  312. var size = node.getSize();
  313. var contentSize = this.app.node.getSize();
  314. var top = contentSize.y/2 - size.y/2;
  315. var left = contentSize.x/2 - size.x/2;
  316. if (left<0) left = 0;
  317. if (top<0) top = 0;
  318. node.setStyles({"left": left, "top": top});
  319. },
  320. getStartMenuNormalSize: function(){
  321. var naviItemNode = this.node.getFirst();
  322. var size = naviItemNode.getComputedSize();
  323. var mt = naviItemNode.getStyle("margin-top").toFloat();
  324. var mb = naviItemNode.getStyle("margin-bottom").toFloat();
  325. var height = size.totalWidth+mt+mb;
  326. var ml = naviItemNode.getStyle("margin-left").toFloat();
  327. var mr = naviItemNode.getStyle("margin-right").toFloat();
  328. var width = size.totalWidth+ml+mr;
  329. return {"width": width, "height": height*this.startNavis.length};
  330. },
  331. setStartMenuWidth: function(){
  332. var naviItemNode = this.node.getFirst();
  333. var size = naviItemNode.getComputedSize();
  334. var ml = naviItemNode.getStyle("margin-left").toFloat();
  335. var mr = naviItemNode.getStyle("margin-right").toFloat();
  336. var width = size.totalWidth+ml+mr;
  337. this.node.setStyle("width", (width*this.startNavis.length)+"px");
  338. },
  339. onResize: function(){
  340. if (this.status === "start"){
  341. this.setNodeCenter(this.node);
  342. }
  343. }
  344. });