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

Full commit
{% 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');
               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.created.substr(0,4) + "<br/>" +
                       "&nbsp;&nbsp; Post code: " + escape(place.post_code) + "<br/>" +
                       "&nbsp;&nbsp; GP: " + escape(place.gp_name) + "</label><br/>" );

       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');

           var btn2 = $('#id_use_account_2_btn');


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

       var useExistingDataClose = function(ev) {

       var address_attrs = [

       var gp_info_attrs = [

       var all_attrs = [].concat(address_attrs, gp_info_attrs, [

       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 {
                           mainform[attr].value = place[attr];
                       // If details are copied from something saved,
                       // value is guaranteed to be good. So we clear
                       // errors.
           if (chosen === null) {
               alert('Please select a set of details on the left');
           } else {

       var useAllBtnClick = function(ev) {

       var useAddressBtnClick = function(ev) {

       var useGPInfoBtnClick = function(ev) {

       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;

               // 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.


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

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


       // 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) {


       /* Load data about existing places */
           type: "GET",
           url: '{% url "cciw.bookings.views.places_json" %}?exclude={{ }}',
           dataType: "json",
           success: handleExistingPlacesData

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

{% endif %}


<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 }}
{% 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 %}
     <p>Details for <b>{{ }}</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 %}

{% cciw_form_field form 'camp' 'Choose camp:' %}

<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

<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 'name' 'Name' %}
{% cciw_form_field form 'sex' 'Sex' %}
{% cciw_form_field form 'date_of_birth' 'Date of birth (YYYY-MM-DD)' %}
{% 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' %}


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


<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' %}

<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) (YYYY-MM-DD)' %}
{% 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' %}


<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 %}


<p>All done! now just:

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

{% endif %}


<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 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>

<th>Select previous booking to copy from</th>
<th>Choose which information to copy</th>
  <div style="max-height: 20em; overflow: auto;";>
    <form name="select_place">
    <div id="id_use_existing_radio_container">
<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" />


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

<div style="display:nonex;">

{% endif %}
{% endblock %}