Phoenix303 has uploaded a new change for review. https://gerrit.wikimedia.org/r/195560
Change subject: Fixed group selector on Special:SearchTranslations ...................................................................... Fixed group selector on Special:SearchTranslations Bug:T54703 Change-Id: I5196b65ffe6ff4e1e8caf33a22555c17062119d3 --- M resources/js/ext.translate.groupselector.js M resources/js/ext.translate.special.searchtranslations.js 2 files changed, 52 insertions(+), 30 deletions(-) git pull ssh://gerrit.wikimedia.org:29418/mediawiki/extensions/Translate refs/changes/60/195560/1 diff --git a/resources/js/ext.translate.groupselector.js b/resources/js/ext.translate.groupselector.js index 4dfd86f..4b8fa46 100644 --- a/resources/js/ext.translate.groupselector.js +++ b/resources/js/ext.translate.groupselector.js @@ -9,7 +9,7 @@ * - onSelect: callback with message group id when selected * - language: language for statistics. */ - function TranslateMessageGroupSelector( element, options ) { + function TranslateMessageGroupSelector( element, options, groups ) { this.$trigger = $( element ); this.$menu = null; this.$search = null; @@ -22,6 +22,7 @@ // selectors. this.customOptions = options; this.flatGroupList = null; + this.groups = groups; this.init(); } @@ -270,10 +271,22 @@ var $selected = this.$menu.find( '.tux-grouptab--selected' ); if ( $selected.hasClass( 'tux-grouptab--all' ) ) { - this.showDefaultGroups(); + if ( this.groups ) { + this.showGroups( this.groups ); + } else { + this.showDefaultGroups(); + } } else if ( $selected.hasClass( 'tux-grouptab--recent' ) ) { this.showRecentGroups(); } + }, + + /** + * Shows the list of filtered message groups. + */ + showGroups: function ( groups ) { + this.$loader.show(); + this.loadMsgGroups( groups ); }, /** @@ -305,26 +318,31 @@ * Show recent message groups. */ showRecentGroups: function () { + this.$loader.show(); + $.when( this.loadRecentGroups() ) + .then( $.proxy( this.loadMsgGroups, this ) ); + }, + + /** + * load message groups. + */ + loadMsgGroups: function ( groups ) { var groupSelector = this; - this.$loader.show(); + $.when( this.loadGroups() ) + .then( function ( allGroups ) { + var rows = []; + $.each( groups, function ( index, id ) { - $.when( this.loadRecentGroups(), this.loadGroups() ) - .then( function ( recentGroups, allGroups ) { - var rows = []; - - $.each( recentGroups, function ( index, id ) { - var group = mw.translate.findGroup( id, allGroups ); - - if ( group ) { - rows.push( groupSelector.prepareMessageGroupRow( group ) ); - } + var group = mw.translate.findGroup( id, allGroups ); + if ( group ) { + rows.push( groupSelector.prepareMessageGroupRow( group ) ); + } + } ); + groupSelector.$loader.hide(); + groupSelector.$list.empty(); + groupSelector.$list.append( rows ); } ); - - groupSelector.$loader.hide(); - groupSelector.$list.empty(); - groupSelector.$list.append( rows ); - } ); }, /** @@ -577,14 +595,14 @@ * msggroupselector PLUGIN DEFINITION */ - $.fn.msggroupselector = function ( options ) { + $.fn.msggroupselector = function ( options, groups ) { return this.each( function () { var $this = $( this ), data = $this.data( 'msggroupselector' ); if ( !data ) { $this.data( 'msggroupselector', - ( data = new TranslateMessageGroupSelector( this, options ) ) + ( data = new TranslateMessageGroupSelector( this, options, groups ) ) ); } diff --git a/resources/js/ext.translate.special.searchtranslations.js b/resources/js/ext.translate.special.searchtranslations.js index 7c37e60..74e9246 100644 --- a/resources/js/ext.translate.special.searchtranslations.js +++ b/resources/js/ext.translate.special.searchtranslations.js @@ -241,17 +241,21 @@ $parent.append( $grouSelectorTrigger ); $grouSelectorTrigger.msggroupselector( { - language: mw.config.get( 'wgUserLanguage' ), - position: { - my: 'left top', - at: 'left top' + language: mw.config.get( 'wgUserLanguage' ), + position: { + my: 'left top', + at: 'left top' + }, + onSelect: function ( group ) { + var uri = new mw.Uri( window.location.href ); + uri.extend( { 'group': group.id } ); + window.location.href = uri.toString(); + } }, - onSelect: function ( group ) { - var uri = new mw.Uri( window.location.href ); - uri.extend( { 'group': group.id } ); - window.location.href = uri.toString(); - } - } ); + $.map( resultGroups, function ( value, index ) { + return [index]; + } ) + ); } } -- To view, visit https://gerrit.wikimedia.org/r/195560 To unsubscribe, visit https://gerrit.wikimedia.org/r/settings Gerrit-MessageType: newchange Gerrit-Change-Id: I5196b65ffe6ff4e1e8caf33a22555c17062119d3 Gerrit-PatchSet: 1 Gerrit-Project: mediawiki/extensions/Translate Gerrit-Branch: master Gerrit-Owner: Phoenix303 <divyalife...@gmail.com> _______________________________________________ MediaWiki-commits mailing list MediaWiki-commits@lists.wikimedia.org https://lists.wikimedia.org/mailman/listinfo/mediawiki-commits