Add basic autocomplete support for "quick row" feature
This commit is contained in:
parent
68bd3047c4
commit
935a6b2a68
|
@ -37,6 +37,17 @@ $(document).on('pagecreate', function() {
|
||||||
});
|
});
|
||||||
|
|
||||||
|
|
||||||
|
// submit "quick row" form upon autocomplete selection
|
||||||
|
$(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.submit();
|
||||||
|
}
|
||||||
|
});
|
||||||
|
|
||||||
|
|
||||||
/**
|
/**
|
||||||
* Automatically set focus to certain fields, on various pages
|
* Automatically set focus to certain fields, on various pages
|
||||||
* TODO: this should accept selector params instead of hard-coding..?
|
* TODO: this should accept selector params instead of hard-coding..?
|
||||||
|
|
|
@ -20,12 +20,21 @@ ${form.render()|n}
|
||||||
% if master.mobile_rows_creatable_via_browse:
|
% if master.mobile_rows_creatable_via_browse:
|
||||||
${h.link_to(add_item_title, url('mobile.{}.create_row'.format(route_prefix), uuid=instance.uuid), class_='ui-btn ui-corner-all')}
|
${h.link_to(add_item_title, url('mobile.{}.create_row'.format(route_prefix), uuid=instance.uuid), class_='ui-btn ui-corner-all')}
|
||||||
% endif
|
% endif
|
||||||
% if master.mobile_rows_quickable:
|
% endif
|
||||||
${h.form(url('mobile.{}.quick_row'.format(route_prefix), uuid=instance.uuid))}
|
% if master.mobile_rows_quickable and master.rows_quickable_for(instance):
|
||||||
${h.csrf_token(request)}
|
${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.text('quick_row_autocomplete_text', placeholder=quick_row_entry_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=quick_row_entry_placeholder, autocomplete='off', **{'data-type': 'search', 'data-url': url('mobile.{}.quick_row'.format(route_prefix), uuid=instance.uuid)})}
|
${h.text('quick_row_entry', placeholder=quick_row_entry_placeholder, autocomplete='off', **{'data-type': 'search', 'data-url': url('mobile.{}.quick_row'.format(route_prefix), uuid=instance.uuid)})}
|
||||||
${h.end_form()}
|
|
||||||
% endif
|
% endif
|
||||||
|
${h.end_form()}
|
||||||
% endif
|
% endif
|
||||||
|
|
||||||
<br />
|
<br />
|
||||||
|
|
|
@ -152,9 +152,9 @@ class BatchMasterView(MasterView):
|
||||||
if kwargs['mobile']:
|
if kwargs['mobile']:
|
||||||
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_row_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)
|
||||||
kwargs['execute_form'] = self.make_execute_form(batch, action_url=url)
|
kwargs['execute_form'] = self.make_execute_form(batch, action_url=url)
|
||||||
|
@ -490,6 +490,18 @@ class BatchMasterView(MasterView):
|
||||||
return False
|
return False
|
||||||
return True
|
return True
|
||||||
|
|
||||||
|
def rows_quickable_for(self, batch):
|
||||||
|
"""
|
||||||
|
Must return boolean indicating whether the "quick row" feature should
|
||||||
|
be allowed for the given batch. By default, returns ``False`` if batch
|
||||||
|
has already been executed or marked complete, and ``True`` otherwise.
|
||||||
|
"""
|
||||||
|
if batch.executed:
|
||||||
|
return False
|
||||||
|
if batch.complete:
|
||||||
|
return False
|
||||||
|
return True
|
||||||
|
|
||||||
def configure_row_grid(self, g):
|
def configure_row_grid(self, g):
|
||||||
super(BatchMasterView, self).configure_row_grid(g)
|
super(BatchMasterView, self).configure_row_grid(g)
|
||||||
|
|
||||||
|
|
|
@ -1790,6 +1790,18 @@ class MasterView(View):
|
||||||
context['row_model_title_plural'] = self.get_row_model_title_plural()
|
context['row_model_title_plural'] = self.get_row_model_title_plural()
|
||||||
context['row_action_url'] = self.get_row_action_url
|
context['row_action_url'] = self.get_row_action_url
|
||||||
|
|
||||||
|
if mobile:
|
||||||
|
|
||||||
|
if self.mobile_rows_creatable:
|
||||||
|
context['add_item_title'] = "Add Record"
|
||||||
|
|
||||||
|
if self.mobile_rows_quickable:
|
||||||
|
context['quick_row_entry_placeholder'] = "Enter search text"
|
||||||
|
|
||||||
|
# quick row does *not* use autocomplete by default
|
||||||
|
context['quick_row_autocomplete'] = False
|
||||||
|
context['quick_row_autocomplete_url'] = '#'
|
||||||
|
|
||||||
context.update(data)
|
context.update(data)
|
||||||
context.update(self.template_kwargs(**context))
|
context.update(self.template_kwargs(**context))
|
||||||
if hasattr(self, 'template_kwargs_{}'.format(template)):
|
if hasattr(self, 'template_kwargs_{}'.format(template)):
|
||||||
|
@ -2552,6 +2564,13 @@ class MasterView(View):
|
||||||
"""
|
"""
|
||||||
return True
|
return True
|
||||||
|
|
||||||
|
def rows_quickable_for(self, instance):
|
||||||
|
"""
|
||||||
|
Must return boolean indicating whether the "quick row" feature should
|
||||||
|
be allowed for the given instance. Returns ``True`` by default.
|
||||||
|
"""
|
||||||
|
return True
|
||||||
|
|
||||||
def row_editable(self, row):
|
def row_editable(self, row):
|
||||||
"""
|
"""
|
||||||
Returns boolean indicating whether or not the given row can be
|
Returns boolean indicating whether or not the given row can be
|
||||||
|
|
Loading…
Reference in a new issue