Main.js 17 KB

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