diff --git a/project/docs/autocomplete_light_registry.py b/project/docs/autocomplete_light_registry.py index c116a5e..41d8783 100644 --- a/project/docs/autocomplete_light_registry.py +++ b/project/docs/autocomplete_light_registry.py @@ -36,18 +36,20 @@ class AutocompleteCurrency(autocomplete_light.AutocompleteModelBase): search_fields = ('name', '^abc_code', '^code') -class AutocompleteMeasure(autocomplete_light.AutocompleteModelBase): +class AutocompleteMeasure(autocomplete_light.AutocompleteModelTemplate): '''Автокомплит ед. измерения ''' autocomplete_js_attributes = {'placeholder': u'Название ед. измерения'} search_fields = ('name', 'full_name', '^code') + choice_template = 'autocomplete_light/docs_measure_choice.html' -class AutocompleteCountry(autocomplete_light.AutocompleteModelBase): +class AutocompleteCountry(autocomplete_light.AutocompleteModelTemplate): '''Автокомплит стран ''' autocomplete_js_attributes = {'placeholder': u'Название страны'} search_fields = ('name', 'full_name', '^code') + choice_template = 'autocomplete_light/docs_country_choice.html' autocomplete_light.register(Country, AutocompleteCountry, name='ACCountry') diff --git a/project/docs/urls.py b/project/docs/urls.py index bed09f7..3a2c231 100644 --- a/project/docs/urls.py +++ b/project/docs/urls.py @@ -2,7 +2,7 @@ from django.conf.urls import * from .views import (InvoiceViews, AktRabotViews, AktSverkiViews, DoverViews, PlatejkaViews, NakladnViews, FakturaViews) -from .views import getview, index, get_pair, get_invoices, get_tbl_items, get_client_by_invoice, toggle_doc_status +from .views import getview, index, get_invoices, get_tbl_items, get_client_by_invoice, toggle_doc_status urlpatterns = patterns('docs.views', @@ -60,7 +60,6 @@ for name, klass in klasses: url(r'^%s/(?P\d+)/email/ajax/$' % name, getview, {'klass': klass, 'oper': 'email_ajax',}, name='docs_%s_email_ajax' % name), - url(r'^ajax_get_pair/(?P\w+)/(?P\w+)/(?P\w+)/(?P.+)/$', get_pair, name='ajax_get_pair'), url(r'^ajax_get_invoices/$', get_invoices, name='ajax_get_invoices'), url(r'^ajax_get_invoices/(?P\d+)/$', get_invoices, name='ajax_get_invoices'), url(r'^ajax_get_tbl_items/(?P\d+)/$', get_tbl_items, name='ajax_get_tbl_items'), diff --git a/project/docs/views/__init__.py b/project/docs/views/__init__.py index 440117f..fa03be4 100644 --- a/project/docs/views/__init__.py +++ b/project/docs/views/__init__.py @@ -11,7 +11,7 @@ from .dover import DoverViews from .platejka import PlatejkaViews from .nakladn import NakladnViews from .faktura import FakturaViews -from .ajax import get_pair, get_invoices, get_tbl_items, get_client_by_invoice, toggle_doc_status +from .ajax import get_invoices, get_tbl_items, get_client_by_invoice, toggle_doc_status @login_required # важно!!! diff --git a/project/docs/views/ajax.py b/project/docs/views/ajax.py index 8fea4b6..51674bc 100644 --- a/project/docs/views/ajax.py +++ b/project/docs/views/ajax.py @@ -11,28 +11,6 @@ from ..models import Invoice from project.customer.utils import raise_if_no_profile -def get_pair(request, model, param1, val1, param2): - if not request.is_ajax(): - return HttpResponseBadRequest() - - if model not in ('Country', 'Measure',): - return HttpResponseBadRequest() - - raise_if_no_profile(request) - - kwargs = {param1: val1} - - try: - q_model = get_model('docs', model) - val2 = getattr(q_model.objects.get(**kwargs), param2) - except: - val2 = None - data = { - 'val': val2, - } - return HttpResponse(json.dumps(data), mimetype='application/json') - - def get_invoices(request, client_id=None): if not request.is_ajax(): return HttpResponseBadRequest() diff --git a/project/static/css/style.css b/project/static/css/style.css index f0eae62..5619b57 100644 --- a/project/static/css/style.css +++ b/project/static/css/style.css @@ -687,3 +687,5 @@ a.popup-unreg {background:url(../img/popup-trash.png) no-repeat 3px center;} .italic {font-style: italic;} .rm_profile {overflow:hidden;} .rm_profile .list-col2 {border-left:none;} + +.yourlabs-autocomplete { overflow: auto !important; } diff --git a/project/templates/autocomplete_light/docs_country_choice.html b/project/templates/autocomplete_light/docs_country_choice.html new file mode 100644 index 0000000..074c474 --- /dev/null +++ b/project/templates/autocomplete_light/docs_country_choice.html @@ -0,0 +1,5 @@ +{% load i18n l10n %} + + +{{ choice }} + diff --git a/project/templates/autocomplete_light/docs_measure_choice.html b/project/templates/autocomplete_light/docs_measure_choice.html new file mode 100644 index 0000000..836288e --- /dev/null +++ b/project/templates/autocomplete_light/docs_measure_choice.html @@ -0,0 +1,5 @@ +{% load i18n l10n %} + + +{{ choice.name }} - {{ choice.full_name }} + diff --git a/project/templates/base.html b/project/templates/base.html index d79bec1..8baf9bb 100644 --- a/project/templates/base.html +++ b/project/templates/base.html @@ -9,7 +9,7 @@ {% block title %}{% endblock %} | Документор - + {% render_block "css" %} diff --git a/project/templates/docs/stub_js.html b/project/templates/docs/stub_js.html index 51b6636..5a87de8 100644 --- a/project/templates/docs/stub_js.html +++ b/project/templates/docs/stub_js.html @@ -10,27 +10,40 @@ formCssClass: 'dynamic-form', }); - var get_pair = function(model, class1, class2, param1, param2) { - $('body').on('selectChoice change', '.' + class1 + ' input', function() { - var $this = $(this); - var this_val = $this.val(); - var $other_input = $this.closest('.row_tbl_items').find('.' + class2 + ' input'); + // units + $('body').on('selectChoice change', '.units input', function(e, choice, autocomplete) { + var name_input = $(this); + var code_input = name_input.closest('.row_tbl_items').find('.units_kod input'); - $.get('/my/docs/ajax_get_pair/' + model + '/' + param1 + '/' + param2 + '/' + this_val + '/', function(data) { - if (data['val']) { - $other_input.val(data['val']); - $this.css('color', 'black') - } - else { - $other_input.val('-'); - $this.css('color', 'red') - } - }); - }) - } - {# model должна быть разрешена в docs.views.get_pair #} - get_pair('Country', 'country_name', 'country_code', 'name', 'code'); - get_pair('Measure', 'units', 'units_kod', 'name', 'code'); + if (choice) { + //console.log(choice.data()); + name_input.val(choice.data('name')); // short name + code_input.val(choice.data('code')); + name_input.css('color', 'black') + } + else { + //console.log(choice, 'No choice!'); + code_input.val('-'); + name_input.css('color', 'red') + } + }); + + // country + $('body').on('selectChoice change', '.country_name input', function(e, choice, autocomplete) { + var name_input = $(this); + var code_input = name_input.closest('.row_tbl_items').find('.country_code input'); + + if (choice) { + //console.log(choice.data()); + code_input.val(choice.data('code')); + name_input.css('color', 'black') + } + else { + //console.log(choice, 'No choice!'); + code_input.val('-'); + name_input.css('color', 'red') + } + }); $('#id_client').on('change', function() { var client_id = $(this).val(); @@ -50,7 +63,7 @@ }); select.prop('selectedIndex', 0); }) - }) + }); $('#id_invoice').on('change', function() { var invoice_id = $(this).val();