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