Refactor "make batch from products query" per Vue.js theme

This commit is contained in:
Lance Edgar 2019-10-31 00:51:22 -05:00
parent 4a35c231f8
commit 847136b69c
2 changed files with 143 additions and 39 deletions

View file

@ -1,5 +1,5 @@
## -*- coding: utf-8; -*- ## -*- coding: utf-8; -*-
<%inherit file="/base.mako" /> <%inherit file="/form.mako" />
<%def name="title()">Create Batch</%def> <%def name="title()">Create Batch</%def>
@ -9,6 +9,7 @@
<%def name="extra_javascript()"> <%def name="extra_javascript()">
${parent.extra_javascript()} ${parent.extra_javascript()}
% if not use_buefy:
<script type="text/javascript"> <script type="text/javascript">
$(function() { $(function() {
@ -21,58 +22,159 @@
}); });
</script> </script>
% endif
</%def> </%def>
<%def name="extra_styles()"> <%def name="extra_styles()">
${parent.extra_styles()} ${parent.extra_styles()}
% if not use_buefy:
<style type="text/css"> <style type="text/css">
.params-wrapper { .params-wrapper {
display: none; display: none;
} }
</style> </style>
% endif
</%def> </%def>
<%def name="render_deform_field(field)"> <%def name="render_deform_field(form, field)">
<div class="field-wrapper ${field.name}"> % if use_buefy:
<div class="field-row"> <b-field horizontal
<label for="${field.oid}">${field.title}</label> % if field.error:
<div class="field"> type="is-danger"
${field.serialize()|n} :message='${form.messages_json(field.error.messages())|n}'
</div> % endif
</div> label="${field.title}">
</div> ${field.serialize(use_buefy=True)|n}
</%def> </b-field>
% else:
<div class="field-wrapper ${field.name}">
<div style="display: flex; justify-content: space-between;"> <div class="field-row">
<label for="${field.oid}">${field.title}</label>
<div class="form"> <div class="field">
${h.form(request.current_route_url(), class_='autodisable')} ${field.serialize()|n}
${h.csrf_token(request)} </div>
${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}">
## TODO: hacky to use deform? at least is explicit..
% for field in pform.make_deform_form():
${render_deform_field(field)}
% endfor
</div> </div>
</div>
% endif
</%def>
<%def name="render_form_innards()">
% if use_buefy:
${h.form(request.current_route_url(), **{'@submit': 'submit{}'.format(form.component_studly)})}
% else:
${h.form(request.current_route_url(), class_='autodisable')}
% endif
${h.csrf_token(request)}
<section>
${render_deform_field(form, dform['batch_type'])}
${render_deform_field(form, dform['description'])}
${render_deform_field(form, dform['notes'])}
% for key, pform in six.iteritems(params_forms):
% if use_buefy:
<div v-show="field_model_batch_type == '${key}'">
% for field in pform.make_deform_form():
${render_deform_field(pform, field)}
% endfor
</div>
% else:
<div class="params-wrapper ${key}">
## TODO: hacky to use deform? at least is explicit..
% for field in pform.make_deform_form():
${render_deform_field(pform, field)}
% endfor
</div>
% endif
% endfor % endfor
</section>
<div class="buttons"> <br />
${h.submit('make-batch', "Create Batch")} <div class="buttons">
${h.link_to("Cancel", url('products'), class_='button')} % if use_buefy:
</div> <b-button type="is-primary"
native-type="submit"
${h.end_form()} :disabled="${form.component_studly}Submitting">
{{ ${form.component_studly}ButtonText }}
</b-button>
<b-button tag="a" href="${url('products')}">
Cancel
</b-button>
% else:
${h.submit('make-batch', "Create Batch")}
${h.link_to("Cancel", url('products'), class_='button')}
% endif
</div> </div>
<ul id="context-menu"> ${h.end_form()}
${self.context_menu_items()} </%def>
</ul>
</div> <%def name="render_form()">
% if use_buefy:
<script type="text/x-template" id="${form.component}-template">
${self.render_form_innards()}
</script>
% else:
<div class="form">
${self.render_form_innards()}
</div>
% endif
</%def>
<%def name="modify_this_page_vars()">
${parent.modify_this_page_vars()}
<script type="text/javascript">
## TODO: ugh, an awful lot of duplicated code here (from /forms/deform_buefy.mako)
let ${form.component_studly} = {
template: '#${form.component}-template',
methods: {
## TODO: deprecate / remove the latter option here
% if form.auto_disable_save or form.auto_disable:
submit${form.component_studly}() {
this.${form.component_studly}Submitting = true
this.${form.component_studly}ButtonText = "Working, please wait..."
}
% endif
}
}
let ${form.component_studly}Data = {
## TODO: ugh, this seems pretty hacky. need to declare some data models
## for various field components to bind to...
% if not form.readonly:
% for field in form.fields:
% if field in dform:
<% field = dform[field] %>
field_model_${field.name}: ${form.get_vuejs_model_value(field)|n},
% endif
% endfor
% endif
## TODO: deprecate / remove the latter option here
% if form.auto_disable_save or form.auto_disable:
${form.component_studly}Submitting: false,
${form.component_studly}ButtonText: ${json.dumps(getattr(form, 'submit_label', getattr(form, 'save_label', "Submit")))|n},
% endif
## TODO: more hackiness, this is for the sake of batch params
## (this of course was *not* copied from normal deform template!)
% for key, pform in params_forms.items():
<% pdform = pform.make_deform_form() %>
% for field in pform.fields:
% if field in pdform:
<% field = pdform[field] %>
field_model_${field.name}: ${pform.get_vuejs_model_value(field)|n},
% endif
% endfor
% endfor
}
</script>
</%def>
${parent.body()}

View file

@ -1051,6 +1051,8 @@ class ProductsView(MasterView):
form = forms.Form(schema=schema, request=self.request, form = forms.Form(schema=schema, request=self.request,
cancel_url=self.get_index_url()) cancel_url=self.get_index_url())
form.auto_disable_save = True
form.submit_label = "Create Batch"
form.set_type('notes', 'text') form.set_type('notes', 'text')
params_forms = {} params_forms = {}