Index: trunk/extensions/Survey/includes/SurveyTag.php |
— | — | @@ -47,6 +47,7 @@ |
48 | 48 | } |
49 | 49 | |
50 | 50 | $this->parameters['class'] = 'surveytag'; |
| 51 | + $this->parameters['survey-data-token'] = $GLOBALS['wgUser']->editToken(); |
51 | 52 | } |
52 | 53 | else { |
53 | 54 | throw new MWException( 'Invalid parameters for survey tag.' ); |
Index: trunk/extensions/Survey/api/ApiSubmitSurvey.php |
— | — | @@ -54,7 +54,7 @@ |
55 | 55 | ) ); |
56 | 56 | |
57 | 57 | foreach ( FormatJson::decode( $params['answers'] ) as $answer ) { |
58 | | - $submission->addAnswer( SurveyAnswer::newFromArray( $answer ) ); |
| 58 | + $submission->addAnswer( SurveyAnswer::newFromArray( (array)$answer ) ); |
59 | 59 | } |
60 | 60 | |
61 | 61 | $submission->writeToDB(); |
Index: trunk/extensions/Survey/resources/jquery.survey.js |
— | — | @@ -9,7 +9,11 @@ |
10 | 10 | ( function ( $ ) { $.fn.mwSurvey = function( options ) { |
11 | 11 | |
12 | 12 | var _this = this; |
| 13 | + this.inputs = []; |
13 | 14 | |
| 15 | + this.identifier = null; |
| 16 | + this.identifierType = null; |
| 17 | + |
14 | 18 | this.getSurveyData = function( options, callback ) { |
15 | 19 | var requestArgs = { |
16 | 20 | 'action': 'query', |
— | — | @@ -20,7 +24,7 @@ |
21 | 25 | 'suprops': '*' |
22 | 26 | }; |
23 | 27 | |
24 | | - requestArgs = $.extend( requestArgs, options.requestArgs ) |
| 28 | + requestArgs[ 'su' + this.identifierType + 's' ] = this.identifier; |
25 | 29 | |
26 | 30 | $.getJSON( |
27 | 31 | wgScriptPath + '/api.php', |
— | — | @@ -85,6 +89,10 @@ |
86 | 90 | break; |
87 | 91 | } |
88 | 92 | |
| 93 | + $input.data( 'question-id', question.id ); |
| 94 | + |
| 95 | + this.inputs.push( $input ); |
| 96 | + |
89 | 97 | return $input; |
90 | 98 | }; |
91 | 99 | |
— | — | @@ -111,21 +119,31 @@ |
112 | 120 | this.getAnswers = function( surveyId ) { |
113 | 121 | var answers = []; |
114 | 122 | |
| 123 | + for ( i in this.inputs ) { |
| 124 | + var $input = this.inputs[i]; |
| 125 | + |
| 126 | + answers.push( { |
| 127 | + 'text': $input.val(), |
| 128 | + 'question_id': $input.data( 'question-id' ) |
| 129 | + } ); |
| 130 | + } |
115 | 131 | |
116 | | - |
117 | 132 | return JSON.stringify( answers ); |
118 | 133 | }; |
119 | 134 | |
120 | 135 | this.submitSurvey = function( surveyId, callback ) { |
| 136 | + var requestArgs = { |
| 137 | + 'action': 'submitsurvey', |
| 138 | + 'format': 'json', |
| 139 | + 'token': $( this ).attr( 'survey-data-token' ), |
| 140 | + 'answers': this.getAnswers( surveyId ) |
| 141 | + }; |
| 142 | + |
| 143 | + requestArgs[this.identifierType] = this.identifier; |
| 144 | + |
121 | 145 | $.post( |
122 | 146 | wgScriptPath + '/api.php', |
123 | | - { |
124 | | - 'action': 'submitsurvey', |
125 | | - 'format': 'json', |
126 | | - 'ids': options.id, |
127 | | - 'token': options.token, |
128 | | - 'answers': this.getAnswers( surveyId ) |
129 | | - }, |
| 147 | + requestArgs, |
130 | 148 | function( data ) { |
131 | 149 | callback(); |
132 | 150 | // TODO |
— | — | @@ -217,26 +235,19 @@ |
218 | 236 | |
219 | 237 | this.init = function() { |
220 | 238 | var $this = $( this ); |
221 | | - var identifier = false; |
222 | | - var type; |
223 | 239 | |
224 | 240 | if ( $this.attr( 'survey-data-id' ) ) { |
225 | | - identifier = $this.attr( 'survey-data-id' ); |
226 | | - type = 'suids'; |
| 241 | + this.identifier = $this.attr( 'survey-data-id' ); |
| 242 | + this.identifierType = 'id'; |
227 | 243 | } |
228 | 244 | else if ( $this.attr( 'survey-data-name' ) ) { |
229 | | - identifier = $this.attr( 'survey-data-name' ); |
230 | | - type = 'sunames'; |
| 245 | + this.identifier = $this.attr( 'survey-data-name' ); |
| 246 | + this.identifierType = 'name'; |
231 | 247 | } |
232 | 248 | |
233 | | - if ( identifier !== false ) { |
234 | | - var requestArgs = {}; |
235 | | - requestArgs[type] = identifier; |
236 | | - |
| 249 | + if ( this.identifier !== null ) { |
237 | 250 | this.getSurveyData( |
238 | | - { |
239 | | - 'requestArgs': requestArgs |
240 | | - }, |
| 251 | + {}, |
241 | 252 | function( surveyData ) { |
242 | 253 | for ( i in surveyData ) { |
243 | 254 | _this.initSurvey( surveyData[i] ); |