diff --git a/app/profile/routes.py b/app/profile/routes.py index 85a68feb..60eef6ad 100644 --- a/app/profile/routes.py +++ b/app/profile/routes.py @@ -33,7 +33,7 @@ def profile(user_id): abort(403) return render_template( 'profile/profile.html.j2', - user=user.to_json_serializeable(), + user=user.to_json_serializeable() ) diff --git a/app/static/js/Utils.js b/app/static/js/Utils.js index 899147b4..c38c5620 100644 --- a/app/static/js/Utils.js +++ b/app/static/js/Utils.js @@ -227,6 +227,54 @@ class Utils { }); } + static deleteProfileAvatarRequest(userId) { + return new Promise((resolve, reject) => { + let modalElement = Utils.elementFromString( + ` + + ` + ); + document.querySelector('#modals').appendChild(modalElement); + let modal = M.Modal.init( + modalElement, + { + dismissible: false, + onCloseEnd: () => { + modal.destroy(); + modalElement.remove(); + } + } + ); + + let confirmElement = modalElement.querySelector('.action-button[data-action="confirm"]'); + confirmElement.addEventListener('click', (event) => { + fetch(`/profile/${userId}/avatar`, {method: 'DELETE', headers: {Accept: 'application/json'}}) + .then( + (response) => { + if (response.status === 403) {app.flash('Forbidden', 'error'); reject(response);} + if (response.status === 404) {app.flash('Not Found', 'error'); reject(response);} + app.flash(`Avatar marked for deletion`); + resolve(response); + }, + (response) => { + app.flash('Something went wrong', 'error'); + reject(response); + } + ); + }); + modal.open(); + }); + } + static deleteJobRequest(userId, jobId) { return new Promise((resolve, reject) => { let job = app.data.users[userId].jobs[jobId]; diff --git a/app/templates/profile/edit_profile.html.j2 b/app/templates/profile/edit_profile.html.j2 index b789e265..5e299262 100644 --- a/app/templates/profile/edit_profile.html.j2 +++ b/app/templates/profile/edit_profile.html.j2 @@ -71,7 +71,7 @@ {% if user.avatar %} user-image {% else %} - user-image + user-image {% endif %}
@@ -79,7 +79,7 @@
@@ -111,83 +111,44 @@
{% endblock page_content %} -{% block modals %} - -{% endblock modals %} - {% block scripts %} {{ super() }} {% endblock scripts %}