r100970 MediaWiki - Code Review archive

Repository:MediaWiki
Revision:r100969‎ | r100970 | r100971 >
Date:13:02, 27 October 2011
Author:catrope
Status:deferred
Tags:
Comment:
[RL2] Split out shared gadget prefs by repo, both in the data structure and on the form. This needs some love, still: repo names need i18n and the h1/h2 tags need better styling
Modified paths:
  • /branches/RL2/extensions/Gadgets/modules/ext.gadgets.preferences.js (modified) (history)

Diff [purge]

Index: branches/RL2/extensions/Gadgets/modules/ext.gadgets.preferences.js
@@ -11,28 +11,33 @@
1212 * This hides the container td for shared gadgets preferences, reorders them by moving them
1313 * into a new td in the right order, updates their label texts, then replaces the old td with
1414 * the new one.
15 - * @param gadgetsByCategory {Object} Map of { categoryID: { gadgetID: gadgetDescription } }
16 - * @param categoryNames {Object} Map of { categoryID: categoryDescription }
 15+ * @param gadgetsByCategory {Object} Map of { repo: { categoryID: { gadgetID: gadgetDescription } } }
 16+ * @param categoryNames {Object} Map of { repo: { categoryID: categoryDescription } }
1717 */
1818 function fixPreferenceForm( gadgetsByCategory, categoryNames ) {
 19+ // TODO i18n the repo names somehow
 20+ // TODO h1 and h2 need better styling
1921 var $oldContainer = $( '#mw-prefsection-gadgetsshared' ).find( '.mw-input' ),
2022 $newContainer = $( '<td>' ).addClass( 'mw-input' ),
2123 $spinner = $oldContainer.closest( '.mw-gadgetsshared-item-unloaded' ),
22 - category, gadget, $oldItem;
23 - for ( category in gadgetsByCategory ) {
24 - if ( category !== '' ) {
25 - $newContainer.append( $( '<h1>' ).text( categoryNames[category] ) );
 24+ repo, category, gadget, $oldItem;
 25+ for ( repo in gadgetsByCategory ) {
 26+ $newContainer.append( $( '<h1>' ).text( repo ) );
 27+ for ( category in gadgetsByCategory[repo] ) {
 28+ if ( category !== '' ) {
 29+ $newContainer.append( $( '<h2>' ).text( categoryNames[repo][category] ) );
 30+ }
 31+ for ( gadget in gadgetsByCategory[repo][category] ) {
 32+ // Find the item belonging to this gadget in $oldContainer
 33+ $oldItem = $oldContainer
 34+ .find( '#mw-input-wpgadgetsshared-' + gadget )
 35+ .closest( '.mw-htmlform-multiselect-item' );
 36+ // Update the label text
 37+ $oldItem.find( 'label' ).text( gadgetsByCategory[repo][category][gadget] );
 38+ // Move the item from $oldContainer to $newContainer
 39+ $newContainer.append( $oldItem );
 40+ }
2641 }
27 - for ( gadget in gadgetsByCategory[category] ) {
28 - // Find the item belonging to this gadget in $oldContainer
29 - $oldItem = $oldContainer
30 - .find( '#mw-input-wpgadgetsshared-' + gadget )
31 - .closest( '.mw-htmlform-multiselect-item' );
32 - // Update the label text
33 - $oldItem.find( 'label' ).text( gadgetsByCategory[category][gadget] );
34 - // Move the item from $oldContainer to $newContainer
35 - $newContainer.append( $oldItem );
36 - }
3742 }
3843 $oldContainer.replaceWith( $newContainer );
3944 // Unhide the container by removing the unloaded class, and remove the spinner too
@@ -41,26 +46,47 @@
4247
4348 // Temporary testing data
4449 var categoryNames = {
45 - 'foo': 'The Foreign Category of Foo'
 50+ 'wiki2': {
 51+ 'foo': 'The Foreign Category of Foo'
 52+ },
 53+ 'wiki3': {
 54+ 'foo': 'The Remote Category of Foo',
 55+ 'bar': 'The Remote Category of Bar'
 56+ }
4657 };
4758 // TODO: Actually fetch this info using AJAX
4859 // TODO: This structure allows cross-pollination of categories when multiple foreign repos are involved, do we want that?
4960 // I guess probably not, because we wouldn't even know where to pull the category message from to begin with.
5061 // Probably needs an extra level for the repo.
5162 var gadgetsByCategory = {
52 - '': {
53 - 'b': 'Gadget B',
54 - 'UTCLiveClock': 'A clock that displays UTC time blah blah blah'
 63+ 'wiki2': {
 64+ '': {
 65+ 'b': 'Gadget B',
 66+ 'UTCLiveClock': 'A clock that displays UTC time blah blah blah'
 67+ },
 68+ 'foo': {
 69+ 'a': 'Gadget A'
 70+ }
5571 },
56 - 'foo': {
57 - 'a': 'Gadget A'
 72+ 'wiki3': {
 73+ '': {
 74+ 'c': 'Gadget C',
 75+ 'd': 'Gadget D'
 76+ },
 77+ 'foo': {
 78+ 'e': 'Gadget E'
 79+ },
 80+ 'bar': {
 81+ 'f': 'Gadget F',
 82+ 'g': 'Gadget G'
 83+ }
5884 }
5985 };
6086
6187 $( function() {
6288 // TODO make all of this nicer once we have AJAX
6389 // Add spinner
64 - $( '#mw-prefsection-gadgetsshared').find( '.mw-gadgetsshared-item-unloaded' ).addClass( 'mw-ajax-loader' );
 90+ $( '#mw-prefsection-gadgetsshared' ).find( '.mw-gadgetsshared-item-unloaded' ).addClass( 'mw-ajax-loader' );
6591 // Simulate AJAX delay
6692 setTimeout( function() { fixPreferenceForm( gadgetsByCategory, categoryNames ) }, 2000 );
6793 } );

Follow-up revisions

RevisionCommit summaryAuthorDate
r101340[RL2] Remove TODO that was addressed in r100970catrope08:57, 31 October 2011

Status & tagging log