| Total Complexity | 78 |
| Complexity/F | 5.57 |
| Lines of Code | 566 |
| Function Count | 14 |
| Duplicated Lines | 30 |
| Ratio | 5.3 % |
| Changes | 9 | ||
| Bugs | 1 | Features | 3 |
Duplicate code is one of the most pungent code smells. A rule that is often used is to re-structure code once it is duplicated in three or more places.
Common duplication problems, and corresponding solutions are:
Complex classes like skins/cat17/src/scripts/membershipForm.js often do a lot of different things. To break such a class down, we need to identify a cohesive component within that class. A common approach to find such a component is to look for fields/methods that share the same prefixes, or suffixes.
Once you have determined the fields that belong together, you can apply the Extract Class refactoring. If the component makes sense as a sub-class, Extract Subclass is also a candidate, and is often faster.
| 1 | $( function () { |
||
| 2 | /** global: WMDE */ |
||
| 3 | |||
| 4 | // TODO Only include this on membership page(s) |
||
| 5 | if ($('body#membership').length == 0) { |
||
| 6 | return; |
||
| 7 | } |
||
| 8 | |||
| 9 | var initData = $( '#init-form.membership' ), |
||
| 10 | store = WMDE.Store.createMembershipStore( |
||
| 11 | WMDE.createInitialStateFromViolatedFields( initData.data( 'violatedFields' ), {} ) |
||
| 12 | ), |
||
| 13 | actions = WMDE.Actions; |
||
| 14 | |||
| 15 | WMDE.StoreUpdates.connectComponentsToStore( |
||
| 16 | [ |
||
| 17 | //MemberShipType |
||
| 18 | WMDE.Components.createRadioComponent( store, $( 'input[name="membership_type"]' ), 'membershipType' ), |
||
| 19 | |||
| 20 | //Amount and periodicity |
||
| 21 | WMDE.Components.createAmountComponent( store, $( '#amount-typed' ), $( 'input[name="amount-grp"]' ), $( '#amount-hidden' ) ), |
||
| 22 | WMDE.Components.createRadioComponent( store, $( 'input[name="periode"]' ), 'paymentIntervalInMonths' ), |
||
| 23 | |||
| 24 | //Personal data |
||
| 25 | WMDE.Components.createRadioComponent( store, $( 'input[name="addressType"]' ), 'addressType' ), |
||
| 26 | //Personal Data |
||
| 27 | WMDE.Components.createSelectMenuComponent( store, $( '#treatment' ), 'salutation' ), |
||
| 28 | WMDE.Components.createSelectMenuComponent( store, $( '#title' ), 'title' ), |
||
| 29 | WMDE.Components.createValidatingTextComponent( store, $( '#first-name' ), 'firstName' ), |
||
| 30 | WMDE.Components.createValidatingTextComponent( store, $( '#surname' ), 'lastName' ), |
||
| 31 | WMDE.Components.createTextComponent( store, $( '#email' ), 'email' ), |
||
| 32 | WMDE.Components.createValidatingTextComponent( store, $( '#street' ), 'street' ), |
||
| 33 | WMDE.Components.createValidatingTextComponent( store, $( '#post-code' ), 'postcode' ), |
||
| 34 | WMDE.Components.createValidatingTextComponent( store, $( '#city' ), 'city' ), |
||
| 35 | WMDE.Components.createSelectMenuComponent( store, $( '#country' ), 'country' ), |
||
| 36 | |||
| 37 | //Company Data |
||
| 38 | WMDE.Components.createValidatingTextComponent( store, $( '#company-name' ), 'companyName' ), |
||
| 39 | WMDE.Components.createValidatingTextComponent( store, $( '#contact-person' ), 'contactPerson' ), |
||
| 40 | WMDE.Components.createValidatingTextComponent( store, $( '#email-company' ), 'email' ), |
||
| 41 | WMDE.Components.createValidatingTextComponent( store, $( '#adress-company' ), 'street' ), |
||
| 42 | WMDE.Components.createValidatingTextComponent( store, $( '#post-code-company' ), 'postcode' ), |
||
| 43 | WMDE.Components.createValidatingTextComponent( store, $( '#city-company' ), 'city' ), |
||
| 44 | WMDE.Components.createSelectMenuComponent( store, $( '#country-company' ), 'country' ), |
||
| 45 | |||
| 46 | //Payment Data |
||
| 47 | WMDE.Components.createRadioComponent( store, $( 'input[name="payment-info"]' ), 'paymentType' ), |
||
| 48 | WMDE.Components.createBankDataComponent( store, { |
||
| 49 | ibanElement: $( '#iban' ), |
||
| 50 | bicElement: $( '#bic' ), |
||
| 51 | accountNumberElement: $( '#account-number' ), |
||
| 52 | bankCodeElement: $( '#bank-code' ), |
||
| 53 | bankNameFieldElement: $( '#field-bank-name' ), |
||
| 54 | bankNameDisplayElement: $( '#bank-name' ), |
||
| 55 | } ), |
||
| 56 | WMDE.Components.createValidatingCheckboxComponent( store, $( '#confirm_sepa' ), 'confirmSepa' ) |
||
| 57 | |||
| 58 | ], |
||
| 59 | store, |
||
| 60 | 'membershipFormContent' |
||
| 61 | ); |
||
| 62 | |||
| 63 | WMDE.StoreUpdates.connectValidatorsToStore( |
||
| 64 | function ( initialValues ) { |
||
| 65 | return [ |
||
| 66 | WMDE.ValidationDispatchers.createFeeValidationDispatcher( |
||
| 67 | WMDE.FormValidation.createFeeValidator( initData.data( 'validate-fee-url' ) ), |
||
| 68 | initialValues |
||
| 69 | ), |
||
| 70 | WMDE.ValidationDispatchers.createAddressValidationDispatcher( |
||
| 71 | WMDE.FormValidation.createAddressValidator( |
||
| 72 | initData.data( 'validate-address-url' ), |
||
| 73 | WMDE.FormValidation.DefaultRequiredFieldsForAddressType |
||
| 74 | ), |
||
| 75 | initialValues |
||
| 76 | ), |
||
| 77 | WMDE.ValidationDispatchers.createEmailValidationDispatcher( |
||
| 78 | WMDE.FormValidation.createEmailAddressValidator( initData.data( 'validate-email-address-url' ) ), |
||
| 79 | initialValues |
||
| 80 | ), |
||
| 81 | WMDE.ValidationDispatchers.createBankDataValidationDispatcher( |
||
| 82 | WMDE.FormValidation.createBankDataValidator( |
||
| 83 | initData.data( 'validate-iban-url' ), |
||
| 84 | initData.data( 'generate-iban-url' ) |
||
| 85 | ), |
||
| 86 | initialValues |
||
| 87 | ), |
||
| 88 | WMDE.ValidationDispatchers.createSepaConfirmationValidationDispatcher( |
||
| 89 | WMDE.FormValidation.createSepaConfirmationValidator(), |
||
| 90 | initialValues |
||
| 91 | ) |
||
| 92 | ]; |
||
| 93 | }, |
||
| 94 | store, |
||
| 95 | initData.data( 'initial-form-values' ), |
||
| 96 | 'membershipFormContent' |
||
| 97 | ); |
||
| 98 | |||
| 99 | // Connect view handlers to changes in specific parts in the global state, designated by 'stateKey' |
||
| 100 | WMDE.StoreUpdates.connectViewHandlersToStore( |
||
| 101 | [ |
||
| 102 | { |
||
| 103 | viewHandler: WMDE.View.createFormPageVisibilityHandler( { |
||
| 104 | personalData: $( "#personalDataPage" ), |
||
| 105 | bankConfirmation: $( '#bankConfirmationPage' ) |
||
| 106 | } ), |
||
| 107 | stateKey: 'formPagination' |
||
| 108 | }, |
||
| 109 | { |
||
| 110 | viewHandler: WMDE.View.createErrorBoxHandler( $( '#validation-errors' ), { |
||
| 111 | amount: 'Betrag', |
||
| 112 | salutation: 'Anrede', |
||
| 113 | title: 'Titel', |
||
| 114 | firstName: 'Vorname', |
||
| 115 | lastName: 'Nachname', |
||
| 116 | companyName: 'Firma', |
||
| 117 | street: 'Straße', |
||
| 118 | postcode: 'PLZ', |
||
| 119 | city: 'Ort', |
||
| 120 | country: 'Land', |
||
| 121 | email: 'E-Mail', |
||
| 122 | dateOfBirth: 'Geburtsdatum', |
||
| 123 | phone: 'Telefonnummer', |
||
| 124 | iban: 'IBAN', |
||
| 125 | bic: 'BIC', |
||
| 126 | accountNumber: 'Kontonummer', |
||
| 127 | bankCode: 'Bankleitzahl', |
||
| 128 | confirmSepa: 'SEPA-Lastschrift' |
||
| 129 | } ), |
||
| 130 | stateKey: 'membershipInputValidation' |
||
| 131 | }, |
||
| 132 | { |
||
| 133 | viewHandler: WMDE.View.createSimpleVisibilitySwitcher( $( '#finishFormSubmit' ), /^PPL$|^$/ ), |
||
| 134 | stateKey: 'membershipFormContent.paymentType' |
||
| 135 | }, |
||
| 136 | { |
||
| 137 | viewHandler: WMDE.View.createSimpleVisibilitySwitcher( $( '#continueFormSubmit' ), 'BEZ' ), |
||
| 138 | stateKey: 'membershipFormContent.paymentType' |
||
| 139 | }, |
||
| 140 | { |
||
| 141 | viewHandler: WMDE.View.createRecurrentPaypalNoticeHandler( |
||
| 142 | WMDE.View.Animator.createSlidingElementAnimator( $( '.notice-ppl-recurrent' ) ) |
||
| 143 | ), |
||
| 144 | stateKey: 'membershipFormContent' |
||
| 145 | }, |
||
| 146 | { |
||
| 147 | viewHandler: WMDE.View.createSlidingVisibilitySwitcher( $( '.fields-direct-debit' ), 'BEZ' ), |
||
| 148 | stateKey: 'membershipFormContent.paymentType' |
||
| 149 | }, |
||
| 150 | { |
||
| 151 | viewHandler: WMDE.View.createSlidingVisibilitySwitcher( $( '.slide-sepa' ), 'sepa' ), |
||
| 152 | stateKey: 'membershipFormContent.debitType' |
||
| 153 | }, |
||
| 154 | { |
||
| 155 | viewHandler: WMDE.View.createSlidingVisibilitySwitcher( $( '.slide-non-sepa' ), 'non-sepa' ), |
||
| 156 | stateKey: 'membershipFormContent.debitType' |
||
| 157 | }, |
||
| 158 | { |
||
| 159 | viewHandler: WMDE.View.createSlidingVisibilitySwitcher( $( '.person-name' ), 'person' ), |
||
| 160 | stateKey: 'membershipFormContent.addressType' |
||
| 161 | }, |
||
| 162 | { |
||
| 163 | viewHandler: WMDE.View.createSlidingVisibilitySwitcher( $( '.company-name' ), 'firma' ), |
||
| 164 | stateKey: 'membershipFormContent.addressType' |
||
| 165 | }, |
||
| 166 | { |
||
| 167 | viewHandler: WMDE.View.createSimpleVisibilitySwitcher( $( '#address-type-2' ).parent(), 'sustaining' ), |
||
| 168 | stateKey: 'membershipFormContent.membershipType' |
||
| 169 | }, |
||
| 170 | { |
||
| 171 | viewHandler: WMDE.View.createFeeOptionSwitcher( [ $( '#amount-1' ), $( '#amount-2' ), $( '#amount-3' ), $( '#amount-4' ), $( '#amount-5' ), $( '#amount-6' ), $( '#amount-7' ) ], { person: 24, firma: 100 } ), |
||
| 172 | stateKey: 'membershipFormContent' |
||
| 173 | }, |
||
| 174 | { |
||
| 175 | viewHandler: WMDE.View.createPaymentSummaryDisplayHandler( |
||
| 176 | $( '.interval-text' ), |
||
| 177 | $( '.amount .text'), |
||
| 178 | $( '.payment-method .text'), |
||
| 179 | { |
||
| 180 | '0': 'einmalig', |
||
| 181 | '1': 'monatlich', |
||
| 182 | '3': 'quartalsweise', |
||
| 183 | '6': 'halbjährlich', |
||
| 184 | '12': 'jährlich' |
||
| 185 | }, |
||
| 186 | { |
||
| 187 | 'BEZ': 'Lastschrift', |
||
| 188 | 'UEB': 'Überweisung', |
||
| 189 | 'MCP': 'Kreditkarte', |
||
| 190 | 'PPL': 'PayPal', |
||
| 191 | 'SUB': 'Sofortüberweisung' |
||
| 192 | }, |
||
| 193 | WMDE.CurrencyFormatter.createCurrencyFormatter( 'de' ), |
||
| 194 | $('.periodicity-icon'), |
||
| 195 | { |
||
| 196 | '0': 'icon-unique', |
||
| 197 | '1': 'icon-repeat_1', |
||
| 198 | '3': 'icon-repeat_3', |
||
| 199 | '6': 'icon-repeat_6', |
||
| 200 | '12': 'icon-repeat_12' |
||
| 201 | }, |
||
| 202 | $('.payment-icon'), |
||
| 203 | { |
||
| 204 | 'PPL': 'icon-paypal', |
||
| 205 | 'MCP': 'icon-credit_card2', |
||
| 206 | 'BEZ': 'icon-SEPA-2', |
||
| 207 | 'UEB': 'icon-ubeiwsung-1' |
||
| 208 | }, |
||
| 209 | $('.amount .info-detail'), |
||
| 210 | { |
||
| 211 | '0': 'Ihr Konto wird einmal belastet.', |
||
| 212 | '1': 'Ihr Konto wird jeden Monat belastet.<br />Ihre monatliche Spende können Sie jederzeit fristlos per E-Mail an [email protected] stornieren.', |
||
| 213 | '3': 'Ihr Konto wird alle drei Monate belastet.<br />Ihre vierteljahrliche Spende können Sie jederzeit fristlos per E-Mail an [email protected] stornieren.', |
||
| 214 | '6': 'Ihr Konto wird alle sechs Monate belastet.<br />Ihre halbjahrliche Spende können Sie jederzeit fristlos per E-Mail an [email protected] stornieren.', |
||
| 215 | '12': 'Ihr Konto wird jährlich belastet.<br />Ihre jährliche Spende können Sie jederzeit fristlos per E-Mail an [email protected] stornieren.' |
||
| 216 | }, |
||
| 217 | $('.payment-method .info-detail'), |
||
| 218 | { |
||
| 219 | 'PPL': 'Nach der Möglichkeit der Adressangabe werden Sie zu PayPal weitergeleitet, wo Sie die Spende abschließen müssen.', |
||
| 220 | 'MCP': 'Nach der Möglichkeit der Adressangabe werden Sie zu unserem Partner Micropayment weitergeleitet, wo Sie Ihre Kreditkarteninformationen eingeben können.', |
||
| 221 | 'BEZ': 'Ich ermächtige die gemeinnützige Wikimedia Fördergesellschaft mbH (Gläubiger-ID: DE25ZZZ00000448435) Zahlungen von meinem Konto mittels Lastschrift einzuziehen. Zugleich weise ich mein Kreditinstitut an, die von der gemeinnützigen Wikimedia Fördergesellschaft mbH auf mein Konto gezogenen Lastschriften einzulösen. <br />Ich kann innerhalb von acht Wochen, beginnend mit dem Belastungsdatum, die Erstattung des belasteten Betrages verlangen. Es gelten dabei die mit meinem Kreditinstitut vereinbarten Bedingungen.', |
||
| 222 | // @fixme: This is in English. Find out what this should be in German |
||
| 223 | 'UEB': 'On the conclusion of the donation process, you will be provided with the Wikimedia bank data so you can transfer the money.' |
||
| 224 | }, |
||
| 225 | $('.address-icon'), |
||
| 226 | { |
||
| 227 | 'person': 'icon-account_circle', |
||
| 228 | 'firma': 'icon-work', |
||
| 229 | 'anonym': 'icon-visibility_off' |
||
| 230 | }, |
||
| 231 | $('.donator-type .text'), |
||
| 232 | { |
||
| 233 | 'person': 'Privat', |
||
| 234 | 'firma': 'Firma', |
||
| 235 | 'anonym': 'Anonymous' |
||
| 236 | }, |
||
| 237 | $('.donator-type .info-detail'), |
||
| 238 | $('.frequency .text'), |
||
| 239 | { |
||
| 240 | '0': 'Einmalig', |
||
| 241 | '1': 'Monatlich', |
||
| 242 | '3': 'Vierteljährlich', |
||
| 243 | '6': 'Halbjährlich', |
||
| 244 | '12': 'Jährlich' |
||
| 245 | }, |
||
| 246 | $('.member-type .text'), |
||
| 247 | { |
||
| 248 | 'sustaining': 'Förder', |
||
| 249 | 'active': 'Aktive' |
||
| 250 | }, |
||
| 251 | $('.membership-type-icon'), |
||
| 252 | { |
||
| 253 | 'sustaining': 'icon-favorite', |
||
| 254 | 'active': 'icon-flash_on' |
||
| 255 | }, |
||
| 256 | $('.member-type .info-detail'), |
||
| 257 | { |
||
| 258 | 'sustaining': 'Sie erhalten regelmäßige Informationen über die Arbeit des Vereins.', |
||
| 259 | 'active': 'Sie bringen sich aktiv im Verein und haben ein Stimmrecht auf der Mitglieder- versammlung.' |
||
| 260 | } |
||
| 261 | ), |
||
| 262 | stateKey: 'membershipFormContent' |
||
| 263 | }, |
||
| 264 | { |
||
| 265 | viewHandler: WMDE.View.createDisplayAddressHandler( { |
||
| 266 | fullName: $( '#membership-confirm-name' ), |
||
| 267 | street: $( '#membership-confirm-street' ), |
||
| 268 | postcode: $( '#membership-confirm-postcode' ), |
||
| 269 | city: $( '#membership-confirm-city' ), |
||
| 270 | country: $( '#membership-confirm-country' ), |
||
| 271 | email: $( '#membership-confirm-mail' ) |
||
| 272 | } ), |
||
| 273 | stateKey: 'membershipFormContent' |
||
| 274 | }, |
||
| 275 | { |
||
| 276 | viewHandler: WMDE.View.createBankDataDisplayHandler( |
||
| 277 | $( '#membership-confirm-iban' ), |
||
| 278 | $( '#membership-confirm-bic' ), |
||
| 279 | $( '#membership-confirm-bankname' ) |
||
| 280 | ), |
||
| 281 | stateKey: 'membershipFormContent' |
||
| 282 | }, |
||
| 283 | { |
||
| 284 | viewHandler: WMDE.View.createFieldValueValidityIndicator( $( '#first-name' ) ), |
||
| 285 | stateKey: 'membershipInputValidation.firstName' |
||
| 286 | }, |
||
| 287 | { |
||
| 288 | viewHandler: WMDE.View.createFieldValueValidityIndicator( $( '#surname' ) ), |
||
| 289 | stateKey: 'membershipInputValidation.lastName' |
||
| 290 | }, |
||
| 291 | { |
||
| 292 | viewHandler: WMDE.View.createFieldValueValidityIndicator( $( '#contact-person' ) ), |
||
| 293 | stateKey: 'membershipInputValidation.contactPerson' |
||
| 294 | }, |
||
| 295 | { |
||
| 296 | viewHandler: WMDE.View.createFieldValueValidityIndicator( $( '.street' ) ), |
||
| 297 | stateKey: 'membershipInputValidation.street' |
||
| 298 | }, |
||
| 299 | { |
||
| 300 | viewHandler: WMDE.View.createFieldValueValidityIndicator( $( '.post-code' ) ), |
||
| 301 | stateKey: 'membershipInputValidation.postcode' |
||
| 302 | }, |
||
| 303 | { |
||
| 304 | viewHandler: WMDE.View.createFieldValueValidityIndicator( $( '.city' ) ), |
||
| 305 | stateKey: 'membershipInputValidation.city' |
||
| 306 | }, |
||
| 307 | { |
||
| 308 | viewHandler: WMDE.View.createFieldValueValidityIndicator( $( '.email' ) ), |
||
| 309 | stateKey: 'membershipInputValidation.email' |
||
| 310 | }, |
||
| 311 | { |
||
| 312 | viewHandler: WMDE.View.createFieldValueValidityIndicator( $( '#company-name' ) ), |
||
| 313 | stateKey: 'membershipInputValidation.companyName' |
||
| 314 | }, |
||
| 315 | { |
||
| 316 | viewHandler: WMDE.View.createFieldValueValidityIndicator( $( '#date-of-birth' ) ), |
||
| 317 | stateKey: 'membershipInputValidation.dateOfBirth' |
||
| 318 | }, |
||
| 319 | { |
||
| 320 | viewHandler: WMDE.View.createFieldValueValidityIndicator( $( '#phone' ) ), |
||
| 321 | stateKey: 'membershipInputValidation.phoneNumber' |
||
| 322 | }, |
||
| 323 | { |
||
| 324 | viewHandler: WMDE.View.createFieldValueValidityIndicator( $( '#iban' ) ), |
||
| 325 | stateKey: 'membershipInputValidation.iban' |
||
| 326 | }, |
||
| 327 | { |
||
| 328 | viewHandler: WMDE.View.createFieldValueValidityIndicator( $( '#bic' ) ), |
||
| 329 | stateKey: 'membershipInputValidation.bic' |
||
| 330 | }, |
||
| 331 | { |
||
| 332 | viewHandler: WMDE.View.createFieldValueValidityIndicator( $( '#account-number' ) ), |
||
| 333 | stateKey: 'membershipInputValidation.accountNumber' |
||
| 334 | }, |
||
| 335 | { |
||
| 336 | viewHandler: WMDE.View.createFieldValueValidityIndicator( $( '#bank-code' ) ), |
||
| 337 | stateKey: 'membershipInputValidation.bankCode' |
||
| 338 | }, |
||
| 339 | { |
||
| 340 | viewHandler: WMDE.View.createFieldValueValidityIndicator( $( '.amount-input' ) ), |
||
| 341 | stateKey: 'membershipInputValidation.amount' |
||
| 342 | } |
||
| 343 | ], |
||
| 344 | store |
||
| 345 | ); |
||
| 346 | |||
| 347 | // Validity checks for different form parts |
||
| 348 | |||
| 349 | function displayErrorBox() { |
||
|
|
|||
| 350 | $( '#validation-errors' ).show(); |
||
| 351 | $( 'html, body' ).animate( { scrollTop: $( '#validation-errors' ).offset().top } ); |
||
| 352 | } |
||
| 353 | |||
| 354 | function addressIsValid() { |
||
| 355 | return store.getState().validity.address; |
||
| 356 | } |
||
| 357 | |||
| 358 | function bankDataIsValid() { |
||
| 359 | var state = store.getState(); |
||
| 360 | // fixme move check to store/validator |
||
| 361 | return state.membershipFormContent.paymentType !== 'BEZ' || |
||
| 362 | ( |
||
| 363 | state.membershipInputValidation.bic.dataEntered && state.membershipInputValidation.bic.isValid && |
||
| 364 | state.membershipInputValidation.iban.dataEntered && state.membershipInputValidation.iban.isValid |
||
| 365 | ) || |
||
| 366 | ( |
||
| 367 | state.membershipInputValidation.accountNumber.dataEntered && state.membershipInputValidation.accountNumber.isValid && |
||
| 368 | state.membershipInputValidation.bankCode.dataEntered && state.membershipInputValidation.bankCode.isValid |
||
| 369 | ); |
||
| 370 | } |
||
| 371 | |||
| 372 | function formDataIsValid() { |
||
| 373 | var validity = store.getState().validity; |
||
| 374 | var state = store.getState(); |
||
| 375 | //console.log(validity.paymentData + " " + addressIsValid() + " " + bankDataIsValid()); |
||
| 376 | return validity.paymentData && state.membershipFormContent.membershipType && addressIsValid() && bankDataIsValid(); |
||
| 377 | } |
||
| 378 | |||
| 379 | |||
| 380 | function triggerValidityCheckForPersonalDataPage() { |
||
| 381 | var formContent = store.getState().membershipFormContent; |
||
| 382 | |||
| 383 | if ( !addressIsValid() ) { |
||
| 384 | if ( formContent.addressType === 'person' ) { |
||
| 385 | store.dispatch( actions.newMarkEmptyFieldsInvalidAction( |
||
| 386 | [ 'salutation', 'firstName', 'lastName', 'street', 'postcode', 'city', 'email' ], |
||
| 387 | [ 'companyName' ] |
||
| 388 | ) ); |
||
| 389 | } else if ( formContent.addressType === 'firma' ) { |
||
| 390 | store.dispatch( actions.newMarkEmptyFieldsInvalidAction( |
||
| 391 | [ 'companyName', 'street', 'postcode', 'city', 'email' ], |
||
| 392 | [ 'firstName', 'lastName', 'salutation' ] |
||
| 393 | ) ); |
||
| 394 | } |
||
| 395 | } |
||
| 396 | |||
| 397 | if ( !bankDataIsValid() ) { |
||
| 398 | store.dispatch( actions.newMarkEmptyFieldsInvalidAction( |
||
| 399 | [ 'iban', 'bic' ] |
||
| 400 | ) ); |
||
| 401 | } |
||
| 402 | |||
| 403 | if ( !store.getState().validity.amount ) { |
||
| 404 | store.dispatch( actions.newMarkEmptyFieldsInvalidAction( [ 'amount' ] ) ); |
||
| 405 | } |
||
| 406 | } |
||
| 407 | |||
| 408 | function hasInvalidFields() { |
||
| 409 | var invalidFields = false; |
||
| 410 | $.each( store.getState().membershipInputValidation, function( key, value ) { |
||
| 411 | if ( value.isValid === false ) { |
||
| 412 | invalidFields = true; |
||
| 413 | } |
||
| 414 | } ); |
||
| 415 | |||
| 416 | return invalidFields; |
||
| 417 | } |
||
| 418 | // fixme Move validation to store again, handle class changes in view handlers |
||
| 419 | handleGroupValidations = function () { |
||
| 420 | var state = store.getState(); |
||
| 421 | |||
| 422 | //1st Group Amount & Periodicity |
||
| 423 | var memberType = $('.member-type'), |
||
| 424 | amount = $('.amount'), |
||
| 425 | paymentMethod = $('.payment-method'), |
||
| 426 | donatorType = $('.donator-type'); |
||
| 427 | |||
| 428 | if (state.membershipFormContent.membershipType) { |
||
| 429 | memberType.addClass('completed').removeClass('disabled invalid'); |
||
| 430 | donatorType.removeClass('disabled'); |
||
| 431 | } |
||
| 432 | |||
| 433 | if (state.membershipFormContent.paymentIntervalInMonths >= 0) { |
||
| 434 | amount.addClass('completed').removeClass('disabled invalid'); |
||
| 435 | paymentMethod.removeClass('disabled'); |
||
| 436 | if (state.membershipInputValidation.amount.dataEntered && !state.membershipInputValidation.amount.isValid) { |
||
| 437 | amount.removeClass('completed').addClass('invalid'); |
||
| 438 | amount.find('.periodicity-icon').removeClass().addClass('periodicity-icon icon-error'); |
||
| 439 | } |
||
| 440 | } |
||
| 441 | else { |
||
| 442 | paymentMethod.addClass('disabled'); |
||
| 443 | } |
||
| 444 | |||
| 445 | if (state.membershipFormContent.paymentType) { |
||
| 446 | paymentMethod.addClass('completed').removeClass('disabled invalid'); |
||
| 447 | if ( |
||
| 448 | ( |
||
| 449 | state.membershipFormContent.debitType == 'sepa' && |
||
| 450 | state.membershipInputValidation.iban.dataEntered && !state.membershipInputValidation.iban.isValid || |
||
| 451 | state.membershipInputValidation.bic.dataEntered && !state.membershipInputValidation.bic.isValid |
||
| 452 | ) |
||
| 453 | || |
||
| 454 | (state.membershipFormContent.debitType == 'non-sepa' && |
||
| 455 | state.membershipInputValidation.bankCode.dataEntered && !state.membershipInputValidation.bankCode.isValid || |
||
| 456 | state.membershipInputValidation.accountNumber.dataEntered && !state.membershipInputValidation.accountNumber.isValid |
||
| 457 | ) |
||
| 458 | ){ |
||
| 459 | paymentMethod.addClass('invalid'); |
||
| 460 | paymentMethod.find('.payment-icon').removeClass().addClass('payment-icon icon-error'); |
||
| 461 | } |
||
| 462 | else { |
||
| 463 | paymentMethod.removeClass('invalid'); |
||
| 464 | } |
||
| 465 | } |
||
| 466 | else { |
||
| 467 | donatorType.addClass('disabled'); |
||
| 468 | } |
||
| 469 | |||
| 470 | View Code Duplication | if (state.membershipFormContent.addressType) { |
|
| 471 | donatorType.addClass('completed').removeClass('disabled invalid'); |
||
| 472 | var validators = state.membershipInputValidation; |
||
| 473 | if ( |
||
| 474 | state.membershipFormContent.addressType == 'person' && |
||
| 475 | ( |
||
| 476 | (validators.email.dataEntered && !validators.email.isValid) || |
||
| 477 | (validators.city.dataEntered && !validators.city.isValid) || |
||
| 478 | (validators.firstName.dataEntered && !validators.firstName.isValid) || |
||
| 479 | (validators.lastName.dataEntered && !validators.lastName.isValid) || |
||
| 480 | (validators.street.dataEntered && !validators.street.isValid) || |
||
| 481 | (validators.postcode.dataEntered && !validators.postcode.isValid) || |
||
| 482 | (validators.salutation.dataEntered && !validators.salutation.isValid) || |
||
| 483 | (validators.firstName.dataEntered && !validators.firstName.isValid) |
||
| 484 | ) |
||
| 485 | || |
||
| 486 | state.membershipFormContent.addressType == 'firma' && |
||
| 487 | ( |
||
| 488 | (validators.contactPerson.dataEntered && !validators.contactPerson.isValid) || |
||
| 489 | (validators.companyName.dataEntered && !validators.companyName.isValid) || |
||
| 490 | (validators.firstName.dataEntered && !validators.firstName.isValid) || |
||
| 491 | (validators.email.dataEntered && !validators.email.isValid) || |
||
| 492 | (validators.city.dataEntered && !validators.city.isValid) || |
||
| 493 | (validators.street.dataEntered && !validators.street.isValid) || |
||
| 494 | (validators.postcode.dataEntered && !validators.postcode.isValid) |
||
| 495 | )){ |
||
| 496 | donatorType.addClass('invalid'); |
||
| 497 | donatorType.find('.payment-icon').removeClass().addClass('payment-icon icon-error'); |
||
| 498 | } |
||
| 499 | } |
||
| 500 | |||
| 501 | |||
| 502 | if (formDataIsValid()) { |
||
| 503 | $('form input[type="submit"]').removeClass('btn-unactive'); |
||
| 504 | } |
||
| 505 | else { |
||
| 506 | $('form input[type="submit"]').addClass('btn-unactive'); |
||
| 507 | } |
||
| 508 | }; |
||
| 509 | $('input').on('click, change', WMDE.StoreUpdates.makeEventHandlerWaitForAsyncFinish( handleGroupValidations, store ) ); |
||
| 510 | setInterval(handleGroupValidations, 1000); |
||
| 511 | |||
| 512 | // TODO move to view handler |
||
| 513 | $('input[name="membership_type"]').on('click', function () { |
||
| 514 | if ($(this).val() == 'active') { |
||
| 515 | $('#company').parent().addClass('disabled'); |
||
| 516 | $('.wrap-field.firma').removeClass('selected'); |
||
| 517 | $('.wrap-field.firma .wrap-info .info-text').removeClass('opened'); |
||
| 518 | $('.wrap-field.personal').addClass('selected'); |
||
| 519 | $('.wrap-field.personal .wrap-info .info-text').addClass('opened'); |
||
| 520 | } |
||
| 521 | else { |
||
| 522 | $('#company').parent().removeClass('disabled'); |
||
| 523 | } |
||
| 524 | }); |
||
| 525 | |||
| 526 | $('form').on('submit', function () { |
||
| 527 | triggerValidityCheckForPersonalDataPage(); |
||
| 528 | handleGroupValidations(); |
||
| 529 | |||
| 530 | if (formDataIsValid()) { |
||
| 531 | return true; |
||
| 532 | } |
||
| 533 | return false; |
||
| 534 | }); |
||
| 535 | |||
| 536 | $("#amount-typed").on('keypress', function (event) { |
||
| 537 | var _element = $(this), |
||
| 538 | keyCode = event.keyCode || event.which, |
||
| 539 | keysAllowed = [44, 46, 48, 49, 50, 51, 52, 53, 54, 55, 56, 57, 0, 8, 9, 13]; |
||
| 540 | |||
| 541 | if ($.inArray(keyCode, keysAllowed) === -1 && event.ctrlKey === false) { |
||
| 542 | event.preventDefault(); |
||
| 543 | } |
||
| 544 | |||
| 545 | if ((keyCode == 44 || keyCode == 46) && $('#amount-typed').val().indexOf('.') > 0) { |
||
| 546 | event.preventDefault(); |
||
| 547 | } |
||
| 548 | |||
| 549 | if (keyCode == 44) { |
||
| 550 | setTimeout( |
||
| 551 | function () { |
||
| 552 | $('#amount-typed').val( |
||
| 553 | $('#amount-typed').val().replace(',','.') |
||
| 554 | ); |
||
| 555 | }, 10); |
||
| 556 | } |
||
| 557 | }); |
||
| 558 | |||
| 559 | // Initialize form pages |
||
| 560 | store.dispatch( actions.newAddPageAction( 'personalData' ) ); |
||
| 561 | store.dispatch( actions.newAddPageAction( 'bankConfirmation' ) ); |
||
| 562 | |||
| 563 | // Set initial form values |
||
| 564 | store.dispatch( actions.newInitializeContentAction( initData.data( 'initial-form-values' ) ) ); |
||
| 565 | |||
| 566 | } ); |