Index: trunk/extensions/ArticleFeedbackv5/modules/jquery.articleFeedbackv5/jquery.articleFeedbackv5.special.js |
— | — | @@ -156,16 +156,28 @@ |
157 | 157 | // Helpful and unhelpful have their own special logic, so break those out. |
158 | 158 | $.each( ['helpful', 'unhelpful' ], function ( index, value ) { |
159 | 159 | $( '.articleFeedbackv5-' + value + '-link' ).live( 'click', function( e ) { |
160 | | - id = $.articleFeedbackv5special.stripID( this, 'articleFeedbackv5-' + value + '-link-' ); |
161 | | - $.articleFeedbackv5special.flagFeedback( id, value ); |
162 | | - // add highlighted class |
163 | | - $( this ).addClass( 'helpful-active' ); |
| 160 | + e.preventDefault(); |
| 161 | + var $l = $( e.target ); |
| 162 | + var id = $l.parents( '.articleFeedbackv5-feedback' ).attr( 'rel' ); |
| 163 | + var activity = $.articleFeedbackv5special.getActivity( id ); |
| 164 | + if ( activity[value] ) { |
| 165 | + return false; |
| 166 | + } |
| 167 | + if ( 'helpful' == value && activity.unhelpful ) { |
| 168 | + $.articleFeedbackv5special.flagFeedback( id, 'unhelpful', -1 ); |
| 169 | + $.articleFeedbackv5special.flagFeedback( id, 'helpful', 1 ); |
| 170 | + } else if ( 'unhelpful' == value && activity.helpful ) { |
| 171 | + $.articleFeedbackv5special.flagFeedback( id, 'helpful', -1 ); |
| 172 | + $.articleFeedbackv5special.flagFeedback( id, 'unhelpful', 1 ); |
| 173 | + } else { |
| 174 | + $.articleFeedbackv5special.flagFeedback( id, value, 1 ); |
| 175 | + } |
164 | 176 | } ) |
165 | 177 | } ); |
166 | 178 | |
167 | 179 | $.each( ['unhide', 'undelete', 'oversight', 'hide', 'abuse', 'delete', 'unoversight'], function ( index, value ) { |
168 | 180 | $( '.articleFeedbackv5-' + value + '-link' ).live( 'click', function( e ) { |
169 | | - $.articleFeedbackv5special.flagFeedback( $.articleFeedbackv5special.stripID( this, 'articleFeedbackv5-' + value + '-link-' ), value ); |
| 181 | + $.articleFeedbackv5special.flagFeedback( $.articleFeedbackv5special.stripID( this, 'articleFeedbackv5-' + value + '-link-' ), value, 1 ); |
170 | 182 | } ) |
171 | 183 | } ); |
172 | 184 | } |
— | — | @@ -309,8 +321,24 @@ |
310 | 322 | }; |
311 | 323 | |
312 | 324 | // }}} |
| 325 | + // {{{ getActivity |
313 | 326 | |
| 327 | + /** |
| 328 | + * Utility method: Gets the activity for a feedback ID |
| 329 | + * |
| 330 | + * @param fid int the feedback ID |
| 331 | + * @return object the activity object |
| 332 | + */ |
| 333 | + $.articleFeedbackv5special.getActivity = function ( fid ) { |
| 334 | + if ( !( fid in $.articleFeedbackv5special.activity ) ) { |
| 335 | + $.articleFeedbackv5special.activity[fid] = { helpful: false, unhelpful: false, abuse: false, hide: false, delete: false }; |
| 336 | + } |
| 337 | + return $.articleFeedbackv5special.activity[fid]; |
| 338 | + }; |
| 339 | + |
314 | 340 | // }}} |
| 341 | + |
| 342 | + // }}} |
315 | 343 | // {{{ Process methods |
316 | 344 | |
317 | 345 | // {{{ flagFeedback |
— | — | @@ -320,8 +348,9 @@ |
321 | 349 | * |
322 | 350 | * @param id int the feedback id |
323 | 351 | * @param type string the type of mark (valid values: hide, abuse, delete, helpful, unhelpful) |
| 352 | + * @param dir int the direction of the mark (-1 = tick down; 1 = tick up) |
324 | 353 | */ |
325 | | - $.articleFeedbackv5special.flagFeedback = function ( id, type ) { |
| 354 | + $.articleFeedbackv5special.flagFeedback = function ( id, type, dir ) { |
326 | 355 | $.ajax( { |
327 | 356 | 'url' : $.articleFeedbackv5special.apiUrl, |
328 | 357 | 'type' : 'POST', |
— | — | @@ -330,6 +359,7 @@ |
331 | 360 | 'pageid' : $.articleFeedbackv5special.page, |
332 | 361 | 'feedbackid': id, |
333 | 362 | 'flagtype' : type, |
| 363 | + 'direction' : dir > 0 ? 'increase' : 'decrease', |
334 | 364 | 'format' : 'json', |
335 | 365 | 'action' : 'articlefeedbackv5-flag-feedback' |
336 | 366 | }, |
— | — | @@ -342,11 +372,19 @@ |
343 | 373 | if ( 'helpful' in data['articlefeedbackv5-flag-feedback'] ) { |
344 | 374 | $( '#articleFeedbackv5-helpful-votes-' + id ).text( data['articlefeedbackv5-flag-feedback'].helpful ); |
345 | 375 | } |
| 376 | + if ( 'helpful' == type || 'unhelpful' == type ) { |
| 377 | + var $l = $( '#articleFeedbackv5-' + type + '-link-' + id ); |
| 378 | + if ( dir > 0 ) { |
| 379 | + $l.addClass( 'helpful-active' ); |
| 380 | + } else { |
| 381 | + $l.removeClass( 'helpful-active' ); |
| 382 | + } |
| 383 | + } |
346 | 384 | // Save activity |
347 | 385 | if ( !( id in $.articleFeedbackv5special.activity ) ) { |
348 | 386 | $.articleFeedbackv5special.activity[id] = { helpful: false, unhelpful: false, abuse: false, hide: false, delete: false }; |
349 | 387 | } |
350 | | - $.articleFeedbackv5special.activity[id][type] = true; |
| 388 | + $.articleFeedbackv5special.activity[id][type] = dir > 0 ? true : false; |
351 | 389 | $.articleFeedbackv5special.storeActivity(); |
352 | 390 | } else if ( data['articlefeedbackv5-flag-feedback'].result == 'Error' ) { |
353 | 391 | msg = data['articlefeedbackv5-flag-feedback'].reason; |
— | — | @@ -395,10 +433,22 @@ |
396 | 434 | 'success': function ( data ) { |
397 | 435 | if ( 'articlefeedbackv5-view-feedback' in data ) { |
398 | 436 | if ( resetContents ) { |
399 | | - $( '#articleFeedbackv5-show-feedback' ).html( data['articlefeedbackv5-view-feedback'].feedback); |
400 | | - } else { |
401 | | - $( '#articleFeedbackv5-show-feedback' ).append( data['articlefeedbackv5-view-feedback'].feedback); |
| 437 | + $( '#articleFeedbackv5-show-feedback' ).empty(); |
402 | 438 | } |
| 439 | + var $newList = $( '<div></div>' ).html( data['articlefeedbackv5-view-feedback'].feedback ); |
| 440 | + $newList.find( '.articleFeedbackv5-feedback' ).each( function () { |
| 441 | + var id = $( this ).attr( 'rel' ); |
| 442 | + if ( id in $.articleFeedbackv5special.activity ) { |
| 443 | + var activity = $.articleFeedbackv5special.getActivity( id ); |
| 444 | + if ( activity.helpful ) { |
| 445 | + $( this ).find( '#articleFeedbackv5-helpful-link-' + id ).addClass( 'helpful-active' ); |
| 446 | + } |
| 447 | + if ( activity.unhelpful ) { |
| 448 | + $( this ).find( '#articleFeedbackv5-unhelpful-link-' + id ).addClass( 'helpful-active' ); |
| 449 | + } |
| 450 | + } |
| 451 | + } ); |
| 452 | + $( '#articleFeedbackv5-show-feedback' ).append( $newList ); |
403 | 453 | $( '#articleFeedbackv5-feedback-count-total' ).text( data['articlefeedbackv5-view-feedback'].count ); |
404 | 454 | $.articleFeedbackv5special.listControls.continue = data['articlefeedbackv5-view-feedback'].continue; |
405 | 455 | // set effects on toolboxes |