/** The deadline management methods for StudentsManager.
 *
 * Note that this class depends on createRecordFromStoreRecord(),
 * onSelectNone() and loadFirstPage() from StudentsManager to be available. */
Ext.define('devilry.extjshelpers.studentsmanager.StudentsManagerManageDeadlines', {
    requires: [
        'devilry.extjshelpers.assignmentgroup.MultiCreateNewDeadlineWindow'
    ],

    /**
     * @private
     */
    onAddDeadline: function() {
        //this.down('studentsmanager_studentsgrid').selModel.selectAll();
        if(this.noneSelected()) {
            this.onSelectNone();
            return;
        }
        var me = this;
        var createDeadlineWindow = Ext.widget('multicreatenewdeadlinewindow', {
            deadlinemodel: this.deadlinemodel,
            onSaveSuccess: function(record) {
                this.close();
                me.addDeadlineToSelected(record);
            }
        });
        createDeadlineWindow.show();
    },

    /**
     * @private
     */
    addDeadlineToSelected: function(record) {
        this.down('studentsmanager_studentsgrid').performActionOnSelected({
            scope: this,
            callback: this.addDeadline,
            extraArgs: [record]
        });
    },

    /**
     * @private
     */
    addDeadline: function(assignmentGroupRecord, index, total, deadlineRecord) {
        var msg = Ext.String.format('Adding deadline to group {0}/{1}', index, total);
        this.getEl().mask(msg);

        var newDeadlineRecord = Ext.ModelManager.create(deadlineRecord.data, this.deadlinemodel);
        newDeadlineRecord.data.assignment_group = assignmentGroupRecord.data.id;
        newDeadlineRecord.save({
            failure: function() {
                console.error('Failed to save record');
            }
        });

        if(index == total) {
            this.loadFirstPage();
            this.getEl().unmask();
        }
    }
});

@@ -1464,24 +1464,311 @@
 mask(msg);%0A%0A
+        this.createDeadline(assignmentGroupRecord, deadlineRecord);%0A%0A        if(index == total) %7B%0A            this.loadFirstPage();%0A            this.getEl().unmask();%0A        %7D%0A    %7D,%0A%0A    /**%0A     * @private%0A     */%0A    createDeadline: function(assignmentGroupRecord, deadlineRecord) %7B%0A
         var 
@@ -2086,117 +2086,8 @@
  %7D);
-%0A%0A        if(index == total) %7B%0A            this.loadFirstPage();%0A            this.getEl().unmask();%0A        %7D
 %0A   

Create deadline in separate method.