Index: trunk/extensions/MoodBar/SpecialFeedbackDashboard.php |
— | — | @@ -278,7 +278,7 @@ |
279 | 279 | $permalink = $GLOBALS['wgUser']->getSkin() |
280 | 280 | ->link( $permalinkTitle, $permalinkText, |
281 | 281 | array(), array('hide-feedback' => '1') ); |
282 | | - return Xml::tags( 'div', array( 'class' => 'fbd-item-permalink' ), "($permalink)" ); |
| 282 | + return Xml::tags( 'div', array( 'class' => 'fbd-item-hide' ), "($permalink)" ); |
283 | 283 | } |
284 | 284 | |
285 | 285 | |
Index: trunk/extensions/MoodBar/modules/ext.moodBar.dashboard/ext.moodBar.dashboard.css |
— | — | @@ -224,7 +224,8 @@ |
225 | 225 | } |
226 | 226 | |
227 | 227 | .fbd-item-permalink, |
228 | | -.fbd-item-show { |
| 228 | +.fbd-item-show, |
| 229 | +.fbd-item-hide { |
229 | 230 | float: right; |
230 | 231 | font-size: 0.8em; |
231 | 232 | } |
Index: trunk/extensions/MoodBar/modules/ext.moodBar.dashboard/ext.moodBar.dashboard.js |
— | — | @@ -194,27 +194,31 @@ |
195 | 195 | } |
196 | 196 | |
197 | 197 | /** |
198 | | - * Show a hidden comment |
| 198 | + * Reload a comment, showing hidden comments if necessary |
| 199 | + * @param $item jQuery item containing the .fbd-item |
| 200 | + * @param show Set to true to show the comment despite its hidden status |
199 | 201 | */ |
200 | | - function showHiddenComment(e) { |
201 | | - var $item = $(this).closest('.fbd-item'); |
| 202 | + function reloadItem( $item, show ) { |
202 | 203 | var cont = $item.data('mbccontinue'); |
203 | 204 | |
204 | 205 | var request = { |
205 | 206 | 'action' : 'query', |
206 | 207 | 'list' : 'moodbarcomments', |
207 | 208 | 'format' : 'json', |
208 | | - 'mbcprop' : 'formatted|hidden', |
| 209 | + 'mbcprop' : 'formatted', |
209 | 210 | 'mbclimit' : 1, |
210 | 211 | 'mbccontinue' : cont |
211 | 212 | }; |
212 | 213 | |
213 | | - var $spinner = $('<span class="mw-ajax-loader"> </span>'); |
214 | | - $item.find('.fbd-item-show').empty().append( $spinner ); |
| 214 | + if ( show ) { |
| 215 | + request.mbcprop = 'formatted|hidden'; |
| 216 | + } |
215 | 217 | |
216 | 218 | $.post( mw.util.wikiScript('api'), request, |
217 | 219 | function( data ) { |
218 | | - if ( data && data.query && data.query.moodbarcomments ) { |
| 220 | + if ( data && data.query && data.query.moodbarcomments && |
| 221 | + data.query.moodbarcomments.length > 0 |
| 222 | + ) { |
219 | 223 | var $content = $j(data.query.moodbarcomments[0].formatted); |
220 | 224 | $item.replaceWith($content); |
221 | 225 | } else { |
— | — | @@ -222,14 +226,84 @@ |
223 | 227 | $item.find('.fbd-item-show').remove(); |
224 | 228 | } |
225 | 229 | }, 'json' ); |
| 230 | + } |
| 231 | + |
| 232 | + /** |
| 233 | + * Show a hidden comment |
| 234 | + */ |
| 235 | + function showHiddenItem(e) { |
| 236 | + var $item = $(this).closest('.fbd-item'); |
226 | 237 | |
| 238 | + var $spinner = $('<span class="mw-ajax-loader"> </span>'); |
| 239 | + $item.find('.fbd-item-show').empty().append( $spinner ); |
| 240 | + |
| 241 | + reloadItem( $item, true ); |
| 242 | + |
227 | 243 | e.preventDefault(); |
228 | 244 | } |
229 | 245 | |
| 246 | + /** |
| 247 | + * Execute an action on an item |
| 248 | + */ |
| 249 | + function doAction( params, $item ) { |
| 250 | + var item_id = $item.data('mbccontinue').split('|')[1]; |
| 251 | + |
| 252 | + $.post( mw.util.wikiScript('api'), |
| 253 | + $.extend( { |
| 254 | + 'action' : 'feedbackdashboard', |
| 255 | + 'token' : mw.user.tokens.get('editToken'), |
| 256 | + 'item' : item_id, |
| 257 | + 'format' : 'json' |
| 258 | + }, params ), |
| 259 | + function(response) { |
| 260 | + if ( response && response.feedbackdashboard ) { |
| 261 | + if ( response.feedbackdashboard.result == 'success' ) { |
| 262 | + reloadItem( $item ); |
| 263 | + } else { |
| 264 | + alert( response.feedbackdashboard.error ); |
| 265 | + } |
| 266 | + } else { |
| 267 | + alert('Unknown error'); |
| 268 | + } |
| 269 | + } ); |
| 270 | + } |
| 271 | + |
| 272 | + /** |
| 273 | + * Restore a hidden item to full visibility (event handler) |
| 274 | + */ |
| 275 | + function restoreItem(e) { |
| 276 | + var $item = $(this).closest('.fbd-item'); |
| 277 | + |
| 278 | + var $spinner = $('<span class="mw-ajax-loader"> </span>'); |
| 279 | + $item.find('.fbd-item-restore').empty().append( $spinner ); |
| 280 | + |
| 281 | + doAction( { 'mbaction' : 'restore' }, $item ); |
| 282 | + |
| 283 | + e.preventDefault(); |
| 284 | + } |
| 285 | + |
| 286 | + /** |
| 287 | + * Hide a item from view (event handler) |
| 288 | + */ |
| 289 | + function hideItem(e) { |
| 290 | + var $item = $(this).closest('.fbd-item'); |
| 291 | + |
| 292 | + var $spinner = $('<span class="mw-ajax-loader"> </span>'); |
| 293 | + $item.find('.fbd-item-hide').empty().append( $spinner ); |
| 294 | + |
| 295 | + doAction( { 'mbaction' : 'hide' }, $item ); |
| 296 | + |
| 297 | + e.preventDefault(); |
| 298 | + } |
| 299 | + |
230 | 300 | // On-load stuff |
231 | 301 | |
232 | | - $('.fbd-item-show a').live( 'click', showHiddenComment ); |
| 302 | + $('.fbd-item-show a').live( 'click', showHiddenItem ); |
233 | 303 | |
| 304 | + $('.fbd-item-hide a').live( 'click', hideItem ); |
| 305 | + |
| 306 | + $('.fbd-item-restore').live( 'click', restoreItem ); |
| 307 | + |
234 | 308 | $( '#fbd-filters' ).children( 'form' ).submit( function( e ) { |
235 | 309 | e.preventDefault(); |
236 | 310 | saveFormState(); |
Index: trunk/extensions/MoodBar/MoodBar.php |
— | — | @@ -22,6 +22,8 @@ |
23 | 23 | $wgAPIModules['moodbar'] = 'ApiMoodBar'; |
24 | 24 | $wgAutoloadClasses['ApiQueryMoodBarComments'] = dirname( __FILE__ ). '/ApiQueryMoodBarComments.php'; |
25 | 25 | $wgAPIListModules['moodbarcomments'] = 'ApiQueryMoodBarComments'; |
| 26 | +$wgAutoloadClasses['ApiFeedbackDashboard'] = dirname(__FILE__).'/ApiFeedbackDashboard.php'; |
| 27 | +$wgAPIModules['feedbackdashboard'] = 'ApiFeedbackDashboard'; |
26 | 28 | |
27 | 29 | // Hooks |
28 | 30 | $wgAutoloadClasses['MoodBarHooks'] = dirname(__FILE__).'/MoodBar.hooks.php'; |
Index: trunk/extensions/MoodBar/ApiFeedbackDashboard.php |
— | — | @@ -0,0 +1,90 @@ |
| 2 | +<?php |
| 3 | + |
| 4 | +class ApiFeedbackDashboard extends ApiBase { |
| 5 | + public function execute() { |
| 6 | + global $wgUser; |
| 7 | + if ( ! $wgUser->isAllowed('moodbar-admin') ) { |
| 8 | + $this->dieUsage( "You don't have permission to do that", 'permission-denied' ); |
| 9 | + } |
| 10 | + |
| 11 | + $params = $this->extractRequestParams(); |
| 12 | + $form = null; |
| 13 | + |
| 14 | + if ( $params['mbaction'] == 'hide' ) { |
| 15 | + $form = new MBHideForm( $params['item'] ); |
| 16 | + } elseif ( $params['mbaction'] == 'restore' ) { |
| 17 | + $form = new MBRestoreForm( $params['item'] ); |
| 18 | + } else { |
| 19 | + throw new MWException( "Action {$params['action']} not implemented" ); |
| 20 | + } |
| 21 | + |
| 22 | + $data = array( |
| 23 | + 'reason' => $params['reason'], |
| 24 | + 'item' => $params['item'], |
| 25 | + ); |
| 26 | + |
| 27 | + $result = null; |
| 28 | + $output = $form->submit( $data ); |
| 29 | + if ( $output === true ) { |
| 30 | + $result = array( 'result' => 'success' ); |
| 31 | + } else { |
| 32 | + $result = array( 'result' => 'error', 'error' => $output ); |
| 33 | + } |
| 34 | + |
| 35 | + $this->getResult()->addValue( null, $this->getModuleName(), $result ); |
| 36 | + } |
| 37 | + |
| 38 | + public function needsToken() { |
| 39 | + return true; |
| 40 | + } |
| 41 | + |
| 42 | + public function getTokenSalt() { |
| 43 | + return ''; |
| 44 | + } |
| 45 | + |
| 46 | + public function getAllowedParams() { |
| 47 | + return array( |
| 48 | + 'mbaction' => array( |
| 49 | + ApiBase::PARAM_REQUIRED => true, |
| 50 | + ApiBase::PARAM_TYPE => array( |
| 51 | + 'hide', |
| 52 | + 'restore', |
| 53 | + ), |
| 54 | + ), |
| 55 | + |
| 56 | + 'item' => array( |
| 57 | + ApiBase::PARAM_REQUIRED => true, |
| 58 | + ApiBase::PARAM_TYPE => 'integer', |
| 59 | + ), |
| 60 | + |
| 61 | + 'reason' => null, |
| 62 | + 'token' => array( |
| 63 | + ApiBase::PARAM_REQUIRED => true, |
| 64 | + ), |
| 65 | + ); |
| 66 | + } |
| 67 | + |
| 68 | + public function mustBePosted() { |
| 69 | + return true; |
| 70 | + } |
| 71 | + |
| 72 | + public function isWriteMode() { |
| 73 | + return true; |
| 74 | + } |
| 75 | + |
| 76 | + public function getVersion() { |
| 77 | + return __CLASS__ . ': $Id$'; |
| 78 | + } |
| 79 | + |
| 80 | + public function getParamDescription() { |
| 81 | + return array( |
| 82 | + 'mbaction' => 'The action to take', |
| 83 | + 'item' => 'The feedback item to apply it to', |
| 84 | + 'reason' => 'The reason to specify in the log', |
| 85 | + ); |
| 86 | + } |
| 87 | + |
| 88 | + public function getDescription() { |
| 89 | + return 'Allows administrators to manage submissions to the feedback dashboard'; |
| 90 | + } |
| 91 | +} |
Property changes on: trunk/extensions/MoodBar/ApiFeedbackDashboard.php |
___________________________________________________________________ |
Added: svn:keywords |
1 | 92 | + Id |