Commit | Line | Data |
---|---|---|
6a488035 TO |
1 | {* |
2 | +--------------------------------------------------------------------+ | |
3 | | CiviCRM version 4.3 | | |
4 | +--------------------------------------------------------------------+ | |
5 | | Copyright CiviCRM LLC (c) 2004-2013 | | |
6 | +--------------------------------------------------------------------+ | |
7 | | This file is a part of CiviCRM. | | |
8 | | | | |
9 | | CiviCRM is free software; you can copy, modify, and distribute it | | |
10 | | under the terms of the GNU Affero General Public License | | |
11 | | Version 3, 19 November 2007 and the CiviCRM Licensing Exception. | | |
12 | | | | |
13 | | CiviCRM is distributed in the hope that it will be useful, but | | |
14 | | WITHOUT ANY WARRANTY; without even the implied warranty of | | |
15 | | MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. | | |
16 | | See the GNU Affero General Public License for more details. | | |
17 | | | | |
18 | | You should have received a copy of the GNU Affero General Public | | |
19 | | License and the CiviCRM Licensing Exception along | | |
20 | | with this program; if not, contact CiviCRM LLC | | |
21 | | at info[AT]civicrm[DOT]org. If you have questions about the | | |
22 | | GNU Affero General Public License or the licensing of CiviCRM, | | |
23 | | see the CiviCRM license FAQ at http://civicrm.org/licensing | | |
24 | +--------------------------------------------------------------------+ | |
25 | *} | |
26 | {if $products} | |
27 | <div id="premiums" class="premiums-group"> | |
28 | {if $context EQ "makeContribution"} | |
29 | <fieldset class="crm-group premiums_select-group"> | |
30 | {if $premiumBlock.premiums_intro_title} | |
31 | <legend>{$premiumBlock.premiums_intro_title}</legend> | |
32 | {/if} | |
33 | {if $premiumBlock.premiums_intro_text} | |
34 | <div id="premiums-intro" class="crm-section premiums_intro-section"> | |
35 | {$premiumBlock.premiums_intro_text} | |
36 | </div> | |
37 | {/if} | |
38 | {/if} | |
39 | ||
40 | {if $context EQ "confirmContribution" OR $context EQ "thankContribution"} | |
41 | <div class="crm-group premium_display-group"> | |
42 | <div class="header-dark"> | |
43 | {if $premiumBlock.premiums_intro_title} | |
44 | {$premiumBlock.premiums_intro_title} | |
45 | {else} | |
46 | {ts}Your Premium Selection{/ts} | |
47 | {/if} | |
48 | </div> | |
49 | {/if} | |
50 | ||
51 | {if $preview} | |
52 | {assign var="showSelectOptions" value="1"} | |
53 | {/if} | |
54 | ||
55 | {strip} | |
56 | <div id="premiums-listings"> | |
57 | {if $showPremium AND !$preview AND $premiumBlock.premiums_nothankyou_position EQ 1} | |
58 | <div class="premium premium-no_thanks" id="premium_id-no_thanks" min_contribution="0"> | |
59 | <div class="premium-short"> | |
60 | <input type="checkbox" disabled="disabled" /> {$premiumBlock.premiums_nothankyou_label} | |
61 | </div> | |
62 | <div class="premium-full"> | |
63 | <input type="checkbox" checked="checked" disabled="disabled" /> {$premiumBlock.premiums_nothankyou_label} | |
64 | </div> | |
65 | </div> | |
66 | {/if} | |
67 | {foreach from=$products item=row} | |
68 | <div class="premium {if $showPremium}premium-selectable{/if}" id="premium_id-{$row.id}" min_contribution="{$row.min_contribution}"> | |
69 | <div class="premium-short"> | |
70 | {if $row.thumbnail}<div class="premium-short-thumbnail"><img src="{$row.thumbnail}" alt="{$row.name}" /></div>{/if} | |
71 | <div class="premium-short-content">{$row.name}</div> | |
72 | <div style="clear:both"></div> | |
73 | </div> | |
74 | ||
75 | <div class="premium-full"> | |
76 | <div class="premium-full-image">{if $row.image}<img src="{$row.image}" alt="{$row.name}" />{/if}</div> | |
77 | <div class="premium-full-content"> | |
78 | <div class="premium-full-title">{$row.name}</div> | |
79 | <div class="premium-full-disabled"> | |
80 | {ts 1=$row.min_contribution}You must contribute at least $%1 to get this item{/ts}<br/> | |
d6cada7c | 81 | <input type="button" value="{ts 1=$row.min_contribution|crmMoney}Contribute %1 Instead{/ts}" amount="{$row.min_contribution}" /> |
6a488035 TO |
82 | </div> |
83 | <div class="premium-full-description"> | |
84 | {$row.description} | |
85 | </div> | |
86 | {if $showSelectOptions } | |
87 | {assign var="pid" value="options_"|cat:$row.id} | |
88 | {if $pid} | |
89 | <div class="premium-full-options"> | |
90 | <p>{$form.$pid.html}</p> | |
91 | </div> | |
92 | {/if} | |
93 | {else} | |
94 | <div class="premium-full-options"> | |
95 | <p><strong>{$row.options}</strong></p> | |
96 | </div> | |
97 | {/if} | |
98 | {if ( ($premiumBlock.premiums_display_min_contribution AND $context EQ "makeContribution") OR $preview EQ 1) AND $row.min_contribution GT 0 } | |
99 | <div class="premium-full-min">{ts 1=$row.min_contribution|crmMoney}Minimum: %1{/ts}</div> | |
100 | {/if} | |
101 | <div style="clear:both"></div> | |
102 | </div> | |
103 | </div> | |
104 | <div style="clear:both"></div> | |
105 | </div> | |
106 | {/foreach} | |
107 | {if $showPremium AND !$preview AND $premiumBlock.premiums_nothankyou_position EQ 2} | |
108 | <div class="premium premium-no_thanks" id="premium_id-no_thanks" min_contribution="0"> | |
109 | <div class="premium-short"> | |
110 | <input type="checkbox" disabled="disabled" /> {$premiumBlock.premiums_nothankyou_label} | |
111 | </div> | |
112 | <div class="premium-full"> | |
113 | <input type="checkbox" checked="checked" disabled="disabled" /> {$premiumBlock.premiums_nothankyou_label} | |
114 | </div> | |
115 | </div> | |
116 | {/if} | |
117 | </div> | |
118 | {/strip} | |
119 | ||
120 | {if $context EQ "makeContribution"} | |
121 | </fieldset> | |
122 | {elseif ! $preview} {* Close premium-display-group div for Confirm and Thank-you pages *} | |
123 | </div> | |
124 | {/if} | |
125 | </div> | |
126 | ||
127 | {if $context EQ "makeContribution"} | |
128 | {literal} | |
129 | <script> | |
130 | cj(function($){ | |
131 | var is_separate_payment = {/literal}{if $membershipBlock.is_separate_payment}{$membershipBlock.is_separate_payment}{else}0{/if}{literal}; | |
132 | ||
133 | // select a new premium | |
134 | function select_premium(premium_id) { | |
135 | if(cj(premium_id).length) { | |
136 | // hide other active premium | |
137 | cj('.premium-full').hide(); | |
138 | cj('.premium-short').show(); | |
139 | // show this one | |
140 | cj('.premium-short', cj(premium_id)).hide(); | |
141 | cj('.premium-full', cj(premium_id)).show(); | |
142 | // record this one | |
143 | var id_parts = premium_id.split('-'); | |
144 | cj('#selectProduct').val(id_parts[1]); | |
145 | } | |
146 | } | |
147 | ||
148 | // click premium to select | |
149 | cj('.premium-short').click(function(){ | |
150 | select_premium( '#'+cj(cj(this).parent()).attr('id') ); | |
151 | }); | |
152 | ||
153 | // select the default premium | |
154 | var premium_id = cj('#selectProduct').val(); | |
155 | if(premium_id == '') premium_id = 'no_thanks'; | |
156 | select_premium('#premium_id-'+premium_id); | |
157 | ||
158 | // get the current amount | |
159 | function get_amount() { | |
160 | var amount; | |
161 | ||
162 | // see if other amount exists and has a value | |
163 | if(cj('.other_amount-content input').length) { | |
164 | amount = Number(cj('.other_amount-content input').val()); | |
165 | if(isNaN(amount)) | |
166 | amount = 0; | |
167 | } | |
168 | ||
169 | function check_price_set(price_set_radio_buttons) { | |
170 | if(!amount) { | |
171 | cj(price_set_radio_buttons).each(function(){ | |
172 | if(cj(this).attr('checked')) { | |
173 | amount = cj(this).attr('data-amount'); | |
174 | if(amount) { | |
175 | amount = Number(amount); | |
176 | if(isNaN(amount)) | |
177 | amount = 0; | |
178 | } | |
179 | } | |
180 | }); | |
181 | } | |
182 | } | |
183 | ||
184 | // check for additional contribution | |
185 | var additional_amount = 0; | |
186 | if(is_separate_payment) { | |
187 | additional_amount = amount; | |
188 | amount = 0; | |
189 | } | |
190 | ||
191 | // next, check for contribution amount price sets | |
192 | check_price_set('.contribution_amount-content input[type="radio"]'); | |
193 | ||
194 | // next, check for membership level price set | |
195 | check_price_set('.membership_amount-content input[type="radio"]'); | |
196 | ||
197 | // make sure amount is a number at this point | |
198 | if(!amount) amount = 0; | |
199 | ||
200 | // account for is_separate_payment | |
201 | if(is_separate_payment && additional_amount) { | |
202 | amount += additional_amount; | |
203 | } | |
204 | ||
205 | return amount; | |
206 | } | |
207 | ||
208 | // update premiums | |
209 | function update_premiums() { | |
210 | var amount = get_amount(); | |
211 | ||
212 | cj('.premium').each(function(){ | |
213 | var min_contribution = cj(this).attr('min_contribution'); | |
214 | if(amount < min_contribution) { | |
215 | cj(this).addClass('premium-disabled'); | |
216 | } else { | |
217 | cj(this).removeClass('premium-disabled'); | |
218 | } | |
219 | }); | |
220 | } | |
221 | cj('.other_amount-content input').change(update_premiums); | |
222 | cj('.contribution_amount-content input[type="radio"]').click(update_premiums); | |
223 | cj('.membership_amount-content input[type="radio"]').click(update_premiums); | |
224 | update_premiums(); | |
225 | ||
226 | // build a list of price sets | |
227 | var amounts = []; | |
228 | var price_sets = {}; | |
229 | cj('#priceset input[type="radio"]').each(function(){ | |
230 | var amount = Number(cj(this).attr('data-amount')); | |
231 | if(!isNaN(amount)) { | |
232 | amounts.push(amount); | |
233 | ||
234 | var id = cj(this).attr('id'); | |
235 | price_sets[amount] = '#'+id; | |
236 | } | |
237 | }); | |
238 | amounts.sort(function(a,b){return a - b}); | |
239 | ||
240 | // make contribution instead buttons work | |
241 | cj('.premium-full-disabled input').click(function(){ | |
242 | var amount = Number(cj(this).attr('amount')); | |
243 | if(price_sets[amount]) { | |
244 | cj(price_sets[amount]).click(); | |
245 | } else { | |
246 | // is there an other amount input box? | |
247 | if(cj('.other_amount-section input').length) { | |
248 | // is this a membership form with separate payment? | |
249 | if(is_separate_payment) { | |
250 | var current_amount = 0; | |
251 | if(cj('#priceset input[type="radio"]:checked').length) { | |
252 | current_amount = Number(cj('#priceset input[type="radio"]:checked').attr('data-amount')); | |
253 | if(!current_amount) current_amount = 0; | |
254 | } | |
255 | var new_amount = amount - current_amount; | |
256 | cj('.other_amount-section input').val(new_amount.toFixed(2)); | |
257 | } else { | |
258 | cj('.other_amount-section input').click(); | |
259 | cj('.other_amount-section input').val(cj(this).attr('amount')); | |
260 | } | |
261 | } else { | |
262 | // find the next best price set | |
263 | var selected_price_set = false; | |
264 | for(var i in amounts) { | |
265 | if(amounts[i] >= amount) { | |
266 | selected_price_set = amounts[i]; | |
267 | break; | |
268 | } | |
269 | } | |
270 | if(!selected_price_set) { | |
271 | selected_price_set = amounts[amounts.length-1]; | |
272 | } | |
273 | cj(price_sets[selected_price_set]).click(); | |
274 | } | |
275 | } | |
276 | update_premiums(); | |
277 | }); | |
278 | ||
279 | // validation of premiums | |
280 | var error_message = '{/literal}{ts escape="js"}You must contribute more to get that item{/ts}{literal}'; | |
281 | cj.validator.addMethod('premiums', function(value, element, params){ | |
282 | var premium_id = cj('#selectProduct').val(); | |
283 | var premium$ = cj('#premium_id-'+premium_id); | |
284 | if(premium$.length) { | |
285 | if(premium$.hasClass('premium-disabled')) { | |
286 | return false; | |
287 | } | |
288 | } | |
289 | return true; | |
290 | }, error_message); | |
291 | ||
292 | // add validation rules | |
293 | CRM.validate.functions.push(function(){ | |
294 | cj('#selectProduct').rules('add', 'premiums'); | |
295 | }); | |
296 | ||
297 | // need to use jquery validate's ignore option, so that it will not ignore hidden fields | |
298 | CRM.validate.params['ignore'] = '.ignore'; | |
299 | }); | |
300 | </script> | |
301 | {/literal} | |
302 | ||
303 | {else} | |
304 | {literal} | |
305 | <script> | |
306 | cj(function(){ | |
307 | cj('.premium-short').hide(); | |
308 | cj('.premium-full').show(); | |
309 | }); | |
310 | </script> | |
311 | {/literal} | |
312 | {/if} | |
313 | {/if} | |
314 |