mirror of
https://gerrit.wikimedia.org/r/mediawiki/extensions/DiscussionTools
synced 2024-11-28 02:00:57 +00:00
Merge "Prompt users when pressing 'cancel' with content in the widget"
This commit is contained in:
commit
2680307b37
|
@ -95,7 +95,8 @@
|
|||
"oojs-ui-core",
|
||||
"mediawiki.editfont.styles",
|
||||
"mediawiki.user",
|
||||
"mediawiki.jqueryMsg"
|
||||
"mediawiki.jqueryMsg",
|
||||
"mediawiki.widgets.AbandonEditDialog"
|
||||
]
|
||||
}
|
||||
},
|
||||
|
|
|
@ -45,7 +45,7 @@ function ReplyWidget( comment, config ) {
|
|||
|
||||
// Events
|
||||
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.beforeUnloadHandler = this.onBeforeUnload.bind( this );
|
||||
|
||||
|
@ -101,10 +101,25 @@ ReplyWidget.prototype.setup = function () {
|
|||
this.bindBeforeUnloadHandler();
|
||||
};
|
||||
|
||||
ReplyWidget.prototype.teardown = function () {
|
||||
// TODO: OOUI prompt if !empty
|
||||
this.unbindBeforeUnloadHandler();
|
||||
this.emit( 'teardown' );
|
||||
ReplyWidget.prototype.teardown = function ( confirm ) {
|
||||
var promise,
|
||||
widget = this;
|
||||
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 () {
|
||||
|
@ -239,4 +254,8 @@ ReplyWidget.prototype.onReplyClick = function () {
|
|||
} );
|
||||
};
|
||||
|
||||
/* Window registration */
|
||||
|
||||
OO.ui.getWindowManager().addWindows( [ new mw.widgets.AbandonEditDialog() ] );
|
||||
|
||||
module.exports = ReplyWidget;
|
||||
|
|
Loading…
Reference in a new issue