|
1
|
|
|
$( function () { |
|
2
|
|
|
/** global: WMDE */ |
|
3
|
|
|
|
|
4
|
|
|
var initData = $( '#init-form' ), |
|
5
|
|
|
store = WMDE.Store.createMembershipStore(), |
|
6
|
|
|
actions = WMDE.Actions; |
|
7
|
|
|
|
|
8
|
|
|
WMDE.StoreUpdates.connectComponentsToStore( |
|
9
|
|
|
[ |
|
10
|
|
|
//MemberShipType |
|
11
|
|
|
WMDE.Components.createRadioComponent( store, $( 'input[name="membership_type"]' ), 'membershipType' ), |
|
12
|
|
|
|
|
13
|
|
|
//Amount and periodicity |
|
14
|
|
|
WMDE.Components.createAmountComponent( |
|
15
|
|
|
store, |
|
16
|
|
|
$( '#amount-typed' ), |
|
17
|
|
|
$( '.wrap-amounts input[type="radio"]' ), |
|
18
|
|
|
$( '#amount-hidden'), |
|
19
|
|
|
WMDE.IntegerCurrency.createCurrencyParser( 'de' ), |
|
20
|
|
|
WMDE.IntegerCurrency.createCurrencyFormatter( 'de' ) |
|
21
|
|
|
), |
|
22
|
|
|
WMDE.Components.createRadioComponent( store, $( '#recurrence .wrap-input input' ), 'paymentIntervalInMonths' ), |
|
23
|
|
|
|
|
24
|
|
|
//Personal data |
|
25
|
|
|
WMDE.Components.createRadioComponent( store, $( 'input[name="adresstyp"]' ), '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, $( '#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_type"]'), '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
|
|
|
|
|
56
|
|
|
WMDE.Components.createTextComponent( store, $( '#date-of-birth' ), 'dateOfBirth' ), |
|
57
|
|
|
|
|
58
|
|
|
// fill hidden form fields with values to match backend |
|
59
|
|
|
WMDE.Components.createTextComponent( store, $( 'input[name="account_number"]' ), 'accountNumber' ), |
|
60
|
|
|
WMDE.Components.createTextComponent( store, $( 'input[name="bank_code"]' ), 'bankCode' ) |
|
61
|
|
|
], |
|
62
|
|
|
store, |
|
63
|
|
|
'membershipFormContent' |
|
64
|
|
|
); |
|
65
|
|
|
|
|
66
|
|
|
WMDE.StoreUpdates.connectValidatorsToStore( |
|
67
|
|
|
function ( initialValues ) { |
|
68
|
|
|
return [ |
|
69
|
|
|
WMDE.ValidationDispatchers.createFeeValidationDispatcher( |
|
70
|
|
|
WMDE.FormValidation.createFeeValidator( |
|
71
|
|
|
initData.data( 'validate-fee-url' ), |
|
72
|
|
|
WMDE.IntegerCurrency.createCurrencyFormatter( 'de' ) |
|
73
|
|
|
), |
|
74
|
|
|
initialValues |
|
75
|
|
|
), |
|
76
|
|
|
WMDE.ValidationDispatchers.createAddressValidationDispatcher( |
|
77
|
|
|
WMDE.FormValidation.createAddressValidator( |
|
78
|
|
|
initData.data( 'validate-address-url' ), |
|
79
|
|
|
WMDE.FormValidation.DefaultRequiredFieldsForAddressType |
|
80
|
|
|
), |
|
81
|
|
|
initialValues |
|
82
|
|
|
), |
|
83
|
|
|
WMDE.ValidationDispatchers.createEmailValidationDispatcher( |
|
84
|
|
|
WMDE.FormValidation.createEmailAddressValidator( initData.data( 'validate-email-address-url' ) ), |
|
85
|
|
|
initialValues |
|
86
|
|
|
), |
|
87
|
|
|
WMDE.ValidationDispatchers.createBankDataValidationDispatcher( |
|
88
|
|
|
WMDE.FormValidation.createBankDataValidator( |
|
89
|
|
|
initData.data( 'validate-iban-url' ), |
|
90
|
|
|
initData.data( 'generate-iban-url' ) |
|
91
|
|
|
), |
|
92
|
|
|
initialValues |
|
93
|
|
|
) |
|
94
|
|
|
]; |
|
95
|
|
|
}, |
|
96
|
|
|
store, |
|
97
|
|
|
initData.data( 'initial-form-values' ), |
|
98
|
|
|
'membershipFormContent' |
|
99
|
|
|
); |
|
100
|
|
|
|
|
101
|
|
|
// Connect view handlers to changes in specific parts in the global state, designated by 'stateKey' |
|
102
|
|
|
WMDE.StoreUpdates.connectViewHandlersToStore( |
|
103
|
|
|
[ |
|
104
|
|
|
{ |
|
105
|
|
|
viewHandler: WMDE.View.createErrorBoxHandler( $( '#validation-errors' ), { |
|
106
|
|
|
amount: 'Betrag', |
|
107
|
|
|
salutation: 'Anrede', |
|
108
|
|
|
title: 'Titel', |
|
109
|
|
|
firstName: 'Vorname', |
|
110
|
|
|
lastName: 'Nachname', |
|
111
|
|
|
companyName: 'Firma', |
|
112
|
|
|
street: 'Straße', |
|
113
|
|
|
postcode: 'PLZ', |
|
114
|
|
|
city: 'Ort', |
|
115
|
|
|
country: 'Land', |
|
116
|
|
|
email: 'E-Mail', |
|
117
|
|
|
dateOfBirth: 'Geburtsdatum', |
|
118
|
|
|
iban: 'IBAN', |
|
119
|
|
|
bic: 'BIC', |
|
120
|
|
|
accountNumber: 'Kontonummer', |
|
121
|
|
|
bankCode: 'Bankleitzahl' |
|
122
|
|
|
} ), |
|
123
|
|
|
stateKey: 'membershipInputValidation' |
|
124
|
|
|
}, |
|
125
|
|
|
// Active membership is not an option for companies |
|
126
|
|
|
{ |
|
127
|
|
|
viewHandler: WMDE.View.createElementClassSwitcher( $('#company').parent(), /active/, 'disabled' ), |
|
128
|
|
|
stateKey: 'membershipFormContent.membershipType' |
|
129
|
|
|
}, |
|
130
|
|
|
{ |
|
131
|
|
|
viewHandler: WMDE.View.createSimpleVisibilitySwitcher( $( '#payment-method .info-text .info-recurrent' ), /^(1|3|6|12)/ ), |
|
132
|
|
|
stateKey: 'membershipFormContent.paymentIntervalInMonths' |
|
133
|
|
|
}, |
|
134
|
|
|
{ |
|
135
|
|
|
viewHandler: WMDE.View.createSuboptionDisplayHandler( |
|
136
|
|
|
$( '#type-donor' ) |
|
137
|
|
|
), |
|
138
|
|
|
stateKey: 'membershipFormContent.addressType' |
|
139
|
|
|
}, |
|
140
|
|
|
{ |
|
141
|
|
|
viewHandler: WMDE.View.createSuboptionDisplayHandler( |
|
142
|
|
|
$( '#recurrence' ) |
|
143
|
|
|
), |
|
144
|
|
|
stateKey: 'membershipFormContent.paymentIntervalInMonths' |
|
145
|
|
|
}, |
|
146
|
|
|
{ |
|
147
|
|
|
viewHandler: WMDE.View.createSuboptionDisplayHandler( |
|
148
|
|
|
$( '#payment-method' ) |
|
149
|
|
|
), |
|
150
|
|
|
stateKey: 'membershipFormContent.paymentType' |
|
151
|
|
|
}, |
|
152
|
|
|
{ |
|
153
|
|
|
viewHandler: WMDE.View.createFeeOptionSwitcher( |
|
154
|
|
|
[ |
|
155
|
|
|
$( '#amount1' ), |
|
156
|
|
|
$( '#amount2' ), |
|
157
|
|
|
$( '#amount3' ), |
|
158
|
|
|
$( '#amount4' ), |
|
159
|
|
|
$( '#amount5' ), |
|
160
|
|
|
$( '#amount6' ), |
|
161
|
|
|
$( '#amount7' ), |
|
162
|
|
|
$( '#amount8' ) |
|
163
|
|
|
], |
|
164
|
|
|
{ // minimum annual amount in cents |
|
165
|
|
|
person: 2400, |
|
166
|
|
|
firma: 10000 |
|
167
|
|
|
} |
|
168
|
|
|
), |
|
169
|
|
|
stateKey: 'membershipFormContent' |
|
170
|
|
|
}, |
|
171
|
|
|
{ |
|
172
|
|
|
viewHandler: WMDE.View.createShySubmitButtonHandler( $( 'form input[type="submit"]' ) ), |
|
173
|
|
|
stateKey: [ WMDE.StateAggregation.Membership.allValiditySectionsAreValid ] |
|
174
|
|
|
}, |
|
175
|
|
|
{ |
|
176
|
|
|
viewHandler: WMDE.View.SectionInfo.createMembershipTypeSectionInfo( |
|
177
|
|
|
$( '.member-type' ), |
|
178
|
|
|
{ |
|
179
|
|
|
'sustaining': 'icon-favorite', |
|
180
|
|
|
'active': 'icon-flash_on' |
|
181
|
|
|
}, |
|
182
|
|
|
WMDE.FormDataExtractor.mapFromRadioLabels( $( '#type-membership .wrap-input' ) ), |
|
183
|
|
|
{ 'sustaining': '', 'active': '' } |
|
184
|
|
|
), |
|
185
|
|
|
stateKey: [ |
|
186
|
|
|
'membershipFormContent.membershipType', |
|
187
|
|
|
function ( store ) { |
|
188
|
|
|
return { |
|
189
|
|
|
isValid: store.membershipFormContent.membershipType !== null, |
|
190
|
|
|
dataEntered: store.membershipFormContent.membershipType !== null |
|
191
|
|
|
} |
|
192
|
|
|
} |
|
193
|
|
|
] |
|
194
|
|
|
}, |
|
195
|
|
|
{ |
|
196
|
|
|
viewHandler: WMDE.View.SectionInfo.createDonorTypeSectionInfo( |
|
197
|
|
|
$( '.donor-type' ), |
|
198
|
|
|
{ |
|
199
|
|
|
'person': 'icon-account_circle', |
|
200
|
|
|
'firma': 'icon-work', |
|
201
|
|
|
'anonym': 'icon-visibility_off' |
|
202
|
|
|
}, |
|
203
|
|
|
WMDE.FormDataExtractor.mapFromRadioLabels( $( '#type-donor .wrap-input' ) ), |
|
204
|
|
|
WMDE.FormDataExtractor.mapFromSelectOptions( $( '#country' ) ) |
|
205
|
|
|
), |
|
206
|
|
|
stateKey: [ |
|
207
|
|
|
'membershipFormContent.addressType', |
|
208
|
|
|
'membershipFormContent.salutation', |
|
209
|
|
|
'membershipFormContent.title', |
|
210
|
|
|
'membershipFormContent.firstName', |
|
211
|
|
|
'membershipFormContent.lastName', |
|
212
|
|
|
'membershipFormContent.companyName', |
|
213
|
|
|
'membershipFormContent.street', |
|
214
|
|
|
'membershipFormContent.postcode', |
|
215
|
|
|
'membershipFormContent.city', |
|
216
|
|
|
'membershipFormContent.country', |
|
217
|
|
|
'membershipFormContent.email', |
|
218
|
|
|
WMDE.StateAggregation.Membership.donorTypeAndAddressAreValid |
|
219
|
|
|
] |
|
220
|
|
|
}, |
|
221
|
|
|
{ |
|
222
|
|
|
viewHandler: WMDE.View.SectionInfo.createAmountFrequencySectionInfo( |
|
223
|
|
|
$( '.amount' ), |
|
224
|
|
|
{ |
|
225
|
|
|
'0': 'icon-unique', |
|
226
|
|
|
'1': 'icon-repeat_1', |
|
227
|
|
|
'3': 'icon-repeat_3', |
|
228
|
|
|
'6': 'icon-repeat_6', |
|
229
|
|
|
'12': 'icon-repeat_12' |
|
230
|
|
|
}, |
|
231
|
|
|
WMDE.FormDataExtractor.mapFromRadioLabels( $( '#recurrence .wrap-input' ) ), |
|
232
|
|
|
WMDE.FormDataExtractor.mapFromRadioInfoTexts( $( '#recurrence .wrap-field' ) ), |
|
233
|
|
|
WMDE.IntegerCurrency.createCurrencyFormatter( 'de' ) |
|
234
|
|
|
), |
|
235
|
|
|
stateKey: [ |
|
236
|
|
|
'membershipFormContent.amount', |
|
237
|
|
|
'membershipFormContent.paymentIntervalInMonths', |
|
238
|
|
|
WMDE.StateAggregation.Membership.amountAndFrequencyAreValid |
|
239
|
|
|
] |
|
240
|
|
|
}, |
|
241
|
|
|
{ |
|
242
|
|
|
viewHandler: WMDE.View.SectionInfo.createPaymentTypeSectionInfo( |
|
243
|
|
|
$( '.payment-method' ), |
|
244
|
|
|
{ |
|
245
|
|
|
'PPL': 'icon-paypal', |
|
246
|
|
|
'MCP': 'icon-credit_card2', |
|
247
|
|
|
'BEZ': 'icon-SEPA-2', |
|
248
|
|
|
'UEB': 'icon-ubeiwsung-1', |
|
249
|
|
|
'SUB': 'icon-TODO' // @todo Find icon for SUB |
|
250
|
|
|
}, |
|
251
|
|
|
WMDE.FormDataExtractor.mapFromRadioLabels( $( '#payment-method .wrap-input' ) ), |
|
252
|
|
|
WMDE.FormDataExtractor.mapFromRadioInfoTexts( $( '#payment-method .wrap-field' ) ) |
|
253
|
|
|
), |
|
254
|
|
|
stateKey: [ |
|
255
|
|
|
'membershipFormContent.paymentType', |
|
256
|
|
|
'membershipFormContent.iban', |
|
257
|
|
|
'membershipFormContent.bic', |
|
258
|
|
|
WMDE.StateAggregation.Membership.paymentAndBankDataAreValid |
|
259
|
|
|
] |
|
260
|
|
|
}, |
|
261
|
|
|
{ |
|
262
|
|
|
viewHandler: WMDE.View.createFieldValueValidityIndicator( $( '#first-name' ) ), |
|
263
|
|
|
stateKey: 'membershipInputValidation.firstName' |
|
264
|
|
|
}, |
|
265
|
|
|
{ |
|
266
|
|
|
viewHandler: WMDE.View.createFieldValueValidityIndicator( $( '#surname' ) ), |
|
267
|
|
|
stateKey: 'membershipInputValidation.lastName' |
|
268
|
|
|
}, |
|
269
|
|
|
{ |
|
270
|
|
|
viewHandler: WMDE.View.createFieldValueValidityIndicator( $( '.street' ) ), |
|
271
|
|
|
stateKey: 'membershipInputValidation.street' |
|
272
|
|
|
}, |
|
273
|
|
|
{ |
|
274
|
|
|
viewHandler: WMDE.View.createFieldValueValidityIndicator( $( '.post-code' ) ), |
|
275
|
|
|
stateKey: 'membershipInputValidation.postcode' |
|
276
|
|
|
}, |
|
277
|
|
|
{ |
|
278
|
|
|
viewHandler: WMDE.View.createFieldValueValidityIndicator( $( '.city' ) ), |
|
279
|
|
|
stateKey: 'membershipInputValidation.city' |
|
280
|
|
|
}, |
|
281
|
|
|
{ |
|
282
|
|
|
viewHandler: WMDE.View.createFieldValueValidityIndicator( $( '.email' ) ), |
|
283
|
|
|
stateKey: 'membershipInputValidation.email' |
|
284
|
|
|
}, |
|
285
|
|
|
{ |
|
286
|
|
|
viewHandler: WMDE.View.createFieldValueValidityIndicator( $( '#company-name' ) ), |
|
287
|
|
|
stateKey: 'membershipInputValidation.companyName' |
|
288
|
|
|
}, |
|
289
|
|
|
{ |
|
290
|
|
|
viewHandler: WMDE.View.createFieldValueValidityIndicator( $( '#date-of-birth' ) ), |
|
291
|
|
|
stateKey: 'membershipInputValidation.dateOfBirth' |
|
292
|
|
|
}, |
|
293
|
|
|
{ |
|
294
|
|
|
viewHandler: WMDE.View.createFieldValueValidityIndicator( $( '#iban' ) ), |
|
295
|
|
|
stateKey: 'membershipInputValidation.iban' |
|
296
|
|
|
}, |
|
297
|
|
|
{ |
|
298
|
|
|
viewHandler: WMDE.View.createFieldValueValidityIndicator( $( '#bic' ) ), |
|
299
|
|
|
stateKey: 'membershipInputValidation.bic' |
|
300
|
|
|
}, |
|
301
|
|
|
{ |
|
302
|
|
|
viewHandler: WMDE.View.createFieldValueValidityIndicator( $( '#account-number' ) ), |
|
303
|
|
|
stateKey: 'membershipInputValidation.accountNumber' |
|
304
|
|
|
}, |
|
305
|
|
|
{ |
|
306
|
|
|
viewHandler: WMDE.View.createFieldValueValidityIndicator( $( '#bank-code' ) ), |
|
307
|
|
|
stateKey: 'membershipInputValidation.bankCode' |
|
308
|
|
|
}, |
|
309
|
|
|
{ |
|
310
|
|
|
viewHandler: WMDE.View.createFieldValueValidityIndicator( $( '#amount-typed' ) ), |
|
311
|
|
|
stateKey: 'membershipInputValidation.amount' |
|
312
|
|
|
} |
|
313
|
|
|
], |
|
314
|
|
|
store |
|
315
|
|
|
); |
|
316
|
|
|
|
|
317
|
|
|
$( 'form' ).on( 'submit', function () { |
|
318
|
|
|
return WMDE.StateAggregation.Membership.allValiditySectionsAreValid( store.getState() ); |
|
319
|
|
|
} ); |
|
320
|
|
|
|
|
321
|
|
|
// Set initial form values |
|
322
|
|
|
var initSetup = initData.data( 'initial-form-values' ); |
|
323
|
|
|
if ( typeof initSetup.amount === 'string' ) { |
|
324
|
|
|
// backend delivers amount as a german-formatted "float" string |
|
325
|
|
|
initSetup.amount = WMDE.IntegerCurrency.createCurrencyParser( 'de' ).parse( initSetup.amount ); |
|
326
|
|
|
} |
|
327
|
|
|
store.dispatch( actions.newInitializeContentAction( initSetup ) ); |
|
328
|
|
|
|
|
329
|
|
|
// Set initial validation state |
|
330
|
|
|
store.dispatch( actions.newInitializeValidationStateAction( |
|
331
|
|
|
initData.data( 'violatedFields' ), |
|
332
|
|
|
{} // membership form has no pages and does not get validation group information |
|
333
|
|
|
) ); |
|
334
|
|
|
|
|
335
|
|
|
// Non-state-changing event behavior |
|
336
|
|
|
|
|
337
|
|
|
// TODO Test if the scrolling behaviors still work, the following lines were just copy-pasted from donation |
|
338
|
|
|
var scroller = WMDE.Scrolling.createAnimatedScroller( $( '.wrap-header, .state-bar' ) ); |
|
339
|
|
|
WMDE.Scrolling.addScrollToLinkAnchors( $( 'a[href*="#"]' ), scroller); |
|
340
|
|
|
WMDE.Scrolling.scrollOnSuboptionChange( $( 'input[name="periode"]' ), $( '#recurrence' ), scroller ); |
|
341
|
|
|
WMDE.Scrolling.scrollOnSuboptionChange( $( 'input[name="addressType"]' ), $( '#type-donor' ), scroller ); |
|
342
|
|
|
WMDE.Scrolling.scrollOnSuboptionChange( $( 'input[name="paymentType"]' ), $( '#donation-payment' ), scroller ); |
|
343
|
|
|
|
|
344
|
|
|
} ); |