在完整日历中的过去日期禁用可编辑的false

时间:2018-10-05 06:17:22

标签: javascript fullcalendar

下面是我的完整日历脚本。

在下面的代码中,在dayRender函数中,我正在检查过去的日期,以禁用比今天短的过去日期上的添加图标。

现在,我想在过去的日期或比今天短的日期设为false。

例如,如果任何用户尝试在比今天短的日期删除标题,那么它将立即恢复。

请帮助我将过去的日期设为可编辑的错误

<script type="text/javascript">
    function getDates(){
        var date = new Date();
            var cellYear = date.getFullYear();
            var cellMonth = (date.getMonth() + 1 <10)?'0'+(date.getMonth() + 1) : (date.getMonth() + 1);
            var cellDay = (date.getDate()<10)?'0'+(date.getDate()):(date.getDate());
            var newDate = cellYear+"-"+cellMonth+"-"+cellDay;   
            return newDate;
    }
    $(document).ready(function() {   
        var date = new Date();
        var d = date.getDate();
        var m = date.getMonth();
        var y = date.getFullYear();
        $('#calendar').fullCalendar({
            header: {
                left: 'prev,next today',
                center: 'title',
                right: 'month,agendaWeek,agendaDay'
            },           
            dayRender: function (date, cell) {
                var cellYear = date.year();
                var cellMonth = (date.month() + 1 <10)?'0'+(date.month() + 1) : (date.month() + 1);
                var cellDay = (date.date()<10)?'0'+(date.date()):(date.date());
                var newDate = cellYear+"-"+cellMonth+"-"+cellDay;
                if(newDate >= getDates()){                  
                    cell.append('<i class="fa fa-plus-square fa-lg" style="color:#18a689"></i>');
                }       
            },
            selectable: true,
            selectHelper: true,           
            <?php if(in_array('Edit-Workorder',$modulePermission)){ ?>
            editable: true,
            <?php } else {?>
            editable: false,
            <?php } ?>            
            droppable: true, // this allows things to be dropped onto the calendar
            eventDrop: function(event, delta, revertFunc) {
                start = event.start.format('MM/DD/YYYY');
                if (!confirm("Are you sure you want to change " + event.title + " on " + start)) {
                    revertFunc();
                }else{
                    var strtdt = event.start.format();
                    $.ajax({
                        url: '<?= Router::url(['controller' => 'Schedules', 'action' => 'updateCalendar']) ?>',
                        data: 'orderId=' + event.ordid + '&start=' + strtdt,
                        type: "POST",
                        success: function (response) {

                        }
                    });  
                } 
            },           
            eventLimit: true, // allow "more" link when too many events
            events: [
            <?php if(!empty($calendar)){ foreach ($calendar as $schdate){ 
                $dte =  date('Y-m-d', strtotime($schdate['client_treat_date'])); ?>
                {
                    title: '<?php echo wordwrap($schdate['client']['name'],15,'\n'); ?>,<?php echo $schdate['load_time']; ?>',
                    start: '<?php echo $dte; ?>',
                    ordid :'<?php echo $schdate['id']; ?>',
                    url: '<?php echo Router::url(array('controller'=>'Orders','action'=>'viewWorkorder','calendarId'=>base64_encode(5),base64_encode($schdate['id']))); ?>'

                },
            <?php } } ?>
            ]
        });
    });
</script>

1 个答案:

答案 0 :(得分:0)

我只是通过比较今天和过去的日期及其对我的工作来更改eventDrop代码。

eventDrop: function(event, delta, revertFunc) {
                todaysdate = getDates();
                backdate = event.start.format('YYYY-MM-DD');
                if(backdate < todaysdate){
                    revertFunc();
                }else{
                    start = event.start.format('MM/DD/YYYY');
                    if (!confirm("Are you sure you want to change " + event.title + " on " + start)) {
                        revertFunc();
                    }else{
                        var strtdt = event.start.format();
                        $.ajax({
                            url: '<?= Router::url(['controller' => 'Schedules', 'action' => 'updateCalendar']) ?>',
                            data: 'orderId=' + event.ordid + '&start=' + strtdt,
                            type: "POST",
                            success: function (response) {                                
                            }
                        });  
                    }
                }
            },