diff options
Diffstat (limited to 'MLEB/Translate/resources/js/ext.translate.special.aggregategroups.js')
-rw-r--r-- | MLEB/Translate/resources/js/ext.translate.special.aggregategroups.js | 65 |
1 files changed, 29 insertions, 36 deletions
diff --git a/MLEB/Translate/resources/js/ext.translate.special.aggregategroups.js b/MLEB/Translate/resources/js/ext.translate.special.aggregategroups.js index 41d4ac0a..cac1edd8 100644 --- a/MLEB/Translate/resources/js/ext.translate.special.aggregategroups.js +++ b/MLEB/Translate/resources/js/ext.translate.special.aggregategroups.js @@ -9,15 +9,14 @@ } function dissociate( event ) { - var params, - $target = $( event.target ), + var $target = $( event.target ), api = new mw.Api(); function successFunction() { $target.parent( 'li' ).remove(); } - params = $.extend( getApiParams( $target ), { + var params = $.extend( getApiParams( $target ), { do: 'dissociate', group: $target.data( 'groupid' ) } ); @@ -31,14 +30,14 @@ } function associate( event, resp ) { - var successFunction, params, subgroupId, i, - $target = $( event.target ), + var $target = $( event.target ), $parent = $target.parents( '.mw-tpa-group' ), parentId = $parent.data( 'id' ), subgroupName = $parent.children( '.tp-group-input' ).val(), api = new mw.Api(); - successFunction = function () { + var subgroupId; + var successFunction = function () { var aAttr, $a, spanAttr, $span, $ol; aAttr = { @@ -63,7 +62,7 @@ // Get the label for the value and make API request if valid subgroupId = ''; - for ( i = 0; i < resp.length; ++i ) { + for ( var i = 0; i < resp.length; ++i ) { if ( subgroupName === resp[ i ].label ) { subgroupId = resp[ i ].id; break; @@ -71,7 +70,7 @@ } if ( subgroupId ) { - params = $.extend( getApiParams( $target ), { + var params = $.extend( getApiParams( $target ), { do: 'associate', group: subgroupId } ); @@ -89,8 +88,7 @@ } function removeGroup( event ) { - var params, - $target = $( event.target ), + var $target = $( event.target ), api = new mw.Api(); function successFunction() { @@ -101,7 +99,7 @@ if ( typeof window.confirm === 'function' && // eslint-disable-next-line no-alert window.confirm( mw.msg( 'tpt-aggregategroup-remove-confirm' ) ) ) { - params = $.extend( getApiParams( $target ), { + var params = $.extend( getApiParams( $target ), { do: 'remove' } ); @@ -120,15 +118,13 @@ aggregateGroupId = $parent.data( 'groupid' ), $displayGroup = $parent.children( '.tp-display-group' ), $editGroup = $parent.children( '.tp-edit-group' ), - successFunction, - params, $aggGroupNameInputName = $editGroup.children( 'input.tp-aggregategroup-edit-name' ), $aggGroupNameInputDesc = $editGroup.children( 'input.tp-aggregategroup-edit-description' ), aggregateGroupName = $aggGroupNameInputName.val(), aggregateGroupDesc = $aggGroupNameInputDesc.val(), api = new mw.Api(); - successFunction = function () { + var successFunction = function () { // Replace the text by the new text without altering the other 2 span tags $displayGroup.children( '.tp-name' ).contents().filter( function () { return this.nodeType === 3; @@ -138,7 +134,7 @@ $editGroup.addClass( 'hidden' ); }; - params = { + var params = { action: 'aggregategroups', do: 'update', groupname: aggregateGroupName, @@ -162,13 +158,12 @@ } $( function () { - var excludeFunction, autocompleteFunction, resp, - api = new mw.Api(), + var api = new mw.Api(), exclude = [], groups = [], $input = $( '.tp-group-input' ); - excludeFunction = function ( event ) { + var excludeFunction = function ( event ) { exclude = []; if ( groups.length === 0 ) { @@ -196,7 +191,8 @@ ); }; - autocompleteFunction = function ( request, response ) { + var resp; + var autocompleteFunction = function ( request, response ) { // Allow case insensitive search var inp = new RegExp( request.term, 'i' ); @@ -245,8 +241,7 @@ } ); $( '#tpt-aggregategroups-save' ).on( 'click', function () { - var successFunction, params, - $aggGroupNameInputName = $( 'input.tp-aggregategroup-add-name' ), + var $aggGroupNameInputName = $( 'input.tp-aggregategroup-add-name' ), $aggGroupNameInputDesc = $( 'input.tp-aggregategroup-add-description' ), aggregateGroupName = $aggGroupNameInputName.val(), aggregateGroupDesc = $aggGroupNameInputDesc.val(); @@ -256,36 +251,34 @@ $aggGroupNameInputName.val( '' ); $aggGroupNameInputDesc.val( '' ); - successFunction = function ( data ) { - var $removeSpan, $editSpan, $displayHeader, $div, $groupSelector, $addButton, - $cancelButton, $divDisplay, $divEdit, $saveButton, - aggregateGroupId = data.aggregategroups.aggregategroupId; + var successFunction = function ( data ) { + var aggregateGroupId = data.aggregategroups.aggregategroupId; - $removeSpan = $( '<span>' ).attr( 'id', aggregateGroupId ) + var $removeSpan = $( '<span>' ).attr( 'id', aggregateGroupId ) .addClass( 'tp-aggregate-remove-ag-button' ); - $editSpan = $( '<span>' ).attr( 'id', aggregateGroupId ) + var $editSpan = $( '<span>' ).attr( 'id', aggregateGroupId ) .addClass( 'tp-aggregate-edit-ag-button' ); // Prints the name and the two spans in a single row - $displayHeader = $( '<h2>' ).addClass( 'tp-name' ).text( aggregateGroupName ) + var $displayHeader = $( '<h2>' ).addClass( 'tp-name' ).text( aggregateGroupName ) .append( $editSpan, $removeSpan ); - $divDisplay = $( '<div>' ).addClass( 'tp-display-group' ) + var $divDisplay = $( '<div>' ).addClass( 'tp-display-group' ) .append( $displayHeader ) .append( $( '<p>' ).addClass( 'tp-desc' ).text( aggregateGroupDesc ) ); - $saveButton = $( '<input>' ) + var $saveButton = $( '<input>' ) .attr( { type: 'button', class: 'tp-aggregategroup-update' } ) .val( mw.msg( 'tpt-aggregategroup-update' ) ); - $cancelButton = $( '<input>' ) + var $cancelButton = $( '<input>' ) .attr( { type: 'button', class: 'tp-aggregategroup-update-cancel' } ) .val( mw.msg( 'tpt-aggregategroup-update-cancel' ) ); - $divEdit = $( '<div>' ) + var $divEdit = $( '<div>' ) .addClass( 'tp-edit-group hidden' ) .append( $( '<label>' ) .text( mw.msg( 'tpt-aggregategroup-edit-name' ) ) ) @@ -310,14 +303,14 @@ ) .append( $saveButton, $cancelButton ); - $div = $( '<div>' ).addClass( 'mw-tpa-group' ) + var $div = $( '<div>' ).addClass( 'mw-tpa-group' ) .append( $divDisplay, $divEdit ) .append( $( '<ol id=\'mw-tpa-grouplist-' + aggregateGroupId + '\'>' ) ); $div.data( 'groupid', aggregateGroupId ); $div.data( 'id', aggregateGroupId ); - $groupSelector = $( '<input>' ).attr( { + var $groupSelector = $( '<input>' ).attr( { type: 'text', class: 'tp-group-input' } ); @@ -329,7 +322,7 @@ // Enable showing all groups when nothing is entered $( this ).autocomplete( 'search', $( this ).val() ); } ); - $addButton = $( '<input>' ) + var $addButton = $( '<input>' ) .attr( { type: 'button', class: 'tp-aggregate-add-button', @@ -353,7 +346,7 @@ $( 'a.tpt-add-new-group' ).before( $div ); }; - params = { + var params = { action: 'aggregategroups', do: 'add', groupname: aggregateGroupName, |