r95695 MediaWiki - Code Review archive

Repository:MediaWiki
Revision:r95694‎ | r95695 | r95696 >
Date:20:34, 29 August 2011
Author:jeroendedauw
Status:deferred
Tags:
Comment:
work on survey admin
Modified paths:
  • /trunk/extensions/Survey/Survey.i18n.php (modified) (history)
  • /trunk/extensions/Survey/Survey.php (modified) (history)
  • /trunk/extensions/Survey/includes/SurveyQuestion.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/specials/SpecialSurvey.php (modified) (history)

Diff [purge]

Index: trunk/extensions/Survey/Survey.php
@@ -104,21 +104,10 @@
105105 $wgGroupPermissions['bot' ]['surveysubmit'] = false;
106106 $wgGroupPermissions['sysop' ]['surveysubmit'] = true;
107107
108 -$egSurveyScriptPath = $wgExtensionAssetsPath === false ? $wgScriptPath . '/extensions' : $wgExtensionAssetsPath;
109 -$egSurveyScriptPath .= '/Survey/resources';
110 -
111 -$egSurveyMessages = array(
112 - 'ext.survey.special.surveys' => array(
113 - 'surveys-special-confirm-delete'
114 - ),
115 - 'jquery.survey' => array(
116 -
117 - )
118 -);
119 -
120108 $moduleTemplate = array(
121109 'localBasePath' => dirname( __FILE__ ),
122 - 'remoteBasePath' => $egSurveyScriptPath
 110+ 'remoteBasePath' => ( $wgExtensionAssetsPath === false ? $wgScriptPath . '/extensions' : $wgExtensionAssetsPath )
 111+ . '/Survey/resources'
123112 );
124113
125114 $wgResourceModules['ext.survey'] = $moduleTemplate + array(
@@ -132,9 +121,25 @@
133122 'ext.survey.special.surveys.js'
134123 ),
135124 'dependencies' => array( 'ext.survey' ),
136 - 'messages' => $egSurveyMessages['ext.survey.special.surveys']
 125+ 'messages' => array(
 126+ 'surveys-special-confirm-delete'
 127+ )
137128 );
138129
 130+$wgResourceModules['ext.survey.special.survey'] = $moduleTemplate + array(
 131+ 'scripts' => array(
 132+ 'ext.survey.special.survey.js'
 133+ ),
 134+ 'dependencies' => array( 'ext.survey' ),
 135+ 'messages' => array(
 136+ 'survey-question-type-text',
 137+ 'survey-question-type-number',
 138+ 'survey-question-type-select',
 139+ 'survey-question-type-radio',
 140+ 'survey-question-label-nr'
 141+ )
 142+);
 143+
139144 $wgResourceModules['ext.survey.jquery'] = $moduleTemplate + array(
140145 'scripts' => array(
141146 'fancybox/jquery.fancybox-1.3.4.js',
@@ -144,7 +149,11 @@
145150 'fancybox/jquery.fancybox-1.3.4.css',
146151 ),
147152 'dependencies' => array( 'ext.survey' ),
148 - 'messages' => $egSurveyMessages['jquery.survey']
 153+ 'messages' => array(
 154+
 155+ )
149156 );
150157
 158+unset( $moduleTemplate );
 159+
151160 $egSurveySettings = array();
Index: trunk/extensions/Survey/Survey.i18n.php
@@ -61,4 +61,9 @@
6262 'survey-special-label-question' => 'Question text',
6363 'survey-special-label-button' => 'Add question',
6464 'survey-special-label-add' => 'New question name',
 65+ 'survey-question-type-text' => 'Free text',
 66+ 'survey-question-type-number' => 'Number',
 67+ 'survey-question-type-select' => 'Dropdown menu',
 68+ 'survey-question-type-radio' => 'Radio boxes',
 69+ 'survey-question-label-nr' => 'Question #$1',
