forked from DGNum/gestioCOF
Merge branch 'Aufinal/transfer_formset' into 'master'
Fix : nouveaux formulaires de transfert si le formset est plein Closes #250 See merge request klub-dev-ens/gestioCOF!404
This commit is contained in:
commit
ee79281f53
2 changed files with 44 additions and 6 deletions
|
@ -11,6 +11,8 @@ Liste des changements notables dans GestioCOF depuis la version 0.1 (septembre
|
||||||
|
|
||||||
## Upcoming
|
## Upcoming
|
||||||
|
|
||||||
|
- La page des transferts permet de créer un nombre illimité de transferts en
|
||||||
|
une fois.
|
||||||
- Nouveau site du COF : les liens sont optionnels dans les descriptions de clubs
|
- Nouveau site du COF : les liens sont optionnels dans les descriptions de clubs
|
||||||
- Mise à jour du lien vers le calendire de la K-Fêt sur la page d'accueil
|
- Mise à jour du lien vers le calendire de la K-Fêt sur la page d'accueil
|
||||||
- Certaines opérations sont à nouveau accessibles depuis la session partagée
|
- Certaines opérations sont à nouveau accessibles depuis la session partagée
|
||||||
|
|
|
@ -20,7 +20,7 @@
|
||||||
--><button type="submit" id="submit" class="btn btn-primary btn-lg">Enregistrer</button>
|
--><button type="submit" id="submit" class="btn btn-primary btn-lg">Enregistrer</button>
|
||||||
{{ transfer_formset.management_form }}
|
{{ transfer_formset.management_form }}
|
||||||
</div>
|
</div>
|
||||||
<table class="transfer_formset table">
|
<table class="transfer_formset table" id="transfer_formset">
|
||||||
<thead>
|
<thead>
|
||||||
<tr>
|
<tr>
|
||||||
<td></td>
|
<td></td>
|
||||||
|
@ -52,6 +52,7 @@
|
||||||
|
|
||||||
<script type="text/javascript">
|
<script type="text/javascript">
|
||||||
$(document).ready(function () {
|
$(document).ready(function () {
|
||||||
|
|
||||||
function getAccountData(trigramme, callback = function() {}) {
|
function getAccountData(trigramme, callback = function() {}) {
|
||||||
$.ajax({
|
$.ajax({
|
||||||
dataType: "json",
|
dataType: "json",
|
||||||
|
@ -75,7 +76,12 @@ $(document).ready(function () {
|
||||||
getAccountData(trigramme, function(data) {
|
getAccountData(trigramme, function(data) {
|
||||||
$input_id.val(data.id);
|
$input_id.val(data.id);
|
||||||
$data.text(data.name);
|
$data.text(data.name);
|
||||||
|
if (!$next.length) {
|
||||||
|
new_row = add_form();
|
||||||
|
new_row.find(".from_acc input").focus();
|
||||||
|
} else {
|
||||||
$next.focus();
|
$next.focus();
|
||||||
|
}
|
||||||
});
|
});
|
||||||
} else {
|
} else {
|
||||||
$input_id.val('');
|
$input_id.val('');
|
||||||
|
@ -83,9 +89,10 @@ $(document).ready(function () {
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
$('.input_from_acc, .input_to_acc').on('input', function() {
|
$(document).on("input", '.input_from_acc, .input_to_acc', function(e) {
|
||||||
var tri = $(this).val().toUpperCase();
|
var target = $(e.target)
|
||||||
updateAccountData(tri, $(this));
|
var tri = target.val().toUpperCase();
|
||||||
|
updateAccountData(tri, target);
|
||||||
});
|
});
|
||||||
|
|
||||||
$('#transfers_form').on('submit', function(e) {
|
$('#transfers_form').on('submit', function(e) {
|
||||||
|
@ -101,7 +108,6 @@ $(document).ready(function () {
|
||||||
method : "POST",
|
method : "POST",
|
||||||
data : data,
|
data : data,
|
||||||
beforeSend: function ($xhr) {
|
beforeSend: function ($xhr) {
|
||||||
$xhr.setRequestHeader("X-CSRFToken", csrftoken);
|
|
||||||
if (password != '')
|
if (password != '')
|
||||||
$xhr.setRequestHeader("KFetPassword", password);
|
$xhr.setRequestHeader("KFetPassword", password);
|
||||||
},
|
},
|
||||||
|
@ -118,6 +124,36 @@ $(document).ready(function () {
|
||||||
}
|
}
|
||||||
});
|
});
|
||||||
}
|
}
|
||||||
|
|
||||||
|
function add_form() {
|
||||||
|
var row_template = `
|
||||||
|
<tr class="transfer_form" id="{{ transfer_formset.empty_form.prefix }}">
|
||||||
|
<td class="from_acc_data"></td>
|
||||||
|
<td class="from_acc">
|
||||||
|
<input type="text" name="from_acc" class="input_from_acc" maxlength="3" autocomplete="off" spellcheck="false">
|
||||||
|
{{ transfer_formset.empty_form.from_acc }}
|
||||||
|
</td>
|
||||||
|
<td class="amount">{{ transfer_formset.empty_form.amount }}</td>
|
||||||
|
<td class="to_acc">
|
||||||
|
<input type="text" name="to_acc" class="input_to_acc" maxlength="3" autocomplete="off" spellcheck="false">
|
||||||
|
{{ transfer_formset.empty_form.to_acc }}
|
||||||
|
</td>
|
||||||
|
<td class="to_acc_data"></td>
|
||||||
|
</tr>`;
|
||||||
|
last_row = $("#transfer_formset tr:last")
|
||||||
|
|
||||||
|
// L'id de chaque form ressemble à `form-<id>`
|
||||||
|
num_rows = parseInt(last_row.attr("id").split("-")[1]);
|
||||||
|
|
||||||
|
new_row = $(row_template.replace(/__prefix__/g, num_rows + 1))
|
||||||
|
last_row.after(new_row)
|
||||||
|
// On incrémente le nombre de formsets dans la form globale
|
||||||
|
$("#id_form-TOTAL_FORMS").val(function(i, oldval) {
|
||||||
|
return ++oldval ;
|
||||||
|
});
|
||||||
|
|
||||||
|
return new_row
|
||||||
|
}
|
||||||
});
|
});
|
||||||
</script>
|
</script>
|
||||||
|
|
||||||
|
|
Loading…
Reference in a new issue