commiting uncommited changes on live site
[weblabels.fsf.org.git] / crm.fsf.org / 20131203 / files / sites / all / modules-old / civicrm / templates / CRM / Price / Form / ParticipantCount.tpl
1 {*
2 +--------------------------------------------------------------------+
3 | CiviCRM version 4.6 |
4 +--------------------------------------------------------------------+
5 | Copyright CiviCRM LLC (c) 2004-2015 |
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
27 {if $priceSet && $allowGroupOnWaitlist}
28 {literal}
29 <script type="text/javascript">
30 var isAdditionalParticipants = false;
31 var pPartiCount = 0;
32 var pPartiRef = Array( );
33 var optionSep = '|';
34
35 CRM.$(function($) {
36 pricesetParticipantCount( );
37 allowGroupOnWaitlist(0, pPartiCount);
38 });
39
40 function pricesetParticipantCount( ) {
41
42 cj("input,#priceset select,#priceset").each(function () {
43
44 if ( cj(this).attr('price') ) {
45 switch( cj(this).attr('type') ) {
46 case 'checkbox':
47 eval( 'var option = ' + cj(this).attr('price') ) ;
48 ele = option[0];
49 optionPart = option[1].split(optionSep);
50 var addCount = 0;
51
52 if ( optionPart[1] ) {
53 addCount = parseInt(optionPart[1]);
54 }
55
56 if( cj(this).prop('checked') ) {
57 pPartiCount += addCount;
58 pPartiRef[ele] += addCount;
59 }
60
61 cj(this).click( function(){
62 if( cj(this).prop('checked') ) {
63 pPartiCount += addCount;
64 pPartiRef[ele] += addCount;
65 } else {
66 pPartiCount -= addCount;
67 pPartiRef[ele] -= addCount;
68 }
69 updateWaitingStatus( pPartiCount );
70 });
71 break;
72
73 case 'radio':
74 //default calcution of element.
75 eval( 'var option = ' + cj(this).attr('price') );
76 ele = option[0];
77 optionPart = option[1].split(optionSep);
78 var addCount = 0;
79
80 if ( optionPart[1] ) {
81 addCount = parseInt(optionPart[1]);
82 }
83 if ( ! pPartiRef[ele] ) {
84 pPartiRef[ele] = 0;
85 }
86
87 if( cj(this).prop('checked') ) {
88 pPartiCount = parseInt(pPartiCount) + addCount - parseInt(pPartiRef[ele]);
89 pPartiRef[ele] = addCount;
90 }
91
92 cj(this).click( function(){
93 pPartiCount = parseInt(pPartiCount) + addCount - parseInt(pPartiRef[ele]);
94 pPartiRef[ele] = addCount;
95 updateWaitingStatus( pPartiCount );
96 })
97
98 break;
99
100 case 'text':
101 // default calcution of element.
102 var textval = parseFloat( cj(this).val() );
103 var addCount = 0;
104 if ( textval ) {
105 eval( 'var option = '+ cj(this).attr('price') );
106 ele = option[0];
107 if ( ! pPartiRef[ele] ) {
108 pPartiRef[ele] = 0;
109 }
110 optionPart = option[1].split(optionSep);
111 if ( optionPart[1] ) {
112 addCount = parseInt( optionPart[1] );
113 var curval = textval * addCount;
114 if ( textval >= 0 ) {
115 pPartiCount = parseInt(pPartiCount) + curval - parseInt(pPartiRef[ele]);
116 pPartiRef[ele] = curval;
117 }
118 }
119 }
120
121 //event driven calculation of element.
122 cj(this).bind( 'keyup', function() { calculateTextCount( this );
123 }).bind( 'blur' , function() { calculateTextCount( this );
124 });
125
126 break;
127
128 case 'select-one':
129
130 //default calcution of element.
131 var ele = cj(this).attr('id');
132 if ( ! pPartiRef[ele] ) {
133 pPartiRef[ele] = 0;
134 }
135 var addcount = 0;
136 eval( 'var selectedText = ' + cj(this).attr('price') );
137 if ( cj(this).val( ) ) {
138 optionPart = selectedText[cj(this).val( )].split(optionSep);
139 if ( optionPart[1] ) {
140 addcount = parseInt( optionPart[1] );
141 }
142 }
143
144 if ( addcount ) {
145 pPartiCount = parseInt(pPartiCount) + addcount - parseInt(pPartiRef[ele]);
146 pPartiRef[ele] = addcount;
147 }
148
149 //event driven calculation of element.
150 cj(this).change( function() {
151 var ele = cj(this).attr('id');
152 if ( ! pPartiRef[ele] ) {
153 pPartiRef[ele] = 0;
154 }
155 eval( 'var selectedText = ' + cj(this).attr('price') );
156 var addcount = 0;
157
158 if ( cj(this).val( ) ) {
159 var optionPart = selectedText[cj(this).val( )].split(optionSep);
160 if ( optionPart[1] ) {
161 addcount = parseInt( optionPart[1] );
162 }
163 }
164
165 if ( addcount ) {
166 pPartiCount = parseInt(pPartiCount) + addcount - parseInt(pPartiRef[ele]);
167 pPartiRef[ele] = addcount;
168 } else {
169 pPartiCount = parseInt(pPartiCount) - parseInt(pPartiRef[ele]);
170 pPartiRef[ele] = 0;
171 }
172 updateWaitingStatus( pPartiCount );
173 });
174 break;
175 }
176 }
177 });
178 }
179
180 function calculateTextCount( object ) {
181 eval( 'var option = ' + cj(object).attr('price') );
182 ele = option[0];
183 if ( ! pPartiRef[ele] ) {
184 pPartiRef[ele] = 0;
185 }
186 var optionPart = option[1].split(optionSep);
187 if ( optionPart[1] ) {
188 addCount = parseInt( optionPart[1] );
189 var textval = parseInt( cj(object).attr('value') );
190 var curval = textval * addCount;
191 if ( textval >= 0 ) {
192 pPartiCount = pPartiCount + curval - parseInt(pPartiRef[ele]);
193 pPartiRef[ele] = curval;
194 } else {
195 pPartiCount = pPartiCount - parseInt(pPartiRef[ele]);
196 pPartiRef[ele] = 0;
197 }
198 updateWaitingStatus( pPartiCount );
199 }
200 }
201
202 function updateWaitingStatus( pricesetParticipantCount ) {
203 allowGroupOnWaitlist( 0, pricesetParticipantCount );
204 }
205 </script>
206 {/literal}
207 {/if}