diff --git a/tailbone/static/js/jquery.ui.tailbone.mobile.js b/tailbone/static/js/jquery.ui.tailbone.mobile.js
new file mode 100644
index 00000000..33a2a7be
--- /dev/null
+++ b/tailbone/static/js/jquery.ui.tailbone.mobile.js
@@ -0,0 +1,78 @@
+
+/******************************************
+ * jQuery Mobile plugins for Tailbone
+ *****************************************/
+
+/******************************************
+ * mobile autocomplete
+ *****************************************/
+
+(function($) {
+
+ $.widget('tailbone.mobileautocomplete', {
+
+ _create: function() {
+ var that = this;
+
+ // snag some element references
+ this.search = this.element.find('.ui-input-search');
+ this.hidden_field = this.element.find('input[type="hidden"]');
+ this.text_field = this.element.find('input[type="text"]');
+ this.ul = this.element.find('ul');
+ this.button = this.element.find('button');
+
+ // establish our autocomplete URL
+ this.url = this.options.url || this.element.data('url');
+
+ // NOTE: much of this code was copied from the jquery mobile demo site
+ // https://demos.jquerymobile.com/1.4.5/listview-autocomplete-remote/
+ this.ul.on('filterablebeforefilter', function(e, data) {
+
+ var $input = $( data.input ),
+ value = $input.val(),
+ html = "";
+ that.ul.html( "" );
+ if ( value && value.length > 2 ) {
+ that.ul.html( "
" );
+ that.ul.listview( "refresh" );
+ $.ajax({
+ url: that.url,
+ data: {
+ term: $input.val()
+ }
+ })
+ .then( function ( response ) {
+ $.each( response, function ( i, val ) {
+ html += '' + val.label + "";
+ });
+ that.ul.html( html );
+ that.ul.listview( "refresh" );
+ that.ul.trigger( "updatelayout");
+ });
+ }
+
+ });
+
+ // when user clicks autocomplete result, hide search etc.
+ this.ul.on('click', 'li', function() {
+ var $li = $(this);
+ that.search.hide();
+ that.hidden_field.val($li.data('uuid'));
+ that.button.text($li.text()).show();
+ that.ul.hide();
+ });
+
+ // when user clicks "change" button, show search etc.
+ this.button.click(function() {
+ that.button.hide();
+ that.ul.empty().show();
+ that.hidden_field.val('');
+ that.search.show();
+ that.text_field.focus();
+ });
+
+ }
+
+ });
+
+})( jQuery );
diff --git a/tailbone/static/js/tailbone.mobile.js b/tailbone/static/js/tailbone.mobile.js
index 9852abba..fb392425 100644
--- a/tailbone/static/js/tailbone.mobile.js
+++ b/tailbone/static/js/tailbone.mobile.js
@@ -29,13 +29,36 @@ $(document).on('pagecontainerchange', function(event, ui) {
});
+$(document).on('pagecreate', function() {
+
+ // setup any autocomplete fields
+ $('.field.autocomplete').mobileautocomplete();
+
+});
+
+
+/**
+ * Automatically set focus to certain fields, on various pages
+ */
+function setfocus() {
+ var el = null;
+ var queries = [
+ '#username',
+ '#new-purchasing-batch-vendor-text',
+ ];
+ $.each(queries, function(i, query) {
+ el = $(query);
+ if (el.is(':visible')) {
+ el.focus();
+ return false;
+ }
+ });
+}
+
+
$(document).on('pageshow', function() {
- // on login page, auto-focus username
- el = $('#username');
- if (el.is(':visible')) {
- el.focus();
- }
+ setfocus();
// TODO: seems like this should be better somehow...
// remove all flash messages after 2.5 seconds
@@ -44,8 +67,28 @@ $(document).on('pageshow', function() {
});
-$(document).on('click', '#datasync-restart', function() {
+// vendor validation for new purchasing batch
+$(document).on('click', 'form[name="new-purchasing-batch"] input[type="submit"]', function() {
+ var $form = $(this).parents('form');
+ if (! $form.find('[name="vendor"]').val()) {
+ alert("Please select a vendor");
+ $form.find('[name="new-purchasing-batch-vendor-text"]').focus();
+ return false;
+ }
+});
- // disable datasync restart button when clicked
+// submit new purchasing batch form on Purchase click
+$(document).on('click', 'form[name="new-purchasing-batch"] [data-role="listview"] a', function() {
+ var $form = $(this).parents('form');
+ var $field = $form.find('[name="purchase"]');
+ var uuid = $(this).parents('li').data('uuid');
+ $field.val(uuid);
+ $form.submit();
+ return false;
+});
+
+
+// disable datasync restart button when clicked
+$(document).on('click', '#datasync-restart', function() {
$(this).button('disable');
});
diff --git a/tailbone/templates/mobile/base.mako b/tailbone/templates/mobile/base.mako
index 31051cd5..575ce278 100644
--- a/tailbone/templates/mobile/base.mako
+++ b/tailbone/templates/mobile/base.mako
@@ -5,16 +5,22 @@
${self.global_title()} » ${self.title()}
+
${h.javascript_link('https://code.jquery.com/jquery-1.12.4.min.js')}
${h.javascript_link('https://code.jquery.com/mobile/1.4.5/jquery.mobile-1.4.5.min.js')}
- ${h.stylesheet_link('https://code.jquery.com/mobile/1.4.5/jquery.mobile-1.4.5.min.css')}
+ ${h.javascript_link(request.static_url('tailbone:static/js/jquery.ui.tailbone.mobile.js'))}
${h.javascript_link(request.static_url('tailbone:static/js/tailbone.mobile.js'))}
+ ${self.extra_javascript()}
+
+ ${h.stylesheet_link('https://code.jquery.com/mobile/1.4.5/jquery.mobile-1.4.5.min.css')}
${h.stylesheet_link(request.static_url('tailbone:static/css/mobile.css'))}
% if not request.rattail_config.production():
-
+
% endif
+ ${self.extra_styles()}
+
${self.mobile_body()}