Skip to content

Commit

Permalink
Merge ece1c9e into a15efd2
Browse files Browse the repository at this point in the history
  • Loading branch information
tony-gaia committed Dec 20, 2016
2 parents a15efd2 + ece1c9e commit 1ad89f6
Show file tree
Hide file tree
Showing 7 changed files with 110 additions and 64 deletions.
Original file line number Diff line number Diff line change
@@ -1,4 +1,38 @@
define(['jQuery', 'handlebars.runtime', 'bootstrap', 'js/handlebars_helpers', 'js/precompiled_handlebars_templates'], function($, Handlebars) {
function _setupDisclaimers(disclaimersSelector, lodgeSelector) {
var $disclaimers = $(disclaimersSelector),
$lodge = $(lodgeSelector),
$form = $lodge.parents('form'),
$buttonClicked;

if($lodge.hasClass('disabled')) {
$lodge.tooltip({});
}

// ensure form only submits when either approve (enterConditions) is enabled or decline is clicked
$(lodgeSelector).click(function() {
$buttonClicked = $(this);
});

$form.submit(function(e) {
if($buttonClicked.is($lodge) && $lodge.hasClass('disabled')) {
e.preventDefault();
}
});

// enable lodge button if the number of checked checkboxes is the same as the number of
// checkboxes in the dislaimer div (which is the parent of the disclaimers selector's elements)
$(disclaimersSelector).change(function(e) {
if($(disclaimersSelector).parent().find(':checked').length === $(disclaimersSelector).length) {
$lodge.removeClass('disabled');
$lodge.tooltip('destroy');
} else {
$lodge.addClass('disabled');
$lodge.tooltip({});
}
});
}

function _layoutItem(item, isRepeat, itemData) {
var itemContainer = $('<div>'),
childrenAnchorPoint;
Expand Down Expand Up @@ -179,12 +213,6 @@ define(['jQuery', 'handlebars.runtime', 'bootstrap', 'js/handlebars_helpers', 'j
$('body').scrollspy({ target: '#sectionList' });
sectionList.affix({ offset: { top: sectionList.offset().top }});
},
setupDisclaimer: function(disclaimersSelector, lodgeSelector) {
$(disclaimersSelector).change(function(e) {
// enable lodge button if the number of checked checkboxes is the same as the number of
// checkboxes in the dislaimer div (which is the parent of the disclaimers selector's elements)
$(lodgeSelector).attr('disabled', $(disclaimersSelector).parent().find(':checked').length !== $(disclaimersSelector).length);
});
}
setupDisclaimer: _setupDisclaimers
};
});
Original file line number Diff line number Diff line change
Expand Up @@ -117,7 +117,9 @@ <h3>Disclaimer</h3>
</div>
<div>
<a data-entry-link="True" class="btn btn-default" href="{% url 'wl_applications:enter_details' %}">Edit Application Details</a>
<button type="submit" id="lodge" class="btn btn-primary pull-right" name="lodge" disabled>
<button type="submit" id="lodge" type="button" name="lodge"
class="btn btn-primary pull-right disabled"
data-title="You must check both dislaimer checkboxes to lodge the application">
{% if is_payment_required %}
Proceed to Payment
{% else %}
Expand Down
Original file line number Diff line number Diff line change
@@ -1,35 +1,35 @@
{% if field.type == 'text' %}
<input class="form-control" type="{{ field.type }}" name="{{ field.name }}" value="{{ field.data }}"></input>
<input class="form-control" type="{{ field.type }}" name="{{ field.name }}" value="{{ field.data }}" {% if field.readonly %}disabled{% endif %}></input>
{% elif field.type == 'text_area' %}
<textarea rows="3" class="form-control" type="{{ field.type }}" name="{{ field.name }}" value="{{ field.data }}"></textarea>
<textarea rows="3" class="form-control" type="{{ field.type }}" name="{{ field.name }}" {% if field.readonly %}disabled{% endif %}>{{ field.data }}</textarea>
{% elif field.type == 'number' %}
<input class="form-control" type="{{ field.type }}" name="{{ field.name }}" value="{{ field.data }}"></input>
<input class="form-control" type="{{ field.type }}" name="{{ field.name }}" value="{{ field.data }}" {% if field.readonly %}disabled{% endif %}></input>
{% elif field.type == 'date' %}
<input id="{{ field.name }}{{ group_index }}_date" class="form-control" name="{{ field.name }}" value="{{ field.data }}"></input>
<input id="{{ field.name }}{{ group_index }}_date" class="form-control" name="{{ field.name }}" value="{{ field.data }}" {% if field.readonly %}disabled{% endif %}></input>
{% elif field.type == 'species' %}
<input name="{{ field.name }}" class="form-control species" autocomplete="off" data-species-type="{{ field.speciesType }}" value="{{ field.data }}"/>
<input name="{{ field.name }}" class="form-control species" autocomplete="off" data-species-type="{{ field.speciesType }}" value="{{ field.data }}" {% if field.readonly %}disabled{% endif %}/>
{% elif field.type == 'label' %}
{% for option in field.options %}
<div>
{% if group_index %}
<input id="{{ option.name }}{{ group_index }}Hidden" name="{{ option.name }}" type="hidden" value="off">
<input id="{{ option.name }}{{ group_index }}Hidden" name="{{ option.name }}" type="hidden" value="off" {% if field.readonly %}disabled{% endif %}>
{% endif %}
<input name="{{ option.name }}" {% if group_index %} id="{{ option.name }}{{ group_index }}" class="extracted-checkbox"{% endif %}
type="checkbox" {% if option.data == 'on' %}checked{% endif %}>
type="checkbox" {% if option.data == 'on' %}checked{% endif %} {% if field.readonly %}disabled{% endif %}>
{{ option.label }}
</div>
{% endfor %}
{% elif field.type == 'radiobuttons' %}
{% for option in field.options %}
<div class="radio">
<label>
<input name="{{ field.name }}" type="radio" value="{{ option.value}}" {% if option.value == field.data %}checked{% endif %}>
<input name="{{ field.name }}" type="radio" value="{{ option.value}}" {% if option.value == field.data %}checked{% endif %} {% if field.readonly %}disabled{% endif %}>
{{ option.label }}
</label>
</div>
{% endfor %}
{% elif field.type == 'select' %}
<select name="{{ field.name}}" class="form-control">
<select name="{{ field.name}}" class="form-control" {% if field.readonly %}disabled{% endif %}>
{% if field.defaultBlank %}
<option disabled {% if not field.data %}selected{% endif %}>Please Choose</option>
{% endif %}
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -54,6 +54,12 @@
</div>
{% endblock %}

{% block messages %}
<div class='hidden'>
{{ block.super }}
</div>
{% endblock %}

{% block intro_title %}
{% if application.licence %}
<h3>Reissue Licence</h3>
Expand Down Expand Up @@ -154,37 +160,35 @@ <h4 class="panel-title">Editable application fields (will appear on licence)</h4
</div>
<div class="panel-body">
{% for item in extracted_fields %}
{% if not item.readonly %}
{% if not item.children %}
<div class="form-group">
<label class="control-label" for="id_{{ item.name }}">{{ item.label }}</label>
{% include 'wl/issue/extracted_field.html' with field=item %}
{% if item.help_text %}
<p class="help-block">{{ item.help_text }}</p>
{% endif %}
</div>
{% else %}
{% if not item.children %}
<div class="form-group">
<label class="control-label" for="id_{{ item.name }}">{{ item.label }}</label>
{% include 'wl/issue/extracted_field.html' with field=item %}
{% if item.help_text %}
<p class="help-block">{{ item.help_text }}</p>
{% endif %}
{% for item_group in item.children %}
<div class="row">
{% with width=item_group|length|derive_col_width %}
{% for child_item in item_group %}
<div class="col-md-{{ width }}">
<div class="form-group">
{% if forloop.parentloop.first %}
<label class="control-label">{{ child_item.label }}</label>
{% endif %}
{% include 'wl/issue/extracted_field.html' with field=child_item group_index=forloop.parentloop.counter %}
</div>
</div>
{% endfor %}
{% endwith %}
</div>
{% endfor %}
</div>
{% else %}
<label class="control-label" for="id_{{ item.name }}">{{ item.label }}</label>
{% if item.help_text %}
<p class="help-block">{{ item.help_text }}</p>
{% endif %}
{% for item_group in item.children %}
<div class="row">
{% with width=item_group|length|derive_col_width %}
{% for child_item in item_group %}
<div class="col-md-{{ width }}">
<div class="form-group">
{% if forloop.parentloop.first %}
<label class="control-label">{{ child_item.label }}</label>
{% endif %}
{% include 'wl/issue/extracted_field.html' with field=child_item group_index=forloop.parentloop.counter %}
</div>
</div>
{% endfor %}
{% endwith %}
</div>
{% endfor %}
{% endif %}
{% endfor %}
</div>
Expand Down
35 changes: 20 additions & 15 deletions wildlifelicensing/apps/applications/views/issue.py
Original file line number Diff line number Diff line change
Expand Up @@ -136,7 +136,8 @@ def post(self, request, *args, **kwargs):
previous_licence.save()

licence.variants.clear()
for index, avl in enumerate(application.variants.through.objects.all().order_by('order')):
for index, avl in enumerate(application.variants.through.objects.filter(application=application).
order_by('order')):
WildlifeLicenceVariantLink.objects.create(licence=licence, variant=avl.variant, order=index)

issue_licence_form.save_m2m()
Expand Down Expand Up @@ -225,22 +226,26 @@ def get(self, request, *args, **kwargs):
issue_licence_form = IssueLicenceForm(request.GET, skip_required=True)
extracted_fields = extract_licence_fields(application.licence_type.application_schema, application.data)

licence = issue_licence_form.save(commit=False)
licence.licence_type = application.licence_type
licence.profile = application.applicant_profile
licence.holder = application.applicant
licence.extracted_fields = update_licence_fields(extracted_fields, request.GET)
if issue_licence_form.is_valid():
licence = issue_licence_form.save(commit=False)
licence.licence_type = application.licence_type
licence.profile = application.applicant_profile
licence.holder = application.applicant
licence.extracted_fields = update_licence_fields(extracted_fields, request.GET)

filename = '%s.pdf' % application.lodgement_number
filename = '%s.pdf' % application.lodgement_number

application.customer_status = 'approved'
application.processing_status = 'issued'
application.licence = licence
application.customer_status = 'approved'
application.processing_status = 'issued'
application.licence = licence

response = HttpResponse(content_type='application/pdf')
response = HttpResponse(content_type='application/pdf')

response.write(create_licence_pdf_bytes(filename, licence, application,
request.build_absolute_uri(reverse('home')),
original_issue_date))
response.write(create_licence_pdf_bytes(filename, licence, application,
request.build_absolute_uri(reverse('home')),
original_issue_date))

return response
else:
return HttpResponse('<script type="text/javascript">window.close()</script>')

return response
6 changes: 6 additions & 0 deletions wildlifelicensing/apps/main/forms.py
Original file line number Diff line number Diff line change
Expand Up @@ -123,6 +123,12 @@ def __init__(self, *args, **kwargs):

self.fields['return_frequency'].initial = return_frequency

def clean(self):
cleaned_data = super(IssueLicenceForm, self).clean()

if cleaned_data.get('end_date') < cleaned_data.get('start_date'):
raise forms.ValidationError('End date must be greater than start date')


class CommunicationsLogEntryForm(forms.ModelForm):
attachment = forms.FileField(required=False)
Expand Down
13 changes: 7 additions & 6 deletions wildlifelicensing/apps/main/pdf.py
Original file line number Diff line number Diff line change
Expand Up @@ -13,8 +13,6 @@
from django.core.files import File
from django.conf import settings

from wildlifelicensing.apps.main.helpers import render_user_name

from ledger.accounts.models import Document

BW_DPAW_HEADER_LOGO = os.path.join(settings.BASE_DIR, 'wildlifelicensing', 'static', 'wl', 'img',
Expand Down Expand Up @@ -240,7 +238,7 @@ def _create_licence(licence_buffer, licence, application, site_url, original_iss
Paragraph('%s %s %s' % (address.locality, address.state, address.postcode), styles['Left']),
Paragraph(address.country.name, styles['Left'])]
delegation.append(Table([[[Paragraph('Licensee:', styles['BoldLeft']), Paragraph('Address', styles['BoldLeft'])],
[Paragraph(render_user_name(application.applicant),
[Paragraph(_format_name(application.applicant, include_first_name=True),
styles['Left'])] + address_paragraphs]],
colWidths=(120, PAGE_WIDTH - (2 * PAGE_MARGIN) - 120),
style=licence_table_style))
Expand Down Expand Up @@ -306,7 +304,8 @@ def _layout_extracted_fields(extracted_fields):
heading_row = []
for child_field in group:
heading_row.append(Paragraph(child_field['label'], styles['BoldLeft']))
table_data.append(heading_row)
if heading_row:
table_data.append(heading_row)

row = []
for child_field in group:
Expand All @@ -323,9 +322,11 @@ def _layout_extracted_fields(extracted_fields):
else:
row.append(Paragraph(child_field['data'], styles['Left']))

table_data.append(row)
if row:
table_data.append(row)

elements.append(Table(table_data, style=TableStyle([('VALIGN', (0, 0), (-1, -1), 'TOP')])))
if table_data:
elements.append(Table(table_data, style=TableStyle([('VALIGN', (0, 0), (-1, -1), 'TOP')])))

return elements

Expand Down

0 comments on commit 1ad89f6

Please sign in to comment.