ordersprinter/webapp/elements/osdatepicker.js

1 line
6.2 KiB
JavaScript
Raw Permalink Normal View History

2020-11-19 23:14:07 +01:00
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(){t