2

I am currently developing a calendar where activities can be drag&dropped to other days. When an activity is dropped into a different day, I show a custom modal using durandal's dialog plugin. The problem is when an user closes the modal, the activity has to revert to its original position. When an activity is dropped the following code is called:

function showDroppedActivityModal(obj) {
    require(['modals/droppedActivityModal/droppedActivityModal', 'moment'], function(droppedActivityModal, moment) {
        droppedActivityModal.show(obj).then(function(response) {
            if(response !== false) {
                ...
            }
            // dialog closes
            else {
                calendarView.revertActivity.notify({ revert: true})
            }
        });
    });
}

In my calendarView I implemented the revertActivity event to set revert to true but the function never re-evaluates itself but i'm able to receive the new revert value (true).

$(activity).draggable({
    revert: function() {
        var revert = false;
        self.revertActivity.attach(function(sender, args) {
            revert = args.revert;
        });
        return revert;
    }
});

Custom event code:

function CalendarEvent(sender) {
    this._sender = sender;
    this._listeners = [];
}

CalendarEvent.prototype = {
    attach : function (listener) {
        this._listeners.push(listener);
    },

    notify : function (args) {
        var index;
        for (index = 0; index < this._listeners.length; index += 1) {
            this._listeners[index](this._sender, args);
        }
    },

    remove : function (listener){
        this._listeners.remove(listener);
    }
};

this.revertActivity = new CalendarEvent(this);
Stvenoo
  • 67
  • 5
  • Just as an 'aside', have a look at this: http://arshaw.com/fullcalendar/ If it does what you want there's no point inventing the wheel. –  May 21 '14 at 10:12

0 Answers0