cciw-website2 / templates / admin / bookings / booking / change_form.html

{% extends "admin/change_form.html" %}
{% load url from future %}
{% block after_related_objects %}
{# Some javascript enhancements  #}
<div>
<h2>Problems and warnings:</h2>
<p>Please check the following list of problems and warnings before saving. They
include problems that normally will stop a booking from being automatically
approved, like the camp being out of space, or a custom discount being applied
for, and warnings due to likely errors, like booking the same place twice.</p>

<p>The booking secretary has the right to ignore these problems, after
 checking with the camp leader where necessary.</p>

<div class="bookingProblems" id="id_problems">

</div>
</div>
<script type="text/javascript">
$(document).ready(function() {
    $('#id_address').parent().append('<input type="submit" value="Copy address details from account"' +
                                     'id="id_use_account_for_camper">');
    $('#id_contact_name').parent().append('<input type="submit" value="Copy contact details from account"' +
                                     'id="id_use_account_for_contact">');


    var getCurrentAccountId = function() {
        var val = $('#id_hidden_account').val();
        val = parseInt(val, 10);
        // NaN madness
        if (val == val) {
            return val;
        } else {
            return undefined;
        }
    }

    $('#id_use_account_for_camper').click(function(ev) {
        ev.preventDefault();
        var accId = getCurrentAccountId();
        if (accId == undefined) return;
        $.ajax({
            type: "GET",
            url: '{% url "cciw.bookings.views.all_account_json" %}?id=' + accId.toString(),
            dataType: "json",
            success: function(json) {
                $('#id_address').val(json.account.address);
                $('#id_post_code').val(json.account.post_code);
                $('#id_phone_number').val(json.account.phone_number);
            }
        })
    });

    $('#id_use_account_for_contact').click(function(ev) {
        ev.preventDefault();
        var accId = getCurrentAccountId();
        if (accId == undefined) return;
        $.ajax({
            type: "GET",
            url: '{% url "cciw.bookings.views.all_account_json" %}?id=' + accId.toString(),
            dataType: "json",
            success: function(json) {
                $('#id_contact_name').val(json.account.name);
                $('#id_contact_phone_number').val(json.account.phone_number);
            }
        })
    });

    var getBookingProblems = function() {
        var formData = $('#booking_form').serialize();
{% if change %}
        formData = formData + "&booking_id={{ object_id }}";
{% endif %}
        $.ajax({
            type: "POST",
            url: '{% url "cciw.bookings.views.booking_problems_json" %}',
            dataType: "json",
            data: formData,
            success: function(json) {
                if (json.valid) {
                    if (json.problems.length == 0) {
                        $('#id_problems').html('<p>No problems found</p>');
                    } else {
                        $('#id_problems').html('<ul></ul>');
                        $.each(json.problems, function(idx, val) {
                            var html = $('<li></li>').text(val);
                            $('#id_problems ul').append(html);
                        });
                    }
                } else {
                    $('#id_problems').html('<i>Form has validation errors, ' +
                        'please correct first. You can see validation errors ' +
                        'by pressing "Save"</i>');
                }
            }});
    }


    $('div.field-camp').append('<div id="place-availability">');

    var getPlaceAvailability = function() {
        var campId = $('#id_camp').val();
        if (campId == undefined || campId == "") {
            $('#place-availability').html('');
        }
        $.ajax({
            type: "GET",
            url: '{% url "cciw.bookings.views.place_availability_json" %}?camp_id=' + campId,
            dataType: "json",
            success: function(json) {
                if (json.status == 'success') {
                    var html = ('Places available: total=' + json.result.total.toString() +
                                ', male=' + json.result.male.toString() +
                                ', female=' + json.result.female.toString())
                    $('#place-availability').html(html);
                }
            }
        })
    };

    $('#id_amount_due').after('<input type="submit" id="id_amount_due_auto" value="">');
    $('#id_amount_due_auto').hide();

    var getExpectedAmountDue = function() {
        $.ajax({
            type: "POST",
            url: '{% url "cciw.bookings.views.get_expected_amount_due" %}',
            data: $('#booking_form').serialize(),
            dataType: "json",
            success: function(json) {
                if (json.status == 'success') {
                    if (json.amount == null) {
                        $('#id_amount_due_auto').hide();
                    } else {
                        $('#id_amount_due_auto').show().val('Set to £' + json.amount.toString());
                        $('#id_amount_due_auto').click(function(ev) {
                            ev.preventDefault();
                            $('#id_amount_due').val(json.amount.toString());
                        });
                    }
                }
            }
        });
    };

    getBookingProblems();
    $('input,select,textarea').change(getBookingProblems);

    getPlaceAvailability();
    $('#id_camp').change(getPlaceAvailability);

    getExpectedAmountDue();
    $('#id_south_wales_transport,#id_price_type,#id_camp').change(getExpectedAmountDue);

});
</script>
{% endblock %}
Tip: Filter by directory path e.g. /media app.js to search for public/media/app.js.
Tip: Use camelCasing e.g. ProjME to search for ProjectModifiedEvent.java.
Tip: Filter by extension type e.g. /repo .js to search for all .js files in the /repo directory.
Tip: Separate your search with spaces e.g. /ssh pom.xml to search for src/ssh/pom.xml.
Tip: Use ↑ and ↓ arrow keys to navigate and return to view the file.
Tip: You can also navigate files with Ctrl+j (next) and Ctrl+k (previous) and view the file with Ctrl+o.
Tip: You can also navigate files with Alt+j (next) and Alt+k (previous) and view the file with Alt+o.