HolidayExplorer.min.js 11 KB

1
  1. MWF.xDesktop.requireApp("Attendance","Explorer",null,false);MWF.xDesktop.requireApp("Template","MDomItem",null,false);MWF.xApplication.Attendance.HolidayExplorer=new Class({Extends:MWF.xApplication.Attendance.Explorer,Implements:[Options,Events],initialize:function(e,t,i,a){this.setOptions(a);this.app=t;this.path="/x_component_Attendance/$HolidayExplorer/";this.cssPath="/x_component_Attendance/$HolidayExplorer/"+this.options.style+"/css.wcss";this._loadCss();this.actions=i;this.node=$(e);this.initData();if(!this.personActions)this.personActions=new MWF.xAction.org.express.RestActions},loadView:function(){this.view=new MWF.xApplication.Attendance.HolidayExplorer.View(this.elementContentNode,this.app,this,this.viewData,this.options.searchKey);this.view.load();this.setContentSize()},createDocument:function(){if(this.view)this.view._createDocument()}});MWF.xApplication.Attendance.HolidayExplorer.View=new Class({Extends:MWF.xApplication.Attendance.Explorer.View,_createItem:function(e){return new MWF.xApplication.Attendance.HolidayExplorer.Document(this.table,e,this.explorer,this)},_getCurrentPageData:function(t,e){this.actions.listHolidayAll(function(e){if(t)t(e)})},_removeDocument:function(e,t,i){this.actions.listHolidayByYearAndName(e.configYear,e.configName,function(e){e.data.each(function(e){this.actions.deleteHoliday(e.id,function(e){}.bind(this),null,false)}.bind(this));if(!t)this.app.notice(this.app.lp.deleteDocumentOK,"success");if(i)i();this.explorer.reload()}.bind(this))},_createDocument:function(){var e=new MWF.xApplication.Attendance.HolidayExplorer.Holiday(this.explorer);e.create()},_openDocument:function(e){this.actions.getHoliday(e.id,function(e){var t=e.data;var s={configYear:t.configYear,configName:t.configName,makeUpClassDay:[]};this.actions.listHolidayByYearAndName(t.configYear,t.configName,function(e){var t,i;e.data.each(function(e){if(e.configType=="Workday"){s.makeUpClassDay.push(e.configDate)}else{if(!t){t=e.configDate}else if(new Date(t)>new Date(e.configDate)){t=e.configDate}if(!i){i=e.configDate}else if(new Date(i)<new Date(e.configDate)){i=e.configDate}}}.bind(this));s.makeUpClassDay=s.makeUpClassDay.join(",");s.startDate=t;s.endDate=i;var a=new MWF.xApplication.Attendance.HolidayExplorer.Holiday(this.explorer,s);a.edit()}.bind(this))}.bind(this))}});MWF.xApplication.Attendance.HolidayExplorer.Document=new Class({Extends:MWF.xApplication.Attendance.Explorer.Document});MWF.xApplication.Attendance.HolidayExplorer.Holiday=new Class({Extends:MWF.widget.Common,options:{width:"500",height:"400"},initialize:function(e,t){this.explorer=e;this.app=e.app;this.data=t||{};this.css=this.explorer.css;this.load()},load:function(){},open:function(e){this.isNew=false;this.isEdited=false;this._open()},create:function(){this.isNew=true;this._open()},edit:function(){this.isEdited=true;this._open()},_open:function(){this.createMarkNode=new Element("div",{styles:this.css.createMarkNode,events:{mouseover:function(e){e.stopPropagation()},mouseout:function(e){e.stopPropagation()}}}).inject(this.app.content,"after");this.createAreaNode=new Element("div",{styles:this.css.createAreaNode});this.createNode();this.createAreaNode.inject(this.createMarkNode,"after");this.createAreaNode.fade("in");this.setCreateNodeSize();this.setCreateNodeSizeFun=this.setCreateNodeSize.bind(this);this.addEvent("resize",this.setCreateNodeSizeFun)},createNode:function(){var e=this;this.createNode=new Element("div",{styles:this.css.createNode}).inject(this.createAreaNode);this.createIconNode=new Element("div",{styles:this.isNew?this.css.createNewNode:this.css.createIconNode}).inject(this.createNode);this.createFormNode=new Element("div",{styles:this.css.createFormNode}).inject(this.createNode);var t=this.app.lp.holiday;var i="width: 99%; border:1px solid #999; background-color:#FFF; border-radius: 3px; box-shadow: 0px 0px 6px #CCC;height: 26px;";var a="width: 99%; border:1px solid #999; background-color:#FFF; border-radius: 3px; box-shadow: 0px 0px 6px #CCC;height: 26px;"+"background : url(/x_component_Attendance/$HolidayExplorer/default/icon/calendar.png) 98% center no-repeat";var s="<table width='100%' height='200' border='0' cellPadding='0' cellSpacing='0'>"+"<tr>"+"<td colspan='2' style='height: 50px; line-height: 50px; text-align: center; min-width: 80px; font-size:18px;font-weight: bold;'>"+t.setHoliday+"</td>"+"</tr>"+"<tr>"+"<td style='height: 30px; line-height: 30px; text-align: left; min-width: 80px; width:25%'>"+t.year+":</td>"+"<td style='; text-align: left;' id='yearArea'>"+"</td>"+"</tr>"+"<tr>"+"<td style='height: 30px; line-height: 30px; text-align: left'>"+t.name+":</td>"+"<td style='; text-align: right;'>"+(!this.isNew&&!this.isEdited?"":"<input type='text' id='configName' "+"style='"+i+"'"+" value='"+(this.data&&this.data.configName?this.data.configName:"")+"'/>")+"</td>"+"</tr>"+"<tr>"+"<td style='height: 30px; line-height: 30px; text-align: left'>"+t.startDate+":</td>"+"<td style='; text-align: right;'>"+(!this.isNew&&!this.isEdited?"":"<input type='text' id='startDate' "+"style='"+a+"'"+" value='"+(this.data&&this.data.startDate?this.data.startDate:"")+"'/>")+"</td>"+"</tr>"+"<tr>"+"<td style='height: 30px; line-height: 30px; text-align: left'>"+t.endDate+":</td>"+"<td style='; text-align: right;'>"+(!this.isNew&&!this.isEdited?"":"<input type='text' id='endDate' "+"style='"+a+"'"+" value='"+(this.data&&this.data.endDate?this.data.endDate:"")+"'/>")+"</td>"+"</tr>"+"<tr>"+"<td style='height: 30px; line-height: 30px; text-align: left'>"+t.makeUpClassDay+":</td>"+"<td style='; text-align: right;'>"+(!this.isNew&&!this.isEdited?"":"<input type='text' id='makeUpClassDay' "+"style='"+a+"'"+" value='"+(this.data&&this.data.makeUpClassDay?this.data.makeUpClassDay:"")+"'/>")+"</td>"+"</tr>"+"</table>";this.createFormNode.set("html",s);this.yearArea=this.createFormNode.getElement("#yearArea");this.configYear=new MDomItem(this.yearArea,{name:"configYear",type:"select",value:this.data.configYear||(new Date).getFullYear(),selectValue:function(){var e=[];var t=(new Date).getFullYear()+5;for(var i=0;i<11;i++){e.push(t--)}return e}},true,this.app);this.configYear.load();this.configName=this.createFormNode.getElement("#configName");this.startDate=this.createFormNode.getElement("#startDate");this.endDate=this.createFormNode.getElement("#endDate");this.makeUpClassDay=this.createFormNode.getElement("#makeUpClassDay");this.startDate.addEvent("click",function(){e.selectCalendar(this)});this.endDate.addEvent("click",function(){e.selectCalendar(this)});this.makeUpClassDay.addEvent("click",function(){e.selectCalendar(this)});this.cancelActionNode=new Element("div",{styles:this.css.createCancelActionNode,text:this.app.lp.cancel}).inject(this.createFormNode);this.createOkActionNode=new Element("div",{styles:this.css.createOkActionNode,text:this.app.lp.ok}).inject(this.createFormNode);this.cancelActionNode.addEvent("click",function(e){this.cancelCreate(e)}.bind(this));this.createOkActionNode.addEvent("click",function(e){this.okCreate(e)}.bind(this))},setCreateNodeSize:function(e,t,i,a){if(!e)e=this.options&&this.options.width?this.options.width:"50%";if(!t)t=this.options&&this.options.height?this.options.height:"50%";if(!i)i=this.options&&this.options.top?this.options.top:0;if(!a)a=this.options&&this.options.left?this.options.left:0;var s=this.app.content.getSize();var n=s.x;var o=s.y;"string"==typeof e&&(1<e.length&&"%"==e.substr(e.length-1,1))&&(e=parseInt(n*parseInt(e,10)/100,10));"string"==typeof t&&(1<t.length&&"%"==t.substr(t.length-1,1))&&(t=parseInt(o*parseInt(t,10)/100,10));300>e&&(e=300);220>t&&(t=220);i=i||parseInt((o-t)/2,10);a=a||parseInt((n-e)/2,10);this.createAreaNode.setStyles({width:""+e+"px",height:""+t+"px",top:""+i+"px",left:""+a+"px"});this.createNode.setStyles({width:""+e+"px",height:""+t+"px"});var r=this.createIconNode?this.createIconNode.getSize():{x:0,y:0};var c=this.formTopNode?this.formTopNode.getSize():{x:0,y:0};var h=this.formBottomNode?this.formBottomNode.getSize():{x:0,y:0};var d=t-r.y-c.y-h.y;this.createFormNode.setStyles({height:""+d+"px"})},cancelCreate:function(e){var t=this;if(this.isNew&&this.configName.get("value")){this.app.confirm("warn",e,this.app.lp.create_cancel_title,this.app.lp.create_cancel,"320px","100px",function(){t.createMarkNode.destroy();t.createAreaNode.destroy();this.close()},function(){this.close()})}else{this.createMarkNode.destroy();this.createAreaNode.destroy();delete t}},okCreate:function(e){var i={id:this.data&&this.data.id?this.data.id:this.app.restActions.getUUID(),configYear:this.configYear.get("value"),configName:this.configName.get("value"),startDate:this.startDate.get("value"),endDate:this.endDate.get("value"),makeUpClassDay:this.makeUpClassDay.get("value")};if(i.configYear&&i.configName&&i.startDate&&i.endDate){var a=new Date(i.endDate);var s=new Date(i.startDate);if(s>a){this.app.notice("开始日期不能大于结束日期","error");return}var t=function(){var t="";this.getDateByRange(s,a).each(function(e){this.app.restActions.saveHoliday({configName:i.configName,configYear:i.configYear,configDate:e,configType:"Holiday"},function(e){if(e.type=="ERROR"){t=e.message}}.bind(this),function(e){flag=false}.bind(this),false)}.bind(this));if(i.makeUpClassDay!=""){i.makeUpClassDay.split(",").each(function(e){this.app.restActions.saveHoliday({configName:i.configName,configYear:i.configYear,configDate:this.dateFormat(new Date(e),"yyyy-MM-dd"),configType:"Workday"},function(e){if(e.type=="ERROR"){t=e.message}},function(e){flag=false}.bind(this),false)}.bind(this))}if(t==""){this.createMarkNode.destroy();this.createAreaNode.destroy();if(this.explorer.view)this.explorer.view.reload();this.app.notice(this.isNew?this.app.lp.createSuccess:this.app.lp.updateSuccess,"success")}else{this.app.notice(t,"error")}}.bind(this);if(!this.isNew){this.explorer.view._removeDocument(i,false,t)}else{t()}}else{this.configName.setStyle("border-color","red");this.configName.focus();this.app.notice(this.app.lp.holiday.inputValid,"error")}},selectCalendar:function(t){MWF.require("MWF.widget.Calendar",function(){var e=new MWF.widget.Calendar(t,{style:"xform",isTime:false,target:this.app.content});e.show()}.bind(this))},getDateByRange:function(e,t){var i=[];while(e<=t){i.push(this.dateFormat(e,"yyyy-MM-dd"));e.setDate(e.getDate()+1)}return i},dateFormat:function(e,t){var i={"M+":e.getMonth()+1,"d+":e.getDate(),"h+":e.getHours(),"m+":e.getMinutes(),"s+":e.getSeconds(),"q+":Math.floor((e.getMonth()+3)/3),S:e.getMilliseconds()};if(/(y+)/.test(t))t=t.replace(RegExp.$1,(e.getFullYear()+"").substr(4-RegExp.$1.length));for(var a in i)if(new RegExp("("+a+")").test(t))t=t.replace(RegExp.$1,RegExp.$1.length==1?i[a]:("00"+i[a]).substr((""+i[a]).length));return t}});