Index: branches/RL2/extensions/Gadgets/modules/ext.gadgets.preferences.js |
— | — | @@ -11,28 +11,33 @@ |
12 | 12 | * This hides the container td for shared gadgets preferences, reorders them by moving them |
13 | 13 | * into a new td in the right order, updates their label texts, then replaces the old td with |
14 | 14 | * 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 } } |
17 | 17 | */ |
18 | 18 | function fixPreferenceForm( gadgetsByCategory, categoryNames ) { |
| 19 | + // TODO i18n the repo names somehow |
| 20 | + // TODO h1 and h2 need better styling |
19 | 21 | var $oldContainer = $( '#mw-prefsection-gadgetsshared' ).find( '.mw-input' ), |
20 | 22 | $newContainer = $( '<td>' ).addClass( 'mw-input' ), |
21 | 23 | $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 | + } |
26 | 41 | } |
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 | | - } |
37 | 42 | } |
38 | 43 | $oldContainer.replaceWith( $newContainer ); |
39 | 44 | // Unhide the container by removing the unloaded class, and remove the spinner too |
— | — | @@ -41,26 +46,47 @@ |
42 | 47 | |
43 | 48 | // Temporary testing data |
44 | 49 | 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 | + } |
46 | 57 | }; |
47 | 58 | // TODO: Actually fetch this info using AJAX |
48 | 59 | // TODO: This structure allows cross-pollination of categories when multiple foreign repos are involved, do we want that? |
49 | 60 | // I guess probably not, because we wouldn't even know where to pull the category message from to begin with. |
50 | 61 | // Probably needs an extra level for the repo. |
51 | 62 | 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 | + } |
55 | 71 | }, |
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 | + } |
58 | 84 | } |
59 | 85 | }; |
60 | 86 | |
61 | 87 | $( function() { |
62 | 88 | // TODO make all of this nicer once we have AJAX |
63 | 89 | // 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' ); |
65 | 91 | // Simulate AJAX delay |
66 | 92 | setTimeout( function() { fixPreferenceForm( gadgetsByCategory, categoryNames ) }, 2000 ); |
67 | 93 | } ); |