summaryrefslogtreecommitdiff
diff options
context:
space:
mode:
Diffstat (limited to 'MLEB/Translate/resources/js/ext.translate.proofread.js')
-rw-r--r--MLEB/Translate/resources/js/ext.translate.proofread.js65
1 files changed, 40 insertions, 25 deletions
diff --git a/MLEB/Translate/resources/js/ext.translate.proofread.js b/MLEB/Translate/resources/js/ext.translate.proofread.js
index cac69e6d..9c5f00fc 100644
--- a/MLEB/Translate/resources/js/ext.translate.proofread.js
+++ b/MLEB/Translate/resources/js/ext.translate.proofread.js
@@ -1,4 +1,3 @@
-/*global alert: false*/
( function ( $, mw ) {
'use strict';
@@ -15,6 +14,12 @@
* sourcelangcode: 'en', // Mandatory source language code
* targetlangcode: 'hi' // Mandatory target language code
* } );
+ *
+ * @param {Element} element
+ * @param {Object} options
+ * @param {Object} options.message
+ * @param {string} options.sourcelangcode Language code.
+ * @param {string} options.targetlangcode Language code.
*/
function Proofread( element, options ) {
this.$message = $( element );
@@ -33,6 +38,7 @@
var proofread = this;
this.render();
+
// No review before translating.
if ( !this.message.translation ) {
this.disableProofread();
@@ -54,12 +60,10 @@
.text( translation );
proofread.message.translation = translation;
proofread.markSelfTranslation();
- // Update stats - to translated state from current state.
- $( '.tux-action-bar .tux-statsbar' )
- .trigger(
- 'change',
- [ 'translated', proofread.message.properties.status ]
- );
+
+ proofread.$message.find( '.tux-proofread-status' )
+ .removeClass( 'translated fuzzy proofread untranslated' )
+ .addClass( proofread.message.properties.status );
}
} );
@@ -72,15 +76,17 @@
translatedBySelf, proofreadBySelf;
// List of all reviewers
- reviewers = $( this.message.properties.reviewers );
+ reviewers = this.message.properties.reviewers || [];
// The id of the current user, converted to string as the are in reviewers
- userId = mw.config.get( 'wgUserId' ) + '';
+ userId = String( mw.config.get( 'wgUserId' ) );
// List of all reviewers excluding the current user.
- otherReviewers = reviewers.not( [userId] );
+ otherReviewers = reviewers.filter( function ( element ) {
+ return element !== userId;
+ } );
/* Whether the current user if the last translator of this message.
* Accepting own translations is prohibited. */
- translatedBySelf = ( this.message.properties['last-translator-text'] === mw.user.getName() );
- proofreadBySelf = $.inArray( userId, reviewers ) > -1;
+ translatedBySelf = ( this.message.properties[ 'last-translator-text' ] === mw.user.getName() );
+ proofreadBySelf = reviewers.indexOf( userId ) > -1;
sourceLangCode = this.options.sourcelangcode;
sourceLangDir = $.uls.data.getDir( sourceLangCode );
@@ -91,8 +97,7 @@
.attr( 'title', mw.msg( 'tux-proofread-action-tooltip' ) )
.addClass(
'tux-proofread-action ' + this.message.properties.status + ' ' + ( proofreadBySelf ? 'accepted' : '' )
- )
- .tipsy( { gravity: 's', delayIn: 1000, className: 'translate-tipsy' } );
+ );
$proofreadEdit = $( '<div>' )
.addClass( 'tux-proofread-edit' )
@@ -147,8 +152,13 @@
$proofreadEdit
)
)
- )
- .addClass( this.message.properties.status );
+ ).addClass( this.message.properties.status );
+
+ if ( !translatedBySelf && !proofreadBySelf ) {
+ // This will get removed later if any of various other reasons prevent it
+ this.message.proofreadable = true;
+ this.message.proofreadAction = this.proofread.bind( this );
+ }
if ( translatedBySelf ) {
this.markSelfTranslation();
@@ -162,6 +172,7 @@
},
disableProofread: function () {
+ this.message.proofreadable = false;
this.$message.find( '.tux-proofread-action' )
.remove();
},
@@ -178,7 +189,6 @@
.append( $( '<div>' )
.addClass( 'translated-by-self' )
.attr( 'title', mw.msg( 'tux-proofread-translated-by-self' ) )
- .tipsy( { gravity: 'e', className: 'translate-tipsy' } )
);
}
},
@@ -188,19 +198,22 @@
proofread: function () {
var reviews, counter, params,
message = this.message,
- $message = this.$message;
+ $message = this.$message,
+ api = new mw.Api();
params = {
action: 'translationreview',
- revision: this.message.properties.revision,
+ revision: this.message.properties.revision
};
if ( !mw.user.isAnon() ) {
params.assert = 'user';
}
- new mw.Api().postWithToken( 'translationreview', params ).done( function () {
- $message.find( '.tux-proofread-action' ).addClass( 'accepted' );
+ api.postWithToken( 'csrf', params ).done( function () {
+ $message.find( '.tux-proofread-action' )
+ .removeClass( 'tux-warning' ) // in case, it failed previously
+ .addClass( 'accepted' );
counter = $message.find( '.tux-proofread-count' );
reviews = counter.data( 'reviewCount' );
@@ -212,13 +225,15 @@
[ 'proofread', message.properties.status ]
);
+ message.properties.status = 'proofread';
+
if ( mw.track ) {
mw.track( 'ext.translate.event.proofread', message );
}
} ).fail( function ( errorCode ) {
$message.find( '.tux-proofread-action' ).addClass( 'tux-warning' );
- // In MW 1.24 alpha postWithToken returns token-missing instead of assertuserfailed
- if ( errorCode === 'assertuserfailed' || errorCode === 'token-missing' ) {
+ if ( errorCode === 'assertuserfailed' ) {
+ // eslint-disable-next-line no-alert
alert( mw.msg( 'tux-session-expired' ) );
}
} );
@@ -236,8 +251,8 @@
} );
this.$message.find( '.tux-proofread-edit' ).on( 'click', function () {
- // Make sure that the tipsy is hidden when going to the editor
- $( '.translate-tipsy' ).remove();
+ // Make sure that the tooltip is hidden when going to the editor
+ $( '.translate-tooltip' ).remove();
proofread.$message.data( 'translateeditor' ).show();
return false;