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
|
||||
* TODO: this should accept selector params instead of hard-coding..?
|
||||
|
|
|
@ -20,12 +20,21 @@ ${form.render()|n}
|
|||
% 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')}
|
||||
% endif
|
||||
% if master.mobile_rows_quickable:
|
||||
% endif
|
||||
% if master.mobile_rows_quickable and master.rows_quickable_for(instance):
|
||||
${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.end_form()}
|
||||
% endif
|
||||
${h.end_form()}
|
||||
% endif
|
||||
|
||||
<br />
|
||||
|
|
|
@ -490,6 +490,18 @@ class BatchMasterView(MasterView):
|
|||
return False
|
||||
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):
|
||||
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_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(self.template_kwargs(**context))
|
||||
if hasattr(self, 'template_kwargs_{}'.format(template)):
|
||||
|
@ -2552,6 +2564,13 @@ class MasterView(View):
|
|||
"""
|
||||
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):
|
||||
"""
|
||||
Returns boolean indicating whether or not the given row can be
|
||||
|
|
Loading…
Reference in a new issue