can delete referral

This commit is contained in:
Son NK 2020-05-02 18:14:09 +02:00
parent 1667356742
commit eff0eb9e32
2 changed files with 46 additions and 0 deletions

View file

@ -69,6 +69,14 @@
Just append <em>?slref={{ referral.code }}</em> to any link on SimpleLogin website.
</div>
<div>
<form method="post">
<input type="hidden" name="form-name" value="delete">
<input type="hidden" name="referral-id" value="{{ referral.id }}">
<span class="delete-referral float-right btn btn-outline-danger">Delete</span>
</form>
</div>
</div>
{% endfor %}
@ -83,4 +91,33 @@
<button class="btn btn-success mt-2">Create a new referral code</button>
</form>
</div>
{% endblock %}
{% block script %}
<script>
$(".delete-referral").on("click", function (e) {
let that = $(this);
bootbox.confirm({
message: "This operation is irreversible, please confirm.",
buttons: {
confirm: {
label: 'Yes, delete it',
className: 'btn-danger'
},
cancel: {
label: 'Cancel',
className: 'btn-outline-primary'
}
},
callback: function (result) {
if (result) {
that.closest("form").submit();
}
}
})
});
</script>
{% endblock %}

View file

@ -39,6 +39,15 @@ def referral_route():
flash("Referral name updated", "success")
return redirect(
url_for("dashboard.referral_route", highlight_id=referral.id)
)
elif request.form.get("form-name") == "delete":
referral_id = request.form.get("referral-id")
referral = Referral.get(referral_id)
if referral and referral.user_id == current_user.id:
Referral.delete(referral.id)
db.session.commit()
flash("Referral deleted", "success")
return redirect(url_for("dashboard.referral_route"))
# Highlight a referral
highlight_id = request.args.get("highlight_id")