2017-05-20 13:57:21 +02:00
|
|
|
{% extends "kfet/base_col_1.html" %}
|
2016-08-26 15:30:40 +02:00
|
|
|
{% load staticfiles %}
|
|
|
|
|
|
|
|
{% block extra_head %}
|
|
|
|
<link rel="stylesheet" type="text/css" href="{% static 'kfet/css/transfers_form.css' %}">
|
|
|
|
{% endblock %}
|
|
|
|
|
|
|
|
{% block title %}Nouveaux transferts{% endblock %}
|
2017-05-20 13:57:21 +02:00
|
|
|
{% block header-title %}Création de transferts{% endblock %}
|
2016-08-26 15:30:40 +02:00
|
|
|
|
2017-05-20 13:57:21 +02:00
|
|
|
{% block main-size %}col-sm-12{% endblock %}
|
2016-08-26 15:30:40 +02:00
|
|
|
|
2017-06-12 01:51:10 +02:00
|
|
|
{% block main %}
|
2016-08-26 15:30:40 +02:00
|
|
|
|
2017-06-12 01:51:10 +02:00
|
|
|
<form id="transfers_form">
|
2017-05-20 13:57:21 +02:00
|
|
|
{% csrf_token %}
|
2016-08-26 20:14:00 +02:00
|
|
|
<div class="transfer_general text-center">
|
|
|
|
<input type="text" name="comment" id="comment" placeholder="Commentaire"><!--
|
|
|
|
--><button type="submit" id="submit" class="btn btn-primary btn-lg">Enregistrer</button>
|
|
|
|
{{ transfer_formset.management_form }}
|
|
|
|
</div>
|
2016-08-26 15:30:40 +02:00
|
|
|
<table class="transfer_formset table">
|
|
|
|
<thead>
|
|
|
|
<tr>
|
|
|
|
<td></td>
|
|
|
|
<td>De</td>
|
|
|
|
<td><span class="glyphicon glyphicon-euro"></span></td>
|
|
|
|
<td>Vers</td>
|
|
|
|
<td></td>
|
|
|
|
</tr>
|
|
|
|
</thead>
|
|
|
|
<tbody>
|
|
|
|
{% for form in transfer_formset %}
|
|
|
|
<tr class="transfer_form" id="{{ form.prefix }}">
|
|
|
|
<td class="from_acc_data"></td>
|
|
|
|
<td class="from_acc">
|
2016-11-17 19:51:36 +01:00
|
|
|
<input type="text" name="from_acc" class="input_from_acc" maxlength="3" autocomplete="off" spellcheck="false">
|
2016-08-26 15:30:40 +02:00
|
|
|
{{ form.from_acc }}
|
|
|
|
</td>
|
|
|
|
<td class="amount">{{ form.amount }}</td>
|
|
|
|
<td class="to_acc">
|
2016-11-17 19:51:36 +01:00
|
|
|
<input type="text" name="to_acc" class="input_to_acc" maxlength="3" autocomplete="off" spellcheck="false">
|
2016-08-26 15:30:40 +02:00
|
|
|
{{ form.to_acc }}
|
|
|
|
</td>
|
|
|
|
<td class="to_acc_data"></td>
|
|
|
|
</tr>
|
|
|
|
{% endfor %}
|
|
|
|
</tbody>
|
|
|
|
</table>
|
|
|
|
</form>
|
|
|
|
|
|
|
|
<script type="text/javascript">
|
|
|
|
$(document).ready(function () {
|
|
|
|
function getAccountData(trigramme, callback = function() {}) {
|
|
|
|
$.ajax({
|
|
|
|
dataType: "json",
|
|
|
|
url : "{% url 'kfet.account.read.json' %}",
|
|
|
|
method : "POST",
|
|
|
|
data : { trigramme: trigramme },
|
|
|
|
success : callback,
|
|
|
|
});
|
|
|
|
}
|
|
|
|
|
|
|
|
function updateAccountData(trigramme, $input) {
|
|
|
|
var $form = $input.closest('.transfer_form');
|
|
|
|
if ($input.attr('name') == 'from_acc') {
|
|
|
|
var $data = $form.find('.from_acc_data');
|
|
|
|
var $next = $form.find('.amount input');
|
|
|
|
} else {
|
|
|
|
var $data = $form.find('.to_acc_data');
|
|
|
|
var $next = $form.next('.transfer_form').find('.from_acc input');
|
|
|
|
}
|
|
|
|
var $input_id = $input.next('input');
|
2016-11-17 19:51:36 +01:00
|
|
|
if (isValidTrigramme(trigramme)) {
|
|
|
|
getAccountData(trigramme, function(data) {
|
|
|
|
$input_id.val(data.id);
|
|
|
|
$data.text(data.name);
|
|
|
|
$next.focus();
|
|
|
|
});
|
|
|
|
} else {
|
|
|
|
$input_id.val('');
|
|
|
|
$data.text('');
|
|
|
|
}
|
2016-08-26 15:30:40 +02:00
|
|
|
}
|
|
|
|
|
|
|
|
$('.input_from_acc, .input_to_acc').on('input', function() {
|
|
|
|
var tri = $(this).val().toUpperCase();
|
2016-11-17 19:51:36 +01:00
|
|
|
updateAccountData(tri, $(this));
|
2016-08-26 15:30:40 +02:00
|
|
|
});
|
|
|
|
|
|
|
|
$('#transfers_form').on('submit', function(e) {
|
|
|
|
e.preventDefault();
|
|
|
|
performTransfers();
|
|
|
|
});
|
|
|
|
|
|
|
|
function performTransfers(password = '') {
|
|
|
|
var data = $('#transfers_form').serialize();
|
|
|
|
$.ajax({
|
|
|
|
dataType: "json",
|
|
|
|
url : "{% url 'kfet.transfers.perform' %}",
|
|
|
|
method : "POST",
|
|
|
|
data : data,
|
|
|
|
beforeSend: function ($xhr) {
|
|
|
|
$xhr.setRequestHeader("X-CSRFToken", csrftoken);
|
|
|
|
if (password != '')
|
|
|
|
$xhr.setRequestHeader("KFetPassword", password);
|
|
|
|
},
|
|
|
|
})
|
|
|
|
.done(function(data) {
|
2016-08-26 20:14:00 +02:00
|
|
|
window.location.href = "{% url 'kfet.transfers' %}";
|
2016-08-26 15:30:40 +02:00
|
|
|
})
|
|
|
|
.fail(function($xhr) {
|
|
|
|
var data = $xhr.responseJSON;
|
|
|
|
switch ($xhr.status) {
|
|
|
|
case 403:
|
|
|
|
requestAuth(data, performTransfers);
|
|
|
|
break;
|
|
|
|
}
|
|
|
|
});
|
|
|
|
}
|
|
|
|
});
|
|
|
|
</script>
|
|
|
|
|
|
|
|
{% endblock %}
|