williamtroup / Calendar.js

đź“… A javascript drag & drop event calendar, that is fully responsive and compatible with all modern browsers.
https://calendar-js.com
MIT License
478 stars 33 forks source link

Changing repeating events #187

Open CedricHH opened 8 months ago

CedricHH commented 8 months ago

First of all ty for the work. I was looking just for smth like this. But ive run into an issue changing existing repeating events, for example when i am assigning them a group. Afterwards i get an oneventadded trigger with a new eventid and strange form/to-dates. Anyone can replicate this? best regards

CedricHH commented 8 months ago
function eventDialogEvent_OK() {
    var fromTime = _element_Dialog_EventEditor_TimeFrom.value.split( ":" ),
        toTime = _element_Dialog_EventEditor_TimeTo.value.split( ":" ),
        title = trimString( _element_Dialog_EventEditor_Title.value ),
        url = trimString( _element_Dialog_EventEditor_Url.value );

    if ( fromTime.length < 2 ) {
        showEventEditorErrorMessage( _options.fromTimeErrorMessage );
    } else if ( toTime.length < 2 ) {
        showEventEditorErrorMessage( _options.toTimeErrorMessage );
    } else if ( title === _string.empty ) {
        showEventEditorErrorMessage( _options.titleErrorMessage );
    } else if ( url.length > 0 && !isValidUrl( url ) ) {
        showEventEditorErrorMessage( _options.urlErrorMessage );

    } else {
         console.log("Debug: Valid initial event details", { fromTime, toTime, title, url });

        var fromDate = getSelectedDate( _element_Dialog_EventEditor_DateFrom ),
            toDate = getSelectedDate( _element_Dialog_EventEditor_DateTo ),
            description = trimString( _element_Dialog_EventEditor_Description.value ),
            location = trimString( _element_Dialog_EventEditor_Location.value ),
            group = trimString( _element_Dialog_EventEditor_Group.value ),
            repeatEnds = getSelectedDate( _element_Dialog_EventEditor_RepeatOptions_RepeatEnds, null ),
            repeatEveryCustomValue = parseInt( _element_Dialog_EventEditor_RepeatEvery_Custom_Value.value ),
            type = getEventTypeInputChecked(),
            alertOffset = parseInt( _element_Dialog_EventEditor_AlertOffset.value );
            console.log("Debug2: Valid initial event details", { fromDate, toDate, title, url });

        if ( isNaN( repeatEveryCustomValue ) ) {               
            console.log("Debug: repeatEveryCustomValue is NaN, setting to default", repeatEveryCustomValue);
             repeatEveryCustomValue = 0;
            _element_Dialog_EventEditor_RepeatEvery_Never.checked = true;
            _element_Dialog_EventEditor_RepeatEvery_Custom_Type_Daily.checked = true;
        }

        if ( isNaN( alertOffset ) ) {
            alertOffset = 0;
        }

        if ( toDate < fromDate ) {
            console.log("Debug: toDate is smaller than fromDate", { fromDate, toDate });

            showEventEditorErrorMessage( _options.toSmallerThanFromErrorMessage );
        } else {
             console.log("Debug: Preparing to save event", { fromDate, toDate, description, location, group, repeatEnds });

            var normalSave = function( newId, newFromDate, newToDate, newRepeatEndsDate, ignoreFields ) {
                ignoreFields = isDefined( ignoreFields ) ? ignoreFields : false;

                setTimeOnDate( newFromDate, _element_Dialog_EventEditor_TimeFrom.value );
                setTimeOnDate( newToDate, _element_Dialog_EventEditor_TimeTo.value );

                if ( !ignoreFields ) {
                    var isExistingEvent = isDefined( newId ),
                        newEvent = {
                            from: newFromDate,
                            to: newToDate,
                            title: title,
                            description: description,
                            location: location,
                            group: group,
                            isAllDay: _element_Dialog_EventEditor_IsAllDay.checked,
                            showAlerts: _element_Dialog_EventEditor_ShowAlerts.checked,
                            showAsBusy: _element_Dialog_EventEditor_ShowAsBusy.checked,
                            color: _element_Dialog_EventEditor_EventDetails.color,
                            colorText: _element_Dialog_EventEditor_EventDetails.colorText,
                            colorBorder: _element_Dialog_EventEditor_EventDetails.colorBorder,
                            repeatEveryExcludeDays: _element_Dialog_EventEditor_EventDetails.repeatEveryExcludeDays,
                            repeatEnds: newRepeatEndsDate,
                            url: url,
                            repeatEveryCustomValue: repeatEveryCustomValue,
                            type: type,
                            customTags: _element_Dialog_EventEditor_EventDetails.customTags,
                            alertOffset: alertOffset
                        };
                    console.log("Debug: keine ignorefields", { newEvent });

                    if ( _element_Dialog_EventEditor_RepeatEvery_Never.checked ) {
                        newEvent.repeatEvery = _enum_RepeatType.never;
                    } else if ( _element_Dialog_EventEditor_RepeatEvery_EveryDay.checked ) {
                        newEvent.repeatEvery = _enum_RepeatType.everyDay;
                    } else if ( _element_Dialog_EventEditor_RepeatEvery_EveryWeek.checked ) {
                        newEvent.repeatEvery = _enum_RepeatType.everyWeek;
                    } else if ( _element_Dialog_EventEditor_RepeatEvery_Every2Weeks.checked ) {
                        newEvent.repeatEvery = _enum_RepeatType.every2Weeks;
                    } else if ( _element_Dialog_EventEditor_RepeatEvery_EveryMonth.checked ) {
                        newEvent.repeatEvery = _enum_RepeatType.everyMonth;
                    } else if ( _element_Dialog_EventEditor_RepeatEvery_EveryYear.checked ) {
                        newEvent.repeatEvery = _enum_RepeatType.everyYear;
                    } else if ( _element_Dialog_EventEditor_RepeatEvery_Custom.checked ) {
                        newEvent.repeatEvery = _enum_RepeatType.custom;
                    }

                    if ( _element_Dialog_EventEditor_RepeatEvery_Custom_Type_Daily.checked ) {
                        newEvent.repeatEveryCustomType = _enum_RepeatCustomType.daily;
                    } else if ( _element_Dialog_EventEditor_RepeatEvery_Custom_Type_Weekly.checked ) {
                        newEvent.repeatEveryCustomType = _enum_RepeatCustomType.weekly;
                    } else if ( _element_Dialog_EventEditor_RepeatEvery_Custom_Type_Monthly.checked ) {
                        newEvent.repeatEveryCustomType = _enum_RepeatCustomType.monthly;
                    } else if ( _element_Dialog_EventEditor_RepeatEvery_Custom_Type_Yearly.checked ) {
                        newEvent.repeatEveryCustomType = _enum_RepeatCustomType.yearly;
                    }

                    if ( !isExistingEvent ) {
                        console.log("Debug: !isExistingEvent:", { newEvent });
                        newEvent.organizerName = _options.organizerName;
                        newEvent.organizerEmailAddress = _options.organizerEmailAddress;
                    } else {
                        newEvent.id = newId; 
                        console.log("Debug: isExistingEvent:", { newEvent});

                    }

                    if ( isExistingEvent ) {
                        _this.updateEvent( newId, newEvent, false );
                         console.log("Debug: isExistingEvent update:", {  newId, newEvent });

                        showNotificationPopUp( _options.eventUpdatedText.replace( "{0}", _element_Dialog_EventEditor_EventDetails.title ) );
                    } else {
                        _this.addEvent( newEvent, false );
                        console.log("Debug: !isExistingEvent update:", { newId, newfromDate, newtoDate, repeatEnds, isExistingEvent });

                        showNotificationPopUp( _options.eventAddedText.replace( "{0}", newEvent.title ) ); //"{0}", newEvent.title ) );
                    }

                    if ( _options.isWidget ) {
                        build( _calendar_CurrentDate );
                    } else {
                        buildFullMonthViewDayEvents();
                        refreshOpenedViews();
                    }

                } else {
                    _element_Dialog_EventEditor_EventDetails.from = newFromDate;
                    _element_Dialog_EventEditor_EventDetails.to = newToDate;
                    _element_Dialog_EventEditor_EventDetails.repeatEnds = newRepeatEndsDate;
                    console.log("Debug: ignorefields:", { _element_Dialog_EventEditor_EventDetails });

                }
            };

            if ( _element_Dialog_EventEditor_ShowEditingRepeatSeriesWarning ) {
                showEventEditorDisabledArea();
                console.log("Debug: RepeatSeriesWarning:", { });
                var onNoEvent = function() {
                    hideEventEditorDisabledArea();
                    normalSave( _element_Dialog_EventEditor_EventDetails.id, fromDate, toDate, repeatEnds );
                    eventDialogEvent_Cancel();
                    console.log("Debug: onNoEvent normalSave:", { _element_Dialog_EventEditor_EventDetails, fromDate, toDate, repeatEnds });

                };

                var onYesEvent = function() {
                    var newFromDate = new Date( _element_Dialog_EventEditor_ShowEditingRepeatSeriesWarningDate ),
                        newToDate = new Date( _element_Dialog_EventEditor_ShowEditingRepeatSeriesWarningDate ),
                        newRepeatEndsDate = new Date( _element_Dialog_EventEditor_ShowEditingRepeatSeriesWarningDate );
                    console.log("Debug1: onYesEvent _element_Dialog_EventEditor_ShowEditingRepeatSeriesWarningDate:", { _element_Dialog_EventEditor_ShowEditingRepeatSeriesWarningDate});

                    hideEventEditorDisabledArea();
                    moveDateForwardDay( newRepeatEndsDate, -1 ); 
                    console.log("Debug1: onYesEvent normalSave:", { _element_Dialog_EventEditor_EventDetails, fromDate, toDate, newRepeatEndsDate });

                    normalSave( _element_Dialog_EventEditor_EventDetails.id, fromDate, toDate, newRepeatEndsDate, true );
                     console.log("Debug2: onYesEvent normalSave:", {  newFromDate, newToDate, repeatEnds});
                    normalSave( null, newFromDate, newToDate, repeatEnds );

                    eventDialogEvent_Cancel();
                };

                showMessageDialog( _options.confirmEventUpdateTitle, _options.confirmEventUpdateMessage, onYesEvent, onNoEvent, false, true, _options.forwardText, _options.seriesText );

            } else {
                console.log("Debug1: norepeatserieswarning normalSave:", { _element_Dialog_EventEditor_EventDetails, fromDate, toDate, repeatEnds});
                normalSave( _element_Dialog_EventEditor_EventDetails.id, fromDate, toDate, repeatEnds );
                eventDialogEvent_Cancel();
            }
        }
    }
}

