5

我尝试将一个项目从可排序的事件列表拖到完整日历。

我没有在亚当肖的完整日历的文档中看到这一点,但也许有人已经做过一次了。

这是jsfiddle:http: //jsfiddle.net/gtbm/VjNFn/2/

这里是所要求的代码:

/* initialize the external events
    -----------------------------------------------------------------*/
$('ol#external-events').sortable({
    opacity: .6,
    placeholder: 'placeholder',
    revert: "invalid",//  250, //          
    helper:   'clone'
});
$('#external-events li.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);

});


    /* initialize the calendar
    -----------------------------------------------------------------*/

$('#calendar').fullCalendar({
    header: {
        left: 'prev,next today',
        center: 'title',
        right: 'month,agendaWeek,agendaDay'
    },
    editable: true,
    droppable: true, // this allows things to be dropped onto the calendar !!!
    drop: function(date, allDay) { // this function is called when something is dropped
        alert('I got it');

        // retrieve the dropped element's stored Event Object
        var originalEventObject = $(this).data('eventObject');

        // we need to copy it, so that multiple events don't have a reference to the same object
        var copiedEventObject = $.extend({}, originalEventObject);

        // assign it the date that was reported
        copiedEventObject.start = date;
        copiedEventObject.allDay = allDay;

        // render the event on the calendar
        // the last `true` argument determines if the event "sticks" (http://arshaw.com/fullcalendar/docs/event_rendering/renderEvent/)
        $('#calendar').fullCalendar('renderEvent', copiedEventObject, true);                
    }
});

我希望你能帮助,提前谢谢,C

4

6 回答 6

2

因此,我设法在月视图中找到了可拖动和可排序列表的解决方案。

你可以在这里找到 jsfiddle:http: //jsfiddle.net/VjNFn/16/ 和代码:

    function getDateFromCell(td, calInstance){
        var cellPos = {
            row: td.parents('tbody').children().index(td.parent()),
            col: td.parent().children().index(td)
        };

        return calInstance.fullCalendar('getView').cellDate(cellPos);
        }

    /* 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
        });

    });     
    $('ol#sortable-events').sortable({
        helper: 'clone',        
        placeholder: 'placeholder',
        start: function(ev, ui) {
            // create an Event Object (http://arshaw.com/fullcalendar/docs/event_data/Event_Object/)
            var eventObject = {
                id:                 $.trim($(ui.item).attr('id')),  // use the element's id as the event id
                title:              $.trim($(ui.item).text()),      // use the element's text as the event title
                start:              new Date("2013-02-18T18:00:00"),//"2013-02-18T18:00:00", //day,
                end:                new Date("2013-02-18T18:00:00"),//"2013-02-18T18:00:00",//day,
                backgroundColor:    $(ui.item).css('background-color'),
                borderColor:        $(ui.item).css('background-color'),
                textColor:          $(ui.item).css('color'),
                allDay: true 
                };

            // store the Event Object in the DOM element so we can get to it later
            $(ui.item).data('eventObject', eventObject);
            $(ui.item).data('dropped', false);

            return  true;      
            },
        stop: function(ev, ui) {
            // Restore place of Event Object if dropped
            if ( $(ui.draggable).data('dropped') == true ) {
                $('ol#sortable-events').nestedSortable('cancel'); 
                $(ui.draggable).data('dropped') = false ;
                }
            }
        }).disableSelection();


    /* initialize the calendar
    -----------------------------------------------------------------*/
    $('#calendar').fullCalendar({
        header: {
            left: 'prev,next today',
            center: 'title',
            right: 'month,agendaWeek,agendaDay'
            },
        defaultView: 'agendaWeek',
        editable: true,
        droppable: true, // this allows things to be dropped onto the calendar !!!
        dropAccept: '#external-events div.external-event',
        drop: function(date, allDay) { // this function is called when something is dropped

            // retrieve the dropped element's stored Event Object
            var originalEventObject = $(this).data('eventObject');

            // we need to copy it, so that multiple events don't have a reference to the same object
            var copiedEventObject = $.extend({}, originalEventObject);

            // assign it the date that was reported
            copiedEventObject.start = date;
            copiedEventObject.allDay = allDay;

            // render the event on the calendar
            // the last `true` argument determines if the event "sticks" (http://arshaw.com/fullcalendar/docs/event_rendering/renderEvent/)
            $('#calendar').fullCalendar('renderEvent', copiedEventObject, true);

            // is the "remove after drop" checkbox checked?
            if ($('#drop-remove').is(':checked')) {
                // if so, remove the element from the "Draggable Events" list
                $(this).remove();
            }
        }
    }).find('td').each(function() {
        $(this).droppable({
            // greedy: false,
            accept: "ol#sortable-events li.sortable-event",
            // activeClass: "active",
            // tolerance: 'pointer',
            hoverClass: "fc-cell-overlay",
            drop: function( event, ui ) {
                // alert('coucou');
                if ( $(ui.draggable).data('dropped') == false ) {
                    // Get the event and init with the date
                    var eventObject = $(ui.draggable).data('eventObject');
                    var ddrop       = getDateFromCell( $(this), $('#calendar') );
                    eventObject.start = ddrop ;
                    eventObject.end = ddrop ;

                    // Delete the event if already dropped
                    $('#calendar').fullCalendar( "removeEvents", eventObject.id );

                    // render the event on the calendar
                    // the last `true` argument determines if the event "sticks" 
                    $('#calendar').fullCalendar('renderEvent', eventObject, true);

                    // Dropped flag is true state now
                    $(ui.draggable).data('dropped') == true
                    }

                return true;                      
                }
            })
        });;

