r96040 MediaWiki - Code Review archive

Repository:MediaWiki
Revision:r96039‎ | r96040 | r96041 >
Date:21:03, 1 September 2011
Author:jeroendedauw
Status:deferred
Tags:
Comment:
work on survey ui
Modified paths:
  • /trunk/extensions/Survey/Survey.php (modified) (history)
  • /trunk/extensions/Survey/api/ApiAddSurvey.php (modified) (history)
  • /trunk/extensions/Survey/api/ApiEditSurvey.php (modified) (history)
  • /trunk/extensions/Survey/api/ApiQuerySurveys.php (modified) (history)
  • /trunk/extensions/Survey/api/ApiSubmitSurvey.php (modified) (history)
  • /trunk/extensions/Survey/includes/SurveyTag.php (modified) (history)
  • /trunk/extensions/Survey/resources/ext.survey.js (modified) (history)
  • /trunk/extensions/Survey/resources/ext.survey.special.survey.js (modified) (history)
  • /trunk/extensions/Survey/resources/jquery.survey.js (modified) (history)

Diff [purge]

Index: trunk/extensions/Survey/Survey.php
@@ -157,7 +157,8 @@
158158 'jquery.survey.js'
159159 ),
160160 'styles' => array(
161 - 'fancybox/jquery.fancybox-1.3.4.css',
 161+ // This file makes the RL go mad for some reason, so for now load it the old fashioned way.
 162+ //'fancybox/jquery.fancybox-1.3.4.css',
162163 ),
163164 'dependencies' => array( 'ext.survey' ),
164165 'messages' => array(
Index: trunk/extensions/Survey/includes/SurveyTag.php
@@ -67,6 +67,12 @@
6868
6969 if ( !$loadedJs ) {
7070 $parser->getOutput()->addModules( 'ext.survey.jquery' );
 71+
 72+ global $wgExtensionAssetsPath, $wgScriptPath;
 73+ $parser->getOutput()->addHeadItem( Html::linkedStyle(
 74+ ( $wgExtensionAssetsPath === false ? $wgScriptPath . '/extensions' : $wgExtensionAssetsPath )
 75+ . '/Survey/resources/fancybox/jquery.fancybox-1.3.4.css'
 76+ ) );
7177 }
7278
7379 return Html::element(
Index: trunk/extensions/Survey/api/ApiSubmitSurvey.php
@@ -49,7 +49,7 @@
5050 }
5151
5252 public function getTokenSalt() {
53 - return '';
 53+ return 'submitsurvey';
5454 }
5555
5656 public function getAllowedParams() {
Index: trunk/extensions/Survey/api/ApiEditSurvey.php
@@ -66,7 +66,7 @@
6767 }
6868
6969 public function getTokenSalt() {
70 - return '';
 70+ return 'editsurvey';
7171 }
7272
7373 public function getAllowedParams() {
Index: trunk/extensions/Survey/api/ApiAddSurvey.php
@@ -74,7 +74,7 @@
7575 }
7676
7777 public function getTokenSalt() {
78 - return '';
 78+ return 'addsurvey';
7979 }
8080
8181 public function getAllowedParams() {
Index: trunk/extensions/Survey/api/ApiQuerySurveys.php
@@ -37,6 +37,8 @@
3838
3939 $surveys = array();
4040
 41+ // TODO
 42+
4143 if ( isset( $params['ids'] ) ) {
4244 foreach ( $params['ids'] as $surveyId ) {
4345 $survey = Survey::newFromId( $surveyId, $params['incquestions'] == 1 );
@@ -96,6 +98,9 @@
9799 ApiBase::PARAM_TYPE => 'integer',
98100 ApiBase::PARAM_DFLT => '0',
99101 ),
 102+ 'enabled' => array(
 103+ ApiBase::PARAM_TYPE => 'integer',
 104+ ),
100105 'limit' => array(
101106 ApiBase :: PARAM_DFLT => 20,
102107 ApiBase :: PARAM_TYPE => 'limit',
@@ -118,6 +123,7 @@
119124 'ids' => 'The IDs of the surveys to return',
120125 'names' => 'The names of the surveys to return',
121126 'incquestions' => 'Include the questions of the surveys or not',
 127+ 'enabled' => 'Enabled state to filter on',
122128 'continue' => 'Offset number from where to continue the query',
123129 'limit' => 'Max amount of words to return',
124130 'token' => 'Edit token. You can get one of these through prop=info.',
Index: trunk/extensions/Survey/resources/ext.survey.special.survey.js
@@ -9,8 +9,6 @@
1010
1111 var _this = this;
1212
13 - var questionTypes = {};
14 -
1513 var $table = null;
1614 var newQuestionNr = 0;
1715 var questionNr = 0;
@@ -95,7 +93,7 @@
9694 'for': 'survey-question-type-' + question.id
9795 } ).text( mw.msg( 'survey-special-label-type' ) ) );
9896
99 - $input.append( survey.htmlSelect( questionTypes, question.type, {
 97+ $input.append( survey.question.getTypeSelector( question.type, {
10098 'id': 'survey-question-type-' + question.id,
10199 'name': 'survey-question-type-' + question.id
102100 } ) );
@@ -133,16 +131,7 @@
134132 $( '#survey-question-text-new' ).focus().select();
135133 };
136134
137 - function initTypes() {
138 - var types = [ 'text', 'number', 'select', 'radio' ];
139 - for ( type in types ) {
140 - questionTypes[survey.msg( 'survey-question-type-' + types[type] )] = type;
141 - }
142 - };
143 -
144135 function setup() {
145 - initTypes();
146 -
147136 $table = $( '#survey-name' ).closest( 'tbody' );
148137
149138 $table.append( '<tr><td colspan="2"><hr /></td></tr>' );
Index: trunk/extensions/Survey/resources/jquery.survey.js
@@ -17,7 +17,9 @@
1818 'action': 'query',
1919 'list': 'surveys',
2020 'format': 'json',
21 - 'sunames': options.names.join( '|' )
 21+ 'sunames': options.names.join( '|' ),
 22+ 'suincquestions': 1,
 23+ 'suenabled': 1
2224 },
2325 function( data ) {
2426 if ( data.surveys ) {
@@ -39,8 +41,32 @@
4042 // TODO
4143 };
4244
 45+ this.getQuestionInput = function( question ) {
 46+ var type = survey.question.type;
 47+
 48+ var $input;
 49+
 50+ switch ( question.type ) {
 51+ case type.TEXT: default:
 52+ $input = $( '<input />' ).attr( {
 53+ 'id': 'survey-question-' + question.id,
 54+ 'class': 'survey-question'
 55+ } );
 56+ break;
 57+ }
 58+
 59+ return $input;
 60+ };
 61+
4362 this.getSurveyQuestion = function( question ) {
44 - return ''; // TODO
 63+ $q = $( '<div />' );
 64+
 65+ $q.append( '<hr />' );
 66+ $q.append( $( '<p />' ).text( question.text ) );
 67+
 68+ $q.append( this.getQuestionInput( question ) )
 69+
 70+ return $q;
4571 };
4672
4773 this.getSurveyQuestions = function( questions ) {
@@ -56,10 +82,10 @@
5783 this.getSurveyBody = function( surveyData ) {
5884 $survey = $( '<div />' );
5985
 86+ $survey.append( $( '<h1 />' ).text( surveyData.name ) );
 87+
6088 $survey.append( this.getSurveyQuestions( surveyData.questions ) );
6189
62 - $survey.append( JSON.stringify( surveyData ) );
63 -
6490 return $survey;
6591 };
6692
Index: trunk/extensions/Survey/resources/ext.survey.js
@@ -52,6 +52,34 @@
5353 return $select;
5454 };
5555
 56+ this.question = new( function() {
 57+
 58+ this.type = new( function() {
 59+ this.TEXT = 0;
 60+ this.NUMBER = 1;
 61+ this.SELECT = 2;
 62+ this.RADIO = 3;
 63+ } );
 64+
 65+ this.getTypeSelector = function( value, attributes ) {
 66+ var options = [];
 67+
 68+ var types = {
 69+ 'text': survey.question.type.TEXT,
 70+ 'number': survey.question.type.NUMBER,
 71+ 'select': survey.question.type.SELECT,
 72+ 'radio': survey.question.type.RADIO
 73+ };
 74+
 75+ for ( msg in types ) {
 76+ options[survey.msg( 'survey-question-type-' + msg )] = types[msg];
 77+ }
 78+
 79+ return survey.htmlSelect( options, value, attributes );
 80+ };
 81+
 82+ } );
 83+
5684 } )();
5785
5886

Status & tagging log