Event add: {"event":{"from":"2023-12-01T08:00:00.000Z","to":"2023-12-01T08:30:00.000Z","title":"* New Event","description":"","location":"","group":"","isAllDay":false,"showAlerts":true,"showAsBusy":true,"color":null,"colorText":null,"colorBorder":null,"repeatEveryExcludeDays":[],"repeatEnds":null,"url":"","repeatEveryCustomValue":"","repeatEvery":0,"repeatEveryCustomType":0,"organizerName":"","organizerEmailAddress":"","type":0,"locked":false,"customTags":null,"alertOffset":0,"id":"acb0eeb9-c268-36e0-36ba-a2164a118c83","created":"2023-12-18T11:04:06.677Z","lastUpdated":"2023-12-18T11:04:06.677Z"}} planungs-kalender-mkg-uksh-kiel/:226 Event add response: Processing 1 event(s): Event erfolgreich hinzugefĂĽgt

calendar4.js:6710 Debug: Valid initial event details {fromTime: Array(2), toTime: Array(2), title: 'neu1', url: ''} calendar4.js:6721 Debug2: Valid initial event details {fromDate: Fri Dec 01 2023 02:00:00 GMT+0100 (Mitteleuropäische Normalzeit), toDate: Fri Dec 01 2023 02:00:00 GMT+0100 (Mitteleuropäische Normalzeit), title: 'neu1', url: ''} calendar4.js:6739 Debug: Preparing to save event {fromDate: Fri Dec 01 2023 02:00:00 GMT+0100 (Mitteleuropäische Normalzeit), toDate: Fri Dec 01 2023 02:00:00 GMT+0100 (Mitteleuropäische Normalzeit), description: '', location: '', group: '', …} calendar4.js:6870 Debug1: norepeatserieswarning normalSave: {_element_Dialog_EventEditor_EventDetails: {…}, fromDate: Fri Dec 01 2023 02:00:00 GMT+0100 (Mitteleuropäische Normalzeit), toDate: Fri Dec 01 2023 02:00:00 GMT+0100 (Mitteleuropäische Normalzeit), repeatEnds: Fri Dec 29 2023 02:00:00 GMT+0100 (Mitteleuropäische Normalzeit)} calendar4.js:6770 Debug: keine ignorefields {newEvent: {…}} calendar4.js:6804 Debug: isExistingEvent: {newEvent: {…}} planungs-kalender-mkg-uksh-kiel/:234 Event aktualisieren: {"event":{"from":"2023-12-01T08:00:00.000Z","to":"2023-12-01T08:30:00.000Z","title":"neu1","description":"","location":"","group":"","isAllDay":false,"showAlerts":true,"showAsBusy":true,"color":null,"colorText":null,"colorBorder":null,"repeatEveryExcludeDays":[6,0],"repeatEnds":"2023-12-29T01:00:00.000Z","url":"","repeatEveryCustomValue":1,"type":0,"customTags":null,"alertOffset":0,"repeatEvery":1,"repeatEveryCustomType":0,"id":"acb0eeb9-c268-36e0-36ba-a2164a118c83","created":"2023-12-18T11:04:26.201Z","lastUpdated":"2023-12-18T11:04:26.201Z"}} calendar4.js:6810 Debug: isExistingEvent update: {newId: 'acb0eeb9-c268-36e0-36ba-a2164a118c83', newEvent: {…}} planungs-kalender-mkg-uksh-kiel/:241 Event erfolgreich aktualisiert: Processing 1 event(s): Event erfolgreich aktualisiert

