r95722 MediaWiki - Code Review archive

Repository:MediaWiki
Revision:r95721‎ | r95722 | r95723 >
Date:22:58, 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/resources/ext.survey.js (modified) (history)
  • /trunk/extensions/Survey/resources/ext.survey.special.survey.css (added) (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
@@ -130,13 +130,21 @@
131131 'scripts' => array(
132132 'ext.survey.special.survey.js'
133133 ),
 134+ 'styles' => array(
 135+ //'ext.survey.special.survey.css'
 136+ ),
134137 'dependencies' => array( 'ext.survey', 'jquery.ui.button' ),
135138 'messages' => array(
136139 'survey-question-type-text',
137140 'survey-question-type-number',
138141 'survey-question-type-select',
139142 'survey-question-type-radio',
140 - 'survey-question-label-nr'
 143+ 'survey-question-label-nr',
 144+ 'survey-special-label-required',
 145+ 'survey-special-label-type',
 146+ 'survey-special-label-text',
 147+ 'survey-special-label-addquestion',
 148+ 'survey-special-label-button',
141149 )
142150 );
143151
Index: trunk/extensions/Survey/Survey.i18n.php
@@ -58,12 +58,15 @@
5959 'surveys-special-unknown-name' => 'There is no survey with the requested name.',
6060 'survey-special-label-name' => 'Survey name',
6161 'survey-special-label-enabled' => 'Survey enabled',
62 - 'survey-special-label-question' => 'Question text',
6362 'survey-special-label-button' => 'Add question',
 63+ 'survey-special-label-addquestion' => 'New question',
6464 'survey-special-label-add' => 'New question name',
6565 'survey-question-type-text' => 'Free text',
6666 'survey-question-type-number' => 'Number',
6767 'survey-question-type-select' => 'Dropdown menu',
6868 'survey-question-type-radio' => 'Radio boxes',
6969 'survey-question-label-nr' => 'Question #$1',
 70+ 'survey-special-label-required' => 'Question is required',
 71+ 'survey-special-label-type' => 'Question type',
 72+ 'survey-special-label-text' => 'Question text',
