MyIndex.js 62 KB

12345678910111213141516171819202122232425262728293031323334353637383940414243444546474849505152535455565758596061626364656667686970717273747576777879808182838485868788899091929394959697989910010110210310410510610710810911011111211311411511611711811912012112212312412512612712812913013113213313413513613713813914014114214314414514614714814915015115215315415515615715815916016116216316416516616716816917017117217317417517617717817918018118218318418518618718818919019119219319419519619719819920020120220320420520620720820921021121221321421521621721821922022122222322422522622722822923023123223323423523623723823924024124224324424524624724824925025125225325425525625725825926026126226326426526626726826927027127227327427527627727827928028128228328428528628728828929029129229329429529629729829930030130230330430530630730830931031131231331431531631731831932032132232332432532632732832933033133233333433533633733833934034134234334434534634734834935035135235335435535635735835936036136236336436536636736836937037137237337437537637737837938038138238338438538638738838939039139239339439539639739839940040140240340440540640740840941041141241341441541641741841942042142242342442542642742842943043143243343443543643743843944044144244344444544644744844945045145245345445545645745845946046146246346446546646746846947047147247347447547647747847948048148248348448548648748848949049149249349449549649749849950050150250350450550650750850951051151251351451551651751851952052152252352452552652752852953053153253353453553653753853954054154254354454554654754854955055155255355455555655755855956056156256356456556656756856957057157257357457557657757857958058158258358458558658758858959059159259359459559659759859960060160260360460560660760860961061161261361461561661761861962062162262362462562662762862963063163263363463563663763863964064164264364464564664764864965065165265365465565665765865966066166266366466566666766866967067167267367467567667767867968068168268368468568668768868969069169269369469569669769869970070170270370470570670770870971071171271371471571671771871972072172272372472572672772872973073173273373473573673773873974074174274374474574674774874975075175275375475575675775875976076176276376476576676776876977077177277377477577677777877978078178278378478578678778878979079179279379479579679779879980080180280380480580680780880981081181281381481581681781881982082182282382482582682782882983083183283383483583683783883984084184284384484584684784884985085185285385485585685785885986086186286386486586686786886987087187287387487587687787887988088188288388488588688788888989089189289389489589689789889990090190290390490590690790890991091191291391491591691791891992092192292392492592692792892993093193293393493593693793893994094194294394494594694794894995095195295395495595695795895996096196296396496596696796896997097197297397497597697797897998098198298398498598698798898999099199299399499599699799899910001001100210031004100510061007100810091010101110121013101410151016101710181019102010211022102310241025102610271028102910301031103210331034103510361037103810391040104110421043104410451046104710481049105010511052105310541055105610571058105910601061106210631064106510661067106810691070107110721073107410751076107710781079108010811082108310841085108610871088108910901091109210931094109510961097109810991100110111021103110411051106110711081109111011111112111311141115111611171118111911201121112211231124112511261127112811291130113111321133113411351136113711381139114011411142114311441145114611471148114911501151115211531154115511561157115811591160116111621163116411651166116711681169117011711172117311741175117611771178117911801181118211831184118511861187118811891190119111921193119411951196119711981199120012011202120312041205120612071208120912101211121212131214121512161217121812191220122112221223122412251226122712281229123012311232123312341235123612371238123912401241124212431244124512461247124812491250125112521253125412551256125712581259126012611262126312641265126612671268126912701271127212731274127512761277127812791280128112821283128412851286128712881289129012911292129312941295129612971298129913001301130213031304130513061307130813091310131113121313131413151316131713181319132013211322132313241325132613271328132913301331133213331334133513361337133813391340134113421343134413451346134713481349135013511352135313541355135613571358135913601361136213631364136513661367136813691370137113721373137413751376137713781379138013811382138313841385138613871388138913901391139213931394139513961397139813991400140114021403140414051406140714081409141014111412141314141415141614171418141914201421142214231424142514261427142814291430143114321433143414351436143714381439144014411442144314441445144614471448
  1. MWF.xApplication.Attendance = MWF.xApplication.Attendance || {};
  2. MWF.require("MWF.xAction.org.express.RestActions", null,false);
  3. MWF.xDesktop.requireApp("Attendance", "lp."+MWF.language, null, false);
  4. MWF.xDesktop.requireApp("Attendance", "Common", null, false);
  5. MWF.xDesktop.requireApp("Attendance", "widget.Calendar", null, false);
  6. MWF.xApplication.Attendance.MyIndex = new Class({
  7. Extends: MWF.widget.Common,
  8. Implements: [Options, Events],
  9. options: {
  10. "style": "default"
  11. },
  12. statusColor : {
  13. "normal" : "#4A90E2", //蓝色,正常
  14. "levelAsked":"#2BC497", //绿色,请假
  15. "late":"#F5A623", //黄色,迟到
  16. //"leaveEarly":"#fe8d03", //橙色,早退
  17. "noSign":"#FF8080", //粉红色,未签到
  18. "appealSuccess" : "#4FB2E3", //黄绿色,申诉通过
  19. //"lackOfTime" : "#dec674",//工时不足人次
  20. "abNormalDuty" : "#8B572A"//异常打卡人次
  21. },
  22. initialize: function(node, app, actions, options){
  23. this.setOptions(options);
  24. this.app = app;
  25. this.lp = app.lp;
  26. this.path = "../x_component_Attendance/$MyIndex/";
  27. this.cssPath = "../x_component_Attendance/$MyIndex/"+this.options.style+"/css.wcss";
  28. this._loadCss();
  29. this.actions = actions;
  30. this.node = $(node);
  31. this.holidayData = {};
  32. this.today = new Date();
  33. //this.preMonthDate = new Date();
  34. //this.preMonthDate.decrement("month", 1);
  35. this.setDate();
  36. this.todayDate = this.today.format( this.lp.dateFormatDay );
  37. this.todayHloidayName = "";
  38. this.todayIsWorkDay = false; //是否调修工作日
  39. this.userName = layout.desktop.session.user.distinguishedName;
  40. },
  41. setDate : function( date ){
  42. this.date = date || new Date(); //this.preMonthDate
  43. this.year = this.date.getFullYear().toString();
  44. var month = this.date.getMonth()+1;
  45. this.month = month.toString().length == 2 ? month : "0"+month;
  46. this.getCycleDate();
  47. },
  48. destroy: function(){
  49. this.node.empty();
  50. },
  51. reload: function(){
  52. this.node.empty();
  53. this.load();
  54. },
  55. load: function(){
  56. this.loadTitleNode();
  57. this.loadContent();
  58. },
  59. loadTitleNode : function(){
  60. var text = this.date.format(this.app.lp.dateFormatMonth);
  61. this.titleNode = new Element("div.titleNode",{
  62. "styles" : this.css.titleNode
  63. }).inject(this.node);
  64. this.titleRightNode = new Element("div.titleRightNode",{
  65. "styles" : this.css.titleRightNode
  66. }).inject(this.titleNode);
  67. //this.titleLeftArrowNode = new Element("div",{
  68. // "styles" : this.css.titleLeftArrowNode
  69. //}).inject(this.titleRightNode);
  70. this.titleTextNode = new Element("div",{
  71. "styles" : this.css.titleTextNode,
  72. "text" : text
  73. }).inject(this.titleRightNode);
  74. this.titleTextNode.setStyles( {
  75. "cursor" : "default"
  76. } );
  77. //this.titleRightArrowNode = new Element("div",{
  78. // "styles" : this.css.titleRightArrowNode
  79. //}).inject(this.titleRightNode);
  80. var cycleText = this.app.lp.cyclText.
  81. replace("{start}",this.cycleStartDate.format(this.app.lp.dateFormatMonthDayLocal)).
  82. replace("{end}",this.cycleEndDate.format(this.app.lp.dateFormatMonthDayLocal));
  83. this.titleCycleTextNode = new Element("div",{
  84. "styles" : this.css.titleCycleTextNode,
  85. "text" : cycleText
  86. }).inject(this.titleRightNode);
  87. this.titleScheduleIconNode = new Element("div",{
  88. "styles" : this.css.titleScheduleIconNode,
  89. "title" : this.lp.seeSchedule
  90. }).inject(this.titleRightNode);
  91. //this.titleLeftArrowNode.addEvents({
  92. // "mouseover": function(){this.titleLeftArrowNode.setStyles(this.css.titleLeftArrowNode_over);}.bind(this),
  93. // "mouseout": function(){this.titleLeftArrowNode.setStyles(this.css.titleLeftArrowNode);}.bind(this),
  94. // "mousedown": function(){this.titleLeftArrowNode.setStyles(this.css.titleLeftArrowNode_down);}.bind(this),
  95. // "mouseup": function(){this.titleLeftArrowNode.setStyles(this.css.titleLeftArrowNode_over);}.bind(this),
  96. // "click": function(){this.changeMonthPrev();}.bind(this)
  97. //});
  98. //this.titleRightArrowNode.addEvents({
  99. // "mouseover": function(){this.titleRightArrowNode.setStyles(this.css.titleRightArrowNode_over);}.bind(this),
  100. // "mouseout": function(){this.titleRightArrowNode.setStyles(this.css.titleRightArrowNode);}.bind(this),
  101. // "mousedown": function(){this.titleRightArrowNode.setStyles(this.css.titleRightArrowNode_down);}.bind(this),
  102. // "mouseup": function(){this.titleRightArrowNode.setStyles(this.css.titleRightArrowNode_over);}.bind(this),
  103. // "click": function(){this.changeMonthNext();}.bind(this)
  104. //});
  105. //this.titleTextNode.addEvents({
  106. // "mouseover": function(){this.titleTextNode.setStyles(this.css.titleTextNode_over);}.bind(this),
  107. // "mouseout": function(){this.titleTextNode.setStyles(this.css.titleTextNode);}.bind(this),
  108. // "mousedown": function(){this.titleTextNode.setStyles(this.css.titleTextNode_down);}.bind(this),
  109. // "mouseup": function(){this.titleTextNode.setStyles(this.css.titleTextNode_over);}.bind(this),
  110. // "click": function(){this.changeMonthSelect();}.bind(this)
  111. //});
  112. this.titleScheduleIconNode.addEvents({
  113. "mouseover": function(){this.titleScheduleIconNode.setStyles(this.css.titleScheduleIconNode_over);}.bind(this),
  114. "mouseout": function(){this.titleScheduleIconNode.setStyles(this.css.titleScheduleIconNode);}.bind(this),
  115. "mousedown": function(){this.titleScheduleIconNode.setStyles(this.css.titleScheduleIconNode_down);}.bind(this),
  116. "mouseup": function(){this.titleScheduleIconNode.setStyles(this.css.titleScheduleIconNode_over);}.bind(this),
  117. "click": function(){this.showSchedule();}.bind(this)
  118. });
  119. },
  120. changeMonthPrev: function(){
  121. this.date.decrement("month", 1);
  122. this.setDate( this.date );
  123. var text = this.date.format(this.app.lp.dateFormatMonth);
  124. this.titleTextNode.set("text", text);
  125. this.reloadContent();
  126. },
  127. changeMonthNext: function(){
  128. this.date.increment("month", 1);
  129. this.setDate( this.date );
  130. var text = this.date.format(this.app.lp.dateFormatMonth);
  131. this.titleTextNode.set("text", text);
  132. this.reloadContent();
  133. },
  134. changeMonthSelect: function(){
  135. if (!this.monthSelector) this.createMonthSelector();
  136. this.monthSelector.show();
  137. },
  138. createMonthSelector: function(){
  139. this.monthSelector = new MWF.xApplication.Attendance.MonthSelector(this.date, this);
  140. },
  141. changeMonthTo: function(d){
  142. this.setDate( d );
  143. var text = this.date.format(this.app.lp.dateFormatMonth);
  144. this.titleTextNode.set("text", text);
  145. this.reloadContent();
  146. },
  147. getCycleDate : function(){
  148. this.actions.getCyclePerson( this.year, this.month, function( json ){
  149. json.data = json.data || [];
  150. this.cycleStartDateString = json.data.cycleStartDateString;
  151. this.cycleEndDateString = json.data.cycleEndDateString;
  152. this.cycleStartDate = new Date( this.cycleStartDateString );
  153. this.cycleEndDate = new Date( this.cycleEndDateString );
  154. this.cycleYearMonth = [];
  155. var start = new Date(this.cycleStartDate.getFullYear(), this.cycleStartDate.getMonth(), 1);
  156. while( start < this.cycleEndDate ){
  157. var year = start.getFullYear().toString();
  158. var month = start.getMonth()+1;
  159. month = month.toString().length === 2 ? month : "0"+month;
  160. start.increment("month", 1);
  161. this.cycleYearMonth.push( { year: year, month: month} )
  162. }
  163. this.isCrossMonth = (this.cycleStartDate.getMonth() != this.cycleEndDate.getMonth());
  164. }.bind(this), null, false )
  165. },
  166. getScheduleData : function( callback ){
  167. var data = {"personList": this.app.getNameFlag(this.userName)};
  168. this.app.orgActions.listUnitSupNestedWithPerson( data, function( json ){
  169. var unitList = json.data;
  170. var sortF = function( a, b ){
  171. return b.level - a.level;
  172. };
  173. unitList.sort( sortF );
  174. var flag = true;
  175. for( var i = 0; i<unitList.length; i++ ){
  176. var unit = unitList[i];
  177. if( unit.level == 1 ){
  178. this.actions.listScheduleByTopUnit( unit.distinguishedName, function( json ){
  179. if( json.data ){
  180. if(callback)callback(json.data);
  181. flag = false;
  182. }
  183. }.bind(this), null, false)
  184. }else{
  185. this.actions.listScheduleByUnit( unit.distinguishedName, function( json ){
  186. if( json.data && json.data.length > 0 ){
  187. if(callback)callback(json.data);
  188. flag = false;
  189. }
  190. }.bind(this), null, false)
  191. }
  192. if( !flag )break;
  193. }
  194. }.bind(this), null, false );
  195. //this.actions.listUnitWithPerson( function( json ){
  196. // debugger;
  197. // var unitList = json.data;
  198. // if( unitList.length > 0 ){
  199. // this.actions.listScheduleByUnit( unitList[0].distinguishedName, function( json ){
  200. // debugger;
  201. // if( json.data && json.data.length > 0 ){
  202. // if(callback)callback(json.data);
  203. // }else{
  204. // this.actions.listScheduleByTopUnit( json.data[0].topUnit, function( json ){
  205. // debugger;
  206. // if(callback)callback(json.data);
  207. // }.bind(this))
  208. // }
  209. // }.bind(this))
  210. // }else{
  211. // if(callback)callback();
  212. // }
  213. //}.bind(this), null, data, false)
  214. },
  215. showSchedule: function( ){
  216. if( this.scheduleNode ){
  217. this.scheduleNode.setStyle("display","block");
  218. this.scheduleNode.position({
  219. relativeTo: this.titleScheduleIconNode,
  220. position: 'bottomLeft',
  221. edge: 'upperCenter',
  222. offset:{
  223. x : -60,
  224. y : 0
  225. }
  226. });
  227. }else{
  228. this.getScheduleData(function( data ){
  229. if( !data || data.length == 0 ){
  230. this.app.notice( this.lp.unfindSchedule,"error");
  231. }else{
  232. this.scheduleNode = new Element("div", {"styles": this.css.scheduleNode}).inject(this.node);
  233. this.scheduleNode.position({
  234. relativeTo: this.titleScheduleIconNode,
  235. position: 'bottomLeft',
  236. edge: 'upperCenter',
  237. offset:{
  238. x : -60,
  239. y : 0
  240. }
  241. });
  242. this.scheduleNode.addEvent("mousedown", function(e){e.stopPropagation();});
  243. document.body.addEvent("mousedown", function(){ this.scheduleNode.setStyle("display","none")}.bind(this));
  244. var d = data[0];
  245. var table = new Element("table", {
  246. "width" : "100%", "border" : "0", "cellpadding" : "5", "cellspacing" : "0", "class" : "filterTable"
  247. }).inject( this.scheduleNode );
  248. var tr = new Element("tr").inject(table);
  249. new Element("td",{ "text" : this.lp.scheduleTable , "styles" : this.css.scheduleTdHead, "colspan" : "2" }).inject(tr);
  250. var table = new Element("table", {
  251. "width" : "100%", "border" : "0", "cellpadding" : "5", "cellspacing" : "0", "class" : "filterTable"
  252. }).inject( this.scheduleNode );
  253. var tr = new Element("tr").inject(table);
  254. new Element("td",{ "text" : this.lp.schedule.workTime + ":" , "styles" : this.css.scheduleTdTitle }).inject(tr);
  255. new Element("td",{ "text" : d.onDutyTime || "" , "styles" : this.css.scheduleTdValue }).inject(tr);
  256. var tr = new Element("tr").inject(table);
  257. new Element("td",{ "text" : this.lp.schedule.offTime +":" , "styles" : this.css.scheduleTdTitle }).inject(tr);
  258. new Element("td",{ "text" : d.offDutyTime || "" , "styles" : this.css.scheduleTdValue }).inject(tr);
  259. var tr = new Element("tr").inject(table);
  260. new Element("td",{ "text" : this.lp.schedule.lateTime + ":" , "styles" : this.css.scheduleTdTitle }).inject(tr);
  261. new Element("td",{ "text" : d.lateStartTime || "" , "styles" : this.css.scheduleTdValue }).inject(tr);
  262. var tr = new Element("tr").inject(table);
  263. new Element("td",{ "text" : this.lp.schedule.leaveEarlyTime + ":" , "styles" : this.css.scheduleTdTitle }).inject(tr);
  264. new Element("td",{ "text" : d.leaveEarlyStartTime || "" , "styles" : this.css.scheduleTdValue }).inject(tr);
  265. var tr = new Element("tr").inject(table);
  266. new Element("td",{ "text" : this.lp.schedule.absenteeismTime+":" , "styles" : this.css.scheduleTdTitle }).inject(tr);
  267. new Element("td",{ "text" : d.absenceStartTime || "" , "styles" : this.css.scheduleTdValue }).inject(tr);
  268. }
  269. }.bind(this))
  270. }
  271. },
  272. reloadContent : function(){
  273. this.calendarArea.empty();
  274. this.statusColorArea.empty();
  275. this.pieChartArea.empty();
  276. this.lineChartArea.empty();
  277. this.loadData();
  278. },
  279. loadContent : function(){
  280. this.loadContentNode();
  281. this.loadData();
  282. // this.setNodeScroll();
  283. this.setContentSize();
  284. },
  285. reloadChart : function(){
  286. this.pieChartArea.empty();
  287. this.lineChartArea.empty();
  288. this.loadPieChart();
  289. this.loadLineChart();
  290. },
  291. loadContentNode: function(){
  292. this.elementContentNode = new Element("div.elementContentNode", {
  293. "styles": this.css.elementContentNode
  294. }).inject(this.node);
  295. this.app.addEvent("resize", function(){
  296. this.setContentSize();
  297. this.reloadChart();
  298. }.bind(this));
  299. this.elementContentListNode = new Element("div.elementContentListNode", {
  300. "styles": this.css.elementContentListNode
  301. }).inject(this.elementContentNode);
  302. this.topContentArea = new Element("div.topContentArea",{
  303. "styles" : this.css.topContentArea
  304. }).inject(this.elementContentListNode);
  305. this.calendarArea = new Element("div.calendarArea",{
  306. "styles" : this.css.calendarArea
  307. }).inject(this.topContentArea);
  308. this.middleContentArea = new Element("div.middleContentArea",{
  309. "styles" : this.css.middleContentArea
  310. }).inject(this.elementContentListNode);
  311. this.middleLeftArea = new Element("div.middleLeftArea",{
  312. "styles" : this.css.middleLeftArea
  313. }).inject(this.middleContentArea);
  314. this.middleLeftTitleArea = new Element("div.middleLeftTitleArea",{
  315. "styles" : this.css.middleLeftTitleArea,
  316. "text": this.lp.attendanceSummary
  317. }).inject(this.middleLeftArea);
  318. this.middleLeftContentArea = new Element("div.middleLeftContentArea",{
  319. "styles" : this.css.middleLeftContentArea
  320. }).inject(this.middleLeftArea);
  321. this.statusColorArea = new Element("div.statusColorArea",{
  322. "styles" : this.css.statusColorArea
  323. }).inject(this.middleLeftContentArea);
  324. this.pieChartArea = new Element("div.pieChartArea",{
  325. "styles" : this.css.pieChartArea
  326. }).inject(this.middleLeftContentArea);
  327. this.middleRightArea = new Element("div.middleRightArea",{
  328. "styles" : this.css.middleRightArea
  329. }).inject(this.middleContentArea);
  330. this.middleRightTitleArea = new Element("div.middleRightTitleArea",{
  331. "styles" : this.css.middleRightTitleArea,
  332. "text": this.lp.attendanceTrendChart
  333. }).inject(this.middleRightArea);
  334. this.middleRightContentArea = new Element("div.middleRightContentArea",{
  335. "styles" : this.css.middleRightContentArea
  336. }).inject(this.middleRightArea);
  337. this.lineChartArea = new Element("div.lineChartArea",{
  338. "styles" : this.css.lineChartArea
  339. }).inject(this.middleRightContentArea)
  340. },
  341. loadData : function(){
  342. // this.listDetailFilterUser( function( data ){
  343. this.listCycleDetailFileterUser( function(data){
  344. this.detailData = data || {};
  345. this.anaylyseDetail();
  346. this.loadStatusColorNode();
  347. this.loadPieChart();
  348. this.loadLineChart();
  349. this.loadHolidayData(function(){
  350. this.loadCalendarContent();
  351. //if(!this.titleInforNode)this.loadTitleInforNode();
  352. }.bind(this));
  353. }.bind(this), this.userName, this.year, this.month )
  354. },
  355. loadHolidayData : function( callback ){
  356. if( this.holidayData && this.holidayData[ this.year ] ) {
  357. //this.loadCalendarContent();
  358. if(callback)callback();
  359. }else{
  360. this.listHolidayFilter( function(data){
  361. var dates = {
  362. workdays : [],
  363. holidays : [],
  364. names : []
  365. };
  366. data.each( function(d){
  367. if( this.dateMap[d.configDate] ){
  368. var m = this.dateMap[d.configDate];
  369. if( d.configType === "Holiday" ){
  370. m.isHoliday = true;
  371. m.holidayName = d.configName;
  372. }else if(d.configType === "Workday"){
  373. m.isWorkday = true;
  374. m.holidayName = d.configName;
  375. }
  376. }
  377. if( !dates.names.contains(d.configName) ){
  378. dates.names.push( d.configName )
  379. }
  380. if( !dates[d.configName] ){
  381. dates[d.configName] = {};
  382. dates[d.configName].holidays = [];
  383. dates[d.configName].workdays = [];
  384. }
  385. if( d.configType == "Holiday" ){
  386. if( d.configDate == this.todayDate ){
  387. this.todayHloidayName = d.configName;
  388. }
  389. dates.holidays.push( d.configDate );
  390. dates[d.configName].holidays.push( d.configDate )
  391. }else{
  392. if( d.configDate == this.todayDate ){
  393. this.todayIsWorkDay = true;
  394. }
  395. dates.workdays.push( d.configDate );
  396. dates[d.configName].workdays.push( d.configDate )
  397. }
  398. }.bind(this));
  399. this.holidayData[this.year] = dates;
  400. if(callback)callback();
  401. }.bind(this), null, this.year)
  402. }
  403. },
  404. loadCalendarContent : function(){
  405. // this.calendarTitle = new Element("div.calendarTitle",{
  406. // "styles" : this.css.calendarTitle
  407. // }).inject(this.calendarArea)
  408. this.canlendarToolbar = new Element("div.canlendarToolbar",{
  409. "styles" : this.css.canlendarToolbar
  410. }).inject(this.calendarArea);
  411. this.canlendarToolbarText = new Element("div",{
  412. "styles" : this.css.canlendarToolbarText,
  413. "text" : this.lp.index.attendanceCalendar
  414. }).inject(this.canlendarToolbar);
  415. this.calendarDate = this.date.clone();
  416. if( this.isCrossMonth ){
  417. this.calendarMonthNode = new Element("div",{
  418. "styles" : this.css.calendarMonthNode
  419. }).inject(this.canlendarToolbar);
  420. this.calendarRightArrowNode = new Element("div",{
  421. "styles" : this.css.calendarRightArrowNode
  422. }).inject(this.calendarMonthNode);
  423. this.calendarCurrentMonthNode = new Element("div",{
  424. "styles" : this.css.calendarCurrentMonthNode,
  425. "text" : (this.calendarDate.getMonth()+1)+this.app.lp.month
  426. }).inject(this.calendarMonthNode);
  427. this.calendarLeftArrowNode = new Element("div",{
  428. "styles" : this.css.calendarLeftArrowNode
  429. }).inject(this.calendarMonthNode);
  430. this.calendarLeftArrowNode.addEvents({
  431. //"mouseover": function(){this.calendarLeftArrowNode.setStyles(this.css.calendarLeftArrowNode_over);}.bind(this),
  432. // "mouseout": function(){this.calendarLeftArrowNode.setStyles(this.css.calendarLeftArrowNode);}.bind(this),
  433. //"mousedown": function(){this.calendarLeftArrowNode.setStyles(this.css.calendarLeftArrowNode_down);}.bind(this),
  434. //"mouseup": function(){this.calendarLeftArrowNode.setStyles(this.css.calendarLeftArrowNode_over);}.bind(this),
  435. "click": function(){this.changeCalendarMonthPrev();}.bind(this)
  436. });
  437. this.calendarRightArrowNode.addEvents({
  438. //"mouseover": function(){this.calendarRightArrowNode.setStyles(this.css.calendarRightArrowNode_over);}.bind(this),
  439. //"mouseout": function(){this.calendarRightArrowNode.setStyles(this.css.calendarRightArrowNode);}.bind(this),
  440. //"mousedown": function(){this.calendarRightArrowNode.setStyles(this.css.calendarRightArrowNode_down);}.bind(this),
  441. //"mouseup": function(){this.calendarRightArrowNode.setStyles(this.css.calendarRightArrowNode_over);}.bind(this),
  442. "click": function(){this.changeCalendarMonthNext();}.bind(this)
  443. });
  444. this.switchCalendarArrow( this.calendarDate );
  445. }
  446. //this.loadHolidayNode();
  447. this.calendarNode = new Element("div.calendarNode",{
  448. "styles" : this.css.calendarNode
  449. }).inject(this.calendarArea);
  450. this.calendar = new MWF.xApplication.Attendance.MyIndex.Calendar(this.calendarNode, this,
  451. {
  452. "holiday" :this.holidayData[this.year],
  453. "detail" :this.detailData,
  454. "eventData" : this.eventData,
  455. "dateMap": this.dateMap
  456. },
  457. {
  458. date : this.date,
  459. cycleStart : this.cycleStartDate,
  460. cycleEnd : this.cycleEndDate
  461. }
  462. );
  463. this.calendar.load();
  464. // this.calendar = new MWF.xApplication.Attendance.Calendar(this.calendarNode, this,
  465. // {
  466. // "holiday" :this.holidayData[this.year],
  467. // "detail" :this.detailData,
  468. // "eventData" : this.eventData
  469. // },
  470. // {
  471. // date : this.date,
  472. // cycleStart : this.cycleStartDate,
  473. // cycleEnd : this.cycleEndDate
  474. // }
  475. // );
  476. // this.calendar.load();
  477. },
  478. switchCalendarArrow : function( date ){
  479. var firstDate = new Date( date.getFullYear() , date.getMonth() , 1, 0, 0, 0 );
  480. if( firstDate <= this.cycleStartDate ){
  481. this.calendarLeftArrowNode.setStyles( this.css.calendarLeftArrowNode_disable );
  482. this.calendarLeftDisable = true;
  483. }else{
  484. this.calendarLeftArrowNode.setStyles( this.css.calendarLeftArrowNode );
  485. this.calendarLeftDisable = false;
  486. }
  487. //alert( "firstDate="+firstDate.format("db") + " " +"cycleStartDate="+ this.cycleStartDate.format("db"))
  488. var lastDate = new Date( date.getFullYear(),date.getMonth()+1, 0, 23, 59, 59);
  489. if( lastDate >= this.cycleEndDate ){
  490. this.calendarRightArrowNode.setStyles( this.css.calendarRightArrowNode_disable );
  491. this.calendarRightDisable = true;
  492. }else{
  493. this.calendarRightArrowNode.setStyles( this.css.calendarRightArrowNode );
  494. this.calendarRightDisable = false;
  495. }
  496. },
  497. changeCalendarMonthPrev: function(){
  498. if( this.calendarLeftDisable )return ;
  499. // jQuery(this.calendarNode).fullCalendar( 'prev' );
  500. this.calendarDate.decrement("month", 1);
  501. this.calendarCurrentMonthNode.set("text",(this.calendarDate.getMonth()+1)+ this.app.lp.month );
  502. this.switchCalendarArrow( this.calendarDate );
  503. this.calendar.date = this.calendarDate;
  504. this.calendar.reLoadCalendar();
  505. },
  506. changeCalendarMonthNext: function(){
  507. if( this.calendarRightDisable )return ;
  508. // jQuery(this.calendarNode).fullCalendar( 'next' );
  509. this.calendarDate.increment("month", 1);
  510. this.calendarCurrentMonthNode.set("text",(this.calendarDate.getMonth()+1)+this.app.lp.month);
  511. this.switchCalendarArrow( this.calendarDate );
  512. this.calendar.date = this.calendarDate;
  513. this.calendar.reLoadCalendar();
  514. //this.date.increment("month", 1);
  515. //this.setDate( this.date );
  516. //var text = this.date.format(this.app.lp.dateFormatMonth);
  517. //this.titleTextNode.set("text", text);
  518. //this.reloadContent();
  519. },
  520. listHolidayFilter : function( callback, name,year,month ){
  521. /*{'q_Year':'2016','q_Name':'五一劳动节','q_Month':'03'}*/
  522. var filter = {};
  523. if( name )filter.q_Name = name;
  524. if( year )filter.q_Year = year;
  525. if( month ){
  526. filter.q_Month = month.toString().length == 2 ? month : "0"+month;
  527. }else{
  528. filter.q_Month = "(0)"
  529. }
  530. this.actions.listHolidayFilter( filter, function(json){
  531. if( callback )callback(json.data);
  532. }.bind(this))
  533. },
  534. loadHolidayNode : function() {
  535. this.holidayAreaNode = new Element("div.holidayAreaNode",{
  536. "styles" : this.css.holidayAreaNode
  537. }).inject(this.canlendarToolbar);
  538. this.holidayActionNode = new Element("div",{
  539. "styles" : this.css.holidayActionNode
  540. }).inject(this.holidayAreaNode);
  541. this.holidayActionTextNode = new Element("div",{
  542. "styles" : this.css.holidayActionTextNode,
  543. "text" : this.lp.holiday.holidaySchedule
  544. }).inject(this.holidayActionNode);
  545. this.holidayActionIconNode = new Element("div",{
  546. "styles" : this.css.holidayActionIconNode
  547. }).inject(this.holidayActionNode);
  548. this.holidayActionNode.addEvents({
  549. "mouseover": function(){this.holidayActionIconNode.setStyles(this.css.holidayActionIconNode_over);}.bind(this),
  550. "mouseout": function(){this.holidayActionIconNode.setStyles(this.css.holidayActionIconNode);}.bind(this),
  551. "click" : function( ev ){
  552. this.switchHoliday( ev.target );
  553. ev.stopPropagation();
  554. }.bind(this)
  555. })
  556. },
  557. switchHoliday: function( el ){
  558. var _self = this;
  559. var flag = false;
  560. if(this.holidayListNode ){
  561. if(this.holidayListNode.retrieve("year") == this.year){
  562. flag = true;
  563. }else{
  564. this.holidayListNode.destroy();
  565. }
  566. }
  567. if(flag){
  568. var parentNode = el.getParent();
  569. this.holidayListNode.inject(parentNode);
  570. if( this.holidayListNode.getStyle("display") == "block" ){
  571. this.holidayListNode.setStyle("display","none");
  572. }else{
  573. this.holidayListNode.setStyle("display","block");
  574. }
  575. }else{
  576. var holidays = this.holidayData[this.year];
  577. var holidayListNode = this.holidayListNode = new Element("div",{
  578. "styles" : this.css.holidayListNode
  579. });
  580. this.holidayListNode.store("year",this.year);
  581. this.app.content.addEvent("click",function(){
  582. _self.holidayListNode.setStyle("display","none");
  583. });
  584. holidays.names.each(function( n ){
  585. var holidayNode = new Element("div",{
  586. "text" : n,
  587. "styles" : this.css.holidayNode
  588. }).inject(holidayListNode);
  589. holidayNode.store("holidays", holidays[n].holidays );
  590. holidayNode.store("workdays", holidays[n].workdays );
  591. holidayNode.addEvents({
  592. "mouseover" : function(){
  593. this.setStyles(_self.css.holidayNode_over);
  594. },
  595. "mouseout" : function(){
  596. this.setStyles(_self.css.holidayNode);
  597. },
  598. "click" : function(e){
  599. _self.holidayListNode.setStyle("display","none");
  600. var holidays = this.retrieve("holidays");
  601. var workdays = this.retrieve("workdays");
  602. this.setStyles(_self.css.holidayNode);
  603. _self.changeMonthTo( new Date((holidays || workdays )[0]) );
  604. //jQuery(_self.calendarNode).fullCalendar( 'gotoDate', (holidays || workdays )[0] );
  605. e.stopPropagation();
  606. }
  607. })
  608. }.bind(this));
  609. var parentNode = el.getParent();
  610. this.holidayListNode.inject(parentNode);
  611. }
  612. },
  613. loadStatusColorNode : function(){
  614. this.statusColorTable = new Element("table",{
  615. "styles" : this.css.statusColorTable
  616. }).inject(this.statusColorArea);
  617. for(var status in this.statusColor){
  618. var tr = new Element("tr",{
  619. "styles" : this.css.statusColorTr,
  620. "title": this.lp[status]
  621. }).inject(this.statusColorTable);
  622. var td = new Element("td").inject(tr);
  623. new Element("div",{
  624. "styles" : {
  625. "margin-top": "8px",
  626. "width": "14px",
  627. "height": "14px",
  628. "border-radius": "14px",
  629. "background-color": this.statusColor[status]
  630. }
  631. }).inject(td);
  632. var td = new Element("td").inject(tr);
  633. new Element("div",{
  634. "styles" : {
  635. "margin-top": "8px",
  636. "min-width": "30px",
  637. "padding-left": "4px",
  638. "font-size": "14px",
  639. "color": "#666"
  640. },
  641. "text": this.lp.statusText[status]
  642. }).inject(td);
  643. var td = new Element("td").inject(tr);
  644. new Element("div",{
  645. "styles" : {
  646. "margin-top": "8px",
  647. "min-width": "60px",
  648. "padding-left": "4px",
  649. "font-size": "12px",
  650. "color": "#999"
  651. },
  652. "text": "("+this.totalData[status] + ""+ this.app.lp.day+")"
  653. }).inject(td);
  654. }
  655. // this.statusColorTable = new Element("table",{
  656. // "styles" : this.css.statusColorTable
  657. // }).inject(this.statusColorArea);
  658. //
  659. // for(var status in this.statusColor){
  660. //
  661. // var tr = new Element("tr",{
  662. // "styles" : this.css.statusColorTr
  663. // }).inject(this.statusColorTable);
  664. // var td = new Element("td",{
  665. // "styles" : this.css.statusColorTd
  666. // }).inject(tr);
  667. // td.setStyle("background-color",this.statusColor[status]);
  668. //
  669. // var tr = new Element("tr",{
  670. // "styles" : this.css.statusTextTr
  671. // }).inject(this.statusColorTable);
  672. // var td = new Element("td",{
  673. // "styles" : this.css.statusTextTd,
  674. // "text" : this.lp[status] +":"+this.totalData[status] + " "+ this.app.lp.day + ( this.rateData[status] ? "("+this.rateData[status]+")" : "" )
  675. // }).inject(tr)
  676. // }
  677. },
  678. loadPieChart : function(){
  679. //this.pieChartTitle = new Element("div.pieChartTitle",{
  680. // "styles" : this.css.pieChartTitle,
  681. // "text" : this.lp.index.pieChart
  682. //}).inject(this.pieChartArea)
  683. this.pieChartNode = new Element("div.pieChartNode",{
  684. "styles" : this.css.pieChartNode
  685. }).inject(this.pieChartArea);
  686. this.pieChart = new MWF.xApplication.Attendance.Echarts(this.pieChartNode, this, this.totalData, this.css);
  687. this.pieChart.load();
  688. },
  689. loadLineChart : function(){
  690. //this.lineChartTitle = new Element("div.lineChartTitle",{
  691. // "styles" : this.css.lineChartTitle,
  692. // "text" : this.lp.index.lineChart
  693. //}).inject(this.lineChartArea)
  694. this.lineChartNode = new Element("div.lineChartNode",{
  695. "styles" : this.css.lineChartNode
  696. }).inject(this.lineChartArea);
  697. //this.lineChart = new MWF.xApplication.Attendance.Echarts(this.lineChartNode, this.app, this.actions, this.css, {"type":"line"});
  698. //this.lineChart.load();
  699. this.lineChart = new MWF.xApplication.Attendance.Echarts(this.lineChartNode, this, this.detailData, {
  700. "type":"line",
  701. "date":this.date,
  702. "cycleStart" : new Date( this.cycleStartDate.getFullYear(), this.cycleStartDate.getMonth(), this.cycleStartDate.getDate() ),
  703. "cycleEnd" : new Date( this.cycleEndDate.getFullYear(), this.cycleEndDate.getMonth(), this.cycleEndDate.getDate() )
  704. });
  705. this.lineChart.load();
  706. },
  707. listCycleDetailFileterUser: function(callback, name){
  708. debugger;
  709. var data = [];
  710. var loadCount = 0;
  711. var startTime = Date.parse( this.cycleStartDate.format("%Y-%m-%d") ).getTime();
  712. var endTime = Date.parse( this.cycleEndDate.format("%Y-%m-%d") ).getTime();
  713. this.cycleYearMonth.each(function(cycle){
  714. var filter = {};
  715. if( name )filter.q_empName = name;
  716. filter.cycleYear = cycle.year;
  717. filter.cycleMonth = cycle.month;
  718. this.actions.listDetailFilterUser( filter, function(json){
  719. data = data.concat( json.data || [] );
  720. loadCount++;
  721. if( loadCount >= this.cycleYearMonth.length ){
  722. data = data.filter( function (d) {
  723. var time = Date.parse(d.recordDateString).getTime();
  724. return (time >= startTime) && (time <= endTime);
  725. }.bind(this));
  726. data.sort( function( a, b ){
  727. return parseInt( a.recordDateString.replace(/-/g,"") ) - parseInt( b.recordDateString.replace(/-/g,"") );
  728. });
  729. if( callback )callback(data);
  730. }
  731. }.bind(this))
  732. }.bind(this))
  733. },
  734. listDetailFilterUser :function( callback, name, year, month ){
  735. //{'q_empName':'林玲','q_year':'2016','q_month':'03'}
  736. var filter = {};
  737. if( name )filter.q_empName = name;
  738. if( year )filter.cycleYear = year;
  739. if( month )filter.cycleMonth = month.toString().length == 2 ? month : "0"+month;
  740. this.actions.listDetailFilterUser( filter, function(json){
  741. var data = json.data || [];
  742. data.sort( function( a, b ){
  743. return parseInt( a.recordDateString.replace(/-/g,"") ) - parseInt( b.recordDateString.replace(/-/g,"") );
  744. //return a.recordDateString - b.recordDateString
  745. });
  746. if( callback )callback(data);
  747. }.bind(this))
  748. },
  749. setContentSize: function(){
  750. var toolbarSize = this.toolbarNode ? this.toolbarNode.getSize() : {"x":0,"y":0};
  751. var titlebarSize = this.titleNode ? this.titleNode.getSize() : {"x":0,"y":0};
  752. var nodeSize = this.node.getSize();
  753. var pt = this.elementContentNode.getStyle("padding-top").toFloat();
  754. var pb = this.elementContentNode.getStyle("padding-bottom").toFloat();
  755. //var filterSize = this.filterNode.getSize();
  756. var filterConditionSize = this.filterConditionNode ? this.filterConditionNode.getSize() : {"x":0,"y":0};
  757. var height = nodeSize.y-toolbarSize.y-pt-pb-filterConditionSize.y-titlebarSize.y-10;
  758. this.elementContentNode.setStyle("height", ""+height+"px");
  759. },
  760. // setNodeScroll: function(){
  761. // var _self = this;
  762. // MWF.require("MWF.widget.ScrollBar", function(){
  763. // new MWF.widget.ScrollBar(this.elementContentNode, {
  764. // "indent": false,"style":"xApp_TaskList", "where": "before", "distance": 30, "friction": 4, "axis": {"x": false, "y": true},
  765. // "onScroll": function(y){
  766. // }
  767. // });
  768. // }.bind(this));
  769. // },
  770. anaylyseDetail : function(){
  771. var events = [];
  772. var dateMap = {};
  773. this.dateMap = dateMap;
  774. var totals = {
  775. levelAsked : 0,
  776. noSign : 0,
  777. late : 0,
  778. appealSuccess : 0,
  779. //leaveEarly : 0,
  780. //lackOfTime : 0,
  781. abNormalDuty : 0,
  782. normal : 0
  783. };
  784. var setDateMap = function (d, type) {
  785. var map = dateMap[d.recordDateString] = {
  786. "on": d.onDutyTime,
  787. "off": d.offDutyTime,
  788. "detailId": d.id
  789. };
  790. if( type === "normal"){
  791. map.text = this.lp.statusText[type];
  792. }else if(type){
  793. map.text = this.lp.statusText[type];
  794. map.color = this.statusColor[type];
  795. }
  796. map.isWorkday = d.isWorkday;
  797. map.isHoliday = d.isHoliday;
  798. }.bind(this);
  799. this.detailData.each( function( d ){
  800. if( this.isAskForLevel(d,"am") || this.isAskForLevel(d,"pm") ){
  801. setDateMap( d, "levelAsked" );
  802. }else if( this.isAppealSuccess(d,"am") || this.isAppealSuccess(d,"pm")){
  803. setDateMap( d, "appealSuccess" );
  804. }else if( this.isAbsent(d,"am") || this.isAbsent(d,"pm")){
  805. setDateMap( d, "noSign" );
  806. }else if( this.isLate(d,"am") || this.isLate(d,"pm")) {
  807. setDateMap( d, "late" );
  808. }else if( this.isLackOfTime(d,"am") || this.isLackOfTime(d,"pm")){
  809. setDateMap( d, "lackOfTime" );
  810. }else if( this.isAbnormalDuty(d,"am") || this.isAbnormalDuty(d,"pm")){
  811. setDateMap( d, "abNormalDuty" );
  812. }else if( this.isHoliday(d, "am") || this.isHoliday(d, "pm")){
  813. setDateMap( d );
  814. }else if( this.isWeekend(d, "am") || this.isWeekend(d, "pm") ){
  815. setDateMap( d );
  816. }else{
  817. setDateMap( d, "normal" );
  818. }
  819. if( this.isAskForLevel(d,"am") ){
  820. events.push( { text:this.lp.levelAsked, start: d.recordDateString, backgroundColor :this.statusColor.levelAsked } );
  821. totals.levelAsked = totals.levelAsked + 0.5
  822. }else if( this.isAppealSuccess(d,"am")){
  823. events.push( { text: this.lp.appealSuccess, start: d.recordDateString, backgroundColor :this.statusColor.appealSuccess } );
  824. totals.appealSuccess = totals.appealSuccess + 0.5
  825. }else if( this.isAbsent(d,"am")){
  826. events.push( { text: this.lp.noSign, start: d.recordDateString, backgroundColor :this.statusColor.noSign } );
  827. totals.noSign = totals.noSign + 0.5
  828. }else if( this.isLate(d,"am")) {
  829. events.push({
  830. text: this.lp.late + ',' + this.lp.signTime + ':' + d.onDutyTime, //+ "迟到时长" + d.lateTimeDuration,
  831. start: d.recordDateString,
  832. backgroundColor: this.statusColor.late
  833. });
  834. totals.late = totals.late + 0.5
  835. }else if( this.isLackOfTime(d,"am")){
  836. events.push( { text: this.lp.lackOfTime + ',' + this.lp.signTime + ':' + d.onDutyTime, start: d.recordDateString, backgroundColor :this.statusColor.lackOfTime } );
  837. totals.lackOfTime = totals.lackOfTime + 0.5
  838. }else if( this.isAbnormalDuty(d,"am")){
  839. events.push( { text: this.lp.abNormalDuty + ',' + this.lp.signTime + ':' + d.onDutyTime, start: d.recordDateString, backgroundColor :this.statusColor.abNormalDuty } );
  840. totals.abNormalDuty = totals.abNormalDuty + 0.5
  841. }else if( this.isHoliday(d, "am") ){
  842. return;
  843. }else if( this.isWeekend(d, "am") ){
  844. return;
  845. }else{
  846. totals.normal = totals.normal + 0.5;
  847. events.push( { text: this.lp.normal + ','+this.lp.signTime +':' + d.onDutyTime, start: d.recordDateString, backgroundColor :this.statusColor.normal } )
  848. }
  849. if( this.isAskForLevel(d,"pm") ){
  850. totals.levelAsked = totals.levelAsked + 0.5;
  851. events.push( { text: this.lp.index.levelAsked, start: d.recordDateString, backgroundColor :this.statusColor.levelAsked } )
  852. }else if( this.isAppealSuccess(d,"pm")){
  853. events.push( { text: this.lp.appealSuccess, start: d.recordDateString, backgroundColor :this.statusColor.appealSuccess } );
  854. totals.appealSuccess = totals.appealSuccess + 0.5;
  855. //}else if( this.isLeaveEarlier(d,"pm")) {
  856. // events.push({
  857. // text: '早退,打卡时间:' + d.offDutyTime, // + "早退时长" + d.leaveEarlierTimeDuration,
  858. // start: d.recordDateString,
  859. // backgroundColor: this.statusColor.leaveEarly
  860. // })
  861. // totals.leaveEarly = totals.leaveEarly + 0.5
  862. }else if( this.isAbsent(d,"pm")){
  863. totals.noSign = totals.noSign + 0.5;
  864. events.push( { text: this.lp.index.absent, start: d.recordDateString, backgroundColor :this.statusColor.noSign } )
  865. /* }else if( this.isLackOfTime(d,"pm")){
  866. events.push( { text: this.lp.lackOfTime + ',' + this.lp.signTime + ':' + d.offDutyTime, start: d.recordDateString, backgroundColor :this.statusColor.lackOfTime } );
  867. totals.lackOfTime = totals.lackOfTime + 0.5*/
  868. }else if( this.isAbnormalDuty(d,"pm")){
  869. events.push( { text: this.lp.abNormalDuty + ',' + this.lp.signTime + ':' + d.offDutyTime, start: d.recordDateString, backgroundColor :this.statusColor.abNormalDuty } );
  870. totals.abNormalDuty = totals.abNormalDuty + 0.5
  871. }else if( this.isHoliday(d, "pm") ){
  872. return;
  873. }else if( this.isWeekend(d, "pm") ){
  874. return;
  875. }else{
  876. if(!!d.offDutyTime){
  877. totals.normal = totals.normal + 0.5;
  878. events.push( { text: this.lp.index.offDutyTime+ d.offDutyTime, start: d.recordDateString, backgroundColor :this.statusColor.normal } )
  879. }
  880. }
  881. }.bind(this) );
  882. this.totalData = totals;
  883. var total = 0;
  884. for( var n in totals ){
  885. total += totals[n];
  886. }
  887. this.rateData = {
  888. levelAsked : (!totals.levelAsked || !total) ? 0 : ((totals.levelAsked/total * 100).toFixed(2) + "%"),
  889. noSign : (!totals.noSign || !total) ? 0 : ((totals.noSign/total * 100).toFixed(2) + "%"),
  890. late : (!totals.late || !total) ? 0 : ((totals.late/total * 100).toFixed(2) + "%"),
  891. //leaveEarly : (!totals.leaveEarly || !total) ? 0 : ((totals.leaveEarly/total* 100).toFixed(2) + "%"),
  892. //lackOfTime : (!totals.lackOfTime || !total) ? 0 : ((totals.lackOfTime/total * 100).toFixed(2) + "%"),
  893. abNormalDuty : (!totals.abNormalDuty || !total) ? 0 : ((totals.abNormalDuty/total* 100).toFixed(2) + "%"),
  894. normal : (!totals.normal || !total) ? 0 : ((totals.normal/total* 100).toFixed(2) + "%"),
  895. appealSuccess : (!totals.appealSuccess || !total) ? 0 : ((totals.appealSuccess/total * 100).toFixed(2) + "%")
  896. };
  897. this.eventData = events;
  898. },
  899. isAppealSuccess : function( d, ap ){
  900. return d.appealStatus == 9
  901. },
  902. isAskForLevel : function( d , ap ){
  903. if( ap == "am" ){
  904. //d.selfHolidayDayTime == "全天" || d.selfHolidayDayTime == "上午"
  905. return d.isGetSelfHolidays && ( ["全天","上午",this.app.lp.wholeDay, this.app.lp.am ].contains(d.selfHolidayDayTime) )
  906. }else{
  907. // return d.isGetSelfHolidays && ( d.selfHolidayDayTime == "全天" || d.selfHolidayDayTime == "下午" )
  908. return d.isGetSelfHolidays && ( ["全天","下午",this.app.lp.wholeDay, this.app.lp.pm ].contains(d.selfHolidayDayTime ) )
  909. }
  910. },
  911. isAbsent : function(d , ap ){
  912. if( ap == "am" ){
  913. // return d.isAbsent && ( d.absentDayTime == "全天" || d.absentDayTime == "上午" )
  914. return d.isAbsent && ["全天","上午",this.app.lp.wholeDay, this.app.lp.am ].contains(d.absentDayTime);
  915. }else{
  916. // return d.isAbsent && ( d.absentDayTime == "全天" || d.absentDayTime == "下午" )
  917. return d.isAbsent && ["全天","下午",this.app.lp.wholeDay, this.app.lp.pm ].contains(d.absentDayTime);
  918. }
  919. },
  920. isLate : function(d, ap ){
  921. return d.isLate
  922. },
  923. //isLeaveEarlier : function( d ){
  924. // return d.isLeaveEarlier
  925. //},
  926. isWorkOvertime : function( d, ap){
  927. return d.isWorkOvertime
  928. },
  929. isLackOfTime : function( d, ap){
  930. return d.isLackOfTime
  931. },
  932. isAbnormalDuty : function(d , ap ){
  933. if( ap == "am" ){
  934. // return d.isAbnormalDuty && ( d.abnormalDutyDayTime == "全天" || d.abnormalDutyDayTime == "上午" )
  935. return d.isAbnormalDuty && ["全天","上午",this.app.lp.wholeDay, this.app.lp.am ].contains(d.abnormalDutyDayTime)
  936. }else{
  937. return d.isAbnormalDuty && ["全天","下午",this.app.lp.wholeDay, this.app.lp.pm ].contains(d.abnormalDutyDayTime);
  938. }
  939. },
  940. isHoliday : function( d, ap ){
  941. if( ap == "am" ){
  942. return d.isHoliday && (!d.onDutyTime || d.onDutyTime == "")
  943. }else{
  944. return d.isHoliday && (!d.offDutyTime || d.offDutyTime == "")
  945. }
  946. },
  947. isWeekend : function( d, ap ){
  948. if(d.isWorkday )return false;
  949. if( ap == "am" ){
  950. return d.isWeekend && (!d.onDutyTime || d.onDutyTime == "")
  951. }else{
  952. return d.isWeekend && (!d.offDutyTime || d.offDutyTime == "")
  953. }
  954. },
  955. toFixed: function (num, d) {
  956. var s=num+"";
  957. if(!d)d=0;
  958. if(s.indexOf(".")==-1)s+=".";
  959. s+=new Array(d+1).join("0");
  960. if(new RegExp("^(-|\\+)?(\\d+(\\.\\d{0,"+(d+1)+"})?)\\d*$").test(s)){
  961. var s="0"+RegExp.$2,pm=RegExp.$1,a=RegExp.$3.length,b=true;
  962. if(a==d+2){
  963. a=s.match(/\d/g);
  964. if(parseInt(a[a.length-1])>4){
  965. for(var i=a.length-2;i>=0;i--){
  966. a[i]=parseInt(a[i])+1;
  967. if(a[i]==10){
  968. a[i]=0;
  969. b=i!=1;
  970. }else break;
  971. }
  972. }
  973. s=a.join("").replace(new RegExp("(\\d+)(\\d{"+d+"})\\d$"),"$1.$2");
  974. }if(b)s=s.substr(1);
  975. return (pm+s).replace(/\.$/,"");
  976. }return this+"";
  977. }
  978. });
  979. MWF.xApplication.Attendance.MyIndex.Calendar = new Class({
  980. Implements: [Options, Events],
  981. options: {
  982. date : "",
  983. cycleStart : "",
  984. cycleEnd : ""
  985. },
  986. initialize: function(container, view, data, options){
  987. // {
  988. // "holiday" :this.holidayData[this.year],
  989. // "detail" :this.detailData,
  990. // "eventData" : this.eventData
  991. // }
  992. this.setOptions(options);
  993. this.view = view;
  994. this.css = this.view.css;
  995. this.container = container;
  996. this.app = this.view.app;
  997. this.data = data;
  998. this.date = this.options.date;
  999. this.today = new Date();
  1000. this.days = {};
  1001. this.weekBegin = 1;
  1002. },
  1003. load: function(){
  1004. debugger;
  1005. // this.titleNode = new Element("div", {"styles": this.css.calendarTitleNode}).inject(this.container);
  1006. // this.scrollNode = new Element("div", {
  1007. // "styles": this.app.inContainer ? this.css.scrollNode_inContainer : this.css.scrollNode
  1008. // }).inject(this.container);
  1009. this.contentWarpNode = new Element("div", {
  1010. "styles": this.css.contentWarpNode
  1011. }).inject(this.container);
  1012. this.contentContainerNode = new Element("div",{
  1013. "styles" : this.css.contentContainerNode
  1014. }).inject(this.contentWarpNode);
  1015. this.bodyNode = new Element("div", {
  1016. "styles": this.css.contentNode
  1017. }).inject(this.contentContainerNode);
  1018. // this.setTitleNode();
  1019. this.setBodyNode();
  1020. this.resetBodySize();
  1021. this.app.addEvent("resize", this.resetBodySize.bind(this));
  1022. },
  1023. resetBodySize: function(){
  1024. var size = this.container.getSize();
  1025. var titleSize = this.titleNode ? this.titleNode.getSize() : {x:0, y:0};
  1026. var y = size.y-titleSize.y;
  1027. if(this.scrollNode)this.scrollNode.setStyle("height", ""+y+"px");
  1028. if (this.contentWarpNode){
  1029. this.contentWarpNode.setStyles({
  1030. "width": (size.x - 30) +"px"
  1031. });
  1032. }
  1033. },
  1034. // setTitleNode: function(){
  1035. // this.prevMonthNode = new Element("div", {"styles": this.css.calendarPrevMonthNode}).inject(this.titleNode);
  1036. //
  1037. // var text = this.date.format(this.app.lp.dateFormatMonth);
  1038. // this.titleTextNode = new Element("div", {"styles": this.css.calendarTitleTextNode, "text": text}).inject(this.titleNode);
  1039. //
  1040. // this.nextMonthNode = new Element("div", {"styles": this.css.calendarNextMonthNode}).inject(this.titleNode);
  1041. //
  1042. // this.prevMonthNode.addEvents({
  1043. // "mouseover": function(){this.prevMonthNode.setStyles(this.css.calendarPrevMonthNode_over);}.bind(this),
  1044. // "mouseout": function(){this.prevMonthNode.setStyles(this.css.calendarPrevMonthNode);}.bind(this),
  1045. // "mousedown": function(){this.prevMonthNode.setStyles(this.css.calendarPrevMonthNode_down);}.bind(this),
  1046. // "mouseup": function(){this.prevMonthNode.setStyles(this.css.calendarPrevMonthNode_over);}.bind(this),
  1047. // "click": function(){this.changeMonthPrev();}.bind(this)
  1048. // });
  1049. // this.nextMonthNode.addEvents({
  1050. // "mouseover": function(){this.nextMonthNode.setStyles(this.css.calendarNextMonthNode_over);}.bind(this),
  1051. // "mouseout": function(){this.nextMonthNode.setStyles(this.css.calendarNextMonthNode);}.bind(this),
  1052. // "mousedown": function(){this.nextMonthNode.setStyles(this.css.calendarNextMonthNode_down);}.bind(this),
  1053. // "mouseup": function(){this.nextMonthNode.setStyles(this.css.calendarNextMonthNode_over);}.bind(this),
  1054. // "click": function(){this.changeMonthNext();}.bind(this)
  1055. // });
  1056. // this.titleTextNode.addEvents({
  1057. // "mouseover": function(){this.titleTextNode.setStyles(this.css.calendarTitleTextNode_over);}.bind(this),
  1058. // "mouseout": function(){this.titleTextNode.setStyles(this.css.calendarTitleTextNode);}.bind(this),
  1059. // "mousedown": function(){this.titleTextNode.setStyles(this.css.calendarTitleTextNode_down);}.bind(this),
  1060. // "mouseup": function(){this.titleTextNode.setStyles(this.css.calendarTitleTextNode_over);}.bind(this),
  1061. // "click": function(){this.changeMonthSelect();}.bind(this)
  1062. // });
  1063. // },
  1064. // changeMonthPrev: function(){
  1065. // this.date.decrement("month", 1);
  1066. // var text = this.date.format(this.app.lp.dateFormatMonth);
  1067. // this.titleTextNode.set("text", text);
  1068. // this.reLoadCalendar();
  1069. // },
  1070. // changeMonthNext: function(){
  1071. // this.date.increment("month", 1);
  1072. // var text = this.date.format(this.app.lp.dateFormatMonth);
  1073. // this.titleTextNode.set("text", text);
  1074. // this.reLoadCalendar();
  1075. // },
  1076. // changeMonthSelect: function(){
  1077. // if (!this.monthSelector) this.createMonthSelector();
  1078. // this.monthSelector.show();
  1079. // },
  1080. // createMonthSelector: function(){
  1081. // this.monthSelector = new MWF.xApplication.Meeting.MonthView.Calendar.MonthSelector(this.date, this);
  1082. // },
  1083. // changeMonthTo: function(d){
  1084. // this.date = d;
  1085. // var text = this.date.format(this.app.lp.dateFormatMonth);
  1086. // this.titleTextNode.set("text", text);
  1087. // this.reLoadCalendar();
  1088. // },
  1089. setBodyNode: function(){
  1090. if( this.weekBegin == "1" ){
  1091. var html = "<tr><th>"+this.app.lp.weeks.Mon+"</th><th>"+this.app.lp.weeks.Tues+"</th><th>"+this.app.lp.weeks.Wed+"</th>" +
  1092. "<th>"+this.app.lp.weeks.Thur+"</th><th>"+this.app.lp.weeks.Fri+"</th><th>"+this.app.lp.weeks.Sat+"</th><th>"+this.app.lp.weeks.Sun+"</th></tr>";
  1093. }else{
  1094. var html = "<tr><th>"+this.app.lp.weeks.Sun+"</th><th>"+this.app.lp.weeks.Mon+"</th><th>"+this.app.lp.weeks.Tues+"</th><th>"+this.app.lp.weeks.Wed+"</th>" +
  1095. "<th>"+this.app.lp.weeks.Thur+"</th><th>"+this.app.lp.weeks.Fri+"</th><th>"+this.app.lp.weeks.Sat+"</th></tr>";
  1096. }
  1097. html += "<tr><td valign='top'></td><td></td><td></td><td></td><td></td><td></td><td></td></tr>";
  1098. html += "<tr><td></td><td></td><td></td><td></td><td></td><td></td><td></td></tr>";
  1099. html += "<tr><td></td><td></td><td></td><td></td><td></td><td></td><td></td></tr>";
  1100. html += "<tr><td></td><td></td><td></td><td></td><td></td><td></td><td></td></tr>";
  1101. html += "<tr><td></td><td></td><td></td><td></td><td></td><td></td><td></td></tr>";
  1102. html += "<tr><td></td><td></td><td></td><td></td><td></td><td></td><td></td></tr>";
  1103. this.calendarTable = new Element("table", {
  1104. "styles": this.css.calendarTable,
  1105. "height": "100%",
  1106. "border": "0",
  1107. "cellPadding": "0",
  1108. "cellSpacing": "0",
  1109. "html": html
  1110. }).inject(this.bodyNode);
  1111. this.calendarTableTitleTr = this.calendarTable.getElement("tr");
  1112. this.calendarTableTitleTr.setStyles(this.css.calendarTableTitleTr);
  1113. var ths = this.calendarTableTitleTr.getElements("th");
  1114. ths.setStyles(this.css.calendarTableTh);
  1115. //var tds = this.calendarTable.getElements("td");
  1116. //tds.setStyles(this.css.calendarTableCell);
  1117. this.loadCalendar();
  1118. },
  1119. reLoadCalendar: function(){
  1120. Object.each(this.days, function(day){
  1121. day.destroy();
  1122. }.bind(this));
  1123. this.loadCalendar();
  1124. },
  1125. loadCalendar: function(){
  1126. var date = this.date.clone();
  1127. date.set("date", 1);
  1128. var week = date.getDay();
  1129. if( this.weekBegin == "1" ){
  1130. var decrementDay = ((week-1)<0) ? 6 : week-1;
  1131. }else{
  1132. var decrementDay = week;
  1133. }
  1134. date.decrement("day", decrementDay);
  1135. var tds = this.calendarTable.getElements("td");
  1136. tds.each(function(td){
  1137. this.loadDay(td, date);
  1138. date.increment();
  1139. }.bind(this));
  1140. },
  1141. loadDay: function(td, date){
  1142. var type = "thisMonth";
  1143. var m = date.get("month");
  1144. var y = date.get("year");
  1145. var d = date.get("date");
  1146. var mm = this.date.get("month");
  1147. var yy = this.date.get("year");
  1148. var mmm = this.today.get("month");
  1149. var yyy = this.today.get("year");
  1150. var ddd = this.today.get("date");
  1151. if ((m==mmm) && (y==yyy) && (d==ddd)){
  1152. type = "today";
  1153. }else if ((m==mm) && (y==yy)){
  1154. type = "thisMonth";
  1155. }else{
  1156. type = "otherMonth";
  1157. }
  1158. debugger;
  1159. var key = date.format(this.app.lp.dateFormat);
  1160. var data = this.data.dateMap[date.format("%Y-%m-%d")] || {};
  1161. this.days[key] = new MWF.xApplication.Attendance.MyIndex.Calendar.Day(td, date, this, type, data);
  1162. },
  1163. reload : function(){
  1164. this.view.reload();
  1165. },
  1166. destroy: function(){
  1167. Object.each(this.days, function(day){
  1168. day.destroy();
  1169. }.bind(this));
  1170. this.container.empty();
  1171. }
  1172. });
  1173. MWF.xApplication.Attendance.MyIndex.Calendar.Day = new Class({
  1174. Implements: [Events],
  1175. initialize: function(td, date, calendar, type, data){
  1176. this.container = td;
  1177. this.calendar = calendar;
  1178. this.view = this.calendar.view;
  1179. this.css = this.calendar.css;
  1180. this.app = this.calendar.app;
  1181. this.date = date.clone();
  1182. this.key = this.date.format(this.app.lp.dateFormat);
  1183. this.data = data;
  1184. this.type = type; //today, otherMonth, thisMonth
  1185. this.load();
  1186. },
  1187. load: function(){
  1188. this.color = "#666";
  1189. if( this.type == "thisMonth" ){
  1190. }else if( this.type == "otherMonth" ){
  1191. this.color = "#ccc";
  1192. }
  1193. this.day = this.date.getDate();
  1194. this.month = this.date.getMonth();
  1195. this.year = this.date.getYear();
  1196. this.node = new Element("div", {
  1197. "styles" : this.css["calendarTableCell_"+this.type]
  1198. }).inject( this.container );
  1199. if( this.type === "today" && (this.calendar.date.format("%Y-%m-%d") !== this.date.format("%Y-%m-%d")) ){
  1200. this.node.setStyle("opacity", "0.5");
  1201. }
  1202. if( this.data.color ){
  1203. this.node.setStyle("border-left", "6px solid "+ this.data.color);
  1204. }
  1205. this.titleNode = new Element("div", {"styles": this.css["dayTitle_"+this.type]}).inject(this.node);
  1206. if( !this.data.color ){
  1207. this.titleNode.setStyle("border-left","5px solid #fff");
  1208. }
  1209. this.titleDayNode = new Element("div", {"styles": this.css["dayTitleDay_"+this.type], "text": this.day}).inject(this.titleNode);
  1210. if(this.type === "today"){
  1211. this.titleDayNode.addClass("mainColor_bg");
  1212. }
  1213. if ((new Date()).diff(this.date)>=0){
  1214. this.titleNode.set("title", this.app.lp.titleNode);
  1215. // this.titleNode.addEvent("click", function(){
  1216. // this.app.addMeeting(this.date);
  1217. // }.bind(this));
  1218. }
  1219. // this.loadMeetings();
  1220. if( this.data.isHoliday ){
  1221. new Element("div", {
  1222. "styles": {
  1223. "margin-top": "5px",
  1224. "margin-left": "10px",
  1225. "color": "#fff",
  1226. "font-weight": "bold",
  1227. "border-radius": "20px",
  1228. "height": "20px",
  1229. "width": "20px",
  1230. // "background-color": "#F23030",
  1231. "background-color": "#f49999",
  1232. "float": "left",
  1233. "line-height": "20px",
  1234. "text-align": "center",
  1235. "font-size" : "12px"
  1236. },
  1237. "text": this.app.lp.offDutyAbbrev,
  1238. "title": this.data.holidayName || ""
  1239. }).inject(this.titleNode)
  1240. }else if( this.data.isWorkday ){
  1241. new Element("div", {
  1242. "styles": {
  1243. "margin-top": "5px",
  1244. "margin-left": "10px",
  1245. "color": "#fff",
  1246. "font-weight": "bold",
  1247. "border-radius": "20px",
  1248. "height": "20px",
  1249. "width": "20px",
  1250. "background-color": "#ccc",
  1251. "float": "left",
  1252. "line-height": "20px",
  1253. "text-align": "center",
  1254. "font-size" : "12px"
  1255. },
  1256. "text": this.app.lp.onDutyAbbrev,
  1257. "title": this.data.holidayName || ""
  1258. }).inject(this.titleNode)
  1259. }
  1260. if( this.data.text ){
  1261. new Element("div", {
  1262. "styles": {
  1263. "margin-right": "10px",
  1264. "color": "#999",
  1265. "float": "right",
  1266. "font-size" : "14px"
  1267. },
  1268. "text": this.data.text
  1269. }).inject(this.titleNode)
  1270. }
  1271. this.contentNode = new Element("div", {"styles": this.css.dayContentNode}).inject(this.node);
  1272. if( !this.data.color ){
  1273. this.contentNode.setStyle("border-left","5px solid #fff");
  1274. }
  1275. if( this.data.on || this.data.off ){
  1276. new Element("div", {
  1277. "styles": {
  1278. "margin-left": "10px",
  1279. "margin-top": "10px",
  1280. "color": "#333",
  1281. "font-weight": "500",
  1282. "font-size" : "14px"
  1283. },
  1284. "text": this.getMintue(this.data.on) + "-" + this.getMintue(this.data.off)
  1285. }).inject(this.contentNode)
  1286. }
  1287. },
  1288. getMintue: function(str){
  1289. var arr = (str || "").split(":");
  1290. if( arr[1] ){
  1291. return arr[0] + ":" + arr[1];
  1292. }else{
  1293. return arr[0]
  1294. }
  1295. },
  1296. destroy: function(){
  1297. this.node.destroy();
  1298. this.titleNode = null;
  1299. this.titleDayNode = null;
  1300. this.contentNode = null;
  1301. delete this.calendar.days[this.key];
  1302. this.container.empty();
  1303. MWF.release(this);
  1304. },
  1305. reload: function(){
  1306. this.view.reload();
  1307. }
  1308. });