docs: autocomplete 1) extended text for units select 2) removed ajax get_pair

remotes/origin/mitri4
Andrey 9 years ago
parent 88373a550d
commit ae7f976e2e
  1. 6
      project/docs/autocomplete_light_registry.py
  2. 3
      project/docs/urls.py
  3. 2
      project/docs/views/__init__.py
  4. 22
      project/docs/views/ajax.py
  5. 5
      project/templates/autocomplete_light/docs_country_choice.html
  6. 5
      project/templates/autocomplete_light/docs_measure_choice.html
  7. 45
      project/templates/docs/stub_js.html

@ -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')

@ -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<id>\d+)/email/ajax/$' % name, getview, {'klass': klass, 'oper': 'email_ajax',},
name='docs_%s_email_ajax' % name),
url(r'^ajax_get_pair/(?P<model>\w+)/(?P<param1>\w+)/(?P<param2>\w+)/(?P<val1>.+)/$', get_pair, name='ajax_get_pair'),
url(r'^ajax_get_invoices/$', get_invoices, name='ajax_get_invoices'),
url(r'^ajax_get_invoices/(?P<client_id>\d+)/$', get_invoices, name='ajax_get_invoices'),
url(r'^ajax_get_tbl_items/(?P<invoice_id>\d+)/$', get_tbl_items, name='ajax_get_tbl_items'),

@ -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 # важно!!!

@ -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()

@ -0,0 +1,5 @@
{% load i18n l10n %}
<span class="div" data-value="{{ choice.pk|unlocalize }}" data-code="{{ choice.code }}">
{{ choice }}
</span>

@ -0,0 +1,5 @@
{% load i18n l10n %}
<span class="div" data-value="{{ choice.pk|unlocalize }}" data-name="{{ choice.name }}" data-code="{{ choice.code }}">
{{ choice.name }} - {{ choice.full_name }}
</span>

@ -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')
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 {
$other_input.val('-');
$this.css('color', 'red')
//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')
}
{# model должна быть разрешена в docs.views.get_pair #}
get_pair('Country', 'country_name', 'country_code', 'name', 'code');
get_pair('Measure', 'units', 'units_kod', 'name', 'code');
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();

Loading…
Cancel
Save