https://www.mediawiki.org/wiki/Special:Code/MediaWiki/113715
Revision: 113715
Author: santhosh
Date: 2012-03-13 11:04:14 +0000 (Tue, 13 Mar 2012)
Log Message:
-----------
Fix the broken 'add new aggregate group' in r113631
Get the list of groups that can be added to the newly created aggregate group
as response from add action,
populate the groups drop down from that.
Some more js cleanup.
Modified Paths:
--------------
trunk/extensions/Translate/api/ApiAggregateGroups.php
trunk/extensions/Translate/resources/ext.translate.special.aggregategroups.js
Modified: trunk/extensions/Translate/api/ApiAggregateGroups.php
===================================================================
--- trunk/extensions/Translate/api/ApiAggregateGroups.php 2012-03-13
10:32:11 UTC (rev 113714)
+++ trunk/extensions/Translate/api/ApiAggregateGroups.php 2012-03-13
11:04:14 UTC (rev 113715)
@@ -29,7 +29,7 @@
$params = $this->extractRequestParams();
$aggregateGroup = $params['aggregategroup'];
$action = $params['do'];
-
+ $output = array();
if ( $action === 'associate' || $action === 'dissociate' ) {
// Group is mandatory only for these two actions
if ( !isset( $params['group'] ) ) {
@@ -66,7 +66,7 @@
TranslateMetadata::set( $aggregateGroup, 'name', false
) ;
TranslateMetadata::set( $aggregateGroup, 'description',
false ) ;
} elseif ( $action === 'add' ) {
- if ( TranslateMetadata::get( $aggregateGroup,
'subgroups') ) {
+ if ( TranslateMetadata::get( $aggregateGroup,
'subgroups' ) ) {
$this->dieUsage( 'Aggregate Group aleady
exists', 'duplicateaggregategroup' );
}
// @FIXME: check that the group id is valid (like, no
commas)
@@ -80,10 +80,12 @@
if ( $desc ) {
TranslateMetadata::set( $aggregateGroup,
'description', $desc ) ;
}
+ // Once new aggregate group added, we need to show all
the pages that can be added to that.
+ $output['groups'] = self::getAllPages();
}
// If we got this far, nothing has failed
- $output = array( 'result' => 'ok' );
+ $output['result'] = 'ok';
$this->getResult()->addValue( null, $this->getModuleName(),
$output );
// Cache needs to be cleared after any changes to groups
MessageGroups::clearCache();
@@ -160,6 +162,17 @@
return __CLASS__ . ': $Id$';
}
+ public static function getAllPages() {
+ $groups = MessageGroups::getAllGroups();
+ $pages = array();
+ foreach ( $groups as $group ) {
+ if ( $group instanceof WikiPageMessageGroup ) {
+ $pages[$group->getId()] =
$group->getTitle()->getPrefixedText();
+ }
+ }
+ return $pages;
+ }
+
public static function getToken( $pageid, $title ) {
global $wgUser;
if ( !$wgUser->isAllowed( self::$right ) ) {
Modified:
trunk/extensions/Translate/resources/ext.translate.special.aggregategroups.js
===================================================================
---
trunk/extensions/Translate/resources/ext.translate.special.aggregategroups.js
2012-03-13 10:32:11 UTC (rev 113714)
+++
trunk/extensions/Translate/resources/ext.translate.special.aggregategroups.js
2012-03-13 11:04:14 UTC (rev 113715)
@@ -110,27 +110,30 @@
} );
$( '#tpt-aggregategroups-save' ). on ( "click", function( event ){
- var aggregateGroup = createId( $(
'input.tp-aggregategroup-add-name' ).val() );
+ var aggregateGroupId = createId( $(
'input.tp-aggregategroup-add-name' ).val() );
var aggregateGroupName = $( 'input.tp-aggregategroup-add-name'
).val();
var aggregateGroupDesc = $(
'input.tp-aggregategroup-add-description' ).val();
- var $select = $( 'select.tp-aggregate-group-chooser' );
+ var $select = $( 'div.mw-tpa-group select' );
var successFunction = function( data, textStatus ) {
if ( data.error ) {
alert( data.error.info );
}else{
- var $removeSpan = $( '<span>' ).attr( 'id',
aggregateGroup ).addClass( 'tp-aggregate-remove-ag-button' );
+ var $removeSpan = $( '<span>' ).attr( 'id',
aggregateGroupId ).addClass( 'tp-aggregate-remove-ag-button' );
var $div = $( "<div class='mw-tpa-group'>" )
.append ( $( '<h2>' ).text(
aggregateGroupName )
.append ( $removeSpan ) )
.append ( $('<p>').text(
aggregateGroupDesc ) )
- .append ( $('<ol
id=\'mw-tpa-grouplist-'+aggregateGroup+'\'>') );
-
+ .append ( $('<ol
id=\'mw-tpa-grouplist-' + aggregateGroupId +'\'>') );
+ $div.data( 'groupid', aggregateGroupId );
+ $div.data( 'id', aggregateGroupId );
if ( $select.length > 0 ){
- var $groupSelector = $( $(
'select.tp-aggregate-group-chooser' )[0] ).clone();
- $groupSelector.attr('id',
'tp-aggregate-groups-select-' + aggregateGroup);
+ var $groupSelector = $( '<select>'
).attr('id', 'mw-tpa-groupselect-' + aggregateGroupId );
+ $.each(data.aggregategroups.groups,
function( key, value) {
+ $groupSelector.append( $(
'<option>', { value : key } ).text( value ) );
+ } );
var $addButton = $( $(
'input.tp-aggregate-add-button' )[0]).clone();
- $addButton.attr( 'id', aggregateGroup);
+ $addButton.attr( 'id', aggregateGroupId
);
$div.append( $groupSelector ).append(
$addButton );
$addButton.click( associate );
$removeSpan.click( removeGroup );
@@ -147,7 +150,7 @@
action: "aggregategroups",
'do' : 'add',
token: $( "#token" ).val(),
- aggregategroup: aggregateGroup,
+ aggregategroup: aggregateGroupId,
groupname : aggregateGroupName,
groupdescription: aggregateGroupDesc,
format: "json"
_______________________________________________
MediaWiki-CVS mailing list
[email protected]
https://lists.wikimedia.org/mailman/listinfo/mediawiki-cvs