calendar4.js:6710 Debug: Valid initial event details {fromTime: Array(2), toTime: Array(2), title: 'neu1', url: ''}fromTime: (2) ['09', '00']title: "neu1"toTime: (2) ['10', '30']url: ""[[Prototype]]: Object calendar4.js:6721 Debug2: Valid initial event details {fromDate: Fri Dec 01 2023 02:00:00 GMT+0100 (Mitteleuropäische Normalzeit), toDate: Fri Dec 01 2023 02:00:00 GMT+0100 (Mitteleuropäische Normalzeit), title: 'neu1', url: ''}fromDate: Fri Dec 01 2023 02:00:00 GMT+0100 (Mitteleuropäische Normalzeit) {}[[Prototype]]: Objecttitle: "neu1"toDate: Fri Dec 01 2023 02:00:00 GMT+0100 (Mitteleuropäische Normalzeit) {}url: ""[[Prototype]]: Object calendar4.js:6739 Debug: Preparing to save event {fromDate: Fri Dec 01 2023 02:00:00 GMT+0100 (Mitteleuropäische Normalzeit), toDate: Fri Dec 01 2023 02:00:00 GMT+0100 (Mitteleuropäische Normalzeit), description: '', location: '', group: '', …}description: ""fromDate: Fri Dec 01 2023 02:00:00 GMT+0100 (Mitteleuropäische Normalzeit) {}group: ""location: ""repeatEnds: Fri Dec 29 2023 02:00:00 GMT+0100 (Mitteleuropäische Normalzeit) {}toDate: Fri Dec 01 2023 02:00:00 GMT+0100 (Mitteleuropäische Normalzeit) {}[[Prototype]]: Object calendar4.js:6840 Debug: RepeatSeriesWarning: {}[[Prototype]]: Objectconstructor: ƒ Object()hasOwnProperty: ƒ hasOwnProperty()isPrototypeOf: ƒ isPrototypeOf()propertyIsEnumerable: ƒ propertyIsEnumerable()toLocaleString: ƒ toLocaleString()toString: ƒ toString()valueOf: ƒ valueOf()defineGetter: ƒ defineGetter()defineSetter: ƒ defineSetter()lookupGetter: ƒ lookupGetter()lookupSetter: ƒ lookupSetter()proto: (...)get proto: ƒ proto()set proto: ƒ proto() calendar4.js:6853 Debug1: onYesEvent _element_Dialog_EventEditor_ShowEditingRepeatSeriesWarningDate: {_element_Dialog_EventEditor_ShowEditingRepeatSeriesWarningDate: Wed Jan 11 2023 00:00:00 GMT+0100 (Mitteleuropäische Normalzeit)}_element_Dialog_EventEditor_ShowEditingRepeatSeriesWarningDate: Wed Jan 11 2023 00:00:00 GMT+0100 (Mitteleuropäische Normalzeit)[[Prototype]]: Object[[Prototype]]: Object calendar4.js:6857 Debug1: onYesEvent normalSave: {_element_Dialog_EventEditor_EventDetails: {…}, fromDate: Fri Dec 01 2023 02:00:00 GMT+0100 (Mitteleuropäische Normalzeit), toDate: Fri Dec 01 2023 02:00:00 GMT+0100 (Mitteleuropäische Normalzeit), newRepeatEndsDate: Tue Jan 10 2023 00:00:00 GMT+0100 (Mitteleuropäische Normalzeit)} calendar4.js:6833 Debug: ignorefields: {_element_Dialog_EventEditor_EventDetails: {…}} calendar4.js:6860 Debug2: onYesEvent normalSave: {newFromDate: Wed Jan 11 2023 00:00:00 GMT+0100 (Mitteleuropäische Normalzeit), newToDate: Wed Jan 11 2023 00:00:00 GMT+0100 (Mitteleuropäische Normalzeit), repeatEnds: Fri Dec 29 2023 02:00:00 GMT+0100 (Mitteleuropäische Normalzeit)} calendar4.js:6770 Debug: keine ignorefields {newEvent: {…}} calendar4.js:6799 Debug: !isExistingEvent: {newEvent: {…}} planungs-kalender-mkg-uksh-kiel/:219 Event add: {"event":{"from":"2023-01-11T08:00:00.000Z","to":"2023-01-11T09:30:00.000Z","title":"neu1","description":"","location":"","group":"","isAllDay":false,"showAlerts":true,"showAsBusy":true,"color":null,"colorText":null,"colorBorder":null,"repeatEveryExcludeDays":[6,0],"repeatEnds":"2023-12-29T01:00:00.000Z","url":"","repeatEveryCustomValue":1,"type":0,"customTags":null,"alertOffset":0,"repeatEvery":1,"repeatEveryCustomType":0,"organizerName":"","organizerEmailAddress":"","id":"dcbc633b-3b6c-92ff-1acd-50b88928b53f","created":"2023-12-18T11:05:41.131Z","lastUpdated":"2023-12-18T11:05:41.131Z"}} calendar4.js:6816 Uncaught ReferenceError: newfromDate is not defined at normalSave (calendar4.js:6816:85) at HTMLInputElement.onYesEvent (calendar4.js:6861:25) normalSave @ calendar4.js:6816 onYesEvent @ calendar4.js:6861 planungs-kalender-mkg-uksh-kiel/:226 Event add response: Processing 1 event(s): Event erfolgreich hinzugefügt