我不认为,这是一个很好的解决方案,因为它一周和一天都不起作用????

请有任何想法!

于 2013-02-19T11:13:22.060 回答
1

将这段代码添加到您的 each 方法中:

$(this).draggable({
    zIndex: 999,
    revert: true,      // will cause the event to go back to its
    revertDuration: 0  //  original position after the drag
});

您可以在更新的 jsfiddle http://jsfiddle.net/EKTWJ/中检查这一点

文档中提到了一些从列表中拖拽的内容

这里有一个完整的工作示例,因此您可以检查页面的来源。

于 2013-02-18T08:49:29.313 回答
1

@Brousse Ouilisse,您非常接近正确答案:(在您的评论中https://stackoverflow.com/a/15251724/1198292您应该更改

$(document)
// To add in calendar function ***********************************
  .bind("sortstart", function(ev, ui) { 
      //_dragElement = ev.target;  <---------- REMOVE THIS
      _dragElement = ui.helper;  <---------- ADD THIS
      currentView.dragStart(_dragElement, ev, ui);    
  })
  .bind("sortstop", function(ev, ui) {
      if (_dragElement) {
          currentView.dragStop(_dragElement, ev, ui);
          _dragElement = null;
      }                       
  })
于 2014-01-14T12:40:40.860 回答
0

我尝试展示解决方案,但我无法让它工作...... http://jsfiddle.net/gtbm/VjNFn/20/

您在这个 jsfiddle 中找不到的是要在此处添加 fullcalendar.js 代码:

/* External Dragging
------------------------------------------------------------------------*/
if (options.droppable) {
$(document)
// To add in calendar function ***********************************
    .bind("sortstart", function(ev, ui) { 
        _dragElement = ev.target;
        currentView.dragStart(_dragElement, ev, ui);    
    })
    .bind("sortstop", function(ev, ui) {
        if (_dragElement) {
            currentView.dragStop(_dragElement, ev, ui);
            _dragElement = null;
        }                       
    })      
    // **********************************************       
    ...

我希望它有帮助,C

于 2013-03-06T15:44:44.933 回答
0

这是一个解决方案。

create: function(event, ui) {
    $(this).children().each( (index, item) => {
        $(item).data('event', { // DATA TO PASS TO CALENDAR
            title: this.data.title,
            type: this.data.type, 
            cells: this.data.cells,
            event_id: this.data.id
        });
    });
},
于 2018-09-08T21:46:43.173 回答
0

设置data-event可排序元素的属性似乎对我有用。它在fullcalendar eventReceive 文档中有所描述

<ul id="sortable-list">
  <li data-event='{"title":"my event"}'>Task</li>
</ul>

也可以使用 jquery 设置数据属性。

$('#selector').data('event', {title: 'my event'})
于 2017-07-31T15:50:26.313 回答