1 line
6.2 KiB
JavaScript
1 line
6.2 KiB
JavaScript
function OsDatePicker(){this.EARLY_DATE=["Der gewählte Tag liegt in der Vergangenheit. Soll dieser dennoch ausgewählt werden?","The chosen date is in the past. Shall this date be take though?","El día seleccionado pertenece al pasado. ¿Debería seguir siendo seleccionado?"];this.isMonthViewVisible=false;this.datefieldelem=null;this.datemonthelem=null;this.lang=0;this.blockedDays={};this.currentDay=null;this.currentMonth=null;this.currentYear=null;this.changeCallbackFct=null;this.init=function(d,g,h,b,f,c,a,e){this.datefieldelem=d;this.datemonthelem=g;this.lang=h;this.blockedDays=this.createHashmapOfBlockedDays(e);this.changeCallbackFct=a;this.currentDay=b;this.currentMonth=f;this.currentYear=c;this.bindClickInDateTextField();this.displayDateInField()};this.getDate=function(){return new Date(this.currentYear,this.currentMonth,this.currentDay)};this.setDate=function(a){this.currentDay=a.getDate();this.currentMonth=a.getMonth();this.currentYear=a.getFullYear();this.off();this.displayDateInField()};this.bindClickInDateTextField=function(){var a=this;$(this.datefieldelem).off("click").on("click",function(b){b.stopImmediatePropagation();b.preventDefault();a.toggle()});$(this.datefieldelem).off("keydown").on("keydown",function(b){b.stopImmediatePropagation();b.preventDefault()});$(this.datefieldelem).off("keypress").on("keypress",function(b){b.stopImmediatePropagation();b.preventDefault()});$(this.datefieldelem).off("keyup").on("keyup",function(b){b.stopImmediatePropagation();b.preventDefault()})};this.createHashmapOfBlockedDays=function(b){var a={};b.forEach(function(c){var d=c.scheduledate;a[d]=c.remark});return a};this.isBlockedDay=function(a,c,b){var d=this.isBlockedDayWithRemark(a,c,b);return d.blocked};this.isBlockedDayWithRemark=function(a,d,b){a=pad(parseInt(a),2);d=pad(parseInt(d)+1,2);var c=b+"-"+d+"-"+a;if(c in this.blockedDays){return{blocked:true,remark:this.blockedDays[c]}}else{return{blocked:false,remark:""}}};this.isTodayBlocked=function(){var a=new Date();return this.isBlockedDay(a.getDate(),a.getMonth(),a.getFullYear())};this.isTodayBlockedWithRemark=function(){var a=new Date();return this.isBlockedDayWithRemark(a.getDate(),a.getMonth(),a.getFullYear())};this.blockDayInHashmap=function(a,d,c,e){a=pad(parseInt(a),2);d=pad(parseInt(d)+1,2);var b=c+"-"+(d)+"-"+a;this.blockedDays[b]=e};this.releaseDayInHashmap=function(a,d,c){a=pad(parseInt(a),2);d=pad(parseInt(d)+1,2);var b=c+"-"+(d)+"-"+a;delete this.blockedDays[b]};this.generateMonthView=function(){var h="<table class='viewdatemonthtable'>";h+=this.getTableHeader(this.currentMonth,this.currentYear);h+="<tr class='center'><td>Mo<td>Di<td>Mi<td>Do<td>Fr<td>Sa<td>So</tr>";var k=new Date();var o=k.getDate();var n=k.getMonth();var p=k.getFullYear();var m=new Date(this.currentYear,this.currentMonth,1);var q=new Date(this.currentYear,this.currentMonth+1,0);var e=q.getDate();var a=this.getPreviousMonth();var c=(new Date(a.year,a.month+1,0)).getDate();var j=this.getNextMonth();var d=m.getDay();if(d==0){d=6}else{d--}var r=d;h+="<tr class='center'>";var f=c-r+1;for(var l=0;l<r;l++){var b=this.datemonthelem+"_"+f+"_"+a.month+"_"+a.year;var g="";if(this.isBlockedDay(f,a.month,a.year)){g=" blocked "}h+="<td id='"+b+"' class='selectableday othermonth "+g+"'>"+f;f++}for(var f=1;f<=e;f++){var b=this.datemonthelem+"_"+f+"_"+this.currentMonth+"_"+this.currentYear;var g="";if(this.isBlockedDay(f,this.currentMonth,this.currentYear)){g=" blocked "}if((f==o)&&(this.currentMonth==n)&&(this.currentYear==p)){h+="<td id='"+b+"' class='selectableday today "+g+"'>"+f}else{h+="<td id='"+b+"' class='selectableday thismonth "+g+"'>"+f}d++;if((d>6)&&(f<e)){h+="</tr><tr class='center'>";d=0}}var f=1;for(var l=d;l<7;l++){var g="";if(this.isBlockedDay(f,j.month,j.year)){g=" blocked "}var b=this.datemonthelem+"_"+f+"_"+j.month+"_"+j.year;h+="<td id='"+b+"' class='selectableday othermonth "+g+"'>"+f;f++}h+="</tr>";h+="</table>";return h};this.updateMonth=function(){var a=this.generateMonthView();$(this.datemonthelem).html(a);this.bindMonthSelector();this.bindDaySelector()};this.on=function(){this.updateMonth();$(this.datemonthelem).show();this.isMonthViewVisible=true;this.bindMonthSelector()};this.off=function(){$(this.datemonthelem).hide();this.isMonthViewVisible=false};this.toggle=function(){if(!this.isMonthViewVisible){this.on()}else{this.off()}};this.getMonthName=function(a){var b=[["Jan","Jan","Ene"],["Feb","Feb","Feb"],["Mär","Mar","Mar"],["Apr","Apr","Abr"],["Mai","May","May"],["Jun","Jun","Jun"],["Jul","Jul","Jul"],["Aug","Aug","Ago"],["Sep","Sep","Sep"],["Okt","Oct","Oct"],["Nov","Nov","Nov"],["Dez","Dec","Dic"]];return b[a][this.lang]};this.getTableHeader=function(c,b){var a="<tr class='center dateselection'><td colspan='2' class='monthdec'><<<td colspan='3'>"+this.getMonthName(c)+" "+b+"<td colspan='2' class='monthinc'>>></tr>";return a};this.displayDateInField=function(){var a=this.currentDay+"."+(this.currentMonth+1)+"."+this.currentYear;$(this.datefieldelem).val(a)};this.getPreviousMonth=function(){var b=this.currentMonth;var a=this.currentYear;if(b==0){a--;b=11}else{b--}return{month:b,year:a}};this.getNextMonth=function(){var b=this.currentMonth;var a=this.currentYear;if(b==11){a++;b=0}else{b++}return{month:b,year:a}};this.bindMonthSelector=function(){var a=this;$(this.datemonthelem+" .monthdec").off("click").on("click",function(c){c.stopImmediatePropagation();c.preventDefault();var b=a.getPreviousMonth();a.currentMonth=b.month;a.currentYear=b.year;a.updateMonth()});$(this.datemonthelem+" .monthinc").off("click").on("click",function(c){c.stopImmediatePropagation();c.preventDefault();var b=a.getNextMonth();a.currentMonth=b.month;a.currentYear=b.year;a.updateMonth()})};this.bindDaySelector=function(){var a=this;$(this.datemonthelem+" .selectableday").off("click").on("click",function(j){j.stopImmediatePropagation();j.preventDefault();var l=this.id.split("_");var c=parseInt(l[1]);var d=parseInt(l[2]);var n=parseInt(l[3]);var h=true;var i=new Date(n,d,c);var k=new Date();k.setHours(0,0,0,0);if(k>i){var b=confirm(a.EARLY_DATE[a.lang]);if(b==false){h=false}}if(h){a.currentDay=c;a.currentMonth=d;a.currentYear=n;a.displayDateInField();if(a.changeCallbackFct!=null){var g=a.isBlockedDayWithRemark(c,d,n);var m=g.blocked;var f=g.remark;a.changeCallbackFct(i,m,f)}}a.toggle()})}}; |