Refactor vendor catalog batch views to use master3
This commit is contained in:
parent
34e81dc50a
commit
19cd6336f9
|
@ -13,37 +13,37 @@
|
||||||
|
|
||||||
$(function() {
|
$(function() {
|
||||||
|
|
||||||
if ($('#VendorCatalog--parser_key option:first').is(':selected')) {
|
if ($('select[name="parser_key"] option:first').is(':selected')) {
|
||||||
$('#VendorCatalog--vendor_uuid-container').hide();
|
$('.vendor_uuid .autocomplete-container').hide();
|
||||||
} else {
|
} else {
|
||||||
$('#VendorCatalog--vendor_uuid').val('');
|
$('.vendor_uuid input[name="vendor_uuid"]').val('');
|
||||||
$('#VendorCatalog--vendor_uuid-display').hide();
|
$('.vendor_uuid .autocomplete-display').hide();
|
||||||
$('#VendorCatalog--vendor_uuid-display button').show();
|
$('.vendor_uuid .autocomplete-display button').show();
|
||||||
$('#VendorCatalog--vendor_uuid-textbox').val('');
|
$('.vendor_uuid .autocomplete-textbox').val('');
|
||||||
$('#VendorCatalog--vendor_uuid-textbox').show();
|
$('.vendor_uuid .autocomplete-textbox').show();
|
||||||
$('#VendorCatalog--vendor_uuid-container').show();
|
$('.vendor_uuid .autocomplete-container').show();
|
||||||
}
|
}
|
||||||
|
|
||||||
$('#VendorCatalog--parser_key').change(function() {
|
$('select[name="parser_key"]').on('selectmenuchange', function() {
|
||||||
if ($(this).find('option:first').is(':selected')) {
|
if ($(this).find('option:first').is(':selected')) {
|
||||||
$('#VendorCatalog--vendor_uuid-container').hide();
|
$('.vendor_uuid .autocomplete-container').hide();
|
||||||
} else {
|
} else {
|
||||||
var vendor = vendormap[$(this).val()];
|
var vendor = vendormap[$(this).val()];
|
||||||
if (vendor) {
|
if (vendor) {
|
||||||
$('#VendorCatalog--vendor_uuid').val(vendor.uuid);
|
$('.vendor_uuid input[name="vendor_uuid"]').val(vendor.uuid);
|
||||||
$('#VendorCatalog--vendor_uuid-textbox').hide();
|
$('.vendor_uuid .autocomplete-textbox').hide();
|
||||||
$('#VendorCatalog--vendor_uuid-display span:first').text(vendor.name);
|
$('.vendor_uuid .autocomplete-display span:first').text(vendor.name);
|
||||||
$('#VendorCatalog--vendor_uuid-display button').hide();
|
$('.vendor_uuid .autocomplete-display button').hide();
|
||||||
$('#VendorCatalog--vendor_uuid-display').show();
|
$('.vendor_uuid .autocomplete-display').show();
|
||||||
$('#VendorCatalog--vendor_uuid-container').show();
|
$('.vendor_uuid .autocomplete-container').show();
|
||||||
} else {
|
} else {
|
||||||
$('#VendorCatalog--vendor_uuid').val('');
|
$('.vendor_uuid input[name="vendor_uuid"]').val('');
|
||||||
$('#VendorCatalog--vendor_uuid-display').hide();
|
$('.vendor_uuid .autocomplete-display').hide();
|
||||||
$('#VendorCatalog--vendor_uuid-display button').show();
|
$('.vendor_uuid .autocomplete-display button').show();
|
||||||
$('#VendorCatalog--vendor_uuid-textbox').val('');
|
$('.vendor_uuid .autocomplete-textbox').val('');
|
||||||
$('#VendorCatalog--vendor_uuid-textbox').show();
|
$('.vendor_uuid .autocomplete-textbox').show();
|
||||||
$('#VendorCatalog--vendor_uuid-container').show();
|
$('.vendor_uuid .autocomplete-container').show();
|
||||||
$('#VendorCatalog--vendor_uuid-textbox').focus();
|
$('.vendor_uuid .autocomplete-textbox').focus();
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
});
|
});
|
||||||
|
|
93
tailbone/views/vendors/catalogs.py
vendored
93
tailbone/views/vendors/catalogs.py
vendored
|
@ -1,8 +1,8 @@
|
||||||
# -*- coding: utf-8 -*-
|
# -*- coding: utf-8; -*-
|
||||||
################################################################################
|
################################################################################
|
||||||
#
|
#
|
||||||
# Rattail -- Retail Software Framework
|
# Rattail -- Retail Software Framework
|
||||||
# Copyright © 2010-2017 Lance Edgar
|
# Copyright © 2010-2018 Lance Edgar
|
||||||
#
|
#
|
||||||
# This file is part of Rattail.
|
# This file is part of Rattail.
|
||||||
#
|
#
|
||||||
|
@ -28,14 +28,18 @@ from __future__ import unicode_literals, absolute_import
|
||||||
|
|
||||||
import logging
|
import logging
|
||||||
|
|
||||||
|
import six
|
||||||
|
|
||||||
from rattail.db import model, api
|
from rattail.db import model, api
|
||||||
from rattail.vendors.catalogs import iter_catalog_parsers
|
from rattail.vendors.catalogs import iter_catalog_parsers
|
||||||
|
|
||||||
import formalchemy
|
import colander
|
||||||
|
from deform import widget as dfwidget
|
||||||
|
from webhelpers2.html import tags
|
||||||
|
|
||||||
from tailbone import forms
|
from tailbone import forms2 as forms
|
||||||
from tailbone.db import Session
|
from tailbone.db import Session
|
||||||
from tailbone.views.batch import FileBatchMasterView2 as FileBatchMasterView
|
from tailbone.views.batch import FileBatchMasterView3 as FileBatchMasterView
|
||||||
|
|
||||||
|
|
||||||
log = logging.getLogger(__name__)
|
log = logging.getLogger(__name__)
|
||||||
|
@ -62,6 +66,17 @@ class VendorCatalogsView(FileBatchMasterView):
|
||||||
'executed',
|
'executed',
|
||||||
]
|
]
|
||||||
|
|
||||||
|
form_fields = [
|
||||||
|
'vendor',
|
||||||
|
'filename',
|
||||||
|
'effective',
|
||||||
|
'created',
|
||||||
|
'created_by',
|
||||||
|
'executed',
|
||||||
|
'executed_by',
|
||||||
|
'rowcount',
|
||||||
|
]
|
||||||
|
|
||||||
row_grid_columns = [
|
row_grid_columns = [
|
||||||
'sequence',
|
'sequence',
|
||||||
'upc',
|
'upc',
|
||||||
|
@ -90,34 +105,54 @@ class VendorCatalogsView(FileBatchMasterView):
|
||||||
def get_instance_title(self, batch):
|
def get_instance_title(self, batch):
|
||||||
return unicode(batch.vendor)
|
return unicode(batch.vendor)
|
||||||
|
|
||||||
def configure_fieldset(self, fs):
|
def configure_form(self, f):
|
||||||
fs.vendor.set(renderer=forms.renderers.VendorFieldRenderer)
|
super(VendorCatalogsView, self).configure_form(f)
|
||||||
fs.filename.set(label="Catalog File")
|
|
||||||
|
# vendor
|
||||||
|
f.set_renderer('vendor', self.render_vendor)
|
||||||
|
if self.creating:
|
||||||
|
f.replace('vendor', 'vendor_uuid')
|
||||||
|
f.set_node('vendor_uuid', colander.String())
|
||||||
|
vendor_display = ""
|
||||||
|
if self.request.method == 'POST':
|
||||||
|
if self.request.POST.get('vendor_uuid'):
|
||||||
|
vendor = self.Session.query(model.Vendor).get(self.request.POST['vendor_uuid'])
|
||||||
|
if vendor:
|
||||||
|
vendor_display = six.text_type(vendor)
|
||||||
|
vendors_url = self.request.route_url('vendors.autocomplete')
|
||||||
|
f.set_widget('vendor_uuid', forms.widgets.JQueryAutocompleteWidget(
|
||||||
|
field_display=vendor_display, service_url=vendors_url))
|
||||||
|
f.set_label('vendor_uuid', "Vendor")
|
||||||
|
else:
|
||||||
|
f.set_readonly('vendor')
|
||||||
|
|
||||||
|
# filename
|
||||||
|
f.set_label('filename', "Catalog File")
|
||||||
|
|
||||||
if self.creating:
|
if self.creating:
|
||||||
parser_options = [(p.display, p.key) for p in self.get_parsers()]
|
|
||||||
parser_options.insert(0, ("(please choose)", ''))
|
f.set_fields([
|
||||||
fs.parser_key.set(renderer=formalchemy.fields.SelectFieldRenderer,
|
'filename',
|
||||||
options=parser_options, label="File Type")
|
'parser_key',
|
||||||
fs.configure(
|
'vendor_uuid',
|
||||||
include=[
|
|
||||||
fs.filename,
|
|
||||||
fs.parser_key,
|
|
||||||
fs.vendor,
|
|
||||||
])
|
])
|
||||||
|
|
||||||
else:
|
parser_values = [(p.key, p.display) for p in self.get_parsers()]
|
||||||
fs.configure(
|
parser_values.insert(0, ('', "(please choose)"))
|
||||||
include=[
|
f.set_widget('parser_key', dfwidget.SelectWidget(values=parser_values))
|
||||||
fs.vendor.readonly(),
|
f.set_label('parser_key', "File Type")
|
||||||
fs.filename,
|
|
||||||
fs.effective.readonly(),
|
# effective
|
||||||
fs.created,
|
if not self.creating:
|
||||||
fs.created_by,
|
f.set_readonly('effective')
|
||||||
fs.executed,
|
|
||||||
fs.executed_by,
|
def render_vendor(self, batch, field):
|
||||||
fs.rowcount,
|
vendor = batch.vendor
|
||||||
])
|
if not vendor:
|
||||||
|
return ""
|
||||||
|
text = "({}) {}".format(vendor.id, vendor.name)
|
||||||
|
url = self.request.route_url('vendors.view', uuid=vendor.uuid)
|
||||||
|
return tags.link_to(text, url)
|
||||||
|
|
||||||
def get_batch_kwargs(self, batch):
|
def get_batch_kwargs(self, batch):
|
||||||
kwargs = super(VendorCatalogsView, self).get_batch_kwargs(batch)
|
kwargs = super(VendorCatalogsView, self).get_batch_kwargs(batch)
|
||||||
|
|
Loading…
Reference in a new issue