[MediaWiki-commits] [Gerrit] Hygiene: Make survey selection easier to read - change (mediawiki...QuickSurveys)

2015-09-02 Thread jenkins-bot (Code Review)
jenkins-bot has submitted this change and it was merged.

Change subject: Hygiene: Make survey selection easier to read
..


Hygiene: Make survey selection easier to read

Change-Id: I20e0b5f9e0ce9177e4c0c4aa89d5dc67ae7ee92d
---
M resources/ext.quicksurveys.init/init.js
1 file changed, 44 insertions(+), 48 deletions(-)

Approvals:
  Jdlrobson: Looks good to me, approved
  jenkins-bot: Verified



diff --git a/resources/ext.quicksurveys.init/init.js 
b/resources/ext.quicksurveys.init/init.js
index d180eda..f4d2e8c 100644
--- a/resources/ext.quicksurveys.init/init.js
+++ b/resources/ext.quicksurveys.init/init.js
@@ -1,10 +1,11 @@
 ( function ( $ ) {
-   var survey, $bodyContent, $place, randomSurvey, surveyIndex,
+   var survey, $bodyContent, $place,
$panel = $( '' ),
-   availableSurveys = mw.config.get( 'wgEnabledQuickSurveys' ),
+   enabledSurveys = mw.config.get( 'wgEnabledQuickSurveys' ),
isMainPage = mw.config.get( 'wgIsMainPage' ),
isArticle = mw.config.get( 'wgIsArticle' ),
-   sessionId = mw.user.generateRandomSessionId();
+   sessionId = mw.user.generateRandomSessionId(),
+   availableSurveys = [];
 
mw.extQuickSurveys = mw.extQuickSurveys || {};
 
@@ -13,57 +14,52 @@
return;
}
 
+   // Find which surveys are available to the user
+   $( enabledSurveys ).each( function ( i, enabledSurvey ) {
+   // Setting the quicksurvey param makes every enabled survey 
available
+   if ( mw.util.getParamValue( 'quicksurvey' ) ) {
+   availableSurveys.push( enabledSurvey );
+   return;
+   } else if (
+   getSurveyToken( enabledSurvey ) !== '~' &&
+   getBucketForSurvey( enabledSurvey ) === 'A'
+   ) {
+   availableSurveys.push( enabledSurvey );
+   }
+   } );
+
if ( availableSurveys.length ) {
-   // Get a random survey that hasn't been dismissed and in 
correct bucket
-   while ( !survey && availableSurveys.length !== 0 ) {
-   surveyIndex = Math.floor( Math.random() * 
availableSurveys.length );
-   randomSurvey = availableSurveys[surveyIndex];
-   // Setting the param quicksurvey bypasses the bucketing
-   if ( mw.util.getParamValue( 'quicksurvey' ) ) {
-   survey = randomSurvey;
-   break;
-   }
-   if (
-   getSurveyToken( randomSurvey ) === '~' ||
-   getBucketForSurvey( randomSurvey ) !== 'A'
-   ) {
-   availableSurveys.splice( surveyIndex, 1 );
-   continue;
-   }
-   survey = randomSurvey;
+   // Get a random available survey
+   survey = availableSurveys[Math.floor( Math.random() * 
availableSurveys.length )];
+   $bodyContent = $( '.mw-content-ltr, .mw-content-rtl' );
+   $place = $bodyContent.find( '> h1, > h2, > h3, > h4, > h5, > 
h6' ).eq( 0 );
+
+   if ( $place.length ) {
+   $panel.insertBefore( $place );
+   } else {
+   $panel.appendTo( $bodyContent );
}
+   // survey.module contains i18n messages
+   mw.loader.using( [ 'ext.quicksurveys.views', survey.module ] 
).done( function () {
+   var panel,
+   options = {
+   survey: survey,
+   templateData: {
+   question: mw.msg( 
survey.question ),
+   description: mw.msg( 
survey.description )
+   }
+   };
 
-   if ( survey ) {
-   $bodyContent = $( '.mw-content-ltr, .mw-content-rtl' );
-   $place = $bodyContent.find( '> h1, > h2, > h3, > h4, > 
h5, > h6' ).eq( 0 );
-
-   if ( $place.length ) {
-   $panel.insertBefore( $place );
+   if ( survey.type === 'internal' ) {
+   panel = new 
mw.extQuickSurveys.views.QuickSurvey( options );
} else {
-   $panel.appendTo( $bodyContent );
+   panel = new 
mw.extQuickSurveys.views.ExternalSurvey( options );
}
-   // survey.module contains i18n messages
-   

[MediaWiki-commits] [Gerrit] Hygiene: Make survey selection easier to read - change (mediawiki...QuickSurveys)

2015-08-28 Thread Robmoen (Code Review)
Robmoen has uploaded a new change for review.

  https://gerrit.wikimedia.org/r/234677

Change subject: Hygiene: Make survey selection easier to read
..

Hygiene: Make survey selection easier to read

Change-Id: I20e0b5f9e0ce9177e4c0c4aa89d5dc67ae7ee92d
---
M resources/ext.quicksurveys.init/init.js
1 file changed, 43 insertions(+), 47 deletions(-)


  git pull ssh://gerrit.wikimedia.org:29418/mediawiki/extensions/QuickSurveys 
refs/changes/77/234677/1

diff --git a/resources/ext.quicksurveys.init/init.js 
b/resources/ext.quicksurveys.init/init.js
index d180eda..4bec70b 100644
--- a/resources/ext.quicksurveys.init/init.js
+++ b/resources/ext.quicksurveys.init/init.js
@@ -1,10 +1,11 @@
 ( function ( $ ) {
var survey, $bodyContent, $place, randomSurvey, surveyIndex,
$panel = $( 'div class=ext-qs-loader-bar 
mw-ajax-loader/div' ),
-   availableSurveys = mw.config.get( 'wgEnabledQuickSurveys' ),
+   enabledSurveys = mw.config.get( 'wgEnabledQuickSurveys' ),
isMainPage = mw.config.get( 'wgIsMainPage' ),
isArticle = mw.config.get( 'wgIsArticle' ),
-   sessionId = mw.user.generateRandomSessionId();
+   sessionId = mw.user.generateRandomSessionId(),
+   availableSurveys = [];
 
mw.extQuickSurveys = mw.extQuickSurveys || {};
 
@@ -13,57 +14,52 @@
return;
}
 
+   // Find which surveys are available to the user
+   $( enabledSurveys ).each( function ( i, enabledSurvey ) {
+   // Setting the quicksurvey param makes every enabled survey 
available
+   if ( mw.util.getParamValue( 'quicksurvey' ) ) {
+   availableSurveys.push( enabledSurvey );
+   return;
+   } else if (
+   getSurveyToken( enabledSurvey ) !== '~' 
+   getBucketForSurvey( enabledSurvey ) === 'A'
+   ) {
+   availableSurveys.push( enabledSurvey );
+   }
+   } );
+
if ( availableSurveys.length ) {
-   // Get a random survey that hasn't been dismissed and in 
correct bucket
-   while ( !survey  availableSurveys.length !== 0 ) {
-   surveyIndex = Math.floor( Math.random() * 
availableSurveys.length );
-   randomSurvey = availableSurveys[surveyIndex];
-   // Setting the param quicksurvey bypasses the bucketing
-   if ( mw.util.getParamValue( 'quicksurvey' ) ) {
-   survey = randomSurvey;
-   break;
-   }
-   if (
-   getSurveyToken( randomSurvey ) === '~' ||
-   getBucketForSurvey( randomSurvey ) !== 'A'
-   ) {
-   availableSurveys.splice( surveyIndex, 1 );
-   continue;
-   }
-   survey = randomSurvey;
+   // Get a random available survey
+   survey = availableSurveys[Math.floor( Math.random() * 
availableSurveys.length )];
+   $bodyContent = $( '.mw-content-ltr, .mw-content-rtl' );
+   $place = $bodyContent.find( ' h1,  h2,  h3,  h4,  h5,  
h6' ).eq( 0 );
+
+   if ( $place.length ) {
+   $panel.insertBefore( $place );
+   } else {
+   $panel.appendTo( $bodyContent );
}
+   // survey.module contains i18n messages
+   mw.loader.using( [ 'ext.quicksurveys.views', survey.module ] 
).done( function () {
+   var panel,
+   options = {
+   survey: survey,
+   templateData: {
+   question: mw.msg( 
survey.question ),
+   description: mw.msg( 
survey.description )
+   }
+   };
 
-   if ( survey ) {
-   $bodyContent = $( '.mw-content-ltr, .mw-content-rtl' );
-   $place = $bodyContent.find( ' h1,  h2,  h3,  h4,  
h5,  h6' ).eq( 0 );
-
-   if ( $place.length ) {
-   $panel.insertBefore( $place );
+   if ( survey.type === 'internal' ) {
+   panel = new 
mw.extQuickSurveys.views.QuickSurvey( options );
} else {
-   $panel.appendTo( $bodyContent );
+   panel = new 
mw.extQuickSurveys.views.ExternalSurvey( options );
}
-   //