summaryrefslogtreecommitdiff
diff options
context:
space:
mode:
Diffstat (limited to 'MLEB/Translate/resources/js/ext.translate.special.managegroups.js')
-rw-r--r--MLEB/Translate/resources/js/ext.translate.special.managegroups.js139
1 files changed, 130 insertions, 9 deletions
diff --git a/MLEB/Translate/resources/js/ext.translate.special.managegroups.js b/MLEB/Translate/resources/js/ext.translate.special.managegroups.js
index 9d727adf..9337ed5f 100644
--- a/MLEB/Translate/resources/js/ext.translate.special.managegroups.js
+++ b/MLEB/Translate/resources/js/ext.translate.special.managegroups.js
@@ -1,10 +1,13 @@
( function () {
- var RenameDropdown;
+ var RenameDropdown,
+ GroupSynchronization;
$( function () {
var windowManager, renameDialog;
RenameDropdown.init();
+ GroupSynchronization.init();
+
// Create and append a window manager.
windowManager = new OO.ui.WindowManager();
windowManager.$element.appendTo( document.body );
@@ -45,6 +48,7 @@
} ).show();
if ( $parentContainer.hasClass( 'smg-change-addition' ) ) {
+ // For a new message, the "add as new" option is hidden.
RenameDropdown.hideOption( '.smg-rename-new-action' );
}
event.preventDefault();
@@ -121,10 +125,11 @@
function toggleLoading( $element, isLoading ) {
if ( isLoading ) {
- $( '.smg-rename-actions' ).hide();
- $element.show().addClass( 'loading' );
+ // hide all the rename buttons, but show the current one with loading animation
+ $( '.smg-rename-actions' ).addClass( 'mw-translate-hide' );
+ $element.removeClass( 'mw-translate-hide' ).addClass( 'loading' );
} else {
- $( '.smg-rename-actions' ).show();
+ $( '.smg-rename-actions' ).removeClass( 'mw-translate-hide' );
$element.removeClass( 'loading' );
}
}
@@ -264,13 +269,13 @@
var $addAsRename = $( '<li>' ).append(
$( '<button>' )
.attr( 'type', 'button' )
- .addClass( 'smg-rename-new-action' )
+ .addClass( 'smg-rename-new-action mw-translate-hide' )
.text( mw.msg( 'translate-smg-rename-new' ) )
),
$addAsNew = $( '<li>' ).append(
$( '<button>' )
.attr( 'type', 'button' )
- .addClass( 'smg-rename-rename-action' )
+ .addClass( 'smg-rename-rename-action mw-translate-hide' )
.text( mw.msg( 'translate-smg-rename-rename' ) )
);
@@ -316,8 +321,9 @@
left: $currentTarget.position().left - $renameMenu.width() + $currentTarget.width()
} ).data( 'custom-data', customData );
- // show all the li's
- $renameMenu.find( 'li' ).show();
+ // When appending, show all the li's by default since based on the
+ // message type (RENAME / NEW) some li's may be hidden previously
+ $renameMenu.find( 'li' ).removeClass( 'mw-translate-hide' );
return this;
}
@@ -337,7 +343,7 @@
* @chainable
*/
function hideOption( optSelector ) {
- $renameMenu.find( optSelector ).parent().hide();
+ $renameMenu.find( optSelector ).parent().addClass( 'mw-translate-hide' );
return this;
}
@@ -350,4 +356,119 @@
hideOption: hideOption
};
}() );
+
+ GroupSynchronization = ( function () {
+ function init() {
+ $( '.js-group-sync-message-resolve' ).on( 'click', markMessageAsResolved );
+ $( '.js-group-sync-group-resolve' ).on( 'click', markGroupAsResolved );
+ }
+
+ function markMessageAsResolved() {
+ var $target = $( this ),
+ groupId = $target.data( 'groupId' ),
+ messageTitle = $target.data( 'msgTitle' );
+
+ showLoading( $target );
+
+ markAsResolved( 'resolveMessage', groupId, messageTitle ).done( function ( response ) {
+ var responseData = response.managegroupsynchronizationcache || null;
+ if ( responseData && responseData.success ) {
+ if ( responseData.data.groupRemainingMessageCount === 0 ) {
+ removeParentGroupBlock( $target );
+ } else {
+ // Remove the message from the DOM
+ $target.parents( '.js-group-sync-message-error' ).remove();
+ }
+ }
+ } ).fail( function ( code, result ) {
+ handleResolutionFailure( code, result, groupId, messageTitle );
+ } ).always( function () {
+ hideLoading( $target );
+ } );
+ }
+
+ function markGroupAsResolved() {
+ var $target = $( this ),
+ groupId = $target.data( 'groupId' );
+
+ showLoading( $target );
+
+ markAsResolved( 'resolveGroup', groupId ).done( function ( response ) {
+ var responseData = response.managegroupsynchronizationcache || null;
+ if ( responseData && responseData.success ) {
+ removeParentGroupBlock( $target );
+ }
+ } ).fail( function ( code, result ) {
+ handleResolutionFailure( code, result, groupId );
+ } ).always( function () {
+ hideLoading( $target );
+ } );
+ }
+
+ function markAsResolved( operation, groupId, messageTitle ) {
+ var params, api = new mw.Api();
+
+ params = {
+ action: 'managegroupsynchronizationcache',
+ group: groupId,
+ operation: operation,
+ assert: 'user',
+ formatversion: 2
+ };
+
+ if ( messageTitle ) {
+ params.title = messageTitle;
+ }
+
+ return api.postWithToken( 'csrf', params );
+ }
+
+ function removeParentGroupBlock( $child ) {
+ // Remove the entire group block from DOM
+ $child.parents( '.js-group-sync-group-errors' ).remove();
+ // If all groups are resolved, remove the group sync error block
+ if ( !$( '.js-group-sync-group-errors' ).length ) {
+ $( '.js-group-sync-groups-with-error' ).remove();
+ }
+ }
+
+ function handleResolutionFailure( code, result, groupId, messageTitle ) {
+ var errorInfo = result && result.error ? result.error.info : null;
+ if ( errorInfo ) {
+ mw.notify( result.error.info, {
+ type: 'error',
+ tag: 'new-error'
+ } );
+ } else {
+ // Unknown error
+ mw.notify( mw.msg( 'translate-smg-unknown-error' ), {
+ type: 'error',
+ tag: 'new-error'
+ } );
+ }
+
+ mw.log.error( 'Error while resolving group or message. Param: ' + JSON.stringify( {
+ groupId: groupId,
+ messageTitle: messageTitle,
+ errorCode: code,
+ errorInfo: errorInfo
+ } ) );
+ }
+
+ function showLoading( $target ) {
+ $target.addClass( 'loading' )
+ .text( mw.msg( 'translate-smg-loading' ) )
+ .removeAttr( 'href' );
+ }
+
+ function hideLoading( $target ) {
+ $target.removeClass( 'loading' )
+ .text( mw.msg( 'translate-smg-group-action-resolve' ) )
+ .prop( 'href', '#' );
+ }
+
+ return {
+ init: init
+ };
+ }() );
}() );