diff --git a/core/modules/edit/js/views/AppView.js b/core/modules/edit/js/views/AppView.js
index ae4f16c..e0b16f2 100644
--- a/core/modules/edit/js/views/AppView.js
+++ b/core/modules/edit/js/views/AppView.js
@@ -317,34 +317,11 @@ 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')) {
- discardDialog = Drupal.dialog('
' + Drupal.t('You have unsaved changes') + '
', {
+ var that = this;
+
+ var discardDialog = Drupal.dialog('' + Drupal.t('You have unsaved changes') + '
', {
title: Drupal.t('Discard changes?'),
dialogClass: 'edit-discard-modal',
resizable: false,
@@ -352,13 +329,13 @@ Drupal.edit.AppView = Backbone.View.extend({
{
text: Drupal.t('Save'),
click: function() {
- closeDiscardDialog('save');
+ discardDialog.close('save');
}
},
{
text: Drupal.t('Discard changes'),
click: function() {
- closeDiscardDialog('discard');
+ discardDialog.close('discard');
}
}
],
@@ -372,6 +349,32 @@ 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();
}
},