DatePicker允许星期日可选日期

时间:2015-10-16 19:10:38

标签: javascript datepicker

我正在使用JQuery Datepicker并以http://jsfiddle.net/gh4muv2p/为例。我想让所有星期日都可以选择。我需要防止选择除星期日以外的所有黄色日期。

其他日子每三天只进行一次颜色编码。

function unavailable(pick) {
var utcPick = new Date(pick.getUTCFullYear(), pick.getUTCMonth(), pick.getUTCDate(), 0, 0, 0);
//-- converts your pick to utc time
var utcStart = new Date(2014, 0, 0).getTime(); //gets utc time
var day = Math.round((utcPick - utcStart) / 86400);
var nwe = noWeekEnds(pick);
var nkd = noKelly(pick);
var assLeave = myAssignedLeave(pick);
var osun = onlySunday(pick);
var Rnd1 = (true) && osun[0];   // First Round full weeks

var myShift = "A";

var Ashift = (day%3===0) && nkd[0] && assLeave[0];  // A Shift
var Bshift = (day%3===1) && nkd[0] && assLeave[0];  // B Shift
var Cshift = (day%3===2) && nkd[0] && assLeave[0];  // C Shift
var Dshift = (true) && nwe[0] && assLeave[0];  // D Shift

var Shift = "";
var ShiftColor = "";
var ShiftColorDayOff = "false";
var DO_ShiftColor = "";
var myRound = "ROUND 1";

if(myShift=="A") (Shift = Ashift) && (ShiftColor = "shiftColor_A");
if(myShift=="B") (Shift = Bshift) && (ShiftColor = "shiftColor_B");
if(myShift=="C") (Shift = Cshift) && (ShiftColor = "shiftColor_C"); 
if(myShift=="D") (Shift = Dshift) && (ShiftColor = "shiftColor_D"); 

if(myShift=="A") (ShiftColorDayOff = (day%3===0)) &&  (DO_ShiftColor = "blue_day_off"); 
if(myShift=="B") (ShiftColorDayOff = (day%3===1)) &&  (DO_ShiftColor = "green_day_off");  
if(myShift=="C") (ShiftColorDayOff = (day%3===2)) &&  (DO_ShiftColor = "red_day_off"); 
if(myShift=="D") (ShiftColorDayOff =  (true) && nwe[0]); 

if((ShiftColorDayOff) && (nkd[0] === false)) return [ false, 'yellow_day_off', 'Kelly!' ];
if((ShiftColorDayOff) && (assLeave[0] === false)) return [ false, 'gray_day_off', 'Assigned Leave!' ];


if(myRound == "ROUND 1") {
    Shift = Rnd1;

        if((ShiftColorDayOff) && (osun[0] === false)){
            if(nkd[0] === false) {
                return [ true, 'yellow_day_off', 'Kelly!' ];
            }else{
                return [ false, DO_ShiftColor, 'unavailable' ];
            }
        }         
}    

return [Shift, ShiftColor, "Available"];  
// remove a tag in CSS to change sunday box 
}

$(document).ready(function () {
$("#datepicker").datepicker({
    beforeShowDay: unavailable
});

$('#datepicker').attr('readonly', true);
});

1 个答案:

答案 0 :(得分:0)

通过将ShiftColor = "kellyDay"添加到ROUND 1 if语句并将true设置为星期几来解决此问题。 http://jsfiddle.net/gh4muv2p/4/

 if(myRound == "ROUND 1") {
    Shift = Rnd1; 

        if((ShiftColorDayOff)  && (osun[0] === false)){
            if(nkd[0] === false) {
                return [ false, 'yellow_day_off', 'Kelly!' ];
            }else{
                return [ false, DO_ShiftColor, 'My Shift' ];
            }
        }else if((ShiftColorDayOff) && (osun[0] === true)){
            if(nkd[0] === false) {
                DO_ShiftColor = "kellyDay" 
                return [ true, DO_ShiftColor, 'Kelly!!' ];
            }
        }
}else{
    if((ShiftColorDayOff) && (nkd[0] === false)) return [ false, 'yellow_day_off', 'Kelly!' ]; 
    if((ShiftColorDayOff) && (assLeave[0] === false)) return [ false, 'gray_day_off', 'Assigned Leave' ]; 
}