2012-06-19 48 views
0

我試圖用FullCalendar,它顯示精細,與進料更新從數據庫和谷歌日曆事件。保存外(可棄)事件數據庫

但我的問題是我怎麼在頁面當被按下時,可以讓我在日曆中傳回的所有事件回我的控制器,所以我可以將它們保存到數據庫上的單個保存按鈕?

一些代碼(視圖):

$(document).ready(function() { 
    /* initialize the external events 
    -----------------------------------------------------------------*/ 
    $('#external-events div.external-event').each(function() { 
     // create an Event Object (http://arshaw.com/fullcalendar/docs/event_data/Event_Object/) 
     // it doesn't need to have a start or end 
     var eventObject = { 
      title: $.trim($(this).text()) // use the element's text as the event title 
     }; 

     // store the Event Object in the DOM element so we can get to it later 
     $(this).data('eventObject', eventObject); 
     // make the event draggable using jQuery UI 
     $(this).draggable({ 
      zIndex: 999, 
      revert: true,  // will cause the event to go back to its 
      revertDuration: 0 // original position after the drag 
     }); 
    }); 

    // -------- Calendar set up ... 
    $('#calendar').fullCalendar({ 
     eventSources: 
     [ 
      { // Uk holidays 
       url: 'http://www.google.com/calendar/feeds/uk__en%40holiday.calendar.google.com/public/basic', 
       color: 'blue', 
       textColor: 'white' 
      }, 
      { // booked availability 
       url: '/avalibility/GetAvail', 
       color: 'red' 
      } 
    ], 
    //... more set up 
}); 

控制器代碼:

public JsonResult GetAvail(double start, double end) 
{ 
    var startDateTime = FromUnixTimestamp(start); 
    var endDateTime = FromUnixTimestamp(end); 

    var events = from e in db.PROJECT_CALENDAR 
         select e; 

    var AvilList = new List<object>(); 
    foreach (var e in events) 
    { 
     AvilList.Add(
      new 
      { 
       id = e.ID, 
       title = e.Title, 
       description = e.Title, 
       start = e.DateStart, 
       end = e.DateEnd 
      }); 
    } 
    return Json(AvilList.ToArray(), JsonRequestBehavior.AllowGet); 
}  

回答

1

您是否嘗試過使用clientEvents回調?像這樣:

var eventsFromCalendar = $('#calendar').fullCalendar('clientEvents'); 

這將返回一個JSON數組與所有fullCalendar事件對象。您可以將此陣列傳遞給您的控制器,然後將它們存儲到數據庫中。

希望有幫助!