Index: trunk/extensions/MoodBar/SpecialMoodBarFeedback.php |
— | — | @@ -14,9 +14,11 @@ |
15 | 15 | |
16 | 16 | $limit = 20; |
17 | 17 | $offset = false; |
| 18 | + $filterType = ''; |
18 | 19 | $id = intval( $par ); |
19 | 20 | if ( $id > 0 ) { |
20 | 21 | $filters = array( 'id' => $id ); |
| 22 | + $filterType = 'id'; |
21 | 23 | } else { |
22 | 24 | // Determine filters and offset from the query string |
23 | 25 | $filters = array(); |
— | — | @@ -29,6 +31,7 @@ |
30 | 32 | $filters['username'] = $username; |
31 | 33 | } |
32 | 34 | $offset = $wgRequest->getVal( 'offset', $offset ); |
| 35 | + $filterType = 'filtered'; |
33 | 36 | } |
34 | 37 | // Do the query |
35 | 38 | $backwards = $wgRequest->getVal( 'dir' ) === 'prev'; |
— | — | @@ -36,13 +39,13 @@ |
37 | 40 | |
38 | 41 | // Output HTML |
39 | 42 | $wgOut->setPageTitle( wfMsg( 'moodbar-feedback-title' ) ); |
40 | | - $wgOut->addHTML( $this->buildForm() ); |
| 43 | + $wgOut->addHTML( $this->buildForm( $filterType ) ); |
41 | 44 | $wgOut->addHTML( $this->buildList( $res ) ); |
42 | 45 | $wgOut->addModuleStyles( 'ext.moodBar.dashboard.styles' ); |
43 | 46 | $wgOut->addModules( 'ext.moodBar.dashboard' ); |
44 | 47 | } |
45 | 48 | |
46 | | - public function buildForm() { |
| 49 | + public function buildForm( $filterType ) { |
47 | 50 | global $wgRequest, $wgMoodBarConfig; |
48 | 51 | $filtersMsg = wfMessage( 'moodbar-feedback-filters' )->escaped(); |
49 | 52 | $typeMsg = wfMessage( 'moodbar-feedback-filters-type' )->escaped(); |
— | — | @@ -64,10 +67,11 @@ |
65 | 68 | array( 'id' => 'fbd-filters-type-issues', 'value' => 'sad' ) ); |
66 | 69 | $usernameTextbox = Html::input( 'username', $wgRequest->getText( 'username' ), 'text', |
67 | 70 | array( 'id' => 'fbd-filters-username', 'class' => 'fbd-filters-input' ) ); |
| 71 | + $filterType = htmlspecialchars( $filterType ); |
68 | 72 | |
69 | 73 | return <<<HTML |
70 | 74 | <div id="fbd-filters"> |
71 | | - <form action="$actionURL"> |
| 75 | + <form action="$actionURL" data-filtertype="$filterType"> |
72 | 76 | <h3 id="fbd-filters-title">$filtersMsg</h3> |
73 | 77 | <fieldset id="fbd-filters-types"> |
74 | 78 | <legend class="fbd-filters-label">$typeMsg</legend> |
— | — | @@ -143,10 +147,13 @@ |
144 | 148 | $olderRow = $res['olderRow']; |
145 | 149 | $newerRow = $res['newerRow']; |
146 | 150 | $html = "<ul id=\"fbd-list\">$list</ul>"; |
147 | | - if ( $olderRow ) { |
148 | | - $moreText = wfMessage( 'moodbar-feedback-more' )->escaped(); |
149 | | - $html .= '<div id="fbd-list-more"><a href="#">' . $moreText . '</a></div>'; |
| 151 | + |
| 152 | + $moreText = wfMessage( 'moodbar-feedback-more' )->escaped(); |
| 153 | + $attribs = array( 'id' => 'fbd-list-more' ); |
| 154 | + if ( !$olderRow ) { |
| 155 | + $attribs['style'] = 'display: none;'; |
150 | 156 | } |
| 157 | + $html .= Html::rawElement( 'div', $attribs, '<a href="#">' . $moreText . '</a></div>' ); |
151 | 158 | |
152 | 159 | $olderURL = $newerURL = false; |
153 | 160 | if ( $olderRow ) { |
Index: trunk/extensions/MoodBar/modules/ext.moodBar.dashboard/ext.moodBar.dashboard.js |
— | — | @@ -16,11 +16,13 @@ |
17 | 17 | |
18 | 18 | function loadFromCookies() { |
19 | 19 | var cookieTypes = $.cookie( 'moodbar-feedback-types' ); |
20 | | - $username = $( '#fbd-filters-username' ); |
| 20 | + $username = $( '#fbd-filters-username' ), |
| 21 | + changed = false; |
21 | 22 | if ( $username.val() == '' ) { |
22 | 23 | var cookieUsername = $.cookie( 'moodbar-feedback-username' ); |
23 | 24 | if ( cookieUsername != '' ) { |
24 | 25 | $username.val( cookieUsername ); |
| 26 | + changed = true; |
25 | 27 | } |
26 | 28 | } |
27 | 29 | |
— | — | @@ -29,27 +31,43 @@ |
30 | 32 | $( '#fbd-filters-type-praise, #fbd-filters-type-confusion, #fbd-filters-type-issues' ).each( function() { |
31 | 33 | if ( !$(this).prop( 'checked' ) && cookieTypes.indexOf( '|' + $(this).val() ) != -1 ) { |
32 | 34 | $(this).prop( 'checked', true ); |
| 35 | + changed = true; |
33 | 36 | } |
34 | 37 | } ); |
35 | 38 | } |
| 39 | + return changed; |
36 | 40 | } |
37 | 41 | |
38 | | - $( '#fbd-filters-set' ).click( setCookies ); |
39 | | - loadFromCookies(); |
| 42 | + function showMessage( text ) { |
| 43 | + $( '#fbd-list-more' ) |
| 44 | + .children( 'a' ) |
| 45 | + .hide() |
| 46 | + .end() |
| 47 | + .children( 'span' ) |
| 48 | + .remove() // Remove any previous messages |
| 49 | + .end() |
| 50 | + .append( $( '<span>' ).text( text ) ); |
| 51 | + } |
40 | 52 | |
41 | | - $( '#fbd-list-more').children( 'a' ).click( function( e ) { |
42 | | - e.preventDefault(); |
43 | | - |
| 53 | + function loadComments( mode ) { |
44 | 54 | var limit = 20, |
45 | 55 | username = $( '#fbd-filters-username' ).val(), |
46 | 56 | types = getSelectedTypes(), |
47 | 57 | reqData; |
48 | 58 | |
| 59 | + if ( mode == 'filter' ) { |
| 60 | + $( '#fbd-list' ).empty(); |
| 61 | + } |
49 | 62 | // Hide the "More" link and put in a spinner |
50 | 63 | $( '#fbd-list-more' ) |
| 64 | + .show() // may have been output with display: none; |
51 | 65 | .addClass( 'mw-ajax-loader' ) |
52 | 66 | .children( 'a' ) |
53 | | - .css( 'visibility', 'hidden' ); // using .hide() messes up the layout |
| 67 | + .css( 'visibility', 'hidden' ) // using .hide() cuts off the spinner |
| 68 | + .show() // showMessage() may have called .hide() |
| 69 | + .end() |
| 70 | + .children( 'span' ) |
| 71 | + .remove(); // Remove any message added by showMessage() |
54 | 72 | |
55 | 73 | // Build the API request |
56 | 74 | reqData = { |
— | — | @@ -57,9 +75,11 @@ |
58 | 76 | 'list': 'moodbarcomments', |
59 | 77 | 'format': 'json', |
60 | 78 | 'mbcprop': 'formatted', |
61 | | - 'mbclimit': limit + 2, // we drop the first and last result |
62 | | - 'mbccontinue': $( '#fbd-list').find( 'li:last' ).data( 'mbccontinue' ) |
| 79 | + 'mbclimit': limit + 2 // we drop the first and last result |
63 | 80 | }; |
| 81 | + if ( mode == 'more' ) { |
| 82 | + reqData['mbccontinue'] = $( '#fbd-list').find( 'li:last' ).data( 'mbccontinue' ); |
| 83 | + } |
64 | 84 | if ( types.length ) { |
65 | 85 | reqData['mbctype'] = types.join( '|' ); |
66 | 86 | } |
— | — | @@ -74,10 +94,10 @@ |
75 | 95 | $( '#fbd-list-more' ) |
76 | 96 | .removeClass( 'mw-ajax-loader' ) |
77 | 97 | .children( 'a' ) |
78 | | - .css( 'visibility', 'visible' ); |
| 98 | + .css( 'visibility', 'visible' ); // Undo visibility: hidden; |
79 | 99 | |
80 | 100 | if ( !data || !data.query || !data.query.moodbarcomments ) { |
81 | | - $( '#fbd-list-more' ).text( mw.msg( 'moodbar-feedback-ajaxerror' ) ); |
| 101 | + showMessage( mw.msg( 'moodbar-feedback-ajaxerror' ) ); |
82 | 102 | return; |
83 | 103 | } |
84 | 104 | |
— | — | @@ -86,11 +106,18 @@ |
87 | 107 | $ul = $( '#fbd-list' ), |
88 | 108 | moreResults = false, |
89 | 109 | i; |
90 | | - if ( len > 0 ) { |
91 | | - // Drop the first element because it duplicates the last shown one |
92 | | - comments.shift(); |
93 | | - len--; |
| 110 | + if ( len == 0 ) { |
| 111 | + if ( mode == 'more' ) { |
| 112 | + showMessage( mw.msg( 'moodbar-feedback-nomore' ) ); |
| 113 | + } else { |
| 114 | + showMessage( mw.msg( 'moodbar-feedback-noresults' ) ); |
| 115 | + } |
| 116 | + return; |
94 | 117 | } |
| 118 | + |
| 119 | + // Drop the first element because it duplicates the last shown one |
| 120 | + comments.shift(); |
| 121 | + len--; |
95 | 122 | if ( len > limit ) { |
96 | 123 | // Drop any elements past the limit. We do know there are more results now |
97 | 124 | len = limit; |
— | — | @@ -102,15 +129,36 @@ |
103 | 130 | } |
104 | 131 | |
105 | 132 | if ( !moreResults ) { |
106 | | - $( '#fbd-list-more' ).text( mw.msg( 'moodbar-feedback-nomore' ) ); |
| 133 | + if ( mode == 'more' ) { |
| 134 | + showMessage( mw.msg( 'moodbar-feedback-nomore' ) ); |
| 135 | + } else { |
| 136 | + $( '#fbd-list-more' ).hide(); |
| 137 | + } |
107 | 138 | } |
108 | 139 | }, |
109 | 140 | 'error': function( jqXHR, textStatus, errorThrown ) { |
110 | | - $( '#fbd-list-more' ) |
111 | | - .removeClass( 'mw-ajax-loader' ) |
112 | | - .text( mw.msg( 'moodbar-feedback-ajaxerror' ) ); |
| 141 | + $( '#fbd-list-more' ).removeClass( 'mw-ajax-loader' ); |
| 142 | + showMessage( mw.msg( 'moodbar-feedback-ajaxerror' ) ); |
113 | 143 | }, |
114 | 144 | 'dataType': 'json' |
115 | 145 | } ); |
| 146 | + } |
| 147 | + |
| 148 | + $( '#fbd-filters' ).children( 'form' ).submit( function( e ) { |
| 149 | + e.preventDefault(); |
| 150 | + setCookies(); |
| 151 | + loadComments( 'filter' ); |
116 | 152 | } ); |
| 153 | + |
| 154 | + $( '#fbd-list-more' ).children( 'a' ).click( function( e ) { |
| 155 | + e.preventDefault(); |
| 156 | + loadComments( 'more' ); |
| 157 | + } ); |
| 158 | + |
| 159 | + var filterType = $( '#fbd-filters' ).children( 'form' ).data( 'filtertype' ); |
| 160 | + if ( filterType != 'filtered' ) { |
| 161 | + if ( loadFromCookies() && filterType != 'id' ) { |
| 162 | + loadComments( 'filter' ); |
| 163 | + } |
| 164 | + } |
117 | 165 | } ); |
Index: trunk/extensions/MoodBar/MoodBar.php |
— | — | @@ -119,7 +119,11 @@ |
120 | 120 | $wgResourceModules['ext.moodBar.dashboard'] = $mbResourceTemplate + array( |
121 | 121 | 'scripts' => 'ext.moodBar.dashboard/ext.moodBar.dashboard.js', |
122 | 122 | 'dependencies' => array( 'mediawiki.util' ), |
123 | | - 'messages' => array( 'moodbar-feedback-nomore', 'moodbar-feedback-ajaxerror' ), |
| 123 | + 'messages' => array( |
| 124 | + 'moodbar-feedback-nomore', |
| 125 | + 'moodbar-feedback-noresults', |
| 126 | + 'moodbar-feedback-ajaxerror' |
| 127 | + ), |
124 | 128 | ); |
125 | 129 | |
126 | 130 | $wgResourceModules['ext.moodBar.dashboard.styles'] = $mbResourceTemplate + array( |