r98040 MediaWiki - Code Review archive

Repository:MediaWiki
Revision:r98039‎ | r98040 | r98041 >
Date:22:11, 24 September 2011
Author:catrope
Status:ok
Tags:
Comment:
MoodBar: Basic JS to make the More link work, will improve tomorrow. In the special page, add a data- property for the continue parameter/
Modified paths:
  • /trunk/extensions/MoodBar/MoodBar.php (modified) (history)
  • /trunk/extensions/MoodBar/SpecialMoodBarFeedback.php (modified) (history)
  • /trunk/extensions/MoodBar/modules/ext.moodBar.dashboard/ext.moodBar.dashboard.js (added) (history)

Diff [purge]

Index: trunk/extensions/MoodBar/SpecialMoodBarFeedback.php
@@ -39,6 +39,7 @@
4040 $wgOut->addHTML( $this->buildForm() );
4141 $wgOut->addHTML( $this->buildList( $res ) );
4242 $wgOut->addModuleStyles( 'ext.moodBar.dashboard.styles' );
 43+ $wgOut->addModules( 'ext.moodBar.dashboard' );
4344 }
4445
4546 public function buildForm() {
@@ -107,9 +108,10 @@
108109 $comment = htmlspecialchars( $row->mbf_comment );
109110 $permalinkURL = htmlspecialchars( SpecialPage::getTitleFor( 'MoodBarFeedback', $row->mbf_id )->getLinkURL() );
110111 $permalinkText = wfMessage( 'moodbar-feedback-permalink' )->escaped();
 112+ $continueData = wfTimestamp( TS_MW, $row->mbf_timestamp ) . '|' . intval( $row->mbf_id );
111113
112114 return <<<HTML
113 - <li class="fbd-item">
 115+ <li class="fbd-item" data-mbccontinue="$continueData">
114116 <div class="fbd-item-emoticon fbd-item-emoticon-$type">
115117 <span class="fbd-item-emoticon-label">$typeMsg</span>
116118 </div>
Index: trunk/extensions/MoodBar/modules/ext.moodBar.dashboard/ext.moodBar.dashboard.js
@@ -0,0 +1,67 @@
 2+jQuery( function( $ ) {
 3+ $( '#fbd-list-more a' ).click( function( e ) {
 4+ e.preventDefault();
 5+
 6+ // TODO spinner
 7+
 8+ var limit = 20,
 9+ username = $( '#fbd-filters-username' ).val(),
 10+ types = [],
 11+ reqData = {
 12+ 'action': 'query',
 13+ 'list': 'moodbarcomments',
 14+ 'format': 'json',
 15+ 'mbcprop': 'formatted',
 16+ 'mbclimit': limit + 2, // we drop the first and last result
 17+ 'mbccontinue': $( '#fbd-list li:last' ).data( 'mbccontinue' )
 18+ };
 19+ $( '#fbd-filters-type-praise, #fbd-filters-type-confusion, #fbd-filters-type-issues' ).each( function() {
 20+ if ( $(this).prop( 'checked' ) ) {
 21+ types.push( $(this).val() );
 22+ }
 23+ } );
 24+ if ( types.length ) {
 25+ reqData['mbctype'] = types.join( '|' );
 26+ }
 27+ if ( username.length ) {
 28+ reqData['mbcuser'] = username;
 29+ }
 30+
 31+ // TODO save jqXhr and protect against duplicate clicks causing concurrent requests
 32+ $.ajax( mw.util.wikiScript( 'api' ), {
 33+ 'data': reqData,
 34+ 'success': function( data ) {
 35+ if ( !data || !data.query || !data.query.moodbarcomments ) {
 36+ // TODO error
 37+ return;
 38+ }
 39+
 40+ var comments = data.query.moodbarcomments,
 41+ len = comments.length,
 42+ $ul = $( '#fbd-list' ),
 43+ moreResults = false,
 44+ i;
 45+ if ( len > 0 ) {
 46+ // Drop the first element because it duplicates the last shown one
 47+ comments.shift();
 48+ len--;
 49+ }
 50+ if ( len > limit ) {
 51+ // Drop any elements past the limit. We do know there are more results now
 52+ len = limit;
 53+ moreResults = true;
 54+ }
 55+
 56+ for ( i = 0; i < len; i++ ) {
 57+ $ul.append( comments[i].formatted );
 58+ }
 59+
 60+ // TODO act on !moreResults
 61+ },
 62+ 'error': function( jqXHR, textStatus, errorThrown ) {
 63+ // TODO
 64+ },
 65+ 'dataType': 'json'
 66+ } );
 67+ } );
 68+} );
Property changes on: trunk/extensions/MoodBar/modules/ext.moodBar.dashboard/ext.moodBar.dashboard.js
___________________________________________________________________
Added: svn:eol-style
169 + native
Index: trunk/extensions/MoodBar/MoodBar.php
@@ -116,6 +116,11 @@
117117 'position' => 'bottom',
118118 );
119119
 120+$wgResourceModules['ext.moodBar.dashboard'] = $mbResourceTemplate + array(
 121+ 'scripts' => 'ext.moodBar.dashboard/ext.moodBar.dashboard.js',
 122+ 'dependencies' => array( 'mediawiki.util' ),
 123+);
 124+
120125 $wgResourceModules['ext.moodBar.dashboard.styles'] = $mbResourceTemplate + array(
121126 'styles' => 'ext.moodBar.dashboard/ext.moodBar.dashboard.css',
122127 );

Status & tagging log