Index: trunk/extensions/Survey/Survey.php |
— | — | @@ -104,21 +104,10 @@ |
105 | 105 | $wgGroupPermissions['bot' ]['surveysubmit'] = false; |
106 | 106 | $wgGroupPermissions['sysop' ]['surveysubmit'] = true; |
107 | 107 | |
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 | | - |
120 | 108 | $moduleTemplate = array( |
121 | 109 | 'localBasePath' => dirname( __FILE__ ), |
122 | | - 'remoteBasePath' => $egSurveyScriptPath |
| 110 | + 'remoteBasePath' => ( $wgExtensionAssetsPath === false ? $wgScriptPath . '/extensions' : $wgExtensionAssetsPath ) |
| 111 | + . '/Survey/resources' |
123 | 112 | ); |
124 | 113 | |
125 | 114 | $wgResourceModules['ext.survey'] = $moduleTemplate + array( |
— | — | @@ -132,9 +121,25 @@ |
133 | 122 | 'ext.survey.special.surveys.js' |
134 | 123 | ), |
135 | 124 | 'dependencies' => array( 'ext.survey' ), |
136 | | - 'messages' => $egSurveyMessages['ext.survey.special.surveys'] |
| 125 | + 'messages' => array( |
| 126 | + 'surveys-special-confirm-delete' |
| 127 | + ) |
137 | 128 | ); |
138 | 129 | |
| 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 | + |
139 | 144 | $wgResourceModules['ext.survey.jquery'] = $moduleTemplate + array( |
140 | 145 | 'scripts' => array( |
141 | 146 | 'fancybox/jquery.fancybox-1.3.4.js', |
— | — | @@ -144,7 +149,11 @@ |
145 | 150 | 'fancybox/jquery.fancybox-1.3.4.css', |
146 | 151 | ), |
147 | 152 | 'dependencies' => array( 'ext.survey' ), |
148 | | - 'messages' => $egSurveyMessages['jquery.survey'] |
| 153 | + 'messages' => array( |
| 154 | + |
| 155 | + ) |
149 | 156 | ); |
150 | 157 | |
| 158 | +unset( $moduleTemplate ); |
| 159 | + |
151 | 160 | $egSurveySettings = array(); |
Index: trunk/extensions/Survey/Survey.i18n.php |
— | — | @@ -61,4 +61,9 @@ |
62 | 62 | 'survey-special-label-question' => 'Question text', |
63 | 63 | 'survey-special-label-button' => 'Add question', |
64 | 64 | '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', |
65 | 70 | ); |
Index: trunk/extensions/Survey/specials/SpecialSurvey.php |
— | — | @@ -39,6 +39,7 @@ |
40 | 40 | } |
41 | 41 | else { |
42 | 42 | $this->showSurvey( $survey ); |
| 43 | + $this->addModules( 'ext.survey.special.survey' ); |
43 | 44 | } |
44 | 45 | } |
45 | 46 | |
— | — | @@ -79,13 +80,15 @@ |
80 | 81 | 'required' => true |
81 | 82 | ); |
82 | 83 | |
83 | | - foreach ( $survey->getQuestions() as $question ) { |
| 84 | + foreach ( $survey->getQuestions() as /* SurveyQuestion */ $question ) { |
84 | 85 | $fields[] = array( |
85 | 86 | 'class' => 'SurveyQuestionField', |
86 | 87 | 'options' => array( |
87 | 88 | 'required' => $question->isRequired(), |
88 | 89 | 'text' => $question->getText(), |
89 | | - 'type' => $question->getType() |
| 90 | + 'type' => $question->getType(), |
| 91 | + 'id' => $question->getId(), |
| 92 | + 'type' => $question->getType(), |
90 | 93 | ) |
91 | 94 | ); |
92 | 95 | } |
— | — | @@ -145,7 +148,7 @@ |
146 | 149 | public function getInputHTML( $value ) { |
147 | 150 | return parent::getInputHTML( $value ) . ' ' . Html::element( |
148 | 151 | 'button', |
149 | | - array(), |
| 152 | + array( 'id' => 'survey-add-question-button' ), |
150 | 153 | wfMsg( 'survey-special-label-button' ) |
151 | 154 | ); |
152 | 155 | } |
— | — | @@ -155,7 +158,9 @@ |
156 | 159 | class SurveyQuestionField extends HTMLFormField { |
157 | 160 | |
158 | 161 | public function getInputHTML( $value ) { |
159 | | - $attribs = array(); |
| 162 | + $attribs = array( |
| 163 | + 'class' => 'survey-question-data' |
| 164 | + ); |
160 | 165 | |
161 | 166 | foreach ( $this->mParams['options'] as $name => $value ) { |
162 | 167 | if ( is_bool( $value ) ) { |
Index: trunk/extensions/Survey/includes/SurveyQuestion.php |
— | — | @@ -273,7 +273,7 @@ |
274 | 274 | * |
275 | 275 | * @since 0.1 |
276 | 276 | * |
277 | | - * @return string |
| 277 | + * @return integer |
278 | 278 | */ |
279 | 279 | public function getType() { |
280 | 280 | return $this->type; |
Index: trunk/extensions/Survey/resources/ext.survey.special.survey.js |
— | — | @@ -5,9 +5,99 @@ |
6 | 6 | * @licence GNU GPL v3 or later |
7 | 7 | * @author Jeroen De Dauw <jeroendedauw at gmail dot com> |
8 | 8 | */ |
9 | | - |
10 | 9 | (function( $ ) { $( document ).ready( function() { |
11 | 10 | |
| 11 | + var _this = this; |
12 | 12 | |
| 13 | + var questionTypes = {}; |
13 | 14 | |
| 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 | + |
14 | 104 | } ); })( jQuery ); |
\ No newline at end of file |
Index: trunk/extensions/Survey/resources/ext.survey.js |
— | — | @@ -19,7 +19,7 @@ |
20 | 20 | return mediaWiki.log.call( mediaWiki.log, 'Survey: ' + message ); |
21 | 21 | } |
22 | 22 | } |
23 | | - } |
| 23 | + }; |
24 | 24 | |
25 | 25 | this.msg = function() { |
26 | 26 | if ( typeof mediaWiki === 'undefined' ) { |
— | — | @@ -34,8 +34,24 @@ |
35 | 35 | else { |
36 | 36 | return mediaWiki.msg.apply( mediaWiki.msg, arguments ); |
37 | 37 | } |
38 | | - } |
| 38 | + }; |
39 | 39 | |
| 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 | + |
40 | 56 | } )(); |
41 | 57 | |
42 | 58 | |