Javascript NoGray日历添加到目前为止的天数,如果该天被阻止,请选中所选的阻止日期后检查可用性 [英] Javascript NoGray Calendar add number of days to date, check availability after chosen blocked dates if that day is blocked

查看:121
本文介绍了Javascript NoGray日历添加到目前为止的天数,如果该天被阻止,请选中所选的阻止日期后检查可用性的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我之前在此位置提出了类似的问题, Javascript NoGray日历查找选择的阻塞日期后的下一个可用日期,如果今天被阻止,检查单个日历。现在对于第二个日历,我想让它检查以前的日期my_cal1,添加一个天,我选择了7天,然后检查是否该日期可用,如果不做同样的事情第一个日历通过检查每一天,直到一个可用的日期,然后选择该日期。因此,为了清楚起见,从第一个日历选择日期起的天数不完全固定,只有当它选择的日期可用时,如果没有,它将移动到下一个可用日期。

I previously asked a similar question at this location, Javascript NoGray Calendar find next available date after chosen blocked dates if today is blocked, for the check the a single calendar. Now for the second calendar, I am trying to make it check the previous date at my_cal1, add a number of days, which I have selected as 7 days, and then check if that date is available and if not to do the same thing as the first calendar by checking each day after until a date it available and then to select that date. So to make clear, the number of days from the first calendar selected date is not fixed completely, only if the date it selects is available and if not, it moves to the next available date.

这里是我试图到目前为止的代码。这是第二个onLoad,onLoad的日历2 my_cal2,我想解决:

Here is the code I am trying so far. It's the second onLoad, the onLoad for calendar 2 my_cal2 that I am trying to resolve:

    my_cal1 = new ng.Calendar({
    input: {date:'date1', month:'month1', year:'year1'},
    selected_date:new Date(),
    display_date:new Date(),
    dates_off:[{date:1, month:0},{date:25, month:11},{date:24, month:6, year:2014},{date:27, month:6, year:2014},{date:28, month:6, year:2014},{date:29, month:6, year:2014},{date:30, month:6, year:2014},{date:31, month:6, year:2014},{date:8, month:7, year:2014},{date:9, month:7, year:2014}],
    events: {
        onDateClick: function(dt){
            this.select_date(dt);
        },
        // code to check if the start date is selectable
        onLoad: function(){
            var st_dt = this.get_start_date().clone();
            while(!this.is_selectable(st_dt)[0]){
                st_dt = st_dt.from_string('today + 1');
            }
            // checking if no dates are selected
            if (!ng.defined(this.get_selected_date())){
                this.select_date(st_dt);
            }
            this.set_start_date(st_dt);
        }
    }
});


    my_cal2 = new ng.Calendar({
    input: {date:'date1', month:'month1', year:'year1'},
    selected_date:new Date(),
    display_date:new Date(),
    dates_off:[{date:1, month:0},{date:25, month:11},{date:24, month:6, year:2014},{date:27, month:6, year:2014},{date:28, month:6, year:2014},{date:29, month:6, year:2014},{date:30, month:6, year:2014},{date:31, month:6, year:2014},{date:8, month:7, year:2014},{date:9, month:7, year:2014}],
    events: {
        onDateClick: function(dt){
            this.select_date(dt);
        },
        // code to check if the start date is selectable
        onLoad: function(){
                var st_dt = this.get_start_date().clone();
                console.log(this.is_selectable(st_dt)[0]);
                while(!this.is_selectable(st_dt)[0])
                {
                    st_dt = st_dt.from_string('today + 1');
                }
                // checking if no dates are selected
                if (!ng.defined(this.get_selected_date()))
                {
                    var stt_dt = this.select_date(st_dt.from_string('today + 7')).clone();
                    console.log(this.is_selectable(stt_dt)[0]);
                    while(!this.is_selectable(stt_dt)[0])
                    {
                        stt_dt = stt_dt.from_string('today + 1');
                    }
                    if (!ng.defined(this.get_selected_date(stt_dt)))
                    {
                        this.select_date(stt_dt);
                    }
                }
                this.set_start_date(stt_dt);
      }
    }
});

任何帮助将不胜感激。提前感谢。

Any help would be much appreciated. Thanks in advance.

UPDATE:

我试过my_cal2.get_selected_date ):

I tried with my_cal2.get_selected_date():

            onLoad: function()
            {
                var theDate = my_cal1.get_start_date();
                theDate = theDate.from_string('today + 7');
                var st_dt = theDate.clone();
                console.log(this.is_selectable(st_dt)[0]);
                while(!this.is_selectable(st_dt)[0])
                {
                    st_dt = st_dt.from_string('today + 1');
                }
                // checking if no dates are selected
                if (!ng.defined(this.get_selected_date()))
                {
                    this.select_date(st_dt);
                }
                this.set_start_date(st_dt);
            },      

这样可以工作,但现在所有日期都不可用,即使他们不是阻止,并且当您使用get_day_since查看两个日期之间的差异时,它不能正常工作。

This works but now all dates before are unavailable, even if they are not blocked, and also when you use get_day_since to see the difference between the two dates, it does not work properly.

仍然需要帮助。谢谢。

推荐答案

是的,我能够找出答案:

Yes, I was able to figure out the answer:

                onLoad: function()
            {
                var theDate = my_cal1.get_start_date().clone();
                theDate = theDate.from_string('today + 7');
                var st_dt = theDate.clone();
                console.log(this.is_selectable(st_dt)[0]);
                while(!this.is_selectable(st_dt)[0])
                {
                    st_dt = st_dt.from_string('today + 1');
                }
                // checking if no dates are selected
                if (!ng.defined(this.get_selected_date()))
                {
                    this.select_date(st_dt);
                }
                var origDate = my_cal1.get_start_date();
                this.set_start_date(origDate);
                this.set_selected_date(st_dt);
            },      

感谢任何试图解决这个问题的人。

Thanks to anyone who was trying to solve this.

这篇关于Javascript NoGray日历添加到目前为止的天数,如果该天被阻止,请选中所选的阻止日期后检查可用性的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