diff --git a/tailbone/forms/renderers/common.py b/tailbone/forms/renderers/common.py
index ac8c496b..d0d072da 100644
--- a/tailbone/forms/renderers/common.py
+++ b/tailbone/forms/renderers/common.py
@@ -1,8 +1,8 @@
-# -*- coding: utf-8 -*-
+# -*- coding: utf-8; -*-
################################################################################
#
# Rattail -- Retail Software Framework
-# Copyright © 2010-2016 Lance Edgar
+# Copyright © 2010-2017 Lance Edgar
#
# This file is part of Rattail.
#
@@ -92,7 +92,14 @@ class AutocompleteFieldRenderer(fa.FieldRenderer):
def service_url(self):
return self.request.route_url(self.service_route)
- def render(self, **kwargs):
+ def render(self, options=None, **kwargs):
+ if kwargs.pop('autocomplete', True):
+ return self.render_autocomplete(**kwargs)
+ # 'selected' is a kwarg for autocomplete template *and* select tag
+ kwargs.pop('selected', None)
+ return self.render_dropdown(options, **kwargs)
+
+ def render_autocomplete(self, **kwargs):
kwargs.setdefault('field_name', self.name)
kwargs.setdefault('field_value', self.field_value)
kwargs.setdefault('field_display', self.field_display)
@@ -100,6 +107,22 @@ class AutocompleteFieldRenderer(fa.FieldRenderer):
kwargs.setdefault('width', self.width)
return render('/forms/field_autocomplete.mako', kwargs)
+ def render_dropdown(self, options, **kwargs):
+ # NOTE: this logic copied from formalchemy.fields.SelectFieldRenderer.render()
+ kwargs.setdefault('auto-enhance', 'true')
+ if callable(options):
+ L = fa_fields._normalized_options(options(self.field.parent))
+ if not self.field.is_required() and not self.field.is_collection:
+ L.insert(0, self.field._null_option)
+ else:
+ L = list(options)
+ if len(L) > 0:
+ if len(L[0]) == 2:
+ L = [(k, self.stringify_value(v)) for k, v in L]
+ else:
+ L = [fa_fields._stringify(k) for k in L]
+ return fa_fields.h.select(self.name, self.value, L, **kwargs)
+
def render_readonly(self, **kwargs):
value = self.field_display
if value is None:
diff --git a/tailbone/forms/renderers/products.py b/tailbone/forms/renderers/products.py
index c576cccd..2834e138 100644
--- a/tailbone/forms/renderers/products.py
+++ b/tailbone/forms/renderers/products.py
@@ -108,6 +108,10 @@ class DepartmentFieldRenderer(SelectFieldRenderer):
Shows the department number as well as the name.
"""
+ def render(self, **kwargs):
+ kwargs.setdefault('auto-enhance', 'true')
+ return super(DepartmentFieldRenderer, self).render(**kwargs)
+
def render_readonly(self, **kwargs):
department = self.raw_value
if not department:
diff --git a/tailbone/forms/renderers/stores.py b/tailbone/forms/renderers/stores.py
index bbe1545c..19d75e35 100644
--- a/tailbone/forms/renderers/stores.py
+++ b/tailbone/forms/renderers/stores.py
@@ -1,8 +1,8 @@
-# -*- coding: utf-8 -*-
+# -*- coding: utf-8; -*-
################################################################################
#
# Rattail -- Retail Software Framework
-# Copyright © 2010-2015 Lance Edgar
+# Copyright © 2010-2017 Lance Edgar
#
# This file is part of Rattail.
#
@@ -24,9 +24,10 @@
Store Field Renderers
"""
-from __future__ import unicode_literals
+from __future__ import unicode_literals, absolute_import
from formalchemy.fields import SelectFieldRenderer
+from webhelpers.html import tags
class StoreFieldRenderer(SelectFieldRenderer):
@@ -34,8 +35,15 @@ class StoreFieldRenderer(SelectFieldRenderer):
Renderer for :class:`rattail.db.model.Store` instance fields.
"""
+ def render(self, **kwargs):
+ kwargs.setdefault('auto-enhance', 'true')
+ return super(StoreFieldRenderer, self).render(**kwargs)
+
def render_readonly(self, **kwargs):
store = self.raw_value
if not store:
- return ''
- return '{0} - {1}'.format(store.id, store.name)
+ return ""
+ text = "({}) {}".format(store.id, store.name)
+ if kwargs.get('hyperlink', True):
+ return tags.link_to(text, self.request.route_url('stores.view', uuid=store.uuid))
+ return text
diff --git a/tailbone/forms/renderers/vendors.py b/tailbone/forms/renderers/vendors.py
index 5647841a..3809132c 100644
--- a/tailbone/forms/renderers/vendors.py
+++ b/tailbone/forms/renderers/vendors.py
@@ -1,8 +1,8 @@
-# -*- coding: utf-8 -*-
+# -*- coding: utf-8; -*-
################################################################################
#
# Rattail -- Retail Software Framework
-# Copyright © 2010-2016 Lance Edgar
+# Copyright © 2010-2017 Lance Edgar
#
# This file is part of Rattail.
#
@@ -41,8 +41,11 @@ class VendorFieldRenderer(AutocompleteFieldRenderer):
def render_readonly(self, **kwargs):
vendor = self.raw_value
if not vendor:
- return ''
- return tags.link_to(vendor, self.request.route_url('vendors.view', uuid=vendor.uuid))
+ return ""
+ text = "({}) {}".format(vendor.id, vendor.name)
+ if kwargs.get('hyperlink', True):
+ return tags.link_to(text, self.request.route_url('vendors.view', uuid=vendor.uuid))
+ return text
class PurchaseFieldRenderer(SelectFieldRenderer):
diff --git a/tailbone/static/js/tailbone.js b/tailbone/static/js/tailbone.js
index 6cf6a536..52618f22 100644
--- a/tailbone/static/js/tailbone.js
+++ b/tailbone/static/js/tailbone.js
@@ -147,12 +147,17 @@ $(function() {
});
/*
- * Fix buttons.
+ * enhance buttons
*/
$('button, a.button').button();
$('input[type=submit]').button();
$('input[type=reset]').button();
+ /*
+ * enhance dropdowns
+ */
+ $('select[auto-enhance="true"]').selectmenu();
+
/* Also automatically disable any buttons marked for that. */
$('a.button[disabled=disabled]').button('option', 'disabled', true);
diff --git a/tailbone/templates/purchases/batches/create.mako b/tailbone/templates/purchases/batches/create.mako
index 0cea8c6a..b98ce7d5 100644
--- a/tailbone/templates/purchases/batches/create.mako
+++ b/tailbone/templates/purchases/batches/create.mako
@@ -1,40 +1,13 @@
-## -*- coding: utf-8 -*-
+## -*- coding: utf-8; -*-
<%inherit file="/newbatch/create.mako" />
-<%def name="head_tags()">
- ${parent.head_tags()}
+<%def name="extra_javascript()">
+ ${parent.extra_javascript()}
+ ${self.func_show_mode()}
%def>
+<%def name="func_show_mode()">
+
+%def>
+
${parent.body()}
diff --git a/tailbone/templates/purchases/batches/order_form.mako b/tailbone/templates/purchases/batches/order_form.mako
index c45b252b..32f1d291 100644
--- a/tailbone/templates/purchases/batches/order_form.mako
+++ b/tailbone/templates/purchases/batches/order_form.mako
@@ -3,8 +3,8 @@
<%def name="title()">Purchase Order Form%def>
-<%def name="head_tags()">
- ${parent.head_tags()}
+<%def name="extra_javascript()">
+ ${parent.extra_javascript()}
${h.javascript_link(request.static_url('tailbone:static/js/numeric.js'))}