[英]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. 在下面的代码中,在dayRender函数中,我正在检查过去的日期,以禁用过去日期小于今天的添加图标。
Now i want to make editbale false on past dates or date less than today. 现在我想在过去的日期或小于今天的日期上使editbale为false。
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代码。
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) {
}
});
}
}
},
声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.