Refactor forms logic when making batch from product query

use colander/deform instead of wtforms.  also make sure param names are unique
per batch type, within form controls
This commit is contained in:
Lance Edgar 2018-01-04 15:08:03 -06:00
parent 2cc0bb1995
commit 80903bde38
2 changed files with 87 additions and 64 deletions

View file

@ -1,4 +1,4 @@
## -*- coding: utf-8 -*-
## -*- coding: utf-8; -*-
<%inherit file="/base.mako" />
<%def name="title()">Products: Create Batch</%def>
@ -12,19 +12,12 @@
<script type="text/javascript">
$(function() {
$('#batch_type').selectmenu({
change: function(event, ui) {
$('.params-wrapper').hide();
$('.params-wrapper.' + ui.item.value).show();
}
$('select[name="batch_type"]').on('selectmenuchange', function(event, ui) {
$('.params-wrapper').hide();
$('.params-wrapper.' + ui.item.value).show();
});
$('.params-wrapper.' + $('#batch_type').val()).show();
$('#make-batch').click(function() {
$(this).button('disable').button('option', 'label', "Working, please wait...");
$(this).parents('form:first').submit();
});
$('.params-wrapper.' + $('select[name="batch_type"]').val()).show();
});
</script>
@ -39,26 +32,41 @@
</style>
</%def>
<%def name="render_deform_field(field)">
<div class="field-wrapper ${field.name}">
<div class="field-row">
<label for="${field.oid}">${field.title}</label>
<div class="field">
${field.serialize()|n}
</div>
</div>
</div>
</%def>
<ul id="context-menu">
${self.context_menu_items()}
</ul>
<div class="form">
${h.form(request.current_route_url())}
${h.form(request.current_route_url(), class_='autodisable')}
${h.csrf_token(request)}
${self.wtfield(form, 'batch_type')}
${render_deform_field(dform['batch_type'])}
${render_deform_field(dform['description'])}
${render_deform_field(dform['notes'])}
% for key, pform in params_forms.items():
<div class="params-wrapper ${key}">
% for name in pform._fields:
${self.wtfield(pform, name)}
## TODO: hacky to use deform? at least is explicit..
% for field in pform.make_deform_form():
${render_deform_field(field)}
% endfor
</div>
% endfor
<div class="buttons">
<button type="button" id="make-batch">Create Batch</button>
${h.submit('make-batch', "Create Batch")}
${h.link_to("Cancel", url('products'), class_='button')}
</div>