/*! * A jQuery plugin which handles the display and change of message group * workflow states. * * @author Niklas Laxström * @license GPL-2.0-or-later */ ( function () { 'use strict'; function WorkflowSelector( container ) { this.$container = $( container ); // Hide the workflow selector when clicking outside of it $( 'html' ).on( 'click', function ( e ) { if ( !e.isDefaultPrevented() ) { $( container ) .find( '.tux-workflow-status-selector' ) .addClass( 'hide' ); } } ); } WorkflowSelector.prototype = { /** * Displays the current state and selector if relevant. * * @param {string} groupId * @param {string} language * @param {string} state */ receiveState: function ( groupId, language, state ) { var instance = this; instance.currentState = state; instance.language = language; // Only if groupId changes, fetch the new states if ( instance.groupId === groupId ) { // But update the display instance.display(); return; } instance.groupId = groupId; mw.translate.getMessageGroup( groupId, 'workflowstates' ) .done( function ( group ) { instance.states = group.workflowstates; instance.display(); } ); }, /** * Calls the WebApi to change the state to a new value. * * @param {string} state * @return {jQuery.Promise} */ changeState: function ( state ) { var params, api = new mw.Api(); params = { action: 'groupreview', group: this.groupId, language: this.language, state: state }; return api.postWithToken( 'csrf', params ); }, /** * Get the text which says that the current state is X. * * @param {string} stateName * @return {string} Text which should be escaped. */ getStateDisplay: function ( stateName ) { return mw.msg( 'translate-workflowstatus', stateName ); }, /** * Actually constructs the DOM and displays the selector. */ display: function () { var instance = this, $display, $list; instance.$container.empty(); if ( !instance.states ) { return; } $list = $( '