Refactor vendor catalog batch views to use master3
This commit is contained in:
parent
34e81dc50a
commit
19cd6336f9
|
@ -13,37 +13,37 @@
|
|||
|
||||
$(function() {
|
||||
|
||||
if ($('#VendorCatalog--parser_key option:first').is(':selected')) {
|
||||
$('#VendorCatalog--vendor_uuid-container').hide();
|
||||
if ($('select[name="parser_key"] option:first').is(':selected')) {
|
||||
$('.vendor_uuid .autocomplete-container').hide();
|
||||
} else {
|
||||
$('#VendorCatalog--vendor_uuid').val('');
|
||||
$('#VendorCatalog--vendor_uuid-display').hide();
|
||||
$('#VendorCatalog--vendor_uuid-display button').show();
|
||||
$('#VendorCatalog--vendor_uuid-textbox').val('');
|
||||
$('#VendorCatalog--vendor_uuid-textbox').show();
|
||||
$('#VendorCatalog--vendor_uuid-container').show();
|
||||
$('.vendor_uuid input[name="vendor_uuid"]').val('');
|
||||
$('.vendor_uuid .autocomplete-display').hide();
|
||||
$('.vendor_uuid .autocomplete-display button').show();
|
||||
$('.vendor_uuid .autocomplete-textbox').val('');
|
||||
$('.vendor_uuid .autocomplete-textbox').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')) {
|
||||
$('#VendorCatalog--vendor_uuid-container').hide();
|
||||
$('.vendor_uuid .autocomplete-container').hide();
|
||||
} else {
|
||||
var vendor = vendormap[$(this).val()];
|
||||
if (vendor) {
|
||||
$('#VendorCatalog--vendor_uuid').val(vendor.uuid);
|
||||
$('#VendorCatalog--vendor_uuid-textbox').hide();
|
||||
$('#VendorCatalog--vendor_uuid-display span:first').text(vendor.name);
|
||||
$('#VendorCatalog--vendor_uuid-display button').hide();
|
||||
$('#VendorCatalog--vendor_uuid-display').show();
|
||||
$('#VendorCatalog--vendor_uuid-container').show();
|
||||
$('.vendor_uuid input[name="vendor_uuid"]').val(vendor.uuid);
|
||||
$('.vendor_uuid .autocomplete-textbox').hide();
|
||||
$('.vendor_uuid .autocomplete-display span:first').text(vendor.name);
|
||||
$('.vendor_uuid .autocomplete-display button').hide();
|
||||
$('.vendor_uuid .autocomplete-display').show();
|
||||
$('.vendor_uuid .autocomplete-container').show();
|
||||
} else {
|
||||
$('#VendorCatalog--vendor_uuid').val('');
|
||||
$('#VendorCatalog--vendor_uuid-display').hide();
|
||||
$('#VendorCatalog--vendor_uuid-display button').show();
|
||||
$('#VendorCatalog--vendor_uuid-textbox').val('');
|
||||
$('#VendorCatalog--vendor_uuid-textbox').show();
|
||||
$('#VendorCatalog--vendor_uuid-container').show();
|
||||
$('#VendorCatalog--vendor_uuid-textbox').focus();
|
||||
$('.vendor_uuid input[name="vendor_uuid"]').val('');
|
||||
$('.vendor_uuid .autocomplete-display').hide();
|
||||
$('.vendor_uuid .autocomplete-display button').show();
|
||||
$('.vendor_uuid .autocomplete-textbox').val('');
|
||||
$('.vendor_uuid .autocomplete-textbox').show();
|
||||
$('.vendor_uuid .autocomplete-container').show();
|
||||
$('.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
|
||||
# Copyright © 2010-2017 Lance Edgar
|
||||
# Copyright © 2010-2018 Lance Edgar
|
||||
#
|
||||
# This file is part of Rattail.
|
||||
#
|
||||
|
@ -28,14 +28,18 @@ from __future__ import unicode_literals, absolute_import
|
|||
|
||||
import logging
|
||||
|
||||
import six
|
||||
|
||||
from rattail.db import model, api
|
||||
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.views.batch import FileBatchMasterView2 as FileBatchMasterView
|
||||
from tailbone.views.batch import FileBatchMasterView3 as FileBatchMasterView
|
||||
|
||||
|
||||
log = logging.getLogger(__name__)
|
||||
|
@ -62,6 +66,17 @@ class VendorCatalogsView(FileBatchMasterView):
|
|||
'executed',
|
||||
]
|
||||
|
||||
form_fields = [
|
||||
'vendor',
|
||||
'filename',
|
||||
'effective',
|
||||
'created',
|
||||
'created_by',
|
||||
'executed',
|
||||
'executed_by',
|
||||
'rowcount',
|
||||
]
|
||||
|
||||
row_grid_columns = [
|
||||
'sequence',
|
||||
'upc',
|
||||
|
@ -90,34 +105,54 @@ class VendorCatalogsView(FileBatchMasterView):
|
|||
def get_instance_title(self, batch):
|
||||
return unicode(batch.vendor)
|
||||
|
||||
def configure_fieldset(self, fs):
|
||||
fs.vendor.set(renderer=forms.renderers.VendorFieldRenderer)
|
||||
fs.filename.set(label="Catalog File")
|
||||
def configure_form(self, f):
|
||||
super(VendorCatalogsView, self).configure_form(f)
|
||||
|
||||
# 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:
|
||||
parser_options = [(p.display, p.key) for p in self.get_parsers()]
|
||||
parser_options.insert(0, ("(please choose)", ''))
|
||||
fs.parser_key.set(renderer=formalchemy.fields.SelectFieldRenderer,
|
||||
options=parser_options, label="File Type")
|
||||
fs.configure(
|
||||
include=[
|
||||
fs.filename,
|
||||
fs.parser_key,
|
||||
fs.vendor,
|
||||
|
||||
f.set_fields([
|
||||
'filename',
|
||||
'parser_key',
|
||||
'vendor_uuid',
|
||||
])
|
||||
|
||||
else:
|
||||
fs.configure(
|
||||
include=[
|
||||
fs.vendor.readonly(),
|
||||
fs.filename,
|
||||
fs.effective.readonly(),
|
||||
fs.created,
|
||||
fs.created_by,
|
||||
fs.executed,
|
||||
fs.executed_by,
|
||||
fs.rowcount,
|
||||
])
|
||||
parser_values = [(p.key, p.display) for p in self.get_parsers()]
|
||||
parser_values.insert(0, ('', "(please choose)"))
|
||||
f.set_widget('parser_key', dfwidget.SelectWidget(values=parser_values))
|
||||
f.set_label('parser_key', "File Type")
|
||||
|
||||
# effective
|
||||
if not self.creating:
|
||||
f.set_readonly('effective')
|
||||
|
||||
def render_vendor(self, batch, field):
|
||||
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):
|
||||
kwargs = super(VendorCatalogsView, self).get_batch_kwargs(batch)
|
||||
|
|
Loading…
Reference in a new issue