Index: trunk/extensions/Survey/Survey.php |
— | — | @@ -130,13 +130,21 @@ |
131 | 131 | 'scripts' => array( |
132 | 132 | 'ext.survey.special.survey.js' |
133 | 133 | ), |
| 134 | + 'styles' => array( |
| 135 | + //'ext.survey.special.survey.css' |
| 136 | + ), |
134 | 137 | 'dependencies' => array( 'ext.survey', 'jquery.ui.button' ), |
135 | 138 | 'messages' => array( |
136 | 139 | 'survey-question-type-text', |
137 | 140 | 'survey-question-type-number', |
138 | 141 | 'survey-question-type-select', |
139 | 142 | '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', |
141 | 149 | ) |
142 | 150 | ); |
143 | 151 | |
Index: trunk/extensions/Survey/Survey.i18n.php |
— | — | @@ -58,12 +58,15 @@ |
59 | 59 | 'surveys-special-unknown-name' => 'There is no survey with the requested name.', |
60 | 60 | 'survey-special-label-name' => 'Survey name', |
61 | 61 | 'survey-special-label-enabled' => 'Survey enabled', |
62 | | - 'survey-special-label-question' => 'Question text', |
63 | 62 | 'survey-special-label-button' => 'Add question', |
| 63 | + 'survey-special-label-addquestion' => 'New question', |
64 | 64 | 'survey-special-label-add' => 'New question name', |
65 | 65 | 'survey-question-type-text' => 'Free text', |
66 | 66 | 'survey-question-type-number' => 'Number', |
67 | 67 | 'survey-question-type-select' => 'Dropdown menu', |
68 | 68 | 'survey-question-type-radio' => 'Radio boxes', |
69 | 69 | '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', |
70 | 73 | ); |
Index: trunk/extensions/Survey/specials/SpecialSurvey.php |
— | — | @@ -65,11 +65,19 @@ |
66 | 66 | $fields = array(); |
67 | 67 | |
68 | 68 | $fields[] = array( |
| 69 | + 'type' => 'hidden', |
| 70 | + 'default' => $survey->getId(), |
| 71 | + 'name' => 'survey-id', |
| 72 | + 'id' => 'survey-id', |
| 73 | + ); |
| 74 | + |
| 75 | + $fields[] = array( |
69 | 76 | 'type' => 'text', |
70 | 77 | //'options' => array(), |
71 | 78 | 'default' => 'ohi', |
72 | 79 | 'label-message' => 'survey-special-label-name', |
73 | | - 'required' => true |
| 80 | + 'required' => true, |
| 81 | + 'id' => 'survey-name', |
74 | 82 | ); |
75 | 83 | |
76 | 84 | $fields[] = array( |
— | — | @@ -77,7 +85,8 @@ |
78 | 86 | //'options' => array(), |
79 | 87 | 'default' => 'there', |
80 | 88 | 'label-message' => 'survey-special-label-enabled', |
81 | | - 'required' => true |
| 89 | + 'required' => true, |
| 90 | + 'id' => 'survey-enabled', |
82 | 91 | ); |
83 | 92 | |
84 | 93 | foreach ( $survey->getQuestions() as /* SurveyQuestion */ $question ) { |
— | — | @@ -93,13 +102,6 @@ |
94 | 103 | ); |
95 | 104 | } |
96 | 105 | |
97 | | - $fields[] = array( |
98 | | - 'class' => 'SurveyAddQuestionField', |
99 | | - 'default' => 'foo', |
100 | | - 'label-message' => 'survey-special-label-add', |
101 | | - 'id' => 'survey-add-question-text' |
102 | | - ); |
103 | | - |
104 | 106 | // getContext was added in 1.18 and since that version is |
105 | 107 | // the second argument for the HTMLForm constructor. |
106 | 108 | if ( is_callable( array( $this, 'getContext' ) ) ) { |
— | — | @@ -116,45 +118,6 @@ |
117 | 119 | |
118 | 120 | } |
119 | 121 | |
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 | | - |
159 | 122 | class SurveyQuestionField extends HTMLFormField { |
160 | 123 | |
161 | 124 | public function getInputHTML( $value ) { |
Index: trunk/extensions/Survey/resources/ext.survey.special.survey.js |
— | — | @@ -15,6 +15,32 @@ |
16 | 16 | var newQuestionNr = 0; |
17 | 17 | var questionNr = 0; |
18 | 18 | |
| 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 | + |
19 | 45 | function addQuestion( question ) { |
20 | 46 | var $tr = $( '<tr />' ).attr( { |
21 | 47 | 'class': 'mw-htmlform-field-SurveyQuestionField' |
— | — | @@ -22,7 +48,7 @@ |
23 | 49 | |
24 | 50 | // TODO: defaulting |
25 | 51 | |
26 | | - $tr.append( $( '<td />' ).attr( { 'class': 'mw-label' } ).html( |
| 52 | + $tr.append( $( '<td />' ).attr( { 'class': 'mw-label question-label' } ).html( |
27 | 53 | $( '<label />' ).text( mw.msg( 'survey-question-label-nr', ++questionNr ) ) |
28 | 54 | ) ); |
29 | 55 | |
— | — | @@ -34,42 +60,60 @@ |
35 | 61 | }; |
36 | 62 | |
37 | 63 | 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 } ); |
39 | 65 | |
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' ) ) ); |
44 | 69 | |
45 | | - var $type = survey.htmlSelect( questionTypes, question.type ); |
| 70 | + $input.append( '<br />' ); |
46 | 71 | |
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, |
48 | 90 | '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' ) ); |
53 | 92 | |
54 | | - // TODO |
| 93 | + if ( question.required ) { |
| 94 | + $required.attr( 'checked', 'checked' ); |
| 95 | + } |
55 | 96 | |
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' ) ) ) ); |
58 | 97 | $input.append( $required ); |
59 | 98 | |
| 99 | + $input.append( $( '<label />' ).attr( { |
| 100 | + 'for': 'survey-question-required-' + question.id |
| 101 | + } ).text( mw.msg( 'survey-special-label-required' ) ) ); |
60 | 102 | |
61 | 103 | return $input; |
62 | 104 | }; |
63 | 105 | |
64 | 106 | function removeQuestion( question ) { |
65 | | - |
| 107 | + $( 'survey-question-div-' + question.id ).slideUp( 'fast', function() { $( this ).remove(); } ) |
66 | 108 | }; |
67 | 109 | |
68 | 110 | function onAddQuestionRequest() { |
69 | 111 | 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(), |
71 | 115 | 'id': 'new-' + newQuestionNr++ |
72 | 116 | } ); |
73 | | - $( '#survey-add-question-text' ).text( '' ); |
| 117 | + $( '#survey-question-text-new' ).focus().select(); |
74 | 118 | }; |
75 | 119 | |
76 | 120 | function initTypes() { |
— | — | @@ -82,24 +126,21 @@ |
83 | 127 | function setup() { |
84 | 128 | initTypes(); |
85 | 129 | |
86 | | - $table = $( '#survey-add-question-text' ).closest( 'tbody' ); |
| 130 | + $table = $( '#survey-name' ).closest( 'tbody' ); |
87 | 131 | |
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>' ); |
94 | 133 | |
95 | | - $( '#survey-add-question-button' ).click( _this.onAddQuestionRequest ).button(); |
| 134 | + addAddQuestionRow(); |
96 | 135 | |
| 136 | + $table.append( '<tr><td colspan="2"><hr /></td></tr>' ); |
| 137 | + |
97 | 138 | $( '.survey-question-data' ).each( function( index, domElement ) { |
98 | 139 | $this = $( domElement ); |
99 | 140 | |
100 | 141 | addQuestion( { |
101 | 142 | 'text': $this.attr( 'data-text' ), |
102 | 143 | 'default': $this.attr( 'data-default' ), |
103 | | - 'required': $this.attr( 'data-required' ), |
| 144 | + 'required': $this.attr( 'data-required' ) == '1', |
104 | 145 | 'id': $this.attr( 'data-id' ), |
105 | 146 | 'type': $this.attr( 'data-type' ), |
106 | 147 | } ); |
Index: trunk/extensions/Survey/resources/ext.survey.js |
— | — | @@ -36,8 +36,8 @@ |
37 | 37 | } |
38 | 38 | }; |
39 | 39 | |
40 | | - this.htmlSelect = function( options, value ) { |
41 | | - $select = $( '<select />' ); |
| 40 | + this.htmlSelect = function( options, value, attributes ) { |
| 41 | + $select = $( '<select />' ).attr( attributes ); |
42 | 42 | |
43 | 43 | for ( message in options ) { |
44 | 44 | 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 |
1 | 7 | + native |