简体   繁体   中英

Disable editable false on past dates in full calendar

Below is my full calendar script..

In below code, In dayRender function i am checking for past date to disable add icon on past dates which are less than today.

Now i want to make editbale false on past dates or date less than today.

Ex- If anyuser try to drop title on date less than today, then it will revert immediately.

Please help me to make editable false on past date

<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>

I just changes my eventDrop code by comparing todays date and past date and its worked for me..

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) {                                
                            }
                        });  
                    }
                }
            },

The technical post webpages of this site follow the CC BY-SA 4.0 protocol. If you need to reprint, please indicate the site URL or the original address.Any question please contact:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM