ScheduleExplorer.min.js 10 KB

1
  1. MWF.xDesktop.requireApp("Attendance","Explorer",null,false);MWF.xDesktop.requireApp("Organization","Selector.package",null,false);MWF.xApplication.Attendance.ScheduleExplorer=new Class({Extends:MWF.xApplication.Attendance.Explorer,Implements:[Options,Events],initialize:function(e,t,i,s){this.setOptions(s);this.app=t;this.path="/x_component_Attendance/$ScheduleExplorer/";this.cssPath="/x_component_Attendance/$ScheduleExplorer/"+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.ScheduleExplorer.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.ScheduleExplorer.View=new Class({Extends:MWF.xApplication.Attendance.Explorer.View,_createItem:function(e){return new MWF.xApplication.Attendance.ScheduleExplorer.Document(this.table,e,this.explorer,this)},_getCurrentPageData:function(e,t){this.actions.listSchedule(function(t){if(e)e(t)})},_removeDocument:function(e,t){this.actions.deleteSchedule(e.id,function(e){this.explorer.view.reload();this.app.notice(this.app.lp.deleteDocumentOK,"success")}.bind(this))},_createDocument:function(){var e=new MWF.xApplication.Attendance.ScheduleExplorer.Schedule(this.explorer);e.create()},_openDocument:function(e){var t=new MWF.xApplication.Attendance.ScheduleExplorer.Schedule(this.explorer,e);t.edit()}});MWF.xApplication.Attendance.ScheduleExplorer.Document=new Class({Extends:MWF.xApplication.Attendance.Explorer.Document});MWF.xApplication.Attendance.ScheduleExplorer.Schedule=new Class({Extends:MWF.widget.Common,options:{width:"600",height:"450"},initialize:function(e,t){this.explorer=e;this.app=e.app;this.data=t||{};this.css=this.explorer.css;this.load()},load:function(){this.data.workTime=this.data.onDutyTime;this.data.offTime=this.data.offDutyTime;this.data.department=this.data.organizationName;this.data.lateTime=this.data.lateStartTime;this.data.leaveEarlyTime=this.data.leaveEarlyStartTime;this.data.absenteeismTime=this.data.absenceStartTime},open:function(e){this.isNew=false;this.isEdited=false},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.department.focus();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.schedule;var i="width: 99%; border:1px solid #999; background-color:#FFF; border-radius: 3px; box-shadow: 0px 0px 6px #CCC;height: 26px;";var s="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/$ScheduleExplorer/default/icon/calendar.png) 98% center no-repeat";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/$PermissionExplorer/default/icon/selectperson.png) 98% center no-repeat";var n="<table width='100%' height='270' 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.setSchedule+"</td>"+"</tr>"+"<tr>"+"<td style='height: 60px; line-height: 60px; text-align: left; min-width: 80px; width:25%' rowspan='2'>"+t.department+":</td>"+"<td style='; text-align: right;'>"+(!this.isNew&&!this.isEdited?"":"<input type='text' id='department' "+"style='"+a+"'"+" value='"+(this.data&&this.data.department?this.data.department:"")+"'/>")+"</td>"+"</tr>"+"<tr>"+"<td style='; text-align: left;font-size:14px;padding-bottom: 5px'>"+(!this.isNew&&!this.isEdited?"":"<input type='button' id='selCompany' "+"style='margin-right:5px'"+" value='选择公司'/>")+(!this.isNew&&!this.isEdited?"":"<input type='button' id='selDepartment' "+" value='选择部门'/>")+"</td>"+"</tr>"+"<tr>"+"<td style='height: 30px; line-height: 30px; text-align: left'>"+t.workTime+":</td>"+"<td style='; text-align: right;'>"+(!this.isNew&&!this.isEdited?"":"<input type='text' id='workTime' "+"style='"+s+"'"+" value='"+(this.data&&this.data.workTime?this.data.workTime:"")+"'/>")+"</td>"+"</tr>"+"<tr>"+"<td style='height: 30px; line-height: 30px; text-align: left'>"+t.offTime+":</td>"+"<td style='; text-align: right;'>"+(!this.isNew&&!this.isEdited?"":"<input type='text' id='offTime' "+"style='"+s+"'"+" value='"+(this.data&&this.data.offTime?this.data.offTime:"")+"'/>")+"</td>"+"</tr>"+"<tr>"+"<td style='height: 30px; line-height: 30px; text-align: left'>"+t.lateTime+":</td>"+"<td style='; text-align: right;'>"+(!this.isNew&&!this.isEdited?"":"<input type='text' id='lateTime' "+"style='"+s+"'"+" value='"+(this.data&&this.data.lateTime?this.data.lateTime:"")+"'/>")+"</td>"+"</tr>"+"<tr>"+"<td style='height: 30px; line-height: 30px; text-align: left'>"+t.leaveEarlyTime+":</td>"+"<td style='; text-align: right;'>"+(!this.isNew&&!this.isEdited?"":"<input type='text' id='leaveEarlyTime' "+"style='"+s+"'"+" value='"+(this.data&&this.data.leaveEarlyTime?this.data.leaveEarlyTime:"")+"'/>")+"</td>"+"</tr>"+"<tr>"+"<td style='height: 30px; line-height: 30px; text-align: left'>"+t.absenteeismTime+":</td>"+"<td style='; text-align: right;'>"+(!this.isNew&&!this.isEdited?"":"<input type='text' id='absenteeismTime' "+"style='"+s+"'"+" value='"+(this.data&&this.data.absenteeismTime?this.data.absenteeismTime:"")+"'/>")+"</td>"+"</tr>"+"</table>";this.createFormNode.set("html",n);this.department=this.createFormNode.getElement("#department");this.workTime=this.createFormNode.getElement("#workTime");this.offTime=this.createFormNode.getElement("#offTime");this.lateTime=this.createFormNode.getElement("#lateTime");this.leaveEarlyTime=this.createFormNode.getElement("#leaveEarlyTime");this.absenteeismTime=this.createFormNode.getElement("#absenteeismTime");this.createFormNode.getElement("#selDepartment").addEvent("click",function(){e.selectDepartment(this,"d")});this.createFormNode.getElement("#selCompany").addEvent("click",function(){e.selectDepartment(this,"c")});this.workTime.addEvent("click",function(){e.selectCalendar(this)});this.offTime.addEvent("click",function(){e.selectCalendar(this)});this.lateTime.addEvent("click",function(){e.selectCalendar(this)});this.leaveEarlyTime.addEvent("click",function(){e.selectCalendar(this)});this.absenteeismTime.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,s){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(!s)s=this.options&&this.options.left?this.options.left:0;var a=this.app.content.getSize();var n=a.x;var o=a.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);s=s||parseInt((n-e)/2,10);this.createAreaNode.setStyles({width:""+e+"px",height:""+t+"px",top:""+i+"px",left:""+s+"px"});this.createNode.setStyles({width:""+e+"px",height:""+t+"px"});var r=this.createIconNode?this.createIconNode.getSize():{x:0,y:0};var h=this.formTopNode?this.formTopNode.getSize():{x:0,y:0};var d=this.formBottomNode?this.formBottomNode.getSize():{x:0,y:0};var l=t-r.y-h.y-d.y;this.createFormNode.setStyles({height:""+l+"px"})},cancelCreate:function(e){var t=this;var i=this.department.get("value");if(this.isNew&&i!=""&&i!="default"){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 t={id:this.data&&this.data.id?this.data.id:null,organizationName:this.department.get("value"),onDutyTime:this.workTime.get("value"),offDutyTime:this.offTime.get("value"),lateStartTime:this.lateTime.get("value"),leaveEarlyStartTime:this.leaveEarlyTime.get("value"),absenceStartTime:this.absenteeismTime.get("value")};if(t.onDutyTime&&t.offDutyTime&&t.lateStartTime){this.app.restActions.saveSchedule(t,function(e){if(e.type=="ERROR"){this.app.notice(e.message,"error")}else{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")}}.bind(this))}else{this.app.notice("请选择上班打卡时间、下班打卡时间和迟到起算时间","error")}},selectCalendar:function(e){MWF.require("MWF.widget.Calendar",function(){var t=new MWF.widget.Calendar(e,{style:"xform",timeOnly:true,isTime:true,target:this.app.content});t.show()}.bind(this))},selectDepartment:function(e,t){var i={type:t=="d"?"department":"company",title:t=="d"?"选择部门":"选择公司",names:this.data.department||[],count:"1",onComplete:function(e){this.data.department=[];e.each(function(e){this.data.department.push(e.data.name)}.bind(this));this.department.set("value",this.data.department)}.bind(this)};var s=new MWF.OrgSelector(this.app.content,i)}});