6570 );
Index: trunk/extensions/Survey/specials/SpecialSurvey.php
@@ -39,6 +39,7 @@
4040 }
4141 else {
4242 $this->showSurvey( $survey );
 43+ $this->addModules( 'ext.survey.special.survey' );
4344 }
4445 }
4546
@@ -79,13 +80,15 @@
8081 'required' => true
8182 );
8283
83 - foreach ( $survey->getQuestions() as $question ) {
 84+ foreach ( $survey->getQuestions() as /* SurveyQuestion */ $question ) {
8485 $fields[] = array(
8586 'class' => 'SurveyQuestionField',
8687 'options' => array(
8788 'required' => $question->isRequired(),
8889 'text' => $question->getText(),
89 - 'type' => $question->getType()
 90+ 'type' => $question->getType(),
 91+ 'id' => $question->getId(),
 92+ 'type' => $question->getType(),
9093 )
9194 );
9295 }
@@ -145,7 +148,7 @@
146149 public function getInputHTML( $value ) {
147150 return parent::getInputHTML( $value ) . ' ' . Html::element(
148151 'button',
149 - array(),
 152+ array( 'id' => 'survey-add-question-button' ),
150153 wfMsg( 'survey-special-label-button' )
151154 );
152155 }
@@ -155,7 +158,9 @@
156159 class SurveyQuestionField extends HTMLFormField {
157160
158161 public function getInputHTML( $value ) {
159 - $attribs = array();
 162+ $attribs = array(
 163+ 'class' => 'survey-question-data'
 164+ );
160165
161166 foreach ( $this->mParams['options'] as $name => $value ) {
162167 if ( is_bool( $value ) ) {
Index: trunk/extensions/Survey/includes/SurveyQuestion.php
@@ -273,7 +273,7 @@
274274 *
275275 * @since 0.1
276276 *
277 - * @return string
 277+ * @return integer
278278 */
279279 public function getType() {
280280 return $this->type;
Index: trunk/extensions/Survey/resources/ext.survey.special.survey.js
@@ -5,9 +5,99 @@
66 * @licence GNU GPL v3 or later
77 * @author Jeroen De Dauw <jeroendedauw at gmail dot com>
88 */
9 -
109 (function( $ ) { $( document ).ready( function() {
1110
 11+ var _this = this;
1212
 13+ var questionTypes = {};
1314
 15+ var $table = null;
 16+ var newQuestionNr = 0;
 17+ var questionNr = 0;
 18+
 19+ function addQuestion( question ) {
 20+ var $tr = $( '<tr />' ).attr( {
 21+ 'class': 'mw-htmlform-field-SurveyQuestionField'
 22+ } );
 23+
 24+ // TODO: defaulting
 25+
 26+ var id = 'foo';
 27+
 28+ $tr.append( $( '<td />' ).attr( { 'class': 'mw-label' } ).html(
 29+ $( '<label />' ).attr( { 'for': id } ).text( survey.msg( 'survey-question-label-nr', ++questionNr ) )
 30+ ) );
 31+
 32+ $tr.append( $( '<td />' ).attr( { 'class': 'mw-input' } ).html(
 33+ getQuestionInput( question )
 34+ ) );
 35+
 36+ $table.append( $tr );
 37+ };
 38+
 39+ function getQuestionInput( question ) {
 40+ var $input = $( '<div />' ).attr( { 'border': '1px' } );
 41+
 42+ var $text = $( '<input />' ).attr( {
 43+ 'type': 'text',
 44+ 'id': 'survey-question-' + question.id
 45+ } );
 46+
 47+ var $type = survey.htmlSelect( questionTypes, question.type );
 48+
 49+ // TODO
 50+
 51+ $input.append( $text, $type );
 52+
 53+ return $input;
 54+ };
 55+
 56+ function removeQuestion( question ) {
 57+
 58+ };
 59+
 60+ function onAddQuestionRequest() {
 61+ addQuestion( {
 62+ 'text': $( '#survey-add-question-text' ).text(),
 63+ 'id': 'new-' + newQuestionNr++
 64+ } );
 65+ $( '#survey-add-question-text' ).text( '' );
 66+ };
 67+
 68+ function initTypes() {
 69+ var types = [ 'text', 'number', 'select', 'radio' ];
 70+ for ( type in types ) {
 71+ questionTypes[survey.msg( 'survey-question-type-' + types[type] )] = type;
 72+ }
 73+ };
 74+
 75+ function setup() {
 76+ initTypes();
 77+
 78+ $table = $( '#survey-add-question-text' ).closest( 'tbody' );
 79+
 80+ $( '#survey-add-question-text' ).keypress( function( event ) {
 81+ if ( event.which == '13' ) {
 82+ event.preventDefault();
 83+ _this.onAddQuestionRequest();
 84+ }
 85+ } );
 86+
 87+ $( '#survey-add-question-button' ).click( _this.onAddQuestionRequest );
 88+
 89+ $( '.survey-question-data' ).each( function( index, domElement ) {
 90+ $this = $( domElement );
 91+
 92+ addQuestion( {
 93+ 'text': $this.attr( 'data-text' ),
 94+ 'default': $this.attr( 'data-default' ),
 95+ 'required': $this.attr( 'data-required' ),
 96+ 'id': $this.attr( 'data-id' ),
 97+ 'type': $this.attr( 'data-type' ),
 98+ } );
 99+ } );
 100+ };
 101+
 102+ setup();
 103+
14104 } ); })( jQuery );
\ No newline at end of file
Index: trunk/extensions/Survey/resources/ext.survey.js
@@ -19,7 +19,7 @@
2020 return mediaWiki.log.call( mediaWiki.log, 'Survey: ' + message );
2121 }
2222 }
23 - }
 23+ };
2424
2525 this.msg = function() {
2626 if ( typeof mediaWiki === 'undefined' ) {
@@ -34,8 +34,24 @@
3535 else {
3636 return mediaWiki.msg.apply( mediaWiki.msg, arguments );
3737 }
38 - }
 38+ };
3939
 40+ this.htmlSelect = function( options, value ) {
 41+ $select = $( '<select />' );
 42+
 43+ for ( message in options ) {
 44+ var attribs = { 'value': options[message] };
 45+
 46+ if ( value === options[message] ) {
 47+ attribs.selected = 'selected';
 48+ }
 49+
 50+ $select.append( $( '<option />' ).text( message ).attr( attribs ) );
 51+ }
 52+
 53+ return $select;
 54+ };
 55+
4056 } )();
4157
4258

Status & tagging log