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);
|
var field = $(event.target);
|
||||||
if (field.hasClass('quick-row')) {
|
if (field.hasClass('quick-row')) {
|
||||||
var form = field.parents('form:first');
|
var form = field.parents('form:first');
|
||||||
form.find('[name="quick_row_entry"]').val(uuid);
|
form.find('[name="quick_entry"]').val(uuid);
|
||||||
form.submit();
|
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) {
|
$(document).on('keypress', function(event) {
|
||||||
var quick_row = $('.ui-page-active #quick_row_entry');
|
var quick_entry = $('.ui-page-active #quick_entry');
|
||||||
if (quick_row.length) {
|
if (quick_entry.length) {
|
||||||
|
|
||||||
// if user hits enter with quick row input focused, submit form
|
// 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 (event.which == 13) { // ENTER
|
||||||
if (quick_row.val()) {
|
if (quick_entry.val()) {
|
||||||
var form = quick_row.parents('form:first');
|
var form = quick_entry.parents('form:first');
|
||||||
form.submit();
|
form.submit();
|
||||||
return false;
|
return false;
|
||||||
}
|
}
|
||||||
|
@ -169,11 +169,11 @@ $(document).on('keypress', function(event) {
|
||||||
} else { // quick row input not focused
|
} else { // quick row input not focused
|
||||||
|
|
||||||
// mimic keyboard wedge if we're so instructed
|
// 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.which >= 48 && event.which <= 57) { // numeric (qwerty)
|
||||||
if (!event.altKey && !event.ctrlKey && !event.metaKey) {
|
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;
|
return false;
|
||||||
}
|
}
|
||||||
|
|
||||||
|
@ -183,8 +183,8 @@ $(document).on('keypress', function(event) {
|
||||||
|
|
||||||
} else if (event.which == 13) { // ENTER
|
} else if (event.which == 13) { // ENTER
|
||||||
// submit form when ENTER is received via keyboard "wedge"
|
// submit form when ENTER is received via keyboard "wedge"
|
||||||
if (quick_row.val()) {
|
if (quick_entry.val()) {
|
||||||
var form = quick_row.parents('form:first');
|
var form = quick_entry.parents('form:first');
|
||||||
form.submit();
|
form.submit();
|
||||||
return false;
|
return false;
|
||||||
}
|
}
|
||||||
|
|
|
@ -23,18 +23,18 @@ ${form.render()|n}
|
||||||
% endif
|
% endif
|
||||||
% endif
|
% endif
|
||||||
% if master.mobile_rows_quickable and master.rows_quickable_for(instance):
|
% 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.form(url('mobile.{}.quick_row'.format(route_prefix), uuid=instance.uuid))}
|
||||||
${h.csrf_token(request)}
|
${h.csrf_token(request)}
|
||||||
% if quick_row_autocomplete:
|
% if quick_row_autocomplete:
|
||||||
<div class="field autocomplete quick-row" data-url="${quick_row_autocomplete_url}">
|
<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')}
|
${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>
|
<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>
|
<button type="button" style="display: none;">Change</button>
|
||||||
</div>
|
</div>
|
||||||
% else:
|
% 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
|
% endif
|
||||||
${h.end_form()}
|
${h.end_form()}
|
||||||
% endif
|
% 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:
|
if self.mobile_rows_creatable:
|
||||||
kwargs.setdefault('add_item_title', "Add Item")
|
kwargs.setdefault('add_item_title', "Add Item")
|
||||||
if self.mobile_rows_quickable:
|
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()))
|
self.rattail_config.product_key_title()))
|
||||||
if kwargs['execute_enabled']:
|
if kwargs['execute_enabled']:
|
||||||
url = self.get_action_url('execute', batch)
|
url = self.get_action_url('execute', batch)
|
||||||
|
|
|
@ -1151,7 +1151,7 @@ class MasterView(View):
|
||||||
|
|
||||||
def make_quick_row_form_schema(self, mobile=False):
|
def make_quick_row_form_schema(self, mobile=False):
|
||||||
schema = colander.MappingSchema()
|
schema = colander.MappingSchema()
|
||||||
schema.add(colander.SchemaNode(colander.String(), name='quick_row_entry'))
|
schema.add(colander.SchemaNode(colander.String(), name='quick_entry'))
|
||||||
return schema
|
return schema
|
||||||
|
|
||||||
def make_quick_row_form_kwargs(self, **kwargs):
|
def make_quick_row_form_kwargs(self, **kwargs):
|
||||||
|
@ -2572,7 +2572,7 @@ class MasterView(View):
|
||||||
row = self.save_quick_row_form(form)
|
row = self.save_quick_row_form(form)
|
||||||
if not row:
|
if not row:
|
||||||
self.request.session.flash("Could not locate/create row for entry: "
|
self.request.session.flash("Could not locate/create row for entry: "
|
||||||
"{}".format(form.validated['quick_row_entry']),
|
"{}".format(form.validated['quick_entry']),
|
||||||
'error')
|
'error')
|
||||||
return self.redirect(parent_url)
|
return self.redirect(parent_url)
|
||||||
return self.redirect_after_quick_row(row, mobile=True)
|
return self.redirect_after_quick_row(row, mobile=True)
|
||||||
|
|
|
@ -725,6 +725,35 @@ class ProductsView(MasterView):
|
||||||
'instance_title': self.get_instance_title(instance),
|
'instance_title': self.get_instance_title(instance),
|
||||||
'form': form})
|
'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):
|
def get_version_child_classes(self):
|
||||||
return [
|
return [
|
||||||
(model.ProductCode, 'product_uuid'),
|
(model.ProductCode, 'product_uuid'),
|
||||||
|
@ -938,6 +967,10 @@ class ProductsView(MasterView):
|
||||||
config.add_route('products.image', '/products/{uuid}/image')
|
config.add_route('products.image', '/products/{uuid}/image')
|
||||||
config.add_view(cls, attr='image', route_name='products.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):
|
class ProductsAutocomplete(AutocompleteView):
|
||||||
"""
|
"""
|
||||||
|
|
|
@ -991,7 +991,7 @@ class ReceivingBatchView(PurchasingBatchView):
|
||||||
|
|
||||||
def save_quick_row_form(self, form):
|
def save_quick_row_form(self, form):
|
||||||
batch = self.get_instance()
|
batch = self.get_instance()
|
||||||
entry = form.validated['quick_row_entry']
|
entry = form.validated['quick_entry']
|
||||||
|
|
||||||
# maybe try to locate existing row first
|
# maybe try to locate existing row first
|
||||||
rows = self.quick_locate_rows(batch, entry)
|
rows = self.quick_locate_rows(batch, entry)
|
||||||
|
|
Loading…
Reference in a new issue