-
{{ contact.website_email }}
- {% if contact.pgp_finger_print %}
-
🗝
- {% endif %}
+
+
+ {{ contact.website_email }}
+ {% if contact.pgp_finger_print %}
+ 🗝
+ {% endif %}
+
+
+
+
+
@@ -216,8 +237,45 @@
}
}
})
-
-
});
+
+ $(".enable-disable-contact").change(async function () {
+ let contactID = $(this).data("contact");
+ let contactEmail = $(this).data("contact-email");
+
+ await blockContact(contactID, contactEmail);
+ })
+
+ async function blockContact(contactID, contactEmail) {
+ let oldValue;
+ try {
+ let res = await fetch(`/api/contacts/${contactID}/toggle`, {
+ method: "POST",
+ headers: {
+ "Content-Type": "application/json",
+ }
+ });
+
+ if (res.ok) {
+ let json = await res.json();
+
+ if (json.block_forward) {
+ toastr.success(`${contactEmail} is blocked`);
+ } else {
+ toastr.success(`${contactEmail} is unblocked`);
+ }
+ } else {
+ toastr.error("Sorry for the inconvenience! Could you refresh the page & retry please?", "Unknown Error");
+ // reset to the original value
+ oldValue = !$(this).prop("checked");
+ $(this).prop("checked", oldValue);
+ }
+ } catch (e) {
+ toastr.error("Sorry for the inconvenience! Could you refresh the page & retry please?", "Unknown Error");
+ // reset to the original value
+ oldValue = !$(this).prop("checked");
+ $(this).prop("checked", oldValue);
+ }
+ }
{% endblock %}
\ No newline at end of file