r96779 MediaWiki - Code Review archive

Repository:MediaWiki
Revision:r96778‎ | r96779 | r96780 >
Date:14:36, 11 September 2011
Author:jeroendedauw
Status:deferred
Tags:
Comment:
work on survey admin ui
Modified paths:
  • /trunk/extensions/Survey/Survey.i18n.php (modified) (history)
  • /trunk/extensions/Survey/Survey.php (modified) (history)
  • /trunk/extensions/Survey/Survey.sql (modified) (history)
  • /trunk/extensions/Survey/includes/Survey.class.php (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
@@ -150,7 +150,8 @@
151151 'survey-special-label-type',
152152 'survey-special-label-text',
153153 'survey-special-label-addquestion',
154 - 'survey-special-label-button',
 154+ 'survey-special-label-add-first',
 155+ 'survey-special-label-add-another',
155156 'survey-special-remove',
156157 'survey-special-remove-confirm',
157158 'survey-special-label-answers'
Index: trunk/extensions/Survey/Survey.sql
@@ -5,13 +5,16 @@
66 -- Surveys
77 CREATE TABLE IF NOT EXISTS /*$wgDBprefix*/surveys (
88 survey_id SMALLINT unsigned NOT NULL auto_increment PRIMARY KEY,
9 - survey_name VARCHAR(255) NOT NULL,
10 - survey_enabled TINYINT NOT NULL default '0',
11 - survey_header TEXT NOT NULL,
12 - survey_footer TEXT NOT NULL,
13 - survey_thanks TEXT NOT NULL,
14 - survey_user_type TINYINT NOT NULL default '0',
15 - survey_namespaces BLOB NOT NULL
 9+ survey_name VARCHAR(255) NOT NULL, -- String indentifier for the survey
 10+ survey_title VARCHAR(255) NOT NULL, -- Title of the survey
 11+ survey_enabled TINYINT NOT NULL default '0', -- If the survey can be taken by users
 12+ survey_header TEXT NOT NULL, -- Text to display above the survey
 13+ survey_footer TEXT NOT NULL, -- Text to display below the survey
 14+ survey_thanks TEXT NOT NULL, -- Text to display after survey submission
 15+ survey_user_type TINYINT NOT NULL default '0', -- Type of users that can participate in the survey
 16+ survey_namespaces BLOB NOT NULL, -- Namespaces on which the survey can be displayed
 17+ survey_ratio TINYINT unsigned NOT NULL, -- Percentage of users to show the survey to
 18+ survey_expiry INT unsigned NOT NULL -- Coockie expiry time for the survey
1619 ) /*$wgDBTableOptions*/;
1720
1821 -- Questions
Index: trunk/extensions/Survey/Survey.i18n.php
@@ -50,7 +50,7 @@
5151
5252 // Special:Surveys
5353 'surveys-special-addnew' => 'Add a new survey',
54 - 'surveys-special-namedoc' => 'Enter the name for the new survey.',
 54+ 'surveys-special-namedoc' => 'Enter a name for the new survey that will be used as simple identifier. For example: editor-motivation.',
5555 'surveys-special-newname' => 'New survey name:',
5656 'surveys-special-add' => 'Add survey',
5757 'surveys-special-existing' => 'Existing surveys',
@@ -97,8 +97,10 @@
9898 // Special:Survey
9999 'surveys-special-unknown-name' => 'There is no survey with the requested name.',
100100 'survey-special-label-name' => 'Survey name',
 101+ 'survey-special-label-title' => 'Survey title',
101102 'survey-special-label-enabled' => 'Survey enabled',
102 - 'survey-special-label-button' => 'Add question',
 103+ 'survey-special-label-add-first' => 'Add question',
 104+ 'survey-special-label-add-another' => 'Add another question',
103105 'survey-special-label-addquestion' => 'New question',
104106 'survey-special-label-add' => 'New question name',
105107 'survey-question-label-nr' => 'Question #$1',
Index: trunk/extensions/Survey/specials/SpecialSurvey.php
@@ -73,13 +73,16 @@
7474 $survey = Survey::newFromId( $wgRequest->getInt( 'survey-id' ), null, false );
7575 }
7676
77 - foreach ( array( 'name', 'header', 'footer', 'thanks' ) as $field ) {
 77+ foreach ( array( 'name', 'title', 'header', 'footer', 'thanks' ) as $field ) {
7878 $survey->setField( $field, $wgRequest->getText( 'survey-' . $field ) );
7979 }
8080
8181 $survey->setField( 'enabled', $wgRequest->getCheck( 'survey-enabled' ) );
82 - $survey->setField( 'user_type', $wgRequest->getInt( 'survey-user_type' ) );
8382
 83+ foreach ( array( 'user_type' ) as $field ) {
 84+ $survey->setField( $field, $wgRequest->getInt( 'survey-' . $field ) );
 85+ }
 86+
8487 $survey->setQuestions( $this->getSubmittedQuestions() );
8588
8689 $survey->writeToDB();
@@ -175,15 +178,23 @@
176179 );
177180
178181 $fields[] = array(
179 - 'type' => 'text',
 182+ 'class' => 'SurveyNameField',
180183 'default' => $survey->getField( 'name' ),
181184 'label-message' => 'survey-special-label-name',
182185 'id' => 'survey-name',
183186 'name' => 'survey-name',
184 - //'disabled' => true
 187+ 'style' => 'font-weight: bold;'
185188 );
186189
187190 $fields[] = array(
 191+ 'type' => 'text',
 192+ 'default' => $survey->getField( 'title' ),
 193+ 'label-message' => 'survey-special-label-title',
 194+ 'id' => 'survey-title',
 195+ 'name' => 'survey-title',
 196+ );
 197+
 198+ $fields[] = array(
188199 'type' => 'check',
189200 'default' => $survey->getField( 'enabled' ) ? '1' : '0',
190201 'label-message' => 'survey-special-label-enabled',
@@ -284,4 +295,20 @@
285296 );
286297 }
287298
 299+}
 300+
 301+class SurveyNameField extends HTMLFormField {
 302+
 303+ public function getInputHTML( $value ) {
 304+ return Html::element(
 305+ 'span',
 306+ array(
 307+ 'id' => $this->mParams['id'],
 308+ 'name' => $this->mParams['name'],
 309+ 'style' => $this->mParams['style']
 310+ ),
 311+ $value
 312+ );
 313+ }
 314+
288315 }
\ No newline at end of file
Index: trunk/extensions/Survey/includes/Survey.class.php
@@ -38,12 +38,15 @@
3939 return array(
4040 'id' => 'id',
4141 'name' => 'str',
 42+ 'title' => 'str',
4243 'enabled' => 'bool',
4344 'header' => 'str',
4445 'footer' => 'str',
4546 'thanks' => 'str',
4647 'user_type' => 'int',
47 - 'namespaces' => 'array'
 48+ 'namespaces' => 'array',
 49+ 'ratio' => 'int',
 50+ 'expiry' => 'int'
4851 );
4952 }
5053
@@ -58,12 +61,15 @@
5962 public static function getDefaults() {
6063 return array(
6164 'name' => '',
 65+ 'title' => '',
6266 'enabled' => '0',
6367 'header' => 'Thank you for taking this short survey. Please fill out the following questions:',
6468 'footer' => '',
6569 'thanks' => 'Thank you for your responses.',
6670 'user_type' => self::$USER_ALL,
6771 'namespaces' => array(),
 72+ 'ratio' => 100,
 73+ 'expiry' => 60 * 60 * 24 * 30
6874 );
6975 }
7076
@@ -288,7 +294,7 @@
289295 foreach ( $submissionsForSurvey as $nr => $submission ) {
290296 $sucecss = $dbw->delete(
291297 'survey_answers',
292 - array( 'answer_submission_id' => $submission->getId() )
 298+ array( 'answer_submission_id' => $submission->id )
293299 ) && $sucecss;
294300
295301 if ( $nr % 500 == 0 ) {
Index: trunk/extensions/Survey/resources/ext.survey.special.survey.js
@@ -70,21 +70,25 @@
7171 $table.append( $tr );
7272
7373 $tr.append( $( '<td />' ).attr( { 'class': 'mw-label question-label' } ).html(
74 - $( '<label />' ).text( mw.msg( 'survey-special-label-addquestion' ) )
 74+ '' //$( '<label />' ).text( mw.msg( 'survey-special-label-addquestion' ) )
7575 ) );
7676
7777 $tr.append( $( '<td />' ).attr( { 'class': 'mw-input' } ).html(
78 - getQuestionInput( { 'id': 'new', 'answers': [], 'type': 0 } )
79 - ).append( $( '<button />' ).button( { 'label': mw.msg( 'survey-special-label-button' ) } )
80 - .click( function() { onAddQuestionRequest(); return false; } )
 78+ '' //getQuestionInput( { 'id': 'new', 'answers': [], 'type': 0 } )
 79+ ).append( $( '<button />' ).button( { 'label': mw.msg( 'survey-special-label-add-first' ) } )
 80+ .click( function() {
 81+ $( this ).button( { 'label': mw.msg( 'survey-special-label-add-another' ) } );
 82+ onAddQuestionRequest();
 83+ return false;
 84+ } )
8185 ) );
82 -
83 - $( '#survey-question-text-new' ).keypress( function( event ) {
84 - if ( event.which == '13' ) {
85 - event.preventDefault();
86 - onAddQuestionRequest();
87 - }
88 - } );
 86+//
 87+// $( '#survey-question-text-new' ).keypress( function( event ) {
 88+// if ( event.which == '13' ) {
 89+// event.preventDefault();
 90+// onAddQuestionRequest();
 91+// }
 92+// } );
8993 };
9094
9195 function addQuestion( question ) {
@@ -187,13 +191,13 @@
188192
189193 function onAddQuestionRequest() {
190194 addQuestion( {
191 - 'text': $( '#survey-question-text-new' ).val(),
192 - 'required': !!$( '#survey-question-required-new' ).attr( 'checked' ),
193 - 'type': $( '#survey-question-type-new' ).val(),
194 - 'id': 'new-' + newQuestionNr++,
195 - 'answers': $( '#survey-question-answers-new' ).val().split( '\n' )
 195+ 'text': '', // $( '#survey-question-text-new' ).val(),
 196+ 'required': false, //!!$( '#survey-question-required-new' ).attr( 'checked' ),
 197+ 'type': 0, // $( '#survey-question-type-new' ).val(),
 198+ 'id': 'new-' + ++newQuestionNr,
 199+ 'answers': [] //$( '#survey-question-answers-new' ).val().split( '\n' )
196200 } );
197 - $( '#survey-question-text-new' ).focus().select();
 201+ $( '#survey-question-text-new-' + newQuestionNr ).focus().select();
198202 $( 'html' ).animate( { scrollTop: $( document ).height() }, 'fast' );
199203 };
200204

Follow-up revisions

RevisionCommit summaryAuthorDate
r96784Follow up to r96779;jeroendedauw15:21, 11 September 2011

Status & tagging log