Source

cciw-website / templates / cciw / bookings / add_place.html

Full commit
  1
  2
  3
  4
  5
  6
  7
  8
  9
 10
 11
 12
 13
 14
 15
 16
 17
 18
 19
 20
 21
 22
 23
 24
 25
 26
 27
 28
 29
 30
 31
 32
 33
 34
 35
 36
 37
 38
 39
 40
 41
 42
 43
 44
 45
 46
 47
 48
 49
 50
 51
 52
 53
 54
 55
 56
 57
 58
 59
 60
 61
 62
 63
 64
 65
 66
 67
 68
 69
 70
 71
 72
 73
 74
 75
 76
 77
 78
 79
 80
 81
 82
 83
 84
 85
 86
 87
 88
 89
 90
 91
 92
 93
 94
 95
 96
 97
 98
 99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
156
157
158
159
160
161
162
163
164
165
166
167
168
169
170
171
172
173
174
175
176
177
178
179
180
181
182
183
184
185
186
187
188
189
190
191
192
193
194
195
196
197
198
199
200
201
202
203
204
205
206
207
208
209
210
211
212
213
214
215
216
217
218
219
220
221
222
223
224
225
226
227
228
229
230
231
232
233
234
235
236
237
238
239
240
241
242
243
244
245
246
247
248
249
250
251
252
253
254
255
256
257
258
259
260
261
262
263
264
265
266
267
268
269
270
271
272
273
274
275
276
277
278
279
280
281
282
283
284
285
286
287
288
289
290
291
292
293
294
295
296
297
298
299
300
301
302
303
304
305
306
307
308
309
310
311
312
313
314
315
316
317
318
319
320
321
322
323
324
325
326
327
328
329
330
331
332
333
334
335
336
337
338
339
340
341
342
343
344
345
346
347
348
349
350
351
352
353
354
355
356
357
358
359
360
361
362
363
364
365
366
367
368
369
370
371
372
373
374
375
376
377
378
379
380
381
382
383
384
385
386
387
388
389
390
391
392
393
394
395
396
397
398
399
400
401
402
403
404
405
406
407
408
409
410
411
{% extends 'cciw/bookings/standard.html' %}
{% load cciwform %}
{% load url from future %}
{% block content %}
{% if not booking_open %}

<p>Booking for {{ thisyear }} cannot continue because prices have not been set.</p>

{% else %}

<script type="text/javascript">
<!--