CedricHH commented 8 months ago

First this line keeps me wondering: var onYesEvent = function() { var newFromDate = new Date( _element_Dialog_EventEditor_ShowEditingRepeatSeriesWarningDate ), //What kind of date is this? by debugging it shows like 11/01/23 newToDate = new Date( _element_Dialog_EventEditor_ShowEditingRepeatSeriesWarningDate ), newRepeatEndsDate = new Date( _element_Dialog_EventEditor_ShowEditingRepeatSeriesWarningDate );

                    hideEventEditorDisabledArea();
                    moveDateForwardDay( newRepeatEndsDate, -1 );
                    normalSave( _element_Dialog_EventEditor_EventDetails.id, fromDate, toDate, newRepeatEndsDate, true );
                    normalSave( null, newFromDate, newToDate, repeatEnds );
                    eventDialogEvent_Cancel();
                };_element_Dialog_EventEditor_ShowEditingRepeatSeriesWarningDate: {_element_Dialog_EventEditor_ShowEditingRepeatSeriesWarningDate: Wed Jan 11 2023 00:00:00 GMT+0100 (Mitteleuropäische Normalzeit)}_element_Dialog_EventEditor_ShowEditingRepeatSeriesWarningDate: Wed Jan 11 2023 00:00:00 GMT+0100 (Mitteleuropäische Normalzeit)[[Prototype]]: Object[[Prototype]]: Object
CedricHH commented 8 months ago

_element_Dialog_EventEditor_ShowEditingRepeatSeriesWarningDate seems not to work for every click, sometime it gets a wrong date