You can not select more than 25 topics
Topics must start with a letter or number, can include dashes ('-') and can be up to 35 characters long.
239 lines
7.5 KiB
239 lines
7.5 KiB
$(document).ready(function() {
|
|
var dlg_msg = $('#dialog-message');
|
|
var dlg_django_msg = $('#django-message');
|
|
|
|
$('form', '#dialogs').each(function() {
|
|
var form = $(this);
|
|
|
|
var options = {
|
|
dataType: 'json',
|
|
timeout: 30000,
|
|
beforeSubmit: function() {
|
|
$(':input', form).attr('disabled', 'disabled');
|
|
$('button', form).attr('disabled', 'disabled');
|
|
},
|
|
complete: function(data) {
|
|
$(':input', form).removeAttr('disabled');
|
|
$('button', form).removeAttr('disabled');
|
|
|
|
},
|
|
|
|
/*beforeSend: function() {
|
|
$('.errors-layout', form).html('').hide();
|
|
},*/
|
|
success: function(data) {
|
|
clear_form_errors(form);
|
|
|
|
if (data.success) {
|
|
console.log('!!!!!!!!!!!!!!!!!!!');
|
|
console.log(data);
|
|
if (form[0].id == 'client-edit-form') {
|
|
$('#id_client_text').hide();
|
|
$('#id_client-deck').html(
|
|
'<span class="div hilight" data-value='+ data.id +
|
|
'><span class="remove div" style="display: inline;">X</span>' + data.name + '</span>');
|
|
|
|
$('#id_client').html('<option selected="selected" value="'+ data.id +'"></option>');
|
|
$('#id_client').trigger('change');
|
|
}
|
|
form.dialog('close');
|
|
form.clearForm();
|
|
|
|
clearResultSearchDiv($("#searchBankResult"));
|
|
|
|
if (data.message) {
|
|
if (dlg_msg) {
|
|
dlg_msg.dialog({title: data.message['title']}).html(data.message['msg']);
|
|
if (data.reload)
|
|
dlg_msg.one('dialogbeforeclose', function(){window.location.reload(true);});
|
|
dlg_msg.dialog('open');
|
|
}
|
|
}
|
|
if (data.action){
|
|
if (data.action == 'client-add'){
|
|
$(data.row_html).insertAfter('#clients_header_row');
|
|
window.clients_edit_del_update();
|
|
$('table#clients').show();
|
|
}
|
|
if (data.action == 'client-edit'){
|
|
$("tr#client_" + data.id).replaceWith(data.row_html);
|
|
window.clients_edit_del_update();
|
|
}
|
|
if (data.action == 'client-delete'){
|
|
$("tr#client_" + data.id).remove();
|
|
}
|
|
}
|
|
else if (data.reload) {
|
|
window.location.reload(true);
|
|
}
|
|
}
|
|
else {
|
|
// process form errors
|
|
if (data.form_errors) {
|
|
var captcha = $(form).find('img.captcha');
|
|
if (captcha) {
|
|
$(form).find('a.captcha_refresh').click();
|
|
}
|
|
var errors = $('.errors-layout', form);
|
|
var html = '<ul>';
|
|
for (var err in data.form_errors) {
|
|
if (data.form_errors.hasOwnProperty(err)) {
|
|
html += '<li>' + data.form_errors[err] + '</li>';
|
|
}
|
|
}
|
|
html += '</ul>';
|
|
errors.append(html).show();
|
|
}
|
|
// process fields errors
|
|
for (var key in data.field_errors) {
|
|
if (data.field_errors.hasOwnProperty(key)) {
|
|
var value = data.field_errors[key];
|
|
var input = $('[name^='+key+'],[field^='+key+']', form);
|
|
input.addClass('ui-state-error'); // highlight field
|
|
}
|
|
}
|
|
}
|
|
}
|
|
};
|
|
form.ajaxForm(options);
|
|
|
|
form
|
|
.ajaxStart(function(){
|
|
$.blockUI.defaults.overlayCSS = {};
|
|
$.blockUI.defaults.css = {};
|
|
$.blockUI({message: '<h1>Пожалуйста, подождите...</h1>', baseZ: '9999'});
|
|
})
|
|
.ajaxStop(function(){
|
|
$.unblockUI();
|
|
});
|
|
});
|
|
|
|
dlg_msg.dialog({
|
|
modal: true,
|
|
autoOpen: false,
|
|
//resizable: false,
|
|
//width: 310,
|
|
buttons: {
|
|
'Закрыть': function() {
|
|
$(this).dialog('close');
|
|
}
|
|
}
|
|
});
|
|
dlg_django_msg.dialog({
|
|
modal: true,
|
|
autoOpen: true,
|
|
//resizable: false,
|
|
//width: 310,
|
|
buttons: {
|
|
'Закрыть': function() {
|
|
$(this).dialog('close');
|
|
}
|
|
}
|
|
});
|
|
});
|
|
|
|
function clear_form_errors(form) {
|
|
$('.errors-layout', form).html('').hide();
|
|
form.find(':input').each(function() {
|
|
$(this).removeClass('ui-state-error'); // remove fields highlight
|
|
});
|
|
}
|
|
|
|
function update_form_fields(form, obj_values) {
|
|
for (var key in obj_values)
|
|
if (obj_values.hasOwnProperty(key)) {
|
|
var value = obj_values[key];
|
|
var input = $(':input[name="' + key + '"]', form);
|
|
if (input) {
|
|
var input_type = input.attr('type');
|
|
|
|
if (input_type == 'checkbox' || input_type == 'radio') {
|
|
input.prop('checked', value);
|
|
} else {
|
|
input.val(value);
|
|
}
|
|
|
|
}
|
|
}
|
|
}
|
|
|
|
|
|
//-------------------------------------------------------
|
|
|
|
|
|
function getType() {
|
|
return isOrg ? "LEGAL" : "INDIVIDUAL";
|
|
}
|
|
|
|
|
|
function getPartOfPersonName(fullName, part) {
|
|
if (!fullName) return;
|
|
return fullName.split(' ')[part];
|
|
}
|
|
|
|
|
|
function expandObject(obj, width, align) {
|
|
obj["templateColWidth"] = width;
|
|
obj["templateColAlign"] = align;
|
|
|
|
return obj
|
|
}
|
|
|
|
|
|
function clearResultSearchDiv(div) {
|
|
|
|
if ($(div).html().trim() !== '') {
|
|
div.html('');
|
|
}
|
|
}
|
|
|
|
|
|
function clearSearchInputs(input) {
|
|
|
|
if (input instanceof Array) {
|
|
var index, len;
|
|
for (index = 0, len = input.length; index < len; ++index) {
|
|
var item = input[index];
|
|
item.val('');
|
|
}
|
|
} else {
|
|
input.val('');
|
|
}
|
|
|
|
}
|
|
|
|
|
|
function join(arr) {
|
|
var separator = arguments.length > 1 ? arguments[1] : ", ";
|
|
return arr.filter(function(n){return n}).join(separator);
|
|
}
|
|
|
|
|
|
function fillResultSearchBankTemplate(obj) {
|
|
|
|
var bankResultDiv = $("#searchBankResult");
|
|
var templateBank = $("#resultSearchBankTemplate").html();
|
|
var template = Handlebars.compile(templateBank);
|
|
var newObj = {};
|
|
newObj['name'] = {};
|
|
|
|
if (obj.hasOwnProperty('bik')) {
|
|
|
|
newObj["bic"] = obj.bik;
|
|
newObj["name"]["full"] = obj.name;
|
|
newObj["name"]["payment"] = obj.short_name;
|
|
newObj["correspondent_account"] = obj.korr_account;
|
|
obj = newObj;
|
|
}
|
|
|
|
if (obj.hasOwnProperty('bank_bik')) {
|
|
|
|
newObj["bic"] = obj.bank_bik;
|
|
newObj["name"]["full"] = obj.bank_name;
|
|
newObj["name"]["payment"] = obj.bank_name;
|
|
newObj["correspondent_account"] = obj.bank_korr_account;
|
|
obj = newObj;
|
|
}
|
|
|
|
bankResultDiv.html(template(obj));
|
|
} |