(function($) {

   $(document).ready(function() {

{% if read_only %}
       $('input,select,textarea').attr('disabled', 'disabled');

{% else %}

       var userData = [];

       var escape = function(t) {
           return t.replace(/&/g, "&amp;").replace(/</g, "&lt;").replace(/>/g, "&gt;").replace(/"/g, "&quot;").replace(/'/g, "&apos;");
       };

       var handleExistingPlacesData = function(json) {
           var places = json['places'];
           userData['places'] = places;
           if (places.length > 0) {
               var cont = $('#id_use_existing_radio_container');
               $('#id_use_existing_btn').show();
               for (var i=0; i < places.length; i++) {
                   var place = places[i];
                   var html = ("<label><input type='radio' name='use_which_booking' value='" +
                       i.toString() + "'>" + escape(place.first_name + " " + place.last_name)
                       + " " + place.created.substr(0,4) + "<br/>" +
                       "&nbsp;&nbsp; Post code: " + escape(place.post_code) + "<br/>" +
                       "&nbsp;&nbsp; GP: " + escape(place.gp_name) + "</label><br/>" );
                   cont.append(html);
               }
               var btn = $('#id_use_existing_radio_container input');
               if (btn.length == 1) {
                   btn.attr('checked', 'checked');
               }
           }
       };

       var handleAccountData = function(json) {
           var account = json['account'];
           userData['account'] = account;
           /* Easiest way to get them where we want is to move it using javascript */
           var btn1 = $('#id_use_account_1_btn');
           btn1.prependTo(btn1.prev('div.form').find('div.formrow'));
           btn1.css({'float':'right'}).show();

           var btn2 = $('#id_use_account_2_btn');
           btn2.prependTo(btn2.prev('div.form').find('div.formrow'));
           btn2.css({'float':'right'}).show();

       }

       var useExistingDataShow = function(ev) {
           ev.preventDefault();
           var popup = $('#id_use_existing_data_popup');
           popup.css({
               "position": "fixed",
               "top": ($(window).height()/2 - popup.height()/2).toString() + "px",
               "left": ($(window).width()/2 - popup.width()/2).toString() + "px"
            });
            popup.fadeIn("fast");
            $('#id_popup_background').fadeIn('fast');
       };

       var useExistingDataClose = function(ev) {
           $('#id_use_existing_data_popup').fadeOut('fast');
           $('#id_popup_background').fadeOut('fast');
       };

       var address_attrs = [
           'address',
           'post_code',
           'phone_number',
           'contact_name',
           'contact_phone_number'
       ];

       var gp_info_attrs = [
           'gp_name',
           'gp_address',
           'gp_phone_number'
       ];

       var all_attrs = [].concat(address_attrs, gp_info_attrs, [
           'first_name',
           'last_name',
           'sex',
           'date_of_birth',
           'church',
           'south_wales_transport',
           'dietary_requirements',
           'medical_card_number',
           'last_tetanus_injection',
           'allergies',
           'regular_medication_required',
           'learning_difficulties',
           'serious_illness'
       ]);

       var useData = function(attrs) {
           var radios = $('input[name=use_which_booking]');
           var chosen = null;
           for (var i=0; i < radios.length; i++) {
               if (radios[i].checked) {
                   chosen = parseInt(radios[i].value, 10);
                   place = userData['places'][chosen];
                   var mainform = document.addplaceform;
                   for (var j=0; j < attrs.length; j++) {
                       var attr = attrs[j];
                       if (mainform[attr].type == 'checkbox') {
                           mainform[attr].checked = place[attr];
                       } else {
                           if (place[attr] == null) {
                               place[attr] = "";
                           }
                           mainform[attr].value = place[attr];
                       }
                       // If details are copied from something saved,
                       // value is guaranteed to be good. So we clear
                       // errors.
                       cciw.standardformClearError(mainform[attr].id)
                   }
               }
           }
           if (chosen === null) {
               alert('Please select a set of details on the left');
           } else {
               useExistingDataClose();
           }
       };

       var useAllBtnClick = function(ev) {
           ev.preventDefault();
           useData(all_attrs);
       };

       var useAddressBtnClick = function(ev) {
           ev.preventDefault();
           useData(address_attrs);
       };

       var useGPInfoBtnClick = function(ev) {
           ev.preventDefault();
           useData(gp_info_attrs);
       };

       var useAccountData = function(nameList, prefix) {
           // exploit the fact that we've named things nicely.
           $.each(nameList, function(idx, val) {
               var control_id = '#id_' + prefix + val;
               $(control_id).val(userData['account'][val]);

               // Data is not quite guaranteed to be good in this case
               // (e.g. Booking.contact_phone_number is required, but
               // BookingAccount.phone_number is not), so we trigger AJAX
               // validation. With fewer fields than for copying place data,
               // this is only a few AJAX calls.

               $(control_id).change();
           });
       };

       var useAccountForCamperAddressClick = function(ev) {
           ev.preventDefault();
           useAccountData(['address', 'post_code', 'phone_number'], '');
       };

       var useAccountForContactDetailsClick = function(ev) {
           ev.preventDefault();
           // copy contact_name, contact_phone_number
           useAccountData(['name', 'phone_number'], 'contact_');
       };

       $('#id_popup_close_btn').click(useExistingDataClose);
       $('#id_use_existing_btn').click(useExistingDataShow);
       $('#id_use_all_btn').click(useAllBtnClick);
       $('#id_use_address_btn').click(useAddressBtnClick);
       $('#id_use_gp_info_btn').click(useGPInfoBtnClick);
       $('#id_use_account_1_btn').click(useAccountForCamperAddressClick);
       $('#id_use_account_2_btn').click(useAccountForContactDetailsClick);

       // Typing enter on text boxes shouldn't activate the 'Use existing
       // data' button
       $('#id_addplaceform input[type=text]').keypress(function(ev) {
           var code = (ev.keyCode || e.which);
           if (code == 13) {
               ev.preventDefault();

           }
       });

       /* Load data about existing places */
       $.ajax({
           type: "GET",
           url: '{% url "cciw.bookings.views.places_json" %}?exclude={{ form.instance.id }}',
           dataType: "json",
           success: handleExistingPlacesData
       });

       /* Load account data */
       $.ajax({
           type: "GET",
           url: '{% url "cciw.bookings.views.account_json" %}',
           dataType: "json",
           success: handleAccountData
       });

{% endif %}

   });
})(jQuery);

//-->
</script>
<form action="" method="POST" id="id_addplaceform" name="addplaceform" class="ajaxify">
{% csrf_token %}

{% if form.errors %}
<div class="userError">The details could not be saved - please correct the
  errors flagged below:

{{ form.non_field_errors }}
</div>
{% else %}

  {% if read_only %}
     <p>This place has been approved or booked, and information here
       can only be changed by an admin.</p>

  {% else %}

     {% if form.instance.id %}
     <p>Details for <b>{{ form.instance.name }}</b>:</p>
     {% else %}
     <p>Please enter the details needed to book a place on a camp. Required fields
       are <b>in bold</b>.</p>
     {% endif %}

  {% endif %}


{% endif %}

<h2>Camp</h2>
{% cciw_form_field form 'camp' 'Choose camp:' %}

<h2>Price</h2>
<p>The 2nd child from the same family is eligible for '2nd child discount'.
Subsequent children from the same family are eligible for '3rd child
discount'.</p>

<p>If you will struggle to pay the full fee, you can also apply for a custom
  discount. The exact price will have to be arranged by contacting the booking
  secretary, and you will not be able to complete the booking process online
  until this has been done if you choose this option.</p>

{% cciw_form_field form 'price_type' 'Price' %}

<h2>Camper details</h2>
 <input type="submit" id="id_use_existing_btn" value="Use previous data" style="display:none; float: right;">
{% cciw_form_field form 'first_name' 'First name' %}
{% cciw_form_field form 'last_name' 'Surname' %}
{% cciw_form_field form 'sex' 'Sex' %}
{% cciw_form_field form 'date_of_birth' 'Date of birth' %}
{% cciw_form_field form 'address' 'Address' %} <input style="display:none;" type="submit" id="id_use_account_1_btn" value="Use account address">
{% cciw_form_field form 'post_code' 'Post code' %}
{% cciw_form_field form 'phone_number' 'Phone number' %}
{% cciw_form_field form 'email' 'Email' %}

<h2>Church</h2>

{% cciw_form_field form 'church' 'Name of church (if any)' %}


<h2>Transport</h2>

<p>If you require transport from South Wales on the CCIW minibus, please tick
this box. The cost for this transport is an additional £{{ south_wales_surcharge }}.</p>

{% cciw_form_field form 'south_wales_transport' 'South Wales transport required' %}
<br/><br/>

<h2>Contact details</h2>

<p>Please enter a contact name and number that can be used <strong>during the week of camp</strong> in case of emergency.</p>

{% cciw_form_field form 'contact_name' 'Name' %} <input style="display:none;" type="submit" id="id_use_account_2_btn" value="Use account name and number">
{% cciw_form_field form 'contact_phone_number' 'Phone number' %}

<h2>Dietary requirements</h2>

<p>Please enter any special dietary requirements here (e.g. vegetarian).</p>
{% cciw_form_field form 'dietary_requirements' 'Dietary requirements' %}

<h2>GP details</h2>

<p>Please enter the details of the camper's GP:</p>

{% cciw_form_field form 'gp_name' 'Name' %}
{% cciw_form_field form 'gp_address' 'Address' %}
{% cciw_form_field form 'gp_phone_number' 'Phone number' %}

<h2>Medical details</h2>

{% cciw_form_field form 'medical_card_number' 'Medical card number' %}
{% cciw_form_field form 'last_tetanus_injection' 'Last tetanus injection (if any)' %}
{% cciw_form_field form 'allergies' 'Allergies (including medication)' %}
{% cciw_form_field form 'regular_medication_required' 'Regular medication required' %}
{% cciw_form_field form 'illnesses' 'Illnesses (e.g. asthma, epilepsy)' %}
{% cciw_form_field form 'learning_difficulties' 'Any learning/behavioural difficulties' %}

<p>If the illnesses, allergies or learning/behavioural difficulties above
include conditions that would affect the safety of camp or our ability to look
after the camper, please indicate below.</p>

<p>This includes, for example, significant deafness or blindness, unstabilised
diabetes or epilepsy, life-threatening allergies, or other conditions which
would normally require supervision in school life, such as autism. You do not
need to tick this box for conditions that are easily managed by medication,
where the camper can administer the medication themselves.</p>

<p>If the box is ticked, a camp leader will then have to manually approve this
place before booking and payment can proceed. This system is needed to avoid
disappointment in the case where we will not be able to cater for the camper's
condition on camp.</p>

{% cciw_form_field form 'serious_illness' 'Serious condition/illness' %}

<h2>Agreements</h2>

<h3>Camper agreement</h3>

<p>The camper must agree to observe the camp's code of conduct. Failure to obey
camp rules can result in the camper being sent home, with no refund.</p>

<h3>Parent/guardian agreement</h3>

<p>In the event of any medical treatment becoming necessary during the camp
every effort will be made to contact the parent/guardian. However, parents are
required to authorise the leadership team to act in their absence where urgent
treatment becomes necessary.</p>

<p>If both camper and parent/guardian agree, tick the box to continue:</p>

{% cciw_form_field form 'agreement' 'Agree to above condtions' %}

{% if not read_only %}

<h2>Save</h2>

<p>All done! now just:


<input type="submit" name="submit" value="Save place details" id="id_save_btn" />

{% endif %}

</form>

<div id="id_use_existing_data_popup" class="inlinepopup" style="display:none;">
<div class="closebar">
<a href="#" id="id_popup_close_btn">Close</a>
</div>
<div class="popupbody">
<p>You can copy information previously entered to save time. Please check
 the data after using this to ensure it is all up to date.</p>

<table>
<tr>
<th>Select previous booking to copy from</th>
<th>Choose which information to copy</th>
</tr>
<tr>
<td>
  <div style="max-height: 20em; overflow: auto;";>
    <form name="select_place">
    <div id="id_use_existing_radio_container">
    </div>
    </form>
  </div>
</td>
<td style="vertical-align:top; text-align:center;">
  <input type="submit" id="id_use_all_btn" value="Use all personal information" /> <br/>
  <input type="submit" id="id_use_address_btn" value="Use address and contact information" /> <br/>
  <input type="submit" id="id_use_gp_info_btn" value="Use GP information" />
</td>

</tr>
</table>
</div>
</div>

<div class="inlinepopup_background" id="id_popup_background"></div>

<div style="display:nonex;">
</div>

{% endif %}
{% endblock %}