' )
.addClass( 'tux-message-filter-result' )
.append( $note, $button );
this.$container.prepend( $result );
}
if ( !query ) {
$result.addClass( 'hide' );
} else {
$result.removeClass( 'hide' )
.find( '.advanced-search' )
.text( mw.msg( 'tux-message-filter-result', resultCount, query ) );
$result.find( 'button' ).on( 'click', function () {
window.location.href = mw.util.getUrl( 'Special:SearchTranslations', { query: query } );
} );
}
this.updateLastMessage();
// Trigger a scroll event for the window to make sure all floating toolbars
// are in their position.
$( window ).trigger( 'scroll' );
},
resize: function () {
var actualWidth = 0;
// Calculate the total width required for the filters
$( '.row.tux-message-selector > li' ).each( function () {
actualWidth += $( this ).outerWidth( true );
} );
// Grid row has a min width. After that scrollbars will appear.
// We are checking whether the message table is wider than the current grid row width.
if ( actualWidth >= parseInt( $( '.nine.columns' ).width(), 10 ) ) {
$( '.tux-message-selector .more ul' ) // Overflow menu
.prepend( $( '.row.tux-message-selector > li.column:last' ).prev() );
// See if more items to be pushed to the overflow menu
this.resize();
}
},
/**
* Start loading messages again with new settings.
*
* @param {Object} changes
*/
changeSettings: function ( changes ) {
// Clear current messages
this.clear();
this.settings = $.extend( this.settings, changes );
if ( this.initialized === false ) {
this.switchMode( this.mode );
}
// Reset the number of messages remaining
this.$loaderInfo.text(
mw.msg( 'tux-messagetable-loading-messages', this.$loader.data( 'pagesize' ) )
);
// Reset the statsbar
this.$statsBar
.empty()
.removeData()
.languagestatsbar( {
language: this.settings.language,
group: this.settings.group
} );
this.initialized = true;
// Reset other info and make visible
this.$loader
.removeData( 'offset' )
.removeAttr( 'data-offset' )
.removeClass( 'hide' );
if ( changes.offset ) {
this.$loader.data( 'offset', changes.offset );
}
this.$header.removeClass( 'hide' );
this.$actionBar.removeClass( 'hide' );
// Start loading messages
this.load( changes.limit );
},
/**
* @param {number} [limit] Only load this many messages and then stop even if there is more.
*/
load: function ( limit ) {
var remaining,
query,
self = this,
offset = this.$loader.data( 'offset' ),
pageSize = limit || this.$loader.data( 'pagesize' );
if ( offset === -1 ) {
return;
}
if ( this.loading ) {
// Avoid duplicate loading - the offset will be wrong and it will result
// in duplicate messages shown in the page
return;
}
this.loading = true;
this.$loaderIcon.removeClass( 'tux-loading-indicator--stopped' );
mw.translate.getMessages(
this.settings.group,
this.settings.language,
offset,
pageSize,
this.settings.filter
).done( function ( result ) {
var messages = result.query.messagecollection,
state, i;
if ( !self.loading ) {
// reject. This was cancelled.
return;
}
if ( result.warnings ) {
for ( i = 0; i !== result.warnings.length; i++ ) {
if ( result.warnings[ i ].code === 'translate-language-disabled-source' ) {
self.handleLoadErrors( [ result.warnings[ i ] ] );
break;
}
}
return;
}
if ( messages.length === 0 ) {
// And this is the first load for the filter...
if ( self.$container.children().length === 0 ) {
self.displayEmptyListHelp();
}
}
$.each( messages, function ( index, message ) {
message.group = self.settings.group;
self.add( message );
self.messages.push( message );
if ( index === 0 && self.mode === 'translate' ) {
$( '.tux-message:first' ).data( 'translateeditor' ).init();
}
} );
state = result.query.metadata && result.query.metadata.state;
$( '.tux-workflow' ).workflowselector(
self.settings.group,
self.settings.language,
state
).removeClass( 'hide' );
// Dynamically loaded messages should pass the search filter if present.
query = $( '.tux-message-filter-box' ).val();
if ( query ) {
self.search( query );
}
if ( result[ 'query-continue' ] === undefined || limit ) {
// End of messages
self.$loader.data( 'offset', -1 )
.addClass( 'hide' );
// Helpfully open the first message in show mode
// TODO: Refactor to avoid direct DOM access
$( '.tux-message-item' ).first().click();
} else {
self.$loader.data( 'offset', result[ 'query-continue' ].messagecollection.mcoffset );
remaining = result.query.metadata.remaining;
self.$loaderInfo.text(
mw.msg( 'tux-messagetable-more-messages', remaining )
);
// Make sure the floating toolbars are visible without the need for scroll
$( window ).trigger( 'scroll' );
}
self.updateHideOwnInProofreadingToggleVisibility();
self.updateLastMessage();
} ).fail( function ( errorCode, response ) {
self.handleLoadErrors( response.errors, errorCode );
} ).always( function () {
self.$loaderIcon.addClass( 'tux-loading-indicator--stopped' );
self.loading = false;
} );
},
updateLastMessage: function () {
var $messages = this.$container.find( itemsClass[ this.mode ] );
// If a message was previously marked as "last", restore it to normal state
$messages.filter( '.last-message' ).removeClass( 'last-message' );
// At the class to the current last shown message
$messages
.not( '.hide' )
.last()
.addClass( 'last-message' );
},
/**
* Creates a uniformly styled button for different actions,
* shown when there are no messages to display.
*
* @param {string} labelMsg A message key for the button label.
* @param {Function} callback A callback for clicking the button.
* @return {jQuery} A button element.
*/
otherActionButton: function ( labelMsg, callback ) {
return $( '