angular-ui / ui-calendar

A complete AngularJS directive for the Arshaw FullCalendar.
http://angular-ui.github.io/ui-calendar/
MIT License
1.49k stars 729 forks source link

AngularJS UI-calendar eventSources not updated #542

Open estellederrien opened 5 years ago

estellederrien commented 5 years ago

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

estellederrien commented 5 years ago

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

estellederrien commented 5 years ago

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

estellederrien commented 5 years ago

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 .