Index: trunk/extensions/MoodBar/modules/ext.moodBar.dashboard/ext.moodBar.dashboard.js |
— | — | @@ -1,10 +1,48 @@ |
2 | 2 | jQuery( function( $ ) { |
| 3 | + function getSelectedTypes() { |
| 4 | + var types = []; |
| 5 | + $( '#fbd-filters-type-praise, #fbd-filters-type-confusion, #fbd-filters-type-issues' ).each( function() { |
| 6 | + if ( $(this).prop( 'checked' ) ) { |
| 7 | + types.push( $(this).val() ); |
| 8 | + } |
| 9 | + } ); |
| 10 | + return types; |
| 11 | + } |
| 12 | + |
| 13 | + function setCookies() { |
| 14 | + $.cookie( 'moodbar-feedback-types', getSelectedTypes().join( '|' ), { 'path': '/', 'expires': 7 } ); |
| 15 | + $.cookie( 'moodbar-feedback-username', $( '#fbd-filters-username' ).val(), { 'path': '/', 'expires': 7 } ); |
| 16 | + } |
| 17 | + |
| 18 | + function loadFromCookies() { |
| 19 | + var cookieTypes = $.cookie( 'moodbar-feedback-types' ); |
| 20 | + $username = $( '#fbd-filters-username' ); |
| 21 | + if ( $username.val() == '' ) { |
| 22 | + var cookieUsername = $.cookie( 'moodbar-feedback-username' ); |
| 23 | + if ( cookieUsername != '' ) { |
| 24 | + $username.val( cookieUsername ); |
| 25 | + } |
| 26 | + } |
| 27 | + |
| 28 | + if ( cookieTypes ) { |
| 29 | + cookieTypes = '|' + cookieTypes; |
| 30 | + $( '#fbd-filters-type-praise, #fbd-filters-type-confusion, #fbd-filters-type-issues' ).each( function() { |
| 31 | + if ( !$(this).prop( 'checked' ) && cookieTypes.indexOf( '|' + $(this).val() ) != -1 ) { |
| 32 | + $(this).prop( 'checked', true ); |
| 33 | + } |
| 34 | + } ); |
| 35 | + } |
| 36 | + } |
| 37 | + |
| 38 | + $( '#fbd-filters-set' ).click( setCookies ); |
| 39 | + loadFromCookies(); |
| 40 | + |
3 | 41 | $( '#fbd-list-more').children( 'a' ).click( function( e ) { |
4 | 42 | e.preventDefault(); |
5 | 43 | |
6 | 44 | var limit = 20, |
7 | 45 | username = $( '#fbd-filters-username' ).val(), |
8 | | - types = [], |
| 46 | + types = getSelectedTypes(), |
9 | 47 | reqData; |
10 | 48 | |
11 | 49 | // Hide the "More" link and put in a spinner |
— | — | @@ -22,11 +60,6 @@ |
23 | 61 | 'mbclimit': limit + 2, // we drop the first and last result |
24 | 62 | 'mbccontinue': $( '#fbd-list').find( 'li:last' ).data( 'mbccontinue' ) |
25 | 63 | }; |
26 | | - $( '#fbd-filters-type-praise, #fbd-filters-type-confusion, #fbd-filters-type-issues' ).each( function() { |
27 | | - if ( $(this).prop( 'checked' ) ) { |
28 | | - types.push( $(this).val() ); |
29 | | - } |
30 | | - } ); |
31 | 64 | if ( types.length ) { |
32 | 65 | reqData['mbctype'] = types.join( '|' ); |
33 | 66 | } |