突出显示的蓝色背景区域应与fullcalendar

时间:2016-09-27 09:19:49

标签: jquery jquery-ui fullcalendar fullcalendar-scheduler

我正在使用fullCalendar-2.9.1以及fullcalendar-scheduler-1.4.0。在我目前的项目中,我有外部元素,我需要拖放到完整的日历中。在将元素拖动到完整日历时,会显示突出显示部分,其中显示拖动元素悬停的所选部分。我已将defaultTimedEventDuration设置为'00:30:00',因此如果未指定结束,则事件的默认持续时间应为30分钟。

我有活动,持续时间为10分钟。我将这些fullcalender事件拖到外部元素框并再次将其拖回fullcalendar。我已在数据('event')中设置事件的开始和结束时间。

现在我的问题是,当我将外部元素拖入fullcalendar时,突出显示部分总是相当于30分钟,因为我猜测是defaultTimedEventDuration。我需要控制突出显示部分的高度,该高度应与拖动元素的持续时间相匹配。

如何根据事件持续时间控制突出显示部分的高度?

$('#external-events .fc-event').each(function() {           
            $(this).data('event', {
                title: $.trim($(this).text()),
                stick: true 
            });         
            $(this).draggable({
                zIndex: 999,
                revert: true,
                revertDuration: 0 
            });

        });
        function makeEventsDraggable () {                 
                $('.fc-draggable').each(function() {                                   
                    $(this).data('event', {
                        title: $.trim($(this).text()),                         
                        stick: true
                     });
                     $(this).draggable({
                         appendTo: ".calander_container",                     
                         helper: function(ev) {
                              return '<div id="draggableHelper" class="fc-event " style="width:'+$(this).parent().width()+'px; height:'+$(this).height()+'px;">'+ $(this).html() +'</div>';
                         },                         
                         zIndex: 9999,
                         revert: true,  
                         revertDuration: 0
                      });

                 });

             }
             var sDate = null;
var resource_id = null;
$('#calendar').fullCalendar({
            defaultView: 'agendaDay',
            defaultDate: '2016-09-07',
            editable: true,
            selectable: true,
            eventLimit: true,
            droppable: true,            
            minTime: '07:00:00', 
            maxTime: '22:00:00',
            slotDuration: '00:05:00',
            scrollTime: sTime,            
            slotLabelInterval: {hours:1},       
            allDaySlot: false, 
            disableDragging: false,
            selectable: false,
            selectHelper: true,
            defaultTimedEventDuration: '00:30:00',
            header: {
                left: 'prev,next today',
                center: 'title',
                right: 'month,agendaWeek,agendaDay'
            },
            views: {                
            },          
            allDaySlot: false,
            resources: [
                { id: 'a', title: 'Room A' },
                { id: 'b', title: 'Room B', eventColor: 'green' },
                { id: 'c', title: 'Room C', eventColor: 'orange' },
                { id: 'd', title: 'Room D', eventColor: 'red' }
            ],
            events: [
                { id: '1', resourceId: 'a', start: '2016-09-06', end: '2016-09-08', title: 'event 1' },
                { id: '2', resourceId: 'a', start: '2016-09-07T09:00:00', end: '2016-09-07T14:00:00', title: 'event 2' },
                { id: '3', resourceId: 'b', start: '2016-09-07T12:00:00', end: '2016-09-08T12:10:00', title: 'event 3' },
                { id: '4', resourceId: 'c', start: '2016-09-07T07:30:00', end: '2016-09-07T07:05:00', title: 'event 4' },
                { id: '5', resourceId: 'd', start: '2016-09-07T10:00:00', end: '2016-09-07T10:20:00', title: 'event 5' }
            ],
      viewRender: function(view, element) {    
              element.on('dblclick',function(e) {                  
                  var defaultDuration = moment.duration($('#calendar').fullCalendar('option', 'defaultTimedEventDuration'));
                  var eDate = slotDate.clone().add(defaultDuration);                    
                  $('#calendar').fullCalendar( 'select', slotDate, eDate, resource_id);
               });       
      },
            select: function(start, end, jsEvent, view, resource) {             
            },
            dayClick: function(date, jsEvent, view, resource) {
              sDate = date;
               resource_id = resource.id;          
            },
           drop: function(date, jsEvent, ui, resourceId) {
                 var oEventObject = $(this).data('event');
                 var duration = null;
                if((oEventObject.start)&&(oEventObject.end)){
                  duration = moment.duration(oEventObject.end.diff(oEventObject.start));                     
                }
                var cEventObject = $.extend({}, oEventObject);                    
                cEventObject.start = date;
                var defaultDuration = null;
               if(duration) {
                 defaultDuration = duration;
               } else {  
                  defaultDuration = moment.duration($('#calendar').fullCalendar('option', 'defaultTimedEventDuration'));
               }
               cEventObject.end = date.clone().add(defaultDuration); 
               cEventObject.resourceId = resourceId;
               $('#calendar').fullCalendar('renderEvent', cEventObject, true);  
               if ($('#drop-remove').is(':checked')) {                  
                  $(this).remove();
                }
                makeEventsDraggable();
             },
            eventReceive: function(event) { 
                console.log('eventReceive', event);
                makeEventsDraggable();
            },
            eventDrop: function(event) {
                if(isEventOverDiv(jsEvent.clientX, jsEvent.clientY)) {
                  $('#calendar').fullCalendar('removeEvents', event._id); 
                  var el = $( "<div class='fc-event'>" ).appendTo( '#external-events-listing' ).text( event.title );
                  el.data('event', { title: event.title, id: event._id, start: event.start, end: event.end, stick: true });                   
                  el.draggable({
                      helper: function(event) {
                          return $(event.target).clone().css({
                              width: $(event.target).width()
                          });
                      },
                      zIndex: 999,                              
                      revert: true,      
                      revertDuration: 0
                  });
              }
              makeEventsDraggable();
           }
       });

1 个答案:

答案 0 :(得分:0)

得到答案。我们需要在el.data中包含持续时间('event',{title:event.title,id:event._id,start:event.start,end:event.end,stick:true})。 ie,el.data('event',{title:event.title,id:event._id,start:event.start,end:event.end,duration:'00:10:00',stick:true})