Commit | Line | Data |
---|---|---|
6a488035 TO |
1 | {* |
2 | +--------------------------------------------------------------------+ | |
1188c7a8 | 3 | | Copyright CiviCRM LLC. All rights reserved. | |
6a488035 | 4 | | | |
1188c7a8 TO |
5 | | This work is published under the GNU AGPLv3 license with some | |
6 | | permitted exceptions and without any warranty. For full license | | |
7 | | and copyright information, see https://civicrm.org/licensing | | |
6a488035 TO |
8 | +--------------------------------------------------------------------+ |
9 | *} | |
10 | ||
11 | {if $priceSet && $allowGroupOnWaitlist} | |
12 | {literal} | |
13 | <script type="text/javascript"> | |
14 | var isAdditionalParticipants = false; | |
15 | var pPartiCount = 0; | |
16 | var pPartiRef = Array( ); | |
17 | var optionSep = '|'; | |
18 | ||
32678ccb | 19 | CRM.$(function($) { |
6a488035 TO |
20 | pricesetParticipantCount( ); |
21 | allowGroupOnWaitlist(0, pPartiCount); | |
22 | }); | |
23 | ||
24 | function pricesetParticipantCount( ) { | |
25 | ||
26 | cj("input,#priceset select,#priceset").each(function () { | |
27 | ||
28 | if ( cj(this).attr('price') ) { | |
29 | switch( cj(this).attr('type') ) { | |
30 | case 'checkbox': | |
31 | eval( 'var option = ' + cj(this).attr('price') ) ; | |
32 | ele = option[0]; | |
33 | optionPart = option[1].split(optionSep); | |
34 | var addCount = 0; | |
35 | ||
36 | if ( optionPart[1] ) { | |
37 | addCount = parseInt(optionPart[1]); | |
38 | } | |
39 | ||
8539f25d | 40 | if( cj(this).prop('checked') ) { |
6a488035 TO |
41 | pPartiCount += addCount; |
42 | pPartiRef[ele] += addCount; | |
43 | } | |
44 | ||
45 | cj(this).click( function(){ | |
8539f25d | 46 | if( cj(this).prop('checked') ) { |
6a488035 TO |
47 | pPartiCount += addCount; |
48 | pPartiRef[ele] += addCount; | |
49 | } else { | |
50 | pPartiCount -= addCount; | |
51 | pPartiRef[ele] -= addCount; | |
52 | } | |
53 | updateWaitingStatus( pPartiCount ); | |
54 | }); | |
55 | break; | |
56 | ||
57 | case 'radio': | |
58 | //default calcution of element. | |
59 | eval( 'var option = ' + cj(this).attr('price') ); | |
60 | ele = option[0]; | |
61 | optionPart = option[1].split(optionSep); | |
62 | var addCount = 0; | |
63 | ||
64 | if ( optionPart[1] ) { | |
65 | addCount = parseInt(optionPart[1]); | |
66 | } | |
67 | if ( ! pPartiRef[ele] ) { | |
68 | pPartiRef[ele] = 0; | |
69 | } | |
70 | ||
8539f25d | 71 | if( cj(this).prop('checked') ) { |
6a488035 TO |
72 | pPartiCount = parseInt(pPartiCount) + addCount - parseInt(pPartiRef[ele]); |
73 | pPartiRef[ele] = addCount; | |
74 | } | |
75 | ||
76 | cj(this).click( function(){ | |
77 | pPartiCount = parseInt(pPartiCount) + addCount - parseInt(pPartiRef[ele]); | |
78 | pPartiRef[ele] = addCount; | |
79 | updateWaitingStatus( pPartiCount ); | |
80 | }) | |
81 | ||
82 | break; | |
83 | ||
84 | case 'text': | |
85 | // default calcution of element. | |
86 | var textval = parseFloat( cj(this).val() ); | |
87 | var addCount = 0; | |
88 | if ( textval ) { | |
89 | eval( 'var option = '+ cj(this).attr('price') ); | |
90 | ele = option[0]; | |
91 | if ( ! pPartiRef[ele] ) { | |
92 | pPartiRef[ele] = 0; | |
93 | } | |
94 | optionPart = option[1].split(optionSep); | |
95 | if ( optionPart[1] ) { | |
96 | addCount = parseInt( optionPart[1] ); | |
97 | var curval = textval * addCount; | |
98 | if ( textval >= 0 ) { | |
99 | pPartiCount = parseInt(pPartiCount) + curval - parseInt(pPartiRef[ele]); | |
100 | pPartiRef[ele] = curval; | |
101 | } | |
102 | } | |
103 | } | |
104 | ||
105 | //event driven calculation of element. | |
106 | cj(this).bind( 'keyup', function() { calculateTextCount( this ); | |
107 | }).bind( 'blur' , function() { calculateTextCount( this ); | |
108 | }); | |
109 | ||
110 | break; | |
111 | ||
112 | case 'select-one': | |
113 | ||
114 | //default calcution of element. | |
115 | var ele = cj(this).attr('id'); | |
116 | if ( ! pPartiRef[ele] ) { | |
117 | pPartiRef[ele] = 0; | |
118 | } | |
119 | var addcount = 0; | |
120 | eval( 'var selectedText = ' + cj(this).attr('price') ); | |
121 | if ( cj(this).val( ) ) { | |
122 | optionPart = selectedText[cj(this).val( )].split(optionSep); | |
123 | if ( optionPart[1] ) { | |
124 | addcount = parseInt( optionPart[1] ); | |
125 | } | |
126 | } | |
127 | ||
128 | if ( addcount ) { | |
129 | pPartiCount = parseInt(pPartiCount) + addcount - parseInt(pPartiRef[ele]); | |
130 | pPartiRef[ele] = addcount; | |
131 | } | |
132 | ||
133 | //event driven calculation of element. | |
134 | cj(this).change( function() { | |
135 | var ele = cj(this).attr('id'); | |
136 | if ( ! pPartiRef[ele] ) { | |
137 | pPartiRef[ele] = 0; | |
138 | } | |
139 | eval( 'var selectedText = ' + cj(this).attr('price') ); | |
140 | var addcount = 0; | |
141 | ||
142 | if ( cj(this).val( ) ) { | |
143 | var optionPart = selectedText[cj(this).val( )].split(optionSep); | |
144 | if ( optionPart[1] ) { | |
145 | addcount = parseInt( optionPart[1] ); | |
146 | } | |
147 | } | |
148 | ||
149 | if ( addcount ) { | |
150 | pPartiCount = parseInt(pPartiCount) + addcount - parseInt(pPartiRef[ele]); | |
151 | pPartiRef[ele] = addcount; | |
152 | } else { | |
153 | pPartiCount = parseInt(pPartiCount) - parseInt(pPartiRef[ele]); | |
154 | pPartiRef[ele] = 0; | |
155 | } | |
156 | updateWaitingStatus( pPartiCount ); | |
157 | }); | |
158 | break; | |
159 | } | |
160 | } | |
161 | }); | |
162 | } | |
163 | ||
164 | function calculateTextCount( object ) { | |
165 | eval( 'var option = ' + cj(object).attr('price') ); | |
166 | ele = option[0]; | |
167 | if ( ! pPartiRef[ele] ) { | |
168 | pPartiRef[ele] = 0; | |
169 | } | |
170 | var optionPart = option[1].split(optionSep); | |
171 | if ( optionPart[1] ) { | |
172 | addCount = parseInt( optionPart[1] ); | |
173 | var textval = parseInt( cj(object).attr('value') ); | |
174 | var curval = textval * addCount; | |
175 | if ( textval >= 0 ) { | |
176 | pPartiCount = pPartiCount + curval - parseInt(pPartiRef[ele]); | |
177 | pPartiRef[ele] = curval; | |
178 | } else { | |
179 | pPartiCount = pPartiCount - parseInt(pPartiRef[ele]); | |
180 | pPartiRef[ele] = 0; | |
181 | } | |
182 | updateWaitingStatus( pPartiCount ); | |
183 | } | |
184 | } | |
185 | ||
186 | function updateWaitingStatus( pricesetParticipantCount ) { | |
187 | allowGroupOnWaitlist( 0, pricesetParticipantCount ); | |
188 | } | |
189 | </script> | |
190 | {/literal} | |
232624b1 | 191 | {/if} |