Index: branches/wmf/1.18wmf1/extensions/UploadWizard/resources/mw.UploadWizardLicenseInput.js |
— | — | @@ -152,11 +152,51 @@ |
153 | 153 | */ |
154 | 154 | setValues: function( values ) { |
155 | 155 | var _this = this; |
156 | | - $j.each( _this.inputs, function( i, $input ) { |
157 | | - var licenseName = $input.data( 'licenseName' ); |
158 | | - // !! to ensure boolean. |
159 | | - $input.attr( 'checked', !!values[licenseName] ); |
160 | | - } ); |
| 156 | + // ugly division between radio and checkbox, because in jquery 1.6.4 if you set any element of a radio input to false, every element |
| 157 | + // is set to false! Unfortunately the incoming data structure is a key-val object so we have to make extra sure it makes sense for |
| 158 | + // a radio button input. |
| 159 | + |
| 160 | + // this works fine for blanking all of a radio input, or for checking/unchecking individual checkboxes |
| 161 | + function setInputsIndividually() { |
| 162 | + $j.each( _this.inputs, function( i, $input ) { |
| 163 | + var licenseName = $input.data( 'licenseName' ); |
| 164 | + // !! to ensure boolean. |
| 165 | + $input.attr( 'checked', !!values[licenseName] ); |
| 166 | + } ); |
| 167 | + } |
| 168 | + |
| 169 | + if ( _this.type === 'radio' ) { |
| 170 | + |
| 171 | + // check if how many license names are set to true in the values requested. Should be 0 or 1 |
| 172 | + var trueCount = 0; |
| 173 | + var trueLicenseName = undefined; |
| 174 | + $j.each( values, function( licenseName, val ) { |
| 175 | + if ( val === true ) { |
| 176 | + trueCount++; |
| 177 | + trueLicenseName = licenseName; |
| 178 | + } |
| 179 | + } ); |
| 180 | + |
| 181 | + if ( trueCount === 0 ) { |
| 182 | + setInputsIndividually(); |
| 183 | + } else if ( trueCount === 1 ) { |
| 184 | + // set just one of the radio inputs and don't touch anything else |
| 185 | + $j.each( _this.inputs, function( i, $input ) { |
| 186 | + var licenseName = $input.data( 'licenseName' ); |
| 187 | + // !! to ensure boolean. |
| 188 | + if ( licenseName === trueLicenseName ) { |
| 189 | + $input.attr( 'checked', true ); |
| 190 | + } |
| 191 | + } ); |
| 192 | + } else { |
| 193 | + mw.log( "too many true values for a radio button!"); |
| 194 | + } |
| 195 | + |
| 196 | + } else if ( _this.type === 'checkbox' ) { |
| 197 | + setInputsIndividually(); |
| 198 | + } else { |
| 199 | + mw.log( "impossible? UploadWizardLicenseInput type neither radio nor checkbox" ); |
| 200 | + } |
161 | 201 | // we use the selector because events can't be unbound unless they're in the DOM. |
162 | 202 | _this.$selector.trigger( 'changeLicenses' ); |
163 | 203 | }, |