Index: trunk/extensions/Survey/Survey.php |
— | — | @@ -192,7 +192,7 @@ |
193 | 193 | 'scripts' => array( |
194 | 194 | 'ext.survey.tag.js' |
195 | 195 | ), |
196 | | - 'dependencies' => array( 'ext.survey.jquery' ), |
| 196 | + 'dependencies' => array( 'ext.survey.jquery', 'jquery.cookie' ), |
197 | 197 | ); |
198 | 198 | |
199 | 199 | unset( $moduleTemplate ); |
Index: trunk/extensions/Survey/specials/SpecialSurvey.php |
— | — | @@ -83,6 +83,8 @@ |
84 | 84 | $survey->setField( $field, $wgRequest->getInt( 'survey-' . $field ) ); |
85 | 85 | } |
86 | 86 | |
| 87 | + $survey->setField( 'namespaces', array() ); |
| 88 | + |
87 | 89 | $survey->setQuestions( $this->getSubmittedQuestions() ); |
88 | 90 | |
89 | 91 | $survey->writeToDB(); |
— | — | @@ -101,9 +103,9 @@ |
102 | 104 | foreach ( $GLOBALS['wgRequest']->getValues() as $name => $value ) { |
103 | 105 | $matches = array(); |
104 | 106 | |
105 | | - if ( preg_match( '/survey-question-text-(\d)+/', $name, $matches ) ) { |
| 107 | + if ( preg_match( '/survey-question-text-(\d+)/', $name, $matches ) ) { |
106 | 108 | $questions[] = $this->getSubmittedQuestion( $matches[1] ); |
107 | | - } elseif ( preg_match( '/survey-question-text-new-(\d)+/', $name, $matches ) ) { |
| 109 | + } elseif ( preg_match( '/survey-question-text-new-(\d+)/', $name, $matches ) ) { |
108 | 110 | $questions[] = $this->getSubmittedQuestion( $matches[1], true ); |
109 | 111 | } |
110 | 112 | } |
Index: trunk/extensions/Survey/specials/SpecialTakeSurvey.php |
— | — | @@ -66,7 +66,8 @@ |
67 | 67 | 'survey', |
68 | 68 | array( |
69 | 69 | 'name' => $subPage, |
70 | | - 'require-enabled' => $GLOBALS['wgUser']->isAllowed( 'surveyadmin' ) ? '0' : '1' |
| 70 | + 'require-enabled' => $GLOBALS['wgUser']->isAllowed( 'surveyadmin' ) ? '0' : '1', |
| 71 | + 'cookie' => 'no' |
71 | 72 | ), |
72 | 73 | wfMsg( 'surveys-takesurvey-loading' ) |
73 | 74 | ) ); |
Index: trunk/extensions/Survey/includes/SurveyTag.php |
— | — | @@ -91,6 +91,7 @@ |
92 | 92 | return array( |
93 | 93 | 'id' => array( 'filter' => FILTER_VALIDATE_INT, 'options' => array( 'min_range' => 1 ) ), |
94 | 94 | 'name' => array(), |
| 95 | + 'cookie' => array(), |
95 | 96 | 'title' => array(), |
96 | 97 | 'require-enabled' => array( 'filter' => FILTER_VALIDATE_INT, 'options' => array( 'min_range' => 0, 'max_range' => 1 ) ), |
97 | 98 | ); |
Index: trunk/extensions/Survey/resources/ext.survey.tag.js |
— | — | @@ -6,10 +6,60 @@ |
7 | 7 | * @author Jeroen De Dauw <jeroendedauw at gmail dot com> |
8 | 8 | */ |
9 | 9 | |
10 | | -(function( $ ) { $( document ).ready( function() { |
| 10 | +(function( $, survey ) { |
11 | 11 | |
12 | | - $( '.surveytag' ).each( function( index, domElement ) { |
13 | | - $( domElement ).mwSurvey(); |
| 12 | + function getCookieName( options ) { |
| 13 | + return ( typeof options.id !== 'undefined' ) ? |
| 14 | + 'survey-id-' + options.id |
| 15 | + : 'survey-name-' + options.name |
| 16 | + } |
| 17 | + |
| 18 | + function shouldShowSurvey( options ) { |
| 19 | + var shouldShow = $.cookie( getCookieName( options ) ) != 'done'; |
| 20 | + survey.log( 'shouldShowSurvey ' + getCookieName( options ) + ': ' + shouldShow.toString() ); |
| 21 | + return shouldShow; |
| 22 | + } |
| 23 | + |
| 24 | + function onSurveyShown( options ) { |
| 25 | + var expirySeconds = ( typeof options.expiry !== 'undefined' ) ? options.expiry : 60 * 60 * 24 * 30; |
| 26 | + var date = new Date(); |
| 27 | + date.setTime( date.getTime() + expirySeconds * 1000 ); |
| 28 | + $.cookie( getCookieName( options ), 'done', { 'expires': date, 'path': '/' } ); |
| 29 | + } |
| 30 | + |
| 31 | + function initTag( $tag ) { |
| 32 | + var options = {}; |
| 33 | + |
| 34 | + if ( $tag.attr( 'survey-data-id' ) ) { |
| 35 | + options['id'] = $tag.attr( 'survey-data-id' ); |
| 36 | + } else if ( $tag.attr( 'survey-data-name' ) ) { |
| 37 | + options['name'] = $tag.attr( 'survey-data-name' ); |
| 38 | + } |
| 39 | + else { |
| 40 | + // TODO |
| 41 | + return; |
| 42 | + } |
| 43 | + |
| 44 | + if ( $tag.attr( 'survey-data-cookie' ) === 'no' ) { |
| 45 | + $tag.mwSurvey( options ); |
| 46 | + } |
| 47 | + else { |
| 48 | + if ( shouldShowSurvey( options ) ) { |
| 49 | + options['onShow'] = function( eventArgs ) { |
| 50 | + onSurveyShown( options ); |
| 51 | + }; |
| 52 | + |
| 53 | + $tag.mwSurvey( options ); |
| 54 | + } |
| 55 | + } |
| 56 | + } |
| 57 | + |
| 58 | + $( document ).ready( function() { |
| 59 | + |
| 60 | + $( '.surveytag' ).each( function( index, domElement ) { |
| 61 | + initTag( $( domElement ) ); |
| 62 | + } ); |
| 63 | + |
14 | 64 | } ); |
15 | 65 | |
16 | | -} ); })( jQuery ); |
\ No newline at end of file |
| 66 | +})( jQuery, window.survey ); |
\ No newline at end of file |
Index: trunk/extensions/Survey/resources/jquery.survey.js |
— | — | @@ -9,6 +9,8 @@ |
10 | 10 | ( function ( $ ) { $.fn.mwSurvey = function( options ) { |
11 | 11 | |
12 | 12 | var _this = this; |
| 13 | + this.options = options; |
| 14 | + |
13 | 15 | this.inputs = []; |
14 | 16 | |
15 | 17 | this.identifier = null; |
— | — | @@ -116,11 +118,11 @@ |
117 | 119 | |
118 | 120 | $input.data( 'question-id', question.id ); |
119 | 121 | |
120 | | - this.inputs.push( $input ); |
| 122 | + this.inputs.push( { 'input': $input, 'type': question.type } ); |
121 | 123 | |
122 | 124 | $q = $( '<div />' ).html( $input ); |
123 | 125 | |
124 | | - if ( question.type == type.CHECK ) { |
| 126 | + if ( question.type === type.CHECK ) { |
125 | 127 | $q.append( $( '<label />' ).text( question.text ).attr( 'for', id ) ); |
126 | 128 | } |
127 | 129 | else { |
— | — | @@ -155,11 +157,19 @@ |
156 | 158 | var answers = []; |
157 | 159 | |
158 | 160 | for ( i in this.inputs ) { |
159 | | - var $input = this.inputs[i]; |
| 161 | + var $input = this.inputs[i].input; |
| 162 | + var id = $input.data( 'question-id' ); |
160 | 163 | |
| 164 | + if ( this.inputs[i].type === survey.question.type.RADIO ) { |
| 165 | + var value = $( 'input:radio[name=survey-question-' + id + ']:checked' ).val(); |
| 166 | + } |
| 167 | + else { |
| 168 | + var value = $input.val(); |
| 169 | + } |
| 170 | + |
161 | 171 | answers.push( { |
162 | | - 'text': $input.val(), |
163 | | - 'question_id': $input.data( 'question-id' ) |
| 172 | + 'text': value, |
| 173 | + 'question_id': id |
164 | 174 | } ); |
165 | 175 | } |
166 | 176 | |
— | — | @@ -264,6 +274,10 @@ |
265 | 275 | } ); |
266 | 276 | |
267 | 277 | $link.click(); |
| 278 | + |
| 279 | + if ( typeof this.options.onShow === 'function' ) { |
| 280 | + this.options.onShow( { 'id': surveyData.id } ); |
| 281 | + } |
268 | 282 | }; |
269 | 283 | |
270 | 284 | this.init = function() { |