diff --git a/core/modules/edit/js/views/AppView.js b/core/modules/edit/js/views/AppView.js index e0b16f2..ae4f16c 100644 --- a/core/modules/edit/js/views/AppView.js +++ b/core/modules/edit/js/views/AppView.js @@ -317,11 +317,34 @@ Drupal.edit.AppView = Backbone.View.extend({ * @see acceptEditorStateChange() */ confirmEntityDeactivation: function (entityModel) { + var that = this; + var discardDialog; + + function closeDiscardDialog (value) { + discardDialog.close(value); + // The active modal has been removed. + that.model.set('activeModal', null); + + // If the targetState is saving, the field must be saved, then the + // entity must be saved. + if (discardDialog.returnValue === 'save') { + entityModel.set('state', 'committing', {confirmed : true}); + } + else { + entityModel.set('state', 'deactivating', {confirmed : true}); + // Editing has been canceled and the changes will not be saved. Mark + // the page for reload if the entityModel declares that it requires + // a reload. + if (entityModel.get('reload')) { + reload = true; + entityModel.set('reload', false); + } + } + } + // Only instantiate if there isn't a modal instance visible yet. if (!this.model.get('activeModal')) { - var that = this; - - var discardDialog = Drupal.dialog('
' + Drupal.t('You have unsaved changes') + '
', { + discardDialog = Drupal.dialog('
' + Drupal.t('You have unsaved changes') + '
', { title: Drupal.t('Discard changes?'), dialogClass: 'edit-discard-modal', resizable: false, @@ -329,13 +352,13 @@ Drupal.edit.AppView = Backbone.View.extend({ { text: Drupal.t('Save'), click: function() { - discardDialog.close('save'); + closeDiscardDialog('save'); } }, { text: Drupal.t('Discard changes'), click: function() { - discardDialog.close('discard'); + closeDiscardDialog('discard'); } } ], @@ -349,32 +372,6 @@ Drupal.edit.AppView = Backbone.View.extend({ }); this.model.set('activeModal', discardDialog); - $(window).on('dialog:afterclose.edit', function (event, dialog, $element) { - if (discardDialog === dialog) { - // The active modal has been removed. - that.model.set('activeModal', null); - - var action = dialog.returnValue; - // If the targetState is saving, the field must be saved, then the - // entity must be saved. - if (action === 'save') { - entityModel.set('state', 'committing', {confirmed : true}); - } - else { - entityModel.set('state', 'deactivating', {confirmed : true}); - // Editing has been canceled and the changes will not be saved. Mark - // the page for reload if the entityModel declares that it requires - // a reload. - if (entityModel.get('reload')) { - reload = true; - entityModel.set('reload', false); - } - } - - $(window).off('dialog:afterclose.edit'); - } - }); - discardDialog.showModal(); } },