7073 );
Index: trunk/extensions/Survey/specials/SpecialSurvey.php
@@ -65,11 +65,19 @@
6666 $fields = array();
6767
6868 $fields[] = array(
 69+ 'type' => 'hidden',
 70+ 'default' => $survey->getId(),
 71+ 'name' => 'survey-id',
 72+ 'id' => 'survey-id',
 73+ );
 74+
 75+ $fields[] = array(
6976 'type' => 'text',
7077 //'options' => array(),
7178 'default' => 'ohi',
7279 'label-message' => 'survey-special-label-name',
73 - 'required' => true
 80+ 'required' => true,
 81+ 'id' => 'survey-name',
7482 );
7583
7684 $fields[] = array(
@@ -77,7 +85,8 @@
7886 //'options' => array(),
7987 'default' => 'there',
8088 'label-message' => 'survey-special-label-enabled',
81 - 'required' => true
 89+ 'required' => true,
 90+ 'id' => 'survey-enabled',
8291 );
8392
8493 foreach ( $survey->getQuestions() as /* SurveyQuestion */ $question ) {
@@ -93,13 +102,6 @@
94103 );
95104 }
96105
97 - $fields[] = array(
98 - 'class' => 'SurveyAddQuestionField',
99 - 'default' => 'foo',
100 - 'label-message' => 'survey-special-label-add',
101 - 'id' => 'survey-add-question-text'
102 - );
103 -
104106 // getContext was added in 1.18 and since that version is
105107 // the second argument for the HTMLForm constructor.
106108 if ( is_callable( array( $this, 'getContext' ) ) ) {
@@ -116,45 +118,6 @@
117119
118120 }
119121
120 -class SurveyAddQuestionField extends HTMLTextField {
121 -
122 - /*
123 - $fields[] = array(
124 - 'type' => 'text',
125 - //'options' => array(),
126 - 'default' => $question->getText(),
127 - 'label-message' => 'survey-special-label-question',
128 - 'required' => $question->isRequired()
129 - );
130 -
131 - $fields[] = array(
132 - 'type' => 'select',
133 - 'options' => array(
134 -
135 - ),
136 - 'label-message' => 'survey-special-label-type',
137 - 'required' => $question->isRequired()
138 - );
139 -
140 - $fields[] = array(
141 - 'class' => 'SurveyQuestionValuesField',
142 - //'options' => array(),
143 - 'default' => '',
144 - 'label-message' => 'survey-special-label-required',
145 - 'required' => true
146 - );
147 - */
148 -
149 - public function getInputHTML( $value ) {
150 - return parent::getInputHTML( $value ) . ' ' . Html::element(
151 - 'button',
152 - array( 'id' => 'survey-add-question-button' ),
153 - wfMsg( 'survey-special-label-button' )
154 - );
155 - }
156 -
157 -}
158 -
159122 class SurveyQuestionField extends HTMLFormField {
160123
161124 public function getInputHTML( $value ) {
Index: trunk/extensions/Survey/resources/ext.survey.special.survey.js
@@ -15,6 +15,32 @@
1616 var newQuestionNr = 0;
1717 var questionNr = 0;
1818
 19+ function addAddQuestionRow() {
 20+ var $tr = $( '<tr />' ).attr( {
 21+ 'class': 'add-question'
 22+ } );
 23+
 24+ $table.append( $tr );
 25+
 26+ $tr.append( $( '<td />' ).attr( { 'class': 'mw-label question-label' } ).html(
 27+ $( '<label />' ).text( mw.msg( 'survey-special-label-addquestion' ) )
 28+ ) );
 29+
 30+ $tr.append( $( '<td />' ).attr( { 'class': 'mw-input' } ).html(
 31+ getQuestionInput( { 'id': 'new' } )
 32+ ).append( $( '<button />' ).button()
 33+ .text( mw.msg( 'survey-special-label-button' ) )
 34+ .click( function() { onAddQuestionRequest(); return false; } )
 35+ ) );
 36+
 37+ $( '#survey-question-text-new' ).keypress( function( event ) {
 38+ if ( event.which == '13' ) {
 39+ event.preventDefault();
 40+ onAddQuestionRequest();
 41+ }
 42+ } );
 43+ };
 44+
1945 function addQuestion( question ) {
2046 var $tr = $( '<tr />' ).attr( {
2147 'class': 'mw-htmlform-field-SurveyQuestionField'
@@ -22,7 +48,7 @@
2349
2450 // TODO: defaulting
2551
26 - $tr.append( $( '<td />' ).attr( { 'class': 'mw-label' } ).html(
 52+ $tr.append( $( '<td />' ).attr( { 'class': 'mw-label question-label' } ).html(
2753 $( '<label />' ).text( mw.msg( 'survey-question-label-nr', ++questionNr ) )
2854 ) );
2955
@@ -34,42 +60,60 @@
3561 };
3662
3763 function getQuestionInput( question ) {
38 - var $input = $( '<div />' ).attr( { 'border': '1px' } );
 64+ var $input = $( '<div />' ).attr( { 'border': '1px solid black', 'id': 'survey-question-div-' + question.id } );
3965
40 - var $text = $( '<input />' ).attr( {
41 - 'type': 'text',
42 - 'id': 'survey-question-' + question.id
43 - } );
 66+ $input.append( $( '<label />' ).attr( {
 67+ 'for': 'survey-question-text-' + question.id
 68+ } ).text( mw.msg( 'survey-special-label-text' ) ) );
4469
45 - var $type = survey.htmlSelect( questionTypes, question.type );
 70+ $input.append( '<br />' );
4671
47 - var $required = $( '<input />' ).attr( {
 72+ $input.append( $( '<textarea />' ).attr( {
 73+ 'rows': 2,
 74+ 'cols': 80,
 75+ 'id': 'survey-question-text-' + question.id
 76+ } ).val( question.text ) );
 77+
 78+ $input.append( '<br />' );
 79+
 80+ $input.append( $( '<label />' ).attr( {
 81+ 'for': 'survey-question-type-' + question.id
 82+ } ).text( mw.msg( 'survey-special-label-type' ) ) );
 83+
 84+ $input.append( survey.htmlSelect( questionTypes, question.type, {
 85+ 'id': 'survey-question-type-' + question.id
 86+ } ) );
 87+
 88+ $required = $( '<input />' ).attr( {
 89+ 'id': 'survey-question-required-' + question.id,
4890 'type': 'checkbox',
49 - 'id': 'survey-required-' + question.id
50 - } ).append( $( '<label />' ) ).attr( {
51 - 'for': 'survey-required-' + question.id
52 - } ).text( mw.msg( 'survey-special-label-required' ) );
 91+ } ).text( mw.msg( 'survey-special-label-type' ) );
5392
54 - // TODO
 93+ if ( question.required ) {
 94+ $required.attr( 'checked', 'checked' );
 95+ }
5596
56 - $input.append( $text.prepend( $( '<p />' ).text( mw.msg( 'survey-special-label-text' ) ) ).append( '<br />' ) );
57 - $input.append( $type.prepend( $( '<label />' ).text( mw.msg( 'survey-special-label-type' ) ) ) );
5897 $input.append( $required );
5998
 99+ $input.append( $( '<label />' ).attr( {
 100+ 'for': 'survey-question-required-' + question.id
 101+ } ).text( mw.msg( 'survey-special-label-required' ) ) );
60102
61103 return $input;
62104 };
63105
64106 function removeQuestion( question ) {
65 -
 107+ $( 'survey-question-div-' + question.id ).slideUp( 'fast', function() { $( this ).remove(); } )
66108 };
67109
68110 function onAddQuestionRequest() {
69111 addQuestion( {
70 - 'text': $( '#survey-add-question-text' ).text(),
 112+ 'text': $( '#survey-question-text-new' ).val(),
 113+ 'required': !!$( '#survey-question-required-new' ).attr( 'checked' ),
 114+ 'type': $( '#survey-question-type-new' ).val(),
71115 'id': 'new-' + newQuestionNr++
72116 } );
73 - $( '#survey-add-question-text' ).text( '' );
 117+ $( '#survey-question-text-new' ).focus().select();
74118 };
75119
76120 function initTypes() {
@@ -82,24 +126,21 @@
83127 function setup() {
84128 initTypes();
85129
86 - $table = $( '#survey-add-question-text' ).closest( 'tbody' );
 130+ $table = $( '#survey-name' ).closest( 'tbody' );
87131
88 - $( '#survey-add-question-text' ).keypress( function( event ) {
89 - if ( event.which == '13' ) {
90 - event.preventDefault();
91 - _this.onAddQuestionRequest();
92 - }
93 - } );
 132+ $table.append( '<tr><td colspan="2"><hr /></td></tr>' );
94133
95 - $( '#survey-add-question-button' ).click( _this.onAddQuestionRequest ).button();
 134+ addAddQuestionRow();
96135
 136+ $table.append( '<tr><td colspan="2"><hr /></td></tr>' );
 137+
97138 $( '.survey-question-data' ).each( function( index, domElement ) {
98139 $this = $( domElement );
99140
100141 addQuestion( {
101142 'text': $this.attr( 'data-text' ),
102143 'default': $this.attr( 'data-default' ),
103 - 'required': $this.attr( 'data-required' ),
 144+ 'required': $this.attr( 'data-required' ) == '1',
104145 'id': $this.attr( 'data-id' ),
105146 'type': $this.attr( 'data-type' ),
106147 } );
Index: trunk/extensions/Survey/resources/ext.survey.js
@@ -36,8 +36,8 @@
3737 }
3838 };
3939
40 - this.htmlSelect = function( options, value ) {
41 - $select = $( '<select />' );
 40+ this.htmlSelect = function( options, value, attributes ) {
 41+ $select = $( '<select />' ).attr( attributes );
4242
4343 for ( message in options ) {
4444 var attribs = { 'value': options[message] };
Index: trunk/extensions/Survey/resources/ext.survey.special.survey.css
@@ -0,0 +1,5 @@
 2+@CHARSET "UTF-8";
 3+
 4+td .question-label {
 5+ vertical-align: middle;
 6+}
Property changes on: trunk/extensions/Survey/resources/ext.survey.special.survey.css
___________________________________________________________________
Added: svn:eol-style
17 + native

Status & tagging log