r113612 MediaWiki - Code Review archive

Repository:MediaWiki
Revision:r113611‎ | r113612 | r113613 >
Date:05:28, 12 March 2012
Author:santhosh
Status:ok
Tags:i18nreview 
Comment:
Remove the restriction of 'page can reside in only one agregategroup'
Now one page can belong to multiple aggregrate groups.
Modified paths:
  • /trunk/extensions/Translate/resources/ext.translate.special.aggregategroups.js (modified) (history)
  • /trunk/extensions/Translate/specials/SpecialAggregateGroups.php (modified) (history)

Diff [purge]

Index: trunk/extensions/Translate/specials/SpecialAggregateGroups.php
@@ -84,7 +84,6 @@
8585 $aggregategroups = ApiAggregateGroups::getAggregateGroups( );
8686 $res = $this->loadPagesFromDB();
8787 $pages = $this->buildPageArray( $res );
88 - $pages = $this->filterUnGroupedPages( $pages, $aggregategroups );
8988 foreach ( $aggregategroups as $id => $group ) {
9089 $wgOut->addHtml( "<div id='tpt-aggregate-group'>" );
9190
@@ -112,7 +111,7 @@
113112 }
114113 $wgOut->addHtml( "</ol>" );
115114
116 - $this->groupSelector ( $pages, $id );
 115+ $this->groupSelector ( $pages, $group );
