Main.js 18 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251252253254255256257258259260261262263264265266267268269270271272273274275276277278279280281282283284285286287288289290291292293294295296297298299300301302303304305306307308309310311312313314315316317318319320321322323324325326327328329330331332333334335336337338339340341342343344345346347348349350351352353354355356357358359360361362363364365366367368369370371372373374375376377378379380381382383384385386387388389390391392393394395396397398399400401402403404405406407408409410411412413414415416417418419420421422423424425426427428429430431432433434435436437438439440441442443444445446447448449450451452453454455456457458459460461462463464465466467468469470471472473474475476477478479480481482483484485486487488489490491492493494495496497498499500501502503504505506507508509510511512513514515516
  1. MWF.xApplication.Attendance = MWF.xApplication.Attendance || {};
  2. MWF.require("MWF.widget.O2Identity", null,false);
  3. //MWF.xDesktop.requireApp("Attendance", "Actions.RestActions", null, false);
  4. MWF.xDesktop.requireApp("Attendance", "Common", null, false);
  5. MWF.xDesktop.requireApp("Template", "MDomItem", null, false);
  6. MWF.xApplication.Attendance.options = {
  7. multitask: false,
  8. executable: true
  9. };
  10. MWF.xApplication.Attendance.Main = new Class({
  11. Extends: MWF.xApplication.Common.Main,
  12. Implements: [Options, Events],
  13. options: {
  14. "curNaviId" : null,
  15. "style": "default",
  16. "name": "Attendance",
  17. "icon": "icon.png",
  18. "width": "1400",
  19. "height": "700",
  20. "isResize": true,
  21. "isMax": true,
  22. "title": MWF.xApplication.Attendance.LP.title
  23. },
  24. onQueryLoad: function(){
  25. this.lp = MWF.xApplication.Attendance.LP;
  26. },
  27. loadApplication: function(callback){
  28. if (!this.options.isRefresh) {
  29. this.maxSize(function () {
  30. this.loadLayout();
  31. }.bind(this));
  32. } else {
  33. this.loadLayout();
  34. }
  35. },
  36. loadLayout: function(){
  37. this.manageUnits =[];
  38. this.manageTopUnits = [];
  39. this.restActions = MWF.Actions.get("x_attendance_assemble_control");
  40. this.personActions = MWF.Actions.get("x_organization_assemble_personal");
  41. this.orgActions = MWF.Actions.get("x_organization_assemble_express");
  42. this.createNode();
  43. this.loadApplicationContent();
  44. },
  45. isAdmin: function(){
  46. return this.isTopUnitManager() || MWF.AC.isAttendanceManager() || MWF.AC.isAdministrator()
  47. },
  48. isUnitManager : function(){
  49. return this.manageUnits.length > 0;
  50. },
  51. isTopUnitManager : function(){
  52. return this.manageTopUnits.length > 0;
  53. },
  54. getNameFlag : function(name){
  55. var t = typeOf(name);
  56. if (t==="array"){
  57. var v = [];
  58. name.each(function(id){
  59. v.push((typeOf(id)==="object") ? (id.distinguishedName || id.id || id.unique || id.name) : id);
  60. });
  61. return v;
  62. }else{
  63. return [(t==="object") ? (name.distinguishedName || name.id || name.unique || name.name) : name];
  64. }
  65. },
  66. loadController: function(callback){
  67. this.restActions.listPermission( function( json ){
  68. json.data = json.data || [];
  69. json.data.each(function(item){
  70. if( item.adminLevel == "COMPANY" && item.adminName == layout.desktop.session.user.distinguishedName){
  71. this.manageTopUnits.push( item.unitName )
  72. }else if( item.adminLevel == "DEPT" && item.adminName == layout.desktop.session.user.distinguishedName ){
  73. this.manageUnits.push( item.unitName )
  74. }
  75. }.bind(this));
  76. if(callback)callback(json);
  77. }.bind(this));
  78. },
  79. createNode: function(){
  80. this.content.setStyle("overflow", "hidden");
  81. this.node = new Element("div", {
  82. "styles": {"width": "100%", "height": "100%", "overflow": "hidden"}
  83. }).inject(this.content);
  84. },
  85. loadApplicationContent: function(){
  86. this.loadController(function(){
  87. this.loaNavi();
  88. }.bind(this));
  89. //this.loadApplicationLayout();
  90. },
  91. loaNavi: function(callback){
  92. this.naviNode = new Element("div.naviNode", {
  93. "styles": this.css.naviNode
  94. }).inject(this.node);
  95. var curNavi = { "id" : "" };
  96. if( this.status ){
  97. curNavi.id = this.status.id
  98. }
  99. if( this.options.curNaviId ){
  100. curNavi.id = this.options.curNaviId;
  101. }
  102. this.navi = new MWF.xApplication.Attendance.Navi(this, this.naviNode, curNavi );
  103. },
  104. clearContent: function(){
  105. if (this.explorerContent){
  106. if (this.explorer && this.explorer.destroy ){
  107. this.explorer.destroy();
  108. }
  109. this.explorerContent.destroy();
  110. this.explorerContent = null;
  111. }
  112. },
  113. openMyIndex : function(){
  114. MWF.xDesktop.requireApp("Attendance", "MyIndex", function(){
  115. this.clearContent();
  116. this.explorerContent = new Element("div", {
  117. "styles": this.css.rightContentNode
  118. }).inject(this.node);
  119. this.explorer = new MWF.xApplication.Attendance.MyIndex(this.explorerContent, this, this.restActions,{"isAdmin":this.isAdmin() } );
  120. this.explorer.load();
  121. }.bind(this));
  122. },
  123. openMyDetail : function(){
  124. MWF.xDesktop.requireApp("Attendance", "MyDetail", function(){
  125. this.clearContent();
  126. this.explorerContent = new Element("div", {
  127. "styles": this.css.rightContentNode
  128. }).inject(this.node);
  129. this.explorer = new MWF.xApplication.Attendance.MyDetail(this.explorerContent, this, this.restActions,{"isAdmin":this.isAdmin() } );
  130. this.explorer.load();
  131. }.bind(this));
  132. },
  133. openUnitIndex : function(){
  134. MWF.xDesktop.requireApp("Attendance", "UnitIndex", function(){
  135. this.clearContent();
  136. this.explorerContent = new Element("div", {
  137. "styles": this.css.rightContentNode
  138. }).inject(this.node);
  139. this.explorer = new MWF.xApplication.Attendance.UnitIndex(this.explorerContent, this, this.restActions,{"isAdmin":this.isAdmin() } );
  140. this.explorer.load();
  141. }.bind(this));
  142. },
  143. openUnitDetail : function(){
  144. MWF.xDesktop.requireApp("Attendance", "UnitDetail", function(){
  145. this.clearContent();
  146. this.explorerContent = new Element("div", {
  147. "styles": this.css.rightContentNode
  148. }).inject(this.node);
  149. this.explorer = new MWF.xApplication.Attendance.UnitDetail(this.explorerContent, this, this.restActions,{"isAdmin":this.isAdmin() } );
  150. this.explorer.load();
  151. }.bind(this));
  152. },
  153. openPeopleDetail : function(){
  154. MWF.xDesktop.requireApp("Attendance", "PeopleDetail", function(){
  155. this.clearContent();
  156. this.explorerContent = new Element("div", {
  157. "styles": this.css.rightContentNode
  158. }).inject(this.node);
  159. this.explorer = new MWF.xApplication.Attendance.PeopleDetail(this.explorerContent, this, this.restActions,{"isAdmin":this.isAdmin() } );
  160. this.explorer.load();
  161. }.bind(this));
  162. },
  163. openTopUnitDetail : function(){
  164. MWF.xDesktop.requireApp("Attendance", "TopUnitDetail", function(){
  165. this.clearContent();
  166. this.explorerContent = new Element("div", {
  167. "styles": this.css.rightContentNode
  168. }).inject(this.node);
  169. this.explorer = new MWF.xApplication.Attendance.TopUnitDetail(this.explorerContent, this, this.restActions,{"isAdmin":this.isAdmin() } );
  170. this.explorer.load();
  171. }.bind(this));
  172. },
  173. openSelfHoliday : function(){
  174. MWF.xDesktop.requireApp("Attendance", "SelfHoliday", function(){
  175. this.clearContent();
  176. this.explorerContent = new Element("div", {
  177. "styles": this.css.rightContentNode
  178. }).inject(this.node);
  179. this.explorer = new MWF.xApplication.Attendance.SelfHoliday(this.explorerContent, this, this.restActions,{"isAdmin":this.isAdmin() } );
  180. this.explorer.load();
  181. }.bind(this));
  182. },
  183. openMyAppealDeal : function(){
  184. MWF.xDesktop.requireApp("Attendance", "MyAppeal", function(){
  185. this.clearContent();
  186. this.explorerContent = new Element("div", {
  187. "styles": this.css.rightContentNode
  188. }).inject(this.node);
  189. this.explorer = new MWF.xApplication.Attendance.MyAppeal(this.explorerContent, this, this.restActions,{"isAdmin":this.isAdmin() } );
  190. this.explorer.load();
  191. }.bind(this));
  192. },
  193. openAppealDeal : function(){
  194. MWF.xDesktop.requireApp("Attendance", "AppealExplorer", function(){
  195. this.clearContent();
  196. this.explorerContent = new Element("div", {
  197. "styles": this.css.rightContentNode
  198. }).inject(this.node);
  199. this.explorer = new MWF.xApplication.Attendance.AppealExplorer(this.explorerContent, this, this.restActions,{"isAdmin":this.isAdmin() } );
  200. this.explorer.load();
  201. }.bind(this));
  202. },
  203. openImporting : function(){
  204. MWF.xDesktop.requireApp("Attendance", "ImportExplorer", function(){
  205. this.clearContent();
  206. this.explorerContent = new Element("div", {
  207. "styles": this.css.rightContentNode
  208. }).inject(this.node);
  209. this.explorer = new MWF.xApplication.Attendance.ImportExplorer(this.explorerContent, this, this.restActions,{"isAdmin":this.isAdmin() } );
  210. this.explorer.load();
  211. }.bind(this));
  212. },
  213. openImportedInvalidInfor : function(){
  214. MWF.xDesktop.requireApp("Attendance", "InvalidInfor", function(){
  215. this.clearContent();
  216. this.explorerContent = new Element("div", {
  217. "styles": this.css.rightContentNode
  218. }).inject(this.node);
  219. this.explorer = new MWF.xApplication.Attendance.InvalidInfor(this.explorerContent, this, this.restActions,{"isAdmin":this.isAdmin() } );
  220. this.explorer.load();
  221. }.bind(this));
  222. },
  223. openAbnormalExport : function(){
  224. MWF.xDesktop.requireApp("Attendance", "AbnormalExport", function(){
  225. this.clearContent();
  226. this.explorerContent = new Element("div", {
  227. "styles": this.css.rightContentNode
  228. }).inject(this.node);
  229. this.explorer = new MWF.xApplication.Attendance.AbnormalExport(this.explorerContent, this, this.restActions,{"isAdmin":this.isAdmin() } );
  230. this.explorer.load();
  231. }.bind(this));
  232. },
  233. openScheduleSetting: function(){
  234. MWF.xDesktop.requireApp("Attendance", "ScheduleExplorer", function(){
  235. this.clearContent();
  236. this.explorerContent = new Element("div", {
  237. "styles": this.css.rightContentNode
  238. }).inject(this.node);
  239. this.explorer = new MWF.xApplication.Attendance.ScheduleExplorer(this.explorerContent, this, this.restActions,{"isAdmin":this.isAdmin() } );
  240. this.explorer.load();
  241. }.bind(this));
  242. },
  243. openPermissionSetting: function(){
  244. MWF.xDesktop.requireApp("Attendance", "PermissionExplorer", function(){
  245. this.clearContent();
  246. this.explorerContent = new Element("div", {
  247. "styles": this.css.rightContentNode
  248. }).inject(this.node);
  249. this.explorer = new MWF.xApplication.Attendance.PermissionExplorer(this.explorerContent, this, this.restActions,{"isAdmin":this.isAdmin() } );
  250. this.explorer.load();
  251. }.bind(this));
  252. },
  253. openHolidaySetting : function(){
  254. MWF.xDesktop.requireApp("Attendance", "HolidayExplorer", function(){
  255. this.clearContent();
  256. this.explorerContent = new Element("div", {
  257. "styles": this.css.rightContentNode
  258. }).inject(this.node);
  259. this.explorer = new MWF.xApplication.Attendance.HolidayExplorer(this.explorerContent, this, this.restActions,{"isAdmin":this.isAdmin() } );
  260. this.explorer.load();
  261. }.bind(this));
  262. },
  263. openStaticsCycleExplorer : function(){
  264. MWF.xDesktop.requireApp("Attendance", "StatisticsCycle", function(){
  265. this.clearContent();
  266. this.explorerContent = new Element("div", {
  267. "styles": this.css.rightContentNode
  268. }).inject(this.node);
  269. this.explorer = new MWF.xApplication.Attendance.StatisticsCycle(this.explorerContent, this, this.restActions,{"isAdmin":this.isAdmin() } );
  270. this.explorer.load();
  271. }.bind(this));
  272. },
  273. openAppSetting : function(){
  274. MWF.xDesktop.requireApp("Attendance", "AppSetting", function(){
  275. var setting = new MWF.xApplication.Attendance.AppSetting(this,this.restActions);
  276. setting.edit();
  277. }.bind(this));
  278. },
  279. openAddressSetting : function(){
  280. MWF.xDesktop.requireApp("Attendance", "AddressExplorer", function(){
  281. this.clearContent();
  282. this.explorerContent = new Element("div", {
  283. "styles": this.css.rightContentNode
  284. }).inject(this.node);
  285. this.explorer = new MWF.xApplication.Attendance.AddressExplorer(this.explorerContent, this, this.restActions,{"isAdmin":this.isAdmin() } );
  286. this.explorer.load();
  287. }.bind(this));
  288. },
  289. openPersonSetting : function(){
  290. MWF.xDesktop.requireApp("Attendance", "PersonSetting", function(){
  291. this.clearContent();
  292. this.explorerContent = new Element("div", {
  293. "styles": this.css.rightContentNode
  294. }).inject(this.node);
  295. this.explorer = new MWF.xApplication.Attendance.PersonSetting(this.explorerContent, this, this.restActions,{"isAdmin":this.isAdmin() } );
  296. this.explorer.load();
  297. }.bind(this));
  298. },
  299. recordStatus: function(){
  300. return this.navi && this.navi.currentItem ? this.navi.currentItem.retrieve("data") : {};
  301. }
  302. });
  303. MWF.xApplication.Attendance.Navi = new Class({
  304. Implements: [Options, Events],
  305. options : {
  306. "id" : ""
  307. },
  308. initialize: function(app, node, options){
  309. this.setOptions(options);
  310. this.app = app;
  311. this.node = $(node);
  312. this.css = this.app.css;
  313. this.currentMenu = null;
  314. this.currentItem = null;
  315. this.menus = {};
  316. this.items = {};
  317. this.elements = [];
  318. this.load();
  319. },
  320. load: function(){
  321. this.scrollNode = new Element("div.naviScrollNode", { "styles" : this.css.naviScrollNode }).inject( this.node );
  322. this.areaNode = new Element("div.naviAreaNode", { "styles" : this.css.naviAreaNode }).inject( this.scrollNode );
  323. this.setNodeScroll();
  324. var naviUrl = this.app.path+"navi.json";
  325. MWF.getJSON(naviUrl, function(json){
  326. json.each(function(navi){
  327. if( navi.access && navi.access == "admin" ){
  328. if( this.app.isAdmin() )this.createNaviNode(navi);
  329. }else if( navi.access && navi.access == "admin_dept" ){
  330. if( this.app.isUnitManager() || this.app.isAdmin() )this.createNaviNode(navi);
  331. }else{
  332. this.createNaviNode(navi);
  333. }
  334. }.bind(this));
  335. if( this.options.id == "" )this.elements[0].click();
  336. this.setContentSize();
  337. this.app.addEvent("resize", this.setContentSize.bind(this));
  338. }.bind(this));
  339. },
  340. setNodeScroll: function(){
  341. MWF.require("MWF.widget.DragScroll", function(){
  342. new MWF.widget.DragScroll(this.scrollNode);
  343. }.bind(this));
  344. MWF.require("MWF.widget.ScrollBar", function(){
  345. new MWF.widget.ScrollBar(this.scrollNode, {"indent": false});
  346. }.bind(this));
  347. },
  348. createNaviNode :function(data){
  349. if( data.type == "sep" ){
  350. var flag = true;
  351. if( data.access == "admin" ){
  352. if( !this.app.isAdmin() )flag = false;
  353. }else if( data.access && data.access == "admin_dept" ){
  354. if( !this.app.isUnitManager() && !this.app.isAdmin() )flag = false;
  355. }
  356. if( flag ){
  357. new Element("div", { "styles": this.css.viewNaviSepartorNode }).inject(this.areaNode);
  358. }
  359. }else if( data.sub && data.sub.length > 0 ){
  360. this.createNaviMenuNode(data);
  361. }else{
  362. this.menus[data.id] = {};
  363. this.createNaviItemNode(data, data.id);
  364. }
  365. },
  366. createNaviMenuNode :function(data){
  367. if( data.access == "admin" ){
  368. if( !this.app.isAdmin() )return;
  369. }else if(data.access == "admin_dept"){
  370. if( !this.app.isUnitManager() && !this.app.isAdmin() )return;
  371. }
  372. var _self = this;
  373. var menuNode = new Element("div", {
  374. "styles": this.css.naviMenuNode
  375. });
  376. menuNode.store("data", data);
  377. menuNode.store("type", "menu");
  378. var textNode = new Element("div", {
  379. "styles": this.css.naviMenuTextNode,
  380. "text": data.title
  381. });
  382. textNode.inject(menuNode);
  383. menuNode.inject(this.areaNode);
  384. this.menus[data.id] = {};
  385. this.menus[data.id].node = menuNode;
  386. this.elements.push(menuNode);
  387. menuNode.addEvents({
  388. "mouseover": function(){ if (_self.currentMenu!=this) this.setStyles(_self.app.css.naviMenuNode_over);},
  389. "mouseout": function(){if (_self.currentMenu!=this) this.setStyles(_self.app.css.naviMenuNode);},
  390. "mousedown": function(){if (_self.currentMenu!=this) this.setStyles(_self.app.css.naviMenuNode_down);},
  391. "mouseup": function(){if (_self.currentMenu!=this) this.setStyles(_self.app.css.naviMenuNode_over);},
  392. "click": function(){
  393. //if (_self.currentNavi!=this) _self.doAction.apply(_self, [this]);
  394. _self.clickMenu.apply(_self, [this]);
  395. }
  396. });
  397. data.sub.each(function( d ){
  398. this.createNaviItemNode( d, data.id, menuNode )
  399. }.bind(this))
  400. },
  401. clickMenu: function(naviNode) {
  402. var navi = naviNode.retrieve("data");
  403. var action = navi.action;
  404. this.closeCurrentMenu();
  405. if( this.menus[navi.id].itemNodes ) {
  406. this.menus[navi.id].itemNodes.each( function(itemNode){
  407. itemNode.setStyle("display","block");
  408. })
  409. }
  410. var type = naviNode.retrieve("type");
  411. if (!navi.target || navi.target != "_blank") {
  412. naviNode.setStyles( this.css.naviMenuNode_current );
  413. this.currentMenu = naviNode;
  414. }
  415. },
  416. closeCurrentMenu:function(){
  417. if( this.currentMenu ) {
  418. var data = this.currentMenu.retrieve("data");
  419. if (this.menus[data.id].itemNodes) {
  420. this.menus[data.id].itemNodes.each(function (itemNode) {
  421. itemNode.setStyle("display", "none");
  422. })
  423. }
  424. this.currentMenu.setStyles( this.css.naviMenuNode);
  425. }
  426. },
  427. createNaviItemNode : function( data,menuId ){
  428. if( data.access == "admin" ){
  429. if( !this.app.isAdmin() )return;
  430. }else if( data.access && data.access == "admin_dept" ){
  431. if( !this.app.isUnitManager() && !this.app.isAdmin() )return;
  432. }
  433. var _self = this;
  434. var items = this.menus[menuId].itemNodes = this.menus[menuId].itemNodes || [];
  435. var itemNode = new Element("div", {
  436. "styles": this.css.naviItemNode
  437. });
  438. itemNode.setStyle("display","block");
  439. items.push(itemNode);
  440. itemNode.store("data", data);
  441. itemNode.store("type", "item");
  442. var textNode = new Element("div", {
  443. "styles": this.css.naviItemTextNode,
  444. "text": data.title
  445. });
  446. textNode.inject(itemNode);
  447. itemNode.inject(this.areaNode);
  448. this.elements.push(itemNode);
  449. this.items[data.id] = itemNode;
  450. itemNode.addEvents({
  451. "mouseover": function(){ if (_self.currentItem!=this) this.setStyles(_self.app.css.naviItemNode_over);},
  452. "mouseout": function(){if (_self.currentItem!=this) this.setStyles(_self.app.css.naviItemNode);},
  453. "mousedown": function(){if (_self.currentItem!=this) this.setStyles(_self.app.css.naviItemNode_down);},
  454. "mouseup": function(){if (_self.currentItem!=this) this.setStyles(_self.app.css.naviItemNode_over);},
  455. "click": function(){
  456. _self.clickItem.apply(_self, [this]);
  457. }
  458. });
  459. if( data.id == this.options.id ){
  460. itemNode.click();
  461. }
  462. },
  463. clickItem : function(naviNode) {
  464. var navi = naviNode.retrieve("data");
  465. var action = navi.action;
  466. var type = naviNode.retrieve("type");
  467. if (!navi.target || navi.target != "_blank") {
  468. if (this.currentItem) this.currentItem.setStyles(this.css.naviItemNode);
  469. naviNode.setStyles(this.css.naviItemNode_current);
  470. this.currentItem = naviNode;
  471. }
  472. if (navi.action && this.app[navi.action]) {
  473. this.app[navi.action].call(this.app, navi);
  474. }
  475. },
  476. setContentSize : function(){
  477. var size = this.app.content.getSize();
  478. this.scrollNode.setStyle("height", size.y - 5 );
  479. }
  480. //loadCalendar: function () {
  481. // var calendarArea = new Element("div#calendarArea",{
  482. // "styles" : this.css.calendarArea
  483. // }).inject(this.node)
  484. // this.calendar = new MWF.xApplication.Attendance.Calendar( calendarArea, this.app, this.actions )
  485. // this.calendar.load();
  486. //}
  487. });