I am dropping an external object into angular-ui-calendar using angular-dragdrop.
The external object is coming from this list:
<div class="fc-event" data-drag="true"
jqyoui-draggable="{animate:true}"
ng-model="test_object"
ng-repeat="test_object in test_objects">
Draggable - {{ test_object.name }}
</div>
The fullcalendar is set up with:
<div id="ApptsCalendar" calendar="ApptsCalendar"
ui-calendar="calendarOptions.calendar"
ng-model="eventSources" data-drop="true"
jqyoui-droppable="{multiple:true, onDrop: 'drop_function'}"
data-jqyoui-options>
</div>
When dropped, I can process that event using fullcalendar 'drop' method with:
$scope.calendarOptions = {
calendar: {
editable: true,
droppable: true,
drop: function(date,jsEvent,ui,resourceId){
console.log("Dropped from calendarOptions")
console.log(resourceId);
$scope.eventSources[0].push({
id:5,
title: 'dropped event (fake)',
start: date
});
}
}
};
or from the angular-dragdrop 'onDrop' callback to call a 'drop' function:
jqyoui-droppable="{multiple:true, onDrop: 'drop'}"
Both can trigger when I want, but neither seem to have the two pieces I need. I need to have the object value being dropped (defined in ng-model) and the date being dropped into.
Basically, I want to push the event to the the eventSources with:
$scope.eventSources[0].push({
id:5,
title: '...name of object...',
start: '...date of target dropped on...'
});
Well, one of the things you wanted is already there. It's
date
on which the event is dropped. You get it from the first argument of thedrop
function. It's amoment
object (according to the docs) so you might want to use.toDate()
in order to get the JSDate
object.The other thing is the value of the event which got dropped. According to the same docs page, the DOM object of the event is accessible using
this
inside drop function.Now, this is a bit unconventional way (I don't see many choices here), what you can do is, with the
ng-repeat
iterating over event objects, you can keep an attribute with value from each object which can later be accessed inside the drop function. For example, see how I addedcustomEventName="{{test_object.name}}"
in here:Then, in the drop function, that can be accessed using
this.getAttribute('customEventName')
like this: