Florianschmidtwelzow has uploaded a new change for review.
https://gerrit.wikimedia.org/r/189212
Change subject: Improvements for answer feature in TalkSectionOverlay
......................................................................
Improvements for answer feature in TalkSectionOverlay
* Reload the discussion after a comment was added
* Show error message, if save failed
* Show a loadingOverlay while the answer is saved
Change-Id: Id38a9f170dc052cd9e43c3ba014aa03285f1e659
---
M includes/Resources.php
M javascripts/modules/talk/TalkSectionOverlay.js
2 files changed, 61 insertions(+), 18 deletions(-)
git pull ssh://gerrit.wikimedia.org:29418/mediawiki/extensions/MobileFrontend
refs/changes/12/189212/1
diff --git a/includes/Resources.php b/includes/Resources.php
index 3695b23..a29b182 100644
--- a/includes/Resources.php
+++ b/includes/Resources.php
@@ -663,6 +663,8 @@
'mobile-frontend-editor-cancel-confirm',
'mobile-frontend-editor-licensing',
'mobile-frontend-editor-licensing-with-terms',
+ 'mobile-frontend-editor-error',
+ 'mobile-frontend-editor-error-conflict',
),
),
diff --git a/javascripts/modules/talk/TalkSectionOverlay.js
b/javascripts/modules/talk/TalkSectionOverlay.js
index f3d759e..b8b152c 100644
--- a/javascripts/modules/talk/TalkSectionOverlay.js
+++ b/javascripts/modules/talk/TalkSectionOverlay.js
@@ -7,6 +7,8 @@
Page = M.require( 'Page' ),
pageApi = M.require( 'pageApi' ),
context = M.require( 'context' ),
+ LoadingOverlay = M.require( 'LoadingOverlay' ),
+ loadingOverlay = new LoadingOverlay(),
TalkSectionOverlay;
/**
@@ -47,19 +49,26 @@
* @inheritdoc
*/
postRender: function ( options ) {
- var self = this;
-
Overlay.prototype.postRender.apply( this, arguments );
if ( !options.section ) {
- pageApi.getPage( options.title ).done( function
( pageData ) {
- var page = new Page( pageData );
- options.section = page.getSection(
options.id );
- self.render( options );
- } );
+ this.renderFromApi( options );
} else {
this.$( '.loading' ).remove();
this._enableComments();
}
+ },
+ /**
+ * @inheritdoc
+ */
+ showSpinner: function () {
+ loadingOverlay.show();
+ },
+ /**
+ * @inheritdoc
+ */
+ clearSpinner: function () {
+ loadingOverlay.hide();
+ this.show();
},
/**
* Enables comments on the current rendered talk topic
@@ -75,6 +84,20 @@
}
},
/**
+ * Loads the discussion from api and add it to the Overlay
+ * @param {Object} options Render options
+ */
+ renderFromApi: function ( options ) {
+ var self = this;
+
+ pageApi.getPage( options.title ).done( function (
pageData ) {
+ var page = new Page( pageData );
+ options.section = page.getSection( options.id );
+ self.render( options );
+ self.clearSpinner();
+ } );
+ },
+ /**
* Handler for focus of textarea
*/
onFocusTextarea: function () {
@@ -88,8 +111,8 @@
self = this;
if ( val ) {
- this.$commentbox.hide();
- this.$( '.loading' ).show();
+ // show a spinner
+ this.showSpinner();
// sign and add newline to front
val = '\n\n' + val + ' ~~~~';
api.postWithToken( 'edit', {
@@ -97,17 +120,35 @@
title: this.options.title,
section: this.options.id,
appendtext: val
- } ).done( function ( data ) {
- self.$( '.loading' ).hide();
- self.$commentbox.show();
- if ( data.error ) {
- self.$textarea.addClass(
'error' );
+ } ).done( function () {
+ popup.show( mw.msg(
'mobile-frontend-talk-reply-success' ), 'toast' );
+ // invalidate the cache
+ pageApi.invalidatePage(
self.options.title );
+
+ self.renderFromApi( self.options );
+ } ).fail( function ( data, response ) {
+ // FIXME: Code sharing with
EditorOverlay?
+ var msg,
+ // When save failed with one of
these error codes, the returned
+ // message in
response.error.info will be forwarded to the user.
+ // FIXME: This shouldn't be
needed when info texts are all localized.
+ whitelistedErrorInfo = [
+ 'readonly',
+ 'blocked',
+ 'autoblocked'
+ ];
+
+ if (
+ response.error &&
+ $.inArray( response.error.code,
whitelistedErrorInfo ) > -1
+ ) {
+ msg = response.error.info;
} else {
- self.hide();
- popup.show( mw.msg(
'mobile-frontend-talk-reply-success' ), 'toast' );
- // invalidate the cache
- pageApi.invalidatePage(
self.title );
+ msg = mw.msg(
'mobile-frontend-editor-error' );
}
+
+ self.clearSpinner();
+ popup.show( msg, 'toast error' );
} );
} else {
this.$textarea.addClass( 'error' );
--
To view, visit https://gerrit.wikimedia.org/r/189212
To unsubscribe, visit https://gerrit.wikimedia.org/r/settings
Gerrit-MessageType: newchange
Gerrit-Change-Id: Id38a9f170dc052cd9e43c3ba014aa03285f1e659
Gerrit-PatchSet: 1
Gerrit-Project: mediawiki/extensions/MobileFrontend
Gerrit-Branch: master
Gerrit-Owner: Florianschmidtwelzow <[email protected]>
_______________________________________________
MediaWiki-commits mailing list
[email protected]
https://lists.wikimedia.org/mailman/listinfo/mediawiki-commits