http://www.mediawiki.org/wiki/Special:Code/MediaWiki/96040
Revision: 96040
Author: jeroendedauw
Date: 2011-09-01 21:03:12 +0000 (Thu, 01 Sep 2011)
Log Message:
-----------
work on survey ui
Modified Paths:
--------------
trunk/extensions/Survey/Survey.php
trunk/extensions/Survey/api/ApiAddSurvey.php
trunk/extensions/Survey/api/ApiEditSurvey.php
trunk/extensions/Survey/api/ApiQuerySurveys.php
trunk/extensions/Survey/api/ApiSubmitSurvey.php
trunk/extensions/Survey/includes/SurveyTag.php
trunk/extensions/Survey/resources/ext.survey.js
trunk/extensions/Survey/resources/ext.survey.special.survey.js
trunk/extensions/Survey/resources/jquery.survey.js
Modified: trunk/extensions/Survey/Survey.php
===================================================================
--- trunk/extensions/Survey/Survey.php 2011-09-01 20:58:45 UTC (rev 96039)
+++ trunk/extensions/Survey/Survey.php 2011-09-01 21:03:12 UTC (rev 96040)
@@ -157,7 +157,8 @@
'jquery.survey.js'
),
'styles' => array(
- 'fancybox/jquery.fancybox-1.3.4.css',
+ // This file makes the RL go mad for some reason, so for now
load it the old fashioned way.
+ //'fancybox/jquery.fancybox-1.3.4.css',
),
'dependencies' => array( 'ext.survey' ),
'messages' => array(
Modified: trunk/extensions/Survey/api/ApiAddSurvey.php
===================================================================
--- trunk/extensions/Survey/api/ApiAddSurvey.php 2011-09-01 20:58:45 UTC
(rev 96039)
+++ trunk/extensions/Survey/api/ApiAddSurvey.php 2011-09-01 21:03:12 UTC
(rev 96040)
@@ -74,7 +74,7 @@
}
public function getTokenSalt() {
- return '';
+ return 'addsurvey';
}
public function getAllowedParams() {
Modified: trunk/extensions/Survey/api/ApiEditSurvey.php
===================================================================
--- trunk/extensions/Survey/api/ApiEditSurvey.php 2011-09-01 20:58:45 UTC
(rev 96039)
+++ trunk/extensions/Survey/api/ApiEditSurvey.php 2011-09-01 21:03:12 UTC
(rev 96040)
@@ -66,7 +66,7 @@
}
public function getTokenSalt() {
- return '';
+ return 'editsurvey';
}
public function getAllowedParams() {
Modified: trunk/extensions/Survey/api/ApiQuerySurveys.php
===================================================================
--- trunk/extensions/Survey/api/ApiQuerySurveys.php 2011-09-01 20:58:45 UTC
(rev 96039)
+++ trunk/extensions/Survey/api/ApiQuerySurveys.php 2011-09-01 21:03:12 UTC
(rev 96040)
@@ -37,6 +37,8 @@
$surveys = array();
+ // TODO
+
if ( isset( $params['ids'] ) ) {
foreach ( $params['ids'] as $surveyId ) {
$survey = Survey::newFromId( $surveyId,
$params['incquestions'] == 1 );
@@ -96,6 +98,9 @@
ApiBase::PARAM_TYPE => 'integer',
ApiBase::PARAM_DFLT => '0',
),
+ 'enabled' => array(
+ ApiBase::PARAM_TYPE => 'integer',
+ ),
'limit' => array(
ApiBase :: PARAM_DFLT => 20,
ApiBase :: PARAM_TYPE => 'limit',
@@ -118,6 +123,7 @@
'ids' => 'The IDs of the surveys to return',
'names' => 'The names of the surveys to return',
'incquestions' => 'Include the questions of the surveys
or not',
+ 'enabled' => 'Enabled state to filter on',
'continue' => 'Offset number from where to continue the
query',
'limit' => 'Max amount of words to return',
'token' => 'Edit token. You can get one of these
through prop=info.',
Modified: trunk/extensions/Survey/api/ApiSubmitSurvey.php
===================================================================
--- trunk/extensions/Survey/api/ApiSubmitSurvey.php 2011-09-01 20:58:45 UTC
(rev 96039)
+++ trunk/extensions/Survey/api/ApiSubmitSurvey.php 2011-09-01 21:03:12 UTC
(rev 96040)
@@ -49,7 +49,7 @@
}
public function getTokenSalt() {
- return '';
+ return 'submitsurvey';
}
public function getAllowedParams() {
Modified: trunk/extensions/Survey/includes/SurveyTag.php
===================================================================
--- trunk/extensions/Survey/includes/SurveyTag.php 2011-09-01 20:58:45 UTC
(rev 96039)
+++ trunk/extensions/Survey/includes/SurveyTag.php 2011-09-01 21:03:12 UTC
(rev 96040)
@@ -67,6 +67,12 @@
if ( !$loadedJs ) {
$parser->getOutput()->addModules( 'ext.survey.jquery' );
+
+ global $wgExtensionAssetsPath, $wgScriptPath;
+ $parser->getOutput()->addHeadItem( Html::linkedStyle(
+ ( $wgExtensionAssetsPath === false ?
$wgScriptPath . '/extensions' : $wgExtensionAssetsPath )
+ .
'/Survey/resources/fancybox/jquery.fancybox-1.3.4.css'
+ ) );
}
return Html::element(
Modified: trunk/extensions/Survey/resources/ext.survey.js
===================================================================
--- trunk/extensions/Survey/resources/ext.survey.js 2011-09-01 20:58:45 UTC
(rev 96039)
+++ trunk/extensions/Survey/resources/ext.survey.js 2011-09-01 21:03:12 UTC
(rev 96040)
@@ -52,6 +52,34 @@
return $select;
};
+ this.question = new( function() {
+
+ this.type = new( function() {
+ this.TEXT = 0;
+ this.NUMBER = 1;
+ this.SELECT = 2;
+ this.RADIO = 3;
+ } );
+
+ this.getTypeSelector = function( value, attributes ) {
+ var options = [];
+
+ var types = {
+ 'text': survey.question.type.TEXT,
+ 'number': survey.question.type.NUMBER,
+ 'select': survey.question.type.SELECT,
+ 'radio': survey.question.type.RADIO
+ };
+
+ for ( msg in types ) {
+ options[survey.msg( 'survey-question-type-' +
msg )] = types[msg];
+ }
+
+ return survey.htmlSelect( options, value, attributes );
+ };
+
+ } );
+
} )();
Modified: trunk/extensions/Survey/resources/ext.survey.special.survey.js
===================================================================
--- trunk/extensions/Survey/resources/ext.survey.special.survey.js
2011-09-01 20:58:45 UTC (rev 96039)
+++ trunk/extensions/Survey/resources/ext.survey.special.survey.js
2011-09-01 21:03:12 UTC (rev 96040)
@@ -9,8 +9,6 @@
var _this = this;
- var questionTypes = {};
-
var $table = null;
var newQuestionNr = 0;
var questionNr = 0;
@@ -95,7 +93,7 @@
'for': 'survey-question-type-' + question.id
} ).text( mw.msg( 'survey-special-label-type' ) ) );
- $input.append( survey.htmlSelect( questionTypes, question.type,
{
+ $input.append( survey.question.getTypeSelector( question.type, {
'id': 'survey-question-type-' + question.id,
'name': 'survey-question-type-' + question.id
} ) );
@@ -133,16 +131,7 @@
$( '#survey-question-text-new' ).focus().select();
};
- function initTypes() {
- var types = [ 'text', 'number', 'select', 'radio' ];
- for ( type in types ) {
- questionTypes[survey.msg( 'survey-question-type-' +
types[type] )] = type;
- }
- };
-
function setup() {
- initTypes();
-
$table = $( '#survey-name' ).closest( 'tbody' );
$table.append( '<tr><td colspan="2"><hr /></td></tr>' );
Modified: trunk/extensions/Survey/resources/jquery.survey.js
===================================================================
--- trunk/extensions/Survey/resources/jquery.survey.js 2011-09-01 20:58:45 UTC
(rev 96039)
+++ trunk/extensions/Survey/resources/jquery.survey.js 2011-09-01 21:03:12 UTC
(rev 96040)
@@ -17,7 +17,9 @@
'action': 'query',
'list': 'surveys',
'format': 'json',
- 'sunames': options.names.join( '|' )
+ 'sunames': options.names.join( '|' ),
+ 'suincquestions': 1,
+ 'suenabled': 1
},
function( data ) {
if ( data.surveys ) {
@@ -39,8 +41,32 @@
// TODO
};
+ this.getQuestionInput = function( question ) {
+ var type = survey.question.type;
+
+ var $input;
+
+ switch ( question.type ) {
+ case type.TEXT: default:
+ $input = $( '<input />' ).attr( {
+ 'id': 'survey-question-' + question.id,
+ 'class': 'survey-question'
+ } );
+ break;
+ }
+
+ return $input;
+ };
+
this.getSurveyQuestion = function( question ) {
- return ''; // TODO
+ $q = $( '<div />' );
+
+ $q.append( '<hr />' );
+ $q.append( $( '<p />' ).text( question.text ) );
+
+ $q.append( this.getQuestionInput( question ) )
+
+ return $q;
};
this.getSurveyQuestions = function( questions ) {
@@ -56,10 +82,10 @@
this.getSurveyBody = function( surveyData ) {
$survey = $( '<div />' );
+ $survey.append( $( '<h1 />' ).text( surveyData.name ) );
+
$survey.append( this.getSurveyQuestions( surveyData.questions )
);
- $survey.append( JSON.stringify( surveyData ) );
-
return $survey;
};
_______________________________________________
MediaWiki-CVS mailing list
[email protected]
https://lists.wikimedia.org/mailman/listinfo/mediawiki-cvs