mirror of
https://gerrit.wikimedia.org/r/mediawiki/extensions/DiscussionTools
synced 2024-11-27 09:43:30 +00:00
Prompt users when pressing 'cancel' with content in the widget
And actually discard the contents when they confirm. For now this uses the generic editor message, but that can be tweaked later. Bug: T240271 Change-Id: I2dfa19b2cc7ac49d7efea37ac8c9429c75934a91
This commit is contained in:
parent
179b29a598
commit
49edbb82ab
|
@ -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