Add "quick lookup" for mobile Products page
only if enabled, otherwise just shows the normal grid
This commit is contained in:
parent
21740ea2fd
commit
950af8b5e0
|
@ -42,7 +42,7 @@ $(document).on('autocompleteitemselected', function(event, uuid) {
|
|||
var field = $(event.target);
|
||||
if (field.hasClass('quick-row')) {
|
||||
var form = field.parents('form:first');
|
||||
form.find('[name="quick_row_entry"]').val(uuid);
|
||||
form.find('[name="quick_entry"]').val(uuid);
|
||||
form.submit();
|
||||
}
|
||||
});
|
||||
|
@ -151,16 +151,16 @@ $(document).on('keypress', function(event) {
|
|||
});
|
||||
|
||||
|
||||
// handle various keypress events for quick row forms
|
||||
// handle various keypress events for quick entry forms
|
||||
$(document).on('keypress', function(event) {
|
||||
var quick_row = $('.ui-page-active #quick_row_entry');
|
||||
if (quick_row.length) {
|
||||
var quick_entry = $('.ui-page-active #quick_entry');
|
||||
if (quick_entry.length) {
|
||||
|
||||
// if user hits enter with quick row input focused, submit form
|
||||
if (quick_row.is(':focus')) {
|
||||
if (quick_entry.is(':focus')) {
|
||||
if (event.which == 13) { // ENTER
|
||||
if (quick_row.val()) {
|
||||
var form = quick_row.parents('form:first');
|
||||
if (quick_entry.val()) {
|
||||
var form = quick_entry.parents('form:first');
|
||||
form.submit();
|
||||
return false;
|
||||
}
|
||||
|
@ -169,11 +169,11 @@ $(document).on('keypress', function(event) {
|
|||
} else { // quick row input not focused
|
||||
|
||||
// mimic keyboard wedge if we're so instructed
|
||||
if (quick_row.data('wedge')) {
|
||||
if (quick_entry.data('wedge')) {
|
||||
|
||||
if (event.which >= 48 && event.which <= 57) { // numeric (qwerty)
|
||||
if (!event.altKey && !event.ctrlKey && !event.metaKey) {
|
||||
quick_row.val(quick_row.val() + event.key);
|
||||
quick_entry.val(quick_entry.val() + event.key);
|
||||
return false;
|
||||
}
|
||||
|
||||
|
@ -183,8 +183,8 @@ $(document).on('keypress', function(event) {
|
|||
|
||||
} else if (event.which == 13) { // ENTER
|
||||
// submit form when ENTER is received via keyboard "wedge"
|
||||
if (quick_row.val()) {
|
||||
var form = quick_row.parents('form:first');
|
||||
if (quick_entry.val()) {
|
||||
var form = quick_entry.parents('form:first');
|
||||
form.submit();
|
||||
return false;
|
||||
}
|
||||
|
|
|
@ -23,18 +23,18 @@ ${form.render()|n}
|
|||
% endif
|
||||
% endif
|
||||
% if master.mobile_rows_quickable and master.rows_quickable_for(instance):
|
||||
<% placeholder = '' if quick_row_entry_placeholder is Undefined else quick_row_entry_placeholder %>
|
||||
<% placeholder = '' if quick_entry_placeholder is Undefined else quick_entry_placeholder %>
|
||||
${h.form(url('mobile.{}.quick_row'.format(route_prefix), uuid=instance.uuid))}
|
||||
${h.csrf_token(request)}
|
||||
% if quick_row_autocomplete:
|
||||
<div class="field autocomplete quick-row" data-url="${quick_row_autocomplete_url}">
|
||||
${h.hidden('quick_row_entry')}
|
||||
${h.hidden('quick_entry')}
|
||||
${h.text('quick_row_autocomplete_text', placeholder=placeholder, autocomplete='off', data_type='search')}
|
||||
<ul data-role="listview" data-inset="true" data-filter="true" data-input="#quick_row_autocomplete_text"></ul>
|
||||
<button type="button" style="display: none;">Change</button>
|
||||
</div>
|
||||
% else:
|
||||
${h.text('quick_row_entry', placeholder=placeholder, autocomplete='off', **{'data-type': 'search', 'data-url': url('mobile.{}.quick_row'.format(route_prefix), uuid=instance.uuid), 'data-wedge': 'true' if quick_row_keyboard_wedge else 'false'})}
|
||||
${h.text('quick_entry', placeholder=placeholder, autocomplete='off', **{'data-type': 'search', 'data-url': url('mobile.{}.quick_row'.format(route_prefix), uuid=instance.uuid), 'data-wedge': 'true' if quick_row_keyboard_wedge else 'false'})}
|
||||
% endif
|
||||
${h.end_form()}
|
||||
% endif
|
||||
|
|
17
tailbone/templates/mobile/products/index.mako
Normal file
17
tailbone/templates/mobile/products/index.mako
Normal file
|
@ -0,0 +1,17 @@
|
|||
## -*- coding: utf-8; -*-
|
||||
<%inherit file="/mobile/master/index.mako" />
|
||||
|
||||
% if master.mobile_creatable and request.has_perm('{}.create'.format(permission_prefix)):
|
||||
${h.link_to("New {}".format(model_title), url('mobile.{}.create'.format(route_prefix)), class_='ui-btn ui-corner-all')}
|
||||
% endif
|
||||
|
||||
% if quick_lookup:
|
||||
|
||||
${h.form(url('mobile.{}.quick_lookup'.format(route_prefix)))}
|
||||
${h.csrf_token(request)}
|
||||
${h.text('quick_entry', placeholder=placeholder, autocomplete='off', **{'data-type': 'search', 'data-url': url('mobile.{}.quick_lookup'.format(route_prefix)), 'data-wedge': 'true' if quick_lookup_keyboard_wedge else 'false'})}
|
||||
${h.end_form()}
|
||||
|
||||
% else: ## not quick_only
|
||||
${grid.render_complete()|n}
|
||||
% endif
|
|
@ -152,7 +152,7 @@ class BatchMasterView(MasterView):
|
|||
if self.mobile_rows_creatable:
|
||||
kwargs.setdefault('add_item_title', "Add Item")
|
||||
if self.mobile_rows_quickable:
|
||||
kwargs.setdefault('quick_row_entry_placeholder', "Enter {}".format(
|
||||
kwargs.setdefault('quick_entry_placeholder', "Enter {}".format(
|
||||
self.rattail_config.product_key_title()))
|
||||
if kwargs['execute_enabled']:
|
||||
url = self.get_action_url('execute', batch)
|
||||
|
|
|
@ -1151,7 +1151,7 @@ class MasterView(View):
|
|||
|
||||
def make_quick_row_form_schema(self, mobile=False):
|
||||
schema = colander.MappingSchema()
|
||||
schema.add(colander.SchemaNode(colander.String(), name='quick_row_entry'))
|
||||
schema.add(colander.SchemaNode(colander.String(), name='quick_entry'))
|
||||
return schema
|
||||
|
||||
def make_quick_row_form_kwargs(self, **kwargs):
|
||||
|
@ -2572,7 +2572,7 @@ class MasterView(View):
|
|||
row = self.save_quick_row_form(form)
|
||||
if not row:
|
||||
self.request.session.flash("Could not locate/create row for entry: "
|
||||
"{}".format(form.validated['quick_row_entry']),
|
||||
"{}".format(form.validated['quick_entry']),
|
||||
'error')
|
||||
return self.redirect(parent_url)
|
||||
return self.redirect_after_quick_row(row, mobile=True)
|
||||
|
|
|
@ -725,6 +725,35 @@ class ProductsView(MasterView):
|
|||
'instance_title': self.get_instance_title(instance),
|
||||
'form': form})
|
||||
|
||||
def mobile_index(self):
|
||||
"""
|
||||
Mobile "home" page for products
|
||||
"""
|
||||
self.mobile = True
|
||||
context = {
|
||||
'quick_lookup': False,
|
||||
'placeholder': "Enter {}".format(self.rattail_config.product_key_title()),
|
||||
'quick_lookup_keyboard_wedge': True,
|
||||
}
|
||||
if self.rattail_config.getbool('rattail', 'products.mobile.quick_lookup', default=False):
|
||||
context['quick_lookup'] = True
|
||||
else:
|
||||
self.listing = True
|
||||
grid = self.make_mobile_grid()
|
||||
context['grid'] = grid
|
||||
return self.render_to_response('index', context, mobile=True)
|
||||
|
||||
def mobile_quick_lookup(self):
|
||||
entry = self.request.POST['quick_entry']
|
||||
provided = GPC(entry, calc_check_digit=False)
|
||||
product = api.get_product_by_upc(self.Session(), provided)
|
||||
if not product:
|
||||
checked = GPC(entry, calc_check_digit='upc')
|
||||
product = api.get_product_by_upc(self.Session(), checked)
|
||||
if not product:
|
||||
raise self.notfound()
|
||||
return self.redirect(self.get_action_url('view', product, mobile=True))
|
||||
|
||||
def get_version_child_classes(self):
|
||||
return [
|
||||
(model.ProductCode, 'product_uuid'),
|
||||
|
@ -938,6 +967,10 @@ class ProductsView(MasterView):
|
|||
config.add_route('products.image', '/products/{uuid}/image')
|
||||
config.add_view(cls, attr='image', route_name='products.image')
|
||||
|
||||
# mobile quick lookup
|
||||
config.add_route('mobile.products.quick_lookup', '/mobile/products/quick-lookup')
|
||||
config.add_view(cls, attr='mobile_quick_lookup', route_name='mobile.products.quick_lookup')
|
||||
|
||||
|
||||
class ProductsAutocomplete(AutocompleteView):
|
||||
"""
|
||||
|
|
|
@ -991,7 +991,7 @@ class ReceivingBatchView(PurchasingBatchView):
|
|||
|
||||
def save_quick_row_form(self, form):
|
||||
batch = self.get_instance()
|
||||
entry = form.validated['quick_row_entry']
|
||||
entry = form.validated['quick_entry']
|
||||
|
||||
# maybe try to locate existing row first
|
||||
rows = self.quick_locate_rows(batch, entry)
|
||||
|
|
Loading…
Reference in a new issue