ui-calendar
ui-calendar copied to clipboard
AngularJS UI-calendar eventSources not updated
AngularJS UI-calendar doesn't update $scope.eventSources data model, after an event Drag and Drop. I need to get the updated model , and nothing works.
I 've tried plenty of things, nothing works.
I've tried few of the solutions mentionned there with no luck : https://github.com/angular-ui/ui-calendar/issues/276
This is my code :
/* config object */
$scope.uiConfig = {
calendar:{
height: 600,
editable: true,
header:{
left: 'month basicWeek basicDay agendaWeek agendaDay',
center: 'title',
right: 'today prev,next'
},
eventClick: $scope.alertEventOnClick,
eventDrop: $scope.alertOnDrop,
eventResize: $scope.alertOnResize,
eventRender: function (event, element) {
if (event.HighPriority == 1) {
event.className ='highPriority';
}
}
}
};
/* load events source that contains custom events on the scope */
$scope.events = agendaFactoryLocalStorage.getAgenda();
$scope.eventSources = [$scope.events];
$scope.alertOnDrop = function(event, delta, revertFunc, jsEvent, ui, view){
$scope.alertMessage = ('Event Droped to make dayDelta ' + delta);
uiCalendarConfig.calendars.myCalendar.fullCalendar('removeEvents');
uiCalendarConfig.calendars.myCalendar.fullCalendar('addEventSource',$scope.events);
});
$scope.save_agenda = function(){
agendaFactoryLocalStorage.updateAgenda($scope.eventSources);
}
$scope.save_agenda still send the same data model, while i 've drag and dropped 1 event , i really dont know what to do, stuck since 3 hours. $scope.eventSources loads correctly, but, drag and drops doesnt change the model, only the 'event ' variable is updated , but it is unique, i 've tried to push it inside $scope.eventSources with no luck
I have added
console.log($scope.events); console.log($scope.eventSources);
inside the $scope.alertOnDrop function, and both are not updated after a drag and drop
This is how my event look like when i dragged it 👍
_allDay: false
_end: Object { _isAMomentObject: true, _i: "2019-02-01T23:00:00.000Z", _f: "YYYY-MM-DDTHH:mm:ss.SSSSZ", … }
_id: 2
_start: {…}
_ambigZone: true
_d: Date 2019-02-19T23:00:00.000Z
_f: "YYYY-MM-DDTHH:mm:ss.SSSSZ"
_fullCalendar: true
_i: "2019-01-29T23:00:00.000Z"
_isAMomentObject: true
_isUTC: true
_locale: Object { _months: (12) […], _monthsShort: (12) […], _fullCalendar_weekCalc: "local", … }
_offset: 0
_pf: Object { empty: false, overflow: -1, charsLeftOver: 0, … }
_tzm: -0
<prototype>: Object { add: hb()
, calendar: jb(), clone: clone()
, … }
allDay: false
className: Array [ "evenement" ]
color: "black"
end: Object { _isAMomentObject: true, _i: "2019-02-01T23:00:00.000Z", _f: "YYYY-MM-DDTHH:mm:ss.SSSSZ", … }
source: Object { events: (6) […], className: [], origArray: (6) […] }
start: Object { _isAMomentObject: true, _i: "2019-01-29T23:00:00.000Z", _f: "YYYY-MM-DDTHH:mm:ss.SSSSZ", … }
stick: true
title: "Equipe 2 vs equipe 3"
<prototype>: {…
Please notice that the correct new date is _d , and the ancient date is _f
Well, i 've found something who will probably work , it is updating $scope.eventSources correctly now after dragging:
$scope.alertOnDrop = function(event, delta, revertFunc, jsEvent, ui, view){
$scope.alertMessage = ('Event Droped to make dayDelta ' + delta);
$scope.eventSources[0][1].start = event.start.format();
};
it is updating the old date value with the dragged date value i still have to get the correct index each times .