docs: changed js for ajax get_pair

remotes/origin/mitri4
Andrey 9 years ago
parent f7d75c235c
commit d66663e0c3
  1. 29
      project/templates/docs/stub_js.html

@ -9,29 +9,28 @@
prefix: '{{ formset.prefix }}', prefix: '{{ formset.prefix }}',
formCssClass: 'dynamic-form', formCssClass: 'dynamic-form',
}); });
var get_pair = function(model, class1, class2, name1, name2) {
$('body').on('focusout', '.' + class1 + ' input', function() { var get_pair = function(model, class1, class2, param1, param2) {
$('body').on('selectChoice change', '.' + class1 + ' input', function() {
var $this = $(this); var $this = $(this);
var $code_input = $this.closest('.row_tbl_items').find('.' + class2 + ' input'); var this_val = $this.val();
var code_input_val = $code_input.val(); var $other_input = $this.closest('.row_tbl_items').find('.' + class2 + ' input');
$.get('/my/docs/ajax_get_pair/' + model + '/' + name1 + '/' + name2 + '/' + $this.val() + '/', function(data){ $.get('/my/docs/ajax_get_pair/' + model + '/' + param1 + '/' + param2 + '/' + this_val + '/', function(data) {
if (data['val']) { if (data['val']) {
$code_input.val(data['val']); $other_input.val(data['val']);
if (($code_input.val() != '')&&(($code_input.val() != code_input_val))) { $this.css('color', 'black')
$code_input.css('color', 'red') }
} else { else {
$code_input.css('color', 'black') $other_input.val('-');
} $this.css('color', 'red')
$this.css('color', 'black');
} }
}); });
}) })
} }
get_pair('Country', 'country_code', 'country_name', 'code', 'name'); {# model должна быть разрешена в docs.views.get_pair #}
get_pair('Country', 'country_name', 'country_code', 'name', 'code'); get_pair('Country', 'country_name', 'country_code', 'name', 'code');
get_pair('Measure', 'units', 'units_kod', 'name', 'code'); get_pair('Measure', 'units', 'units_kod', 'name', 'code');
get_pair('Measure', 'units_kod', 'units', 'code', 'name');
$('#id_client').on('change', function() { $('#id_client').on('change', function() {
var client_id = $(this).val(); var client_id = $(this).val();
@ -112,7 +111,7 @@
} else { } else {
$('#fix_block').hide(); $('#fix_block').hide();
} }
$('#id_fixes').change(function(){ $('#id_fixes').change(function(){
$('#fix_block').toggle(); $('#fix_block').toggle();
$('#id_fix_doc_num').val(''); $('#id_fix_doc_num').val('');
$('#id_fix_doc_date').val(''); $('#id_fix_doc_date').val('');

Loading…
Cancel
Save