http://www.mediawiki.org/wiki/Special:Code/MediaWiki/98040

Revision: 98040
Author:   catrope
Date:     2011-09-24 22:11:40 +0000 (Sat, 24 Sep 2011)
Log Message:
-----------
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
    trunk/extensions/MoodBar/SpecialMoodBarFeedback.php

Added Paths:
-----------
    
trunk/extensions/MoodBar/modules/ext.moodBar.dashboard/ext.moodBar.dashboard.js

Modified: trunk/extensions/MoodBar/MoodBar.php
===================================================================
--- trunk/extensions/MoodBar/MoodBar.php        2011-09-24 21:59:05 UTC (rev 
98039)
+++ trunk/extensions/MoodBar/MoodBar.php        2011-09-24 22:11:40 UTC (rev 
98040)
@@ -116,6 +116,11 @@
        'position' => 'bottom',
 );
 
+$wgResourceModules['ext.moodBar.dashboard'] = $mbResourceTemplate + array(
+       'scripts' => 'ext.moodBar.dashboard/ext.moodBar.dashboard.js',
+       'dependencies' => array( 'mediawiki.util' ),
+);
+
 $wgResourceModules['ext.moodBar.dashboard.styles'] = $mbResourceTemplate + 
array(
        'styles' => 'ext.moodBar.dashboard/ext.moodBar.dashboard.css',
 );

Modified: trunk/extensions/MoodBar/SpecialMoodBarFeedback.php
===================================================================
--- trunk/extensions/MoodBar/SpecialMoodBarFeedback.php 2011-09-24 21:59:05 UTC 
(rev 98039)
+++ trunk/extensions/MoodBar/SpecialMoodBarFeedback.php 2011-09-24 22:11:40 UTC 
(rev 98040)
@@ -39,6 +39,7 @@
                $wgOut->addHTML( $this->buildForm() );
                $wgOut->addHTML( $this->buildList( $res ) );
                $wgOut->addModuleStyles( 'ext.moodBar.dashboard.styles' );
+               $wgOut->addModules( 'ext.moodBar.dashboard' );
        }
        
        public function buildForm() {
@@ -107,9 +108,10 @@
                $comment = htmlspecialchars( $row->mbf_comment );
                $permalinkURL = htmlspecialchars( SpecialPage::getTitleFor( 
'MoodBarFeedback', $row->mbf_id )->getLinkURL() );
                $permalinkText = wfMessage( 'moodbar-feedback-permalink' 
)->escaped();
+               $continueData = wfTimestamp( TS_MW, $row->mbf_timestamp ) . '|' 
. intval( $row->mbf_id );
                
                return <<<HTML
-               <li class="fbd-item">
+               <li class="fbd-item" data-mbccontinue="$continueData">
                        <div class="fbd-item-emoticon fbd-item-emoticon-$type">
                                <span 
class="fbd-item-emoticon-label">$typeMsg</span>
                        </div>

Added: 
trunk/extensions/MoodBar/modules/ext.moodBar.dashboard/ext.moodBar.dashboard.js
===================================================================
--- 
trunk/extensions/MoodBar/modules/ext.moodBar.dashboard/ext.moodBar.dashboard.js 
                            (rev 0)
+++ 
trunk/extensions/MoodBar/modules/ext.moodBar.dashboard/ext.moodBar.dashboard.js 
    2011-09-24 22:11:40 UTC (rev 98040)
@@ -0,0 +1,67 @@
+jQuery( function( $ ) {
+       $( '#fbd-list-more a' ).click( function( e ) {
+               e.preventDefault();
+               
+               // TODO spinner
+               
+               var     limit = 20,
+                       username = $( '#fbd-filters-username' ).val(),
+                       types = [],
+                       reqData = {
+                               'action': 'query',
+                               'list': 'moodbarcomments',
+                               'format': 'json',
+                               'mbcprop': 'formatted',
+                               'mbclimit': limit + 2, // we drop the first and 
last result
+                               'mbccontinue': $( '#fbd-list li:last' ).data( 
'mbccontinue' )
+                       };
+               $( '#fbd-filters-type-praise, #fbd-filters-type-confusion, 
#fbd-filters-type-issues' ).each( function() {
+                       if ( $(this).prop( 'checked' ) ) {
+                               types.push( $(this).val() );
+                       }
+               } );
+               if ( types.length ) {
+                       reqData['mbctype'] = types.join( '|' );
+               }
+               if ( username.length ) {
+                       reqData['mbcuser'] = username;
+               }
+               
+               // TODO save jqXhr and protect against duplicate clicks causing 
concurrent requests
+               $.ajax( mw.util.wikiScript( 'api' ), {
+                       'data': reqData,
+                       'success': function( data ) {
+                               if ( !data || !data.query || 
!data.query.moodbarcomments ) {
+                                       // TODO error
+                                       return;
+                               }
+                               
+                               var     comments = data.query.moodbarcomments,
+                                       len = comments.length,
+                                       $ul = $( '#fbd-list' ),
+                                       moreResults = false,
+                                       i;
+                               if ( len > 0 ) {
+                                       // Drop the first element because it 
duplicates the last shown one
+                                       comments.shift();
+                                       len--;
+                               }
+                               if ( len > limit ) {
+                                       // Drop any elements past the limit. We 
do know there are more results now
+                                       len = limit;
+                                       moreResults = true;
+                               }
+                               
+                               for ( i = 0; i < len; i++ ) {
+                                       $ul.append( comments[i].formatted );
+                               }
+                               
+                               // TODO act on !moreResults
+                       },
+                       'error': function( jqXHR, textStatus, errorThrown ) {
+                               // TODO
+                       },
+                       'dataType': 'json'
+               } );
+       } );
+} );


Property changes on: 
trunk/extensions/MoodBar/modules/ext.moodBar.dashboard/ext.moodBar.dashboard.js
___________________________________________________________________
Added: svn:eol-style
   + native


_______________________________________________
MediaWiki-CVS mailing list
[email protected]
https://lists.wikimedia.org/mailman/listinfo/mediawiki-cvs

Reply via email to