mirror of
https://gitlab.crans.org/bde/nk20
synced 2025-06-25 11:37:22 +02:00
Merge remote-tracking branch 'origin/master' into activity
This commit is contained in:
37
static/js/alias.js
Normal file
37
static/js/alias.js
Normal file
@ -0,0 +1,37 @@
|
||||
|
||||
$("#alias_input").on('keypress',function(e) {
|
||||
if(e.which == 13) {
|
||||
$("#alias_submit").click();
|
||||
}
|
||||
});
|
||||
|
||||
function create_alias(note_id){
|
||||
$.post("/api/note/alias/",
|
||||
{
|
||||
"csrfmiddlewaretoken": CSRF_TOKEN,
|
||||
"name": $("#alias_input").val(),
|
||||
"note": note_id
|
||||
}
|
||||
).done(function(){
|
||||
$("#alias_table").load(location.href+ " #alias_table");
|
||||
addMsg("Alias ajouté","success");
|
||||
})
|
||||
.fail(function(xhr, textStatus, error){
|
||||
errMsg(xhr.responseJSON);
|
||||
});
|
||||
}
|
||||
// on click of button "delete" , call the API
|
||||
function delete_button(button_id){
|
||||
$.ajax({
|
||||
url:"/api/note/alias/"+button_id+"/",
|
||||
method:"DELETE",
|
||||
headers: {"X-CSRFTOKEN": CSRF_TOKEN}
|
||||
})
|
||||
.done(function(){
|
||||
addMsg('Alias supprimé','success');
|
||||
$("#alias_table").load(location.href + " #alias_table");
|
||||
})
|
||||
.fail(function(xhr,textStatus, error){
|
||||
errMsg(xhr.responseJSON);
|
||||
});
|
||||
}
|
@ -28,7 +28,15 @@ function addMsg(msg, alert_type) {
|
||||
+ msg + "</div>\n";
|
||||
msgDiv.html(html);
|
||||
}
|
||||
|
||||
/**
|
||||
* add Muliple error message from err_obj
|
||||
* @param err_obj {error_code:erro_message}
|
||||
*/
|
||||
function errMsg(errs_obj){
|
||||
for (const err_msg of Object.values(errs_obj)) {
|
||||
addMsg(err_msg,'danger');
|
||||
}
|
||||
}
|
||||
/**
|
||||
* Reload the balance of the user on the right top corner
|
||||
*/
|
||||
@ -265,7 +273,16 @@ function autoCompleteNote(field_id, alias_matched_id, note_list_id, notes, notes
|
||||
}
|
||||
|
||||
// When a validate button is clicked, we switch the validation status
|
||||
function de_validate(id, validated) {
|
||||
function in_validate(id, validated) {
|
||||
|
||||
let invalidity_reason;
|
||||
let reason_obj = $("#invalidity_reason_" + id);
|
||||
|
||||
if (validated)
|
||||
invalidity_reason = reason_obj.val();
|
||||
else
|
||||
invalidity_reason = null;
|
||||
|
||||
$("#validate_" + id).html("<strong style=\"font-size: 16pt;\">⟳ ...</strong>");
|
||||
|
||||
// Perform a PATCH request to the API in order to update the transaction
|
||||
@ -278,12 +295,13 @@ function de_validate(id, validated) {
|
||||
"X-CSRFTOKEN": CSRF_TOKEN
|
||||
},
|
||||
data: {
|
||||
"resourcetype": "RecurrentTransaction",
|
||||
valid: !validated
|
||||
resourcetype: "RecurrentTransaction",
|
||||
valid: !validated,
|
||||
invalidity_reason: invalidity_reason,
|
||||
},
|
||||
success: function () {
|
||||
// Refresh jQuery objects
|
||||
$(".validate").click(de_validate);
|
||||
$(".validate").click(in_validate);
|
||||
|
||||
refreshBalance();
|
||||
// error if this method doesn't exist. Please define it.
|
||||
|
@ -167,7 +167,7 @@ function reset() {
|
||||
function consumeAll() {
|
||||
notes_display.forEach(function(note_display) {
|
||||
buttons.forEach(function(button) {
|
||||
consume(note_display.id, button.dest, button.quantity * note_display.quantity, button.amount,
|
||||
consume(note_display.id, note_display.name, button.dest, button.quantity * note_display.quantity, button.amount,
|
||||
button.name + " (" + button.category_name + ")", button.type, button.category_id, button.id);
|
||||
});
|
||||
});
|
||||
@ -176,6 +176,7 @@ function consumeAll() {
|
||||
/**
|
||||
* Create a new transaction from a button through the API.
|
||||
* @param source The note that paid the item (type: int)
|
||||
* @param source_alias The alias used for the source (type: str)
|
||||
* @param dest The note that sold the item (type: int)
|
||||
* @param quantity The quantity sold (type: int)
|
||||
* @param amount The price of one item, in cents (type: int)
|
||||
@ -184,7 +185,7 @@ function consumeAll() {
|
||||
* @param category The category id of the button (type: int)
|
||||
* @param template The button id (type: int)
|
||||
*/
|
||||
function consume(source, dest, quantity, amount, reason, type, category, template) {
|
||||
function consume(source, source_alias, dest, quantity, amount, reason, type, category, template) {
|
||||
$.post("/api/note/transaction/transaction/",
|
||||
{
|
||||
"csrfmiddlewaretoken": CSRF_TOKEN,
|
||||
@ -195,12 +196,32 @@ function consume(source, dest, quantity, amount, reason, type, category, templat
|
||||
"polymorphic_ctype": type,
|
||||
"resourcetype": "RecurrentTransaction",
|
||||
"source": source,
|
||||
"source_alias": source_alias,
|
||||
"destination": dest,
|
||||
"category": category,
|
||||
"template": template
|
||||
}, reset).fail(function (e) {
|
||||
reset();
|
||||
|
||||
addMsg("Une erreur est survenue lors de la transaction : " + e.responseText, "danger");
|
||||
$.post("/api/note/transaction/transaction/",
|
||||
{
|
||||
"csrfmiddlewaretoken": CSRF_TOKEN,
|
||||
"quantity": quantity,
|
||||
"amount": amount,
|
||||
"reason": reason,
|
||||
"valid": false,
|
||||
"invalidity_reason": "Solde insuffisant",
|
||||
"polymorphic_ctype": type,
|
||||
"resourcetype": "RecurrentTransaction",
|
||||
"source": source,
|
||||
"source_alias": source_alias,
|
||||
"destination": dest,
|
||||
"category": category,
|
||||
"template": template
|
||||
}).done(function() {
|
||||
reset();
|
||||
addMsg("La transaction n'a pas pu être validée pour cause de solde insuffisant.", "danger");
|
||||
}).fail(function () {
|
||||
reset();
|
||||
errMsg(e.responseJSON);
|
||||
});
|
||||
});
|
||||
}
|
||||
|
@ -83,19 +83,41 @@ $("#transfer").click(function() {
|
||||
"polymorphic_ctype": TRANSFER_POLYMORPHIC_CTYPE,
|
||||
"resourcetype": "Transaction",
|
||||
"source": user_id,
|
||||
"destination": dest.id
|
||||
}, function () {
|
||||
"destination": dest.id,
|
||||
"destination_alias": dest.name
|
||||
}).done(function () {
|
||||
addMsg("Le transfert de "
|
||||
+ pretty_money(dest.quantity * 100 * $("#amount").val()) + " de votre note "
|
||||
+ " vers la note " + dest.name + " a été fait avec succès !", "success");
|
||||
|
||||
reset();
|
||||
}).fail(function (err) {
|
||||
addMsg("Le transfert de "
|
||||
+ pretty_money(dest.quantity * 100 * $("#amount").val()) + " de votre note "
|
||||
+ " vers la note " + dest.name + " a échoué : " + err.responseText, "danger");
|
||||
}).fail(function () {
|
||||
$.post("/api/note/transaction/transaction/",
|
||||
{
|
||||
"csrfmiddlewaretoken": CSRF_TOKEN,
|
||||
"quantity": dest.quantity,
|
||||
"amount": 100 * $("#amount").val(),
|
||||
"reason": $("#reason").val(),
|
||||
"valid": false,
|
||||
"invalidity_reason": "Solde insuffisant",
|
||||
"polymorphic_ctype": TRANSFER_POLYMORPHIC_CTYPE,
|
||||
"resourcetype": "Transaction",
|
||||
"source": user_id,
|
||||
"destination": dest.id,
|
||||
"destination_alias": dest.name
|
||||
}).done(function () {
|
||||
addMsg("Le transfert de "
|
||||
+ pretty_money(dest.quantity * 100 * $("#amount").val()) + " de votre note "
|
||||
+ " vers la note " + dest.name + " a échoué : Solde insuffisant", "danger");
|
||||
|
||||
reset();
|
||||
reset();
|
||||
}).fail(function (err) {
|
||||
addMsg("Le transfert de "
|
||||
+ pretty_money(dest.quantity * 100 * $("#amount").val()) + " de votre note "
|
||||
+ " vers la note " + dest.name + " a échoué : " + err.responseText, "danger");
|
||||
|
||||
reset();
|
||||
});
|
||||
});
|
||||
});
|
||||
}
|
||||
@ -112,19 +134,43 @@ $("#transfer").click(function() {
|
||||
"polymorphic_ctype": TRANSFER_POLYMORPHIC_CTYPE,
|
||||
"resourcetype": "Transaction",
|
||||
"source": source.id,
|
||||
"destination": dest.id
|
||||
}, function () {
|
||||
"source_alias": source.name,
|
||||
"destination": dest.id,
|
||||
"destination_alias": dest.name
|
||||
}).done(function () {
|
||||
addMsg("Le transfert de "
|
||||
+ pretty_money(source.quantity * dest.quantity * 100 * $("#amount").val()) + " de la note " + source.name
|
||||
+ " vers la note " + dest.name + " a été fait avec succès !", "success");
|
||||
|
||||
reset();
|
||||
}).fail(function (err) {
|
||||
addMsg("Le transfert de "
|
||||
+ pretty_money(source.quantity * dest.quantity * 100 * $("#amount").val()) + " de la note " + source.name
|
||||
+ " vers la note " + dest.name + " a échoué : " + err.responseText, "danger");
|
||||
$.post("/api/note/transaction/transaction/",
|
||||
{
|
||||
"csrfmiddlewaretoken": CSRF_TOKEN,
|
||||
"quantity": source.quantity * dest.quantity,
|
||||
"amount": 100 * $("#amount").val(),
|
||||
"reason": $("#reason").val(),
|
||||
"valid": false,
|
||||
"invalidity_reason": "Solde insuffisant",
|
||||
"polymorphic_ctype": TRANSFER_POLYMORPHIC_CTYPE,
|
||||
"resourcetype": "Transaction",
|
||||
"source": source.id,
|
||||
"source_alias": source.name,
|
||||
"destination": dest.id,
|
||||
"destination_alias": dest.name
|
||||
}).done(function () {
|
||||
addMsg("Le transfert de "
|
||||
+ pretty_money(source.quantity * dest.quantity * 100 * $("#amount").val()) + " de la note " + source.name
|
||||
+ " vers la note " + dest.name + " a échoué : Solde insuffisant", "danger");
|
||||
|
||||
reset();
|
||||
reset();
|
||||
}).fail(function (err) {
|
||||
addMsg("Le transfert de "
|
||||
+ pretty_money(source.quantity * dest.quantity * 100 * $("#amount").val()) + " de la note " + source.name
|
||||
+ " vers la note " + dest.name + " a échoué : " + err.responseText, "danger");
|
||||
|
||||
reset();
|
||||
});
|
||||
});
|
||||
});
|
||||
});
|
||||
@ -157,15 +203,17 @@ $("#transfer").click(function() {
|
||||
"polymorphic_ctype": SPECIAL_TRANSFER_POLYMORPHIC_CTYPE,
|
||||
"resourcetype": "SpecialTransaction",
|
||||
"source": source,
|
||||
"source_alias": source.name,
|
||||
"destination": dest,
|
||||
"destination_alias": dest.name,
|
||||
"last_name": $("#last_name").val(),
|
||||
"first_name": $("#first_name").val(),
|
||||
"bank": $("#bank").val()
|
||||
}, function () {
|
||||
}).done(function () {
|
||||
addMsg("Le crédit/retrait a bien été effectué !", "success");
|
||||
reset();
|
||||
}).fail(function (err) {
|
||||
addMsg("Le crédit/transfert a échoué : " + err.responseText, "danger");
|
||||
addMsg("Le crédit/retrait a échoué : " + err.responseText, "danger");
|
||||
reset();
|
||||
});
|
||||
}
|
||||
|
Reference in New Issue
Block a user