117116 $addButton = Html::element( 'input',
118117 array( 'type' => 'button',
119118 'value' => wfMsg( 'tpt-aggregategroup-add' ),
@@ -148,7 +147,7 @@
149148 $wgOut->addHtml( $newGroupDiv );
150149 }
151150
152 - protected function groupSelector( $pages, $id ) {
 151+ protected function groupSelector( $pages, $group ) {
153152 global $wgOut;
154153 $out = $wgOut;
155154 if ( !count( $pages ) ) {
@@ -156,16 +155,19 @@
157156 return;
158157 }
159158 $options = "\n";
 159+ $subgroups = $group['subgroups'];
160160 if ( count( $pages ) ) {
161161 foreach ( $pages as $pageId => $page ) {
162162 $title = $page['title']->getText();
163163 $pageid = TranslatablePage::getMessageGroupIdFromTitle( $page['title'] ) ;
164 - $options .= Xml::option( $title , $pageid, false , array( 'id' => $pageid ) ) . "\n";
 164+ if ( ! isset( $subgroups[$pageid] ) ) {
 165+ $options .= Xml::option( $title , $pageid, false , array( 'id' => $pageid ) ) . "\n";
 166+ }
165167 }
166168 }
167169 $selector = Xml::tags( 'select',
168170 array(
169 - 'id' => 'tp-aggregate-groups-select-' . $id,
 171+ 'id' => 'tp-aggregate-groups-select-' . $group['id'],
170172 'name' => 'group',
171173 'class' => 'tp-aggregate-group-chooser',
172174 ),
@@ -174,17 +176,4 @@
175177 $out->addHtml( $selector );
176178 }
177179
178 - protected function filterUnGroupedPages( $pages, $aggregategroups ) {
179 - foreach ( $aggregategroups as $aggregategroup ) {
180 - $subgroups = $aggregategroup['subgroups'];
181 - foreach ( $pages as $id => $page ) {
182 - $pageid = TranslatablePage::getMessageGroupIdFromTitle( $page['title'] ) ;
183 - if ( isset( $subgroups[$pageid] ) ) {
184 - unset( $pages[$id] );
185 - }
186 - }
187 - }
188 - return $pages;
189 - }
190 -
191180 }
Index: trunk/extensions/Translate/resources/ext.translate.special.aggregategroups.js
@@ -4,17 +4,20 @@
55
66 function associate( event ){
77 var aggregategroup = event.target.id;
8 - var selected = $( '#tp-aggregate-groups-select-'+ aggregategroup + ' option:selected' ).text();
9 - var group = $( '#tp-aggregate-groups-select-'+ aggregategroup + ' option:selected' ).val();
 8+ var $selected = $( '#tp-aggregate-groups-select-'+ aggregategroup + ' option:selected' );
 9+ var groupName = $selected.text();
 10+ var groupId = $selected.val();
1011 var $select= $( 'select.tp-aggregate-group-chooser' ) ;
1112
1213 var successFunction = function( data, textStatus ) {
1314 if ( data.error ) {
1415 alert( data.error.info );
1516 }else{
16 - $( '#tp-aggregate-groups-ol-'+ aggregategroup ).append( '<li><a id='+group+' href='+selected+'>'+selected+'</a><span class=\'tp-aggregate-remove-button\' id='+group+'></span></li>' );
17 - $( 'option#'+ group ).remove();
18 - $( 'span#'+group ).on ( "click", function(event){ dissociate(event); } );
 17+ $( '#tp-aggregate-groups-ol-'+ aggregategroup ).append( '<li><a id='+groupId+' href='+groupName+'>'+groupName+'</a><span class=\'tp-aggregate-remove-button\' id='+groupId+'></span></li>' );
 18+ // remove this group from the select.
 19+ $selected.remove();
 20+ // bind click event to the dissociate(remove) button.
 21+ $( 'span#'+groupId ).on ( "click", function(event){ dissociate(event); } );
1922 }
2023 };
2124
@@ -22,7 +25,7 @@
2326 action: "aggregategroups",
2427 'do' : 'associate',
2528 token: $( "#token" ).val(),
26 - group: group,
 29+ group: groupId,
2730 aggregategroup: aggregategroup,
2831 format: "json"
2932 };
@@ -30,19 +33,16 @@
3134 }
3235
3336 function dissociate(event){
34 - var group = event.target.id;
35 - var selected = $( 'a#'+group ).text();
36 - var $select= $( 'select.tp-aggregate-group-chooser' ) ;
37 - var aggregategroup = $( 'a#'+group ).closest( 'div' ).find( 'h2' ).attr( 'id' );
38 -
 37+ var groupId = event.target.id;
 38+ var groupName = $( 'a#'+groupId ).text();
 39+ var aggregategroup = $( 'a#'+groupId ).closest( 'div' ).find( 'h2' ).attr( 'id' );
 40+ var $select = $( '#tp-aggregate-groups-select-'+ aggregategroup );
3941 var successFunction = function( data, textStatus ) {
4042 if ( data.error ) {
4143 alert( data.error.info );
4244 }else{
43 - $select.each( function(){
44 - $( this ).append( '<option value="'+group+'">'+selected+'</option>' );
45 - } );
46 - $( 'span#'+ group ).closest( 'li' ).remove();
 45+ $select .append( '<option value="'+groupId+'">'+groupName+'</option>' );
 46+ $( 'span#'+ groupId ).closest( 'li' ).remove();
4747 }
4848 };
4949
@@ -50,7 +50,7 @@
5151 action: "aggregategroups",
5252 'do' : 'dissociate',
5353 token: $( "#token" ).val(),
54 - group: group,
 54+ group: groupId,
5555 aggregategroup: aggregategroup,
5656 format: "json"
5757 };
@@ -59,19 +59,10 @@
6060
6161 function removeGroup(event){
6262 var aggregategroup = event.target.id;
63 - var $select= $( 'select.tp-aggregate-group-chooser') ;
64 -
6563 var successFunction = function( data, textStatus ) {
6664 if ( data.error ) {
6765 alert( data.error.info );
6866 }else{
69 - $( 'span#'+ aggregategroup ).parent().parent().find('li a').each(function(){
70 - $groupId = $( this ).attr('id');
71 - $groupName = $( this ).text();
72 - $select.each( function(){
73 - $ (this ).append('<option value="'+$groupId+'">'+$groupName+'</option>');
74 - } );
75 - });
7667 $( 'span#'+ aggregategroup ).closest('div#tpt-aggregate-group').remove();
7768 }
7869 };

Status & tagging log