| Index: trunk/extensions/ArticleFeedbackv5/modules/jquery.articleFeedbackv5/jquery.articleFeedbackv5.special.js |
| — | — | @@ -1,14 +1,76 @@ |
| | 2 | +/** |
| | 3 | + * ArticleFeedback special page |
| | 4 | + * |
| | 5 | + * This file handles the display of feedback responses and moderation tools for |
| | 6 | + * privileged users. The flow goes like this: |
| | 7 | + * |
| | 8 | + * User arrives at special page -> basic markup is created without data -> ajax |
| | 9 | + * request is sent to pull most recent feedback |
| | 10 | + * |
| | 11 | + * For each change to the selected filter or sort method, or when more feedback |
| | 12 | + * is requested, another ajax request is sent. |
| | 13 | + * |
| | 14 | + * This file is long, so it's commented with manual fold markers. To use folds |
| | 15 | + * this way in vim: |
| | 16 | + * set foldmethod=marker |
| | 17 | + * set foldlevel=0 |
| | 18 | + * set foldcolumn=0 |
| | 19 | + * |
| | 20 | + * @package ArticleFeedback |
| | 21 | + * @subpackage Resources |
| | 22 | + * @author Greg Chiasson <gchiasson@omniti.com> |
| | 23 | + * @version $Id$ |
| | 24 | + */ |
| | 25 | + |
| 2 | 26 | ( function ( $ ) { |
| | 27 | + |
| | 28 | +// {{{ articleFeedbackv5 definition |
| | 29 | + |
| 3 | 30 | $.articleFeedbackv5special = {}; |
| 4 | 31 | |
| 5 | | - $.articleFeedbackv5special.page = undefined; |
| 6 | | - $.articleFeedbackv5special.filter = 'visible'; |
| 7 | | - $.articleFeedbackv5special.sort = 'newest'; |
| 8 | | - $.articleFeedbackv5special.limit = 25; |
| 9 | | - $.articleFeedbackv5special.offset = 0; |
| | 32 | + // {{{ Properties |
| | 33 | + |
| | 34 | + /** |
| | 35 | + * What page is this? |
| | 36 | + */ |
| | 37 | + $.articleFeedbackv5special.page = undefined; |
| | 38 | + |
| | 39 | + /** |
| | 40 | + * The name of the filter used to select feedback |
| | 41 | + */ |
| | 42 | + $.articleFeedbackv5special.filter = 'visible'; |
| | 43 | + |
| | 44 | + /** |
| | 45 | + * The name of the sorting method used |
| | 46 | + */ |
| | 47 | + $.articleFeedbackv5special.sort = 'newest'; |
| | 48 | + |
| | 49 | + /** |
| | 50 | + * The number of responses to display per data pull |
| | 51 | + */ |
| | 52 | + $.articleFeedbackv5special.limit = 25; |
| | 53 | + |
| | 54 | + /** |
| | 55 | + * The index at which to start the pull |
| | 56 | + */ |
| | 57 | + $.articleFeedbackv5special.offset = 0; |
| | 58 | + |
| | 59 | + /** |
| | 60 | + * ??? |
| | 61 | + */ |
| 10 | 62 | $.articleFeedbackv5special.showing = 0; |
| 11 | | - $.articleFeedbackv5special.apiUrl = undefined; |
| 12 | 63 | |
| | 64 | + /** |
| | 65 | + * The url to which to send the request |
| | 66 | + */ |
| | 67 | + $.articleFeedbackv5special.apiUrl = undefined; |
| | 68 | + |
| | 69 | + // }}} |
| | 70 | + // {{{ Init methods |
| | 71 | + |
| | 72 | + /** |
| | 73 | + * Binds events for each of the controls |
| | 74 | + */ |
| 13 | 75 | $.articleFeedbackv5special.setBinds = function() { |
| 14 | 76 | $( '#aft5-filter' ).bind( 'change', function(e) { |
| 15 | 77 | $.articleFeedbackv5special.filter = $(this).val(); |
| — | — | @@ -38,14 +100,41 @@ |
| 39 | 101 | } ); |
| 40 | 102 | } |
| 41 | 103 | |
| | 104 | + // }}} |
| | 105 | + // {{{ Moderation methods |
| | 106 | + |
| | 107 | + // {{{ hideFeedback |
| | 108 | + |
| | 109 | + /** |
| | 110 | + * Hides a response |
| | 111 | + * |
| | 112 | + * @param id int the feedback id |
| | 113 | + */ |
| 42 | 114 | $.articleFeedbackv5special.hideFeedback = function ( id ) { |
| 43 | 115 | $.articleFeedbackv5special.flagFeedback( id, 'hide' ); |
| 44 | 116 | } |
| 45 | 117 | |
| | 118 | + // }}} |
| | 119 | + // {{{ abuseFeedback |
| | 120 | + |
| | 121 | + /** |
| | 122 | + * Flags a response as abuse |
| | 123 | + * |
| | 124 | + * @param id int the feedback id |
| | 125 | + */ |
| 46 | 126 | $.articleFeedbackv5special.abuseFeedback = function ( id ) { |
| 47 | 127 | $.articleFeedbackv5special.flagFeedback( id, 'abuse' ); |
| 48 | 128 | } |
| 49 | 129 | |
| | 130 | + // }}} |
| | 131 | + // {{{ flagFeedback |
| | 132 | + |
| | 133 | + /** |
| | 134 | + * Sends the request to mark a response |
| | 135 | + * |
| | 136 | + * @param id int the feedback id |
| | 137 | + * @param type string the type of mark ('hide' or 'abuse') |
| | 138 | + */ |
| 50 | 139 | $.articleFeedbackv5special.flagFeedback = function ( id, type ) { |
| 51 | 140 | $.ajax( { |
| 52 | 141 | 'url' : $.articleFeedbackv5special.apiUrl, |
| — | — | @@ -77,8 +166,20 @@ |
| 78 | 167 | return false; |
| 79 | 168 | } |
| 80 | 169 | |
| 81 | | - // ie, on loading next page, don't reset the view, but on sort/filter |
| 82 | | - // remove what was there and start over. |
| | 170 | + // }}} |
| | 171 | + |
| | 172 | + // }}} |
| | 173 | + // {{{ Process methods |
| | 174 | + |
| | 175 | + // {{{ loadFeedback |
| | 176 | + |
| | 177 | + /** |
| | 178 | + * Pulls in a set of responses. |
| | 179 | + * |
| | 180 | + * When a next-page load is requested, it appends the new responses; on a |
| | 181 | + * sort or filter change, the existing responses are removed from the view |
| | 182 | + * and replaced. |
| | 183 | + */ |
| 83 | 184 | $.articleFeedbackv5special.loadFeedback = function ( resetContents ) { |
| 84 | 185 | $.ajax( { |
| 85 | 186 | 'url' : $.articleFeedbackv5special.apiUrl, |
| — | — | @@ -121,9 +222,19 @@ |
| 122 | 223 | |
| 123 | 224 | return false; |
| 124 | 225 | } |
| | 226 | + |
| | 227 | + // }}} |
| | 228 | + |
| | 229 | + // }}} |
| | 230 | + |
| | 231 | +// }}} |
| | 232 | + |
| 125 | 233 | } )( jQuery ); |
| 126 | 234 | |
| 127 | 235 | $( document ).ready( function() { |
| | 236 | + |
| | 237 | +// {{{ Kick off when ready |
| | 238 | + |
| 128 | 239 | // This was failing sometimes when it was in the function above. |
| 129 | 240 | // I think it maky have been a race condition. |
| 130 | 241 | $.articleFeedbackv5special.apiUrl = mw.util.wikiScript('api'); |
| — | — | @@ -132,4 +243,8 @@ |
| 133 | 244 | // Set up event binds and do initial data fetch. |
| 134 | 245 | $.articleFeedbackv5special.setBinds(); |
| 135 | 246 | $.articleFeedbackv5special.loadFeedback( true ); |
| | 247 | + |
| | 248 | +// }}} |
| | 249 | + |
| 136 | 250 | } ); |
| | 251 | + |