我会弹出一个模式(带有 ajax 加载的内容)
$('#calendar').fullcalendar({
/* ... options ... */
dayClick: function( date, jsEvent, view ) {
// some info in console
console.log('Clicked on: ' + date.format());
console.log('Coordinates: ' + jsEvent.pageX + ',' + jsEvent.pageY);
console.log('Current view: ' + view.name);
// Here you load the modal
$('#ajax_modal').load('nestable_list.php', {event_date: date.format()}, function(){
$('#ajax_modal').modal();
});
},
/* ... other options ... */
});
带有nestable list 和按钮保存。在此文件中,您将要求您使用数据库连接的核心 php 文件,以便您创建列表并初始化插件。
我的模态内容的远程 php 文件是这样的:
<?php $date_str = $_GET['event_date'];
$date = date('d-m-Y', strtotime($date_str)); //format the way you need
$res = $db->query("SELECT event_id, title FROM events_table WHERE event_date = '$date' ORDER BY index");
?>
<div class="modal-header">
<button type="button" class="close close-icon-medium" data-dismiss="modal" aria-hidden="true"></button>
<h4 class="modal-title">Edit</h4>
</div>
<div class="modal-body">
<div class="dd" id="nestable">
<ol class="dd-list">
<?php foreach($res AS $row) : ?>
<li class="dd-item" data-id="<?=$row['event_id']?>">
<div class="dd-handle"><?=$row['title']?></div>
</li>
<?php endforeach; ?>
</ol>
</div>
</div>
<div class="modal-footer">
<button class="btn btn-sm save" type="button"> Save</button>
<button type="button" class="btn btn-sm" data-dismiss="modal">Cancel</button>
</div>
您也可以在 php 文件的底部添加您的 javascript
$(document).ready(function(){
$('#nestable').nestable({ /* options here */});
$('.save').on('click', function(){
// loop over li elements and save index with ajax to another file.
// close modal
// you are done here
});
});
一旦对列表进行排序并单击保存按钮,您就可以使用当前选定的索引更新每个事件(在 DB 中添加 event_index 列),然后刷新日历页面。与
$('#calendar').fullCalendar( 'refetchEvents' );
NB 事件索引字段将默认为 0,然后每天从 1 到 n,这将允许以所需的方式获取无序和有序事件。 (在您的查询中添加“ORDER BY event_index”)。将 ORDER BY 添加到从 DB 获取事件的查询中