Merge "Prompt users when pressing 'cancel' with content in the widget"

This commit is contained in:
jenkins-bot 2019-12-13 19:00:41 +00:00 committed by Gerrit Code Review
commit 2680307b37
2 changed files with 26 additions and 6 deletions

View file

@ -95,7 +95,8 @@
"oojs-ui-core", "oojs-ui-core",
"mediawiki.editfont.styles", "mediawiki.editfont.styles",
"mediawiki.user", "mediawiki.user",
"mediawiki.jqueryMsg" "mediawiki.jqueryMsg",
"mediawiki.widgets.AbandonEditDialog"
] ]
} }
}, },

View file

@ -45,7 +45,7 @@ function ReplyWidget( comment, config ) {
// Events // Events
this.replyButton.connect( this, { click: 'onReplyClick' } ); this.replyButton.connect( this, { click: 'onReplyClick' } );
this.cancelButton.connect( this, { click: 'teardown' } ); this.cancelButton.connect( this, { click: [ 'teardown', true ] } );
this.$element.on( 'keydown', this.onKeyDown.bind( this ) ); this.$element.on( 'keydown', this.onKeyDown.bind( this ) );
this.beforeUnloadHandler = this.onBeforeUnload.bind( this ); this.beforeUnloadHandler = this.onBeforeUnload.bind( this );
@ -101,10 +101,25 @@ ReplyWidget.prototype.setup = function () {
this.bindBeforeUnloadHandler(); this.bindBeforeUnloadHandler();
}; };
ReplyWidget.prototype.teardown = function () { ReplyWidget.prototype.teardown = function ( confirm ) {
// TODO: OOUI prompt if !empty var promise,
this.unbindBeforeUnloadHandler(); widget = this;
this.emit( 'teardown' ); if ( confirm && !this.isEmpty() ) {
// TODO: Override messages in dialog to be more ReplyWidget specific
promise = OO.ui.getWindowManager().openWindow( 'abandonedit' )
.closed.then( function ( data ) {
if ( !( data && data.action === 'discard' ) ) {
return $.Deferred().reject().promise();
}
} );
} else {
promise = $.Deferred().resolve().promise();
}
promise.then( function () {
widget.unbindBeforeUnloadHandler();
widget.clear();
widget.emit( 'teardown' );
} );
}; };
ReplyWidget.prototype.focus = function () { ReplyWidget.prototype.focus = function () {
@ -239,4 +254,8 @@ ReplyWidget.prototype.onReplyClick = function () {
} ); } );
}; };
/* Window registration */
OO.ui.getWindowManager().addWindows( [ new mw.widgets.AbandonEditDialog() ] );
module.exports = ReplyWidget; module.exports = ReplyWidget;