diff --git a/app/controllers/main/routes.py b/app/controllers/main/routes.py index 84677f6e1..ce0f1662b 100644 --- a/app/controllers/main/routes.py +++ b/app/controllers/main/routes.py @@ -387,6 +387,7 @@ def addNote(): flash("Failed to add profile note", "danger") return "Failed to add profile note", 500 + @main_bp.route('//deleteNote', methods=['POST']) def deleteNote(username): """ diff --git a/app/models/note.py b/app/models/note.py index 86c108ce1..c06e022e4 100644 --- a/app/models/note.py +++ b/app/models/note.py @@ -4,6 +4,6 @@ class Note(baseModel): createdBy = ForeignKeyField(User) createdOn = DateTimeField() - noteContent = CharField() + noteContent = TextField() isPrivate = BooleanField(default=False) noteType = CharField(null=True) diff --git a/app/static/js/userProfile.js b/app/static/js/userProfile.js index 7fe6a2c8b..61af76787 100644 --- a/app/static/js/userProfile.js +++ b/app/static/js/userProfile.js @@ -176,6 +176,9 @@ $(document).ready(function(){ $("#addNoteButton").click(function() { bonnerNoteOff() + $("#addNoteTextArea").val('') + $("#notesSaveButton").data('mode', 'add') + $("#notesSaveButton").data('noteid', null) $("#noteModal").modal("toggle") }); @@ -191,6 +194,9 @@ $(document).ready(function(){ $("#addBonnerNoteButton").click(function() { bonnerNoteOn() + $("#addNoteTextArea").val('') + $("#notesSaveButton").data('mode', 'add') + $("#notesSaveButton").data('noteid', null) $("#noteModal").modal("toggle"); }); @@ -199,6 +205,17 @@ $(document).ready(function(){ event.preventDefault() let username = $("#notesSaveButton").data('username') let isBonner = $("#bonnerInput").is(":checked") + let mode = $("#notesSaveButton").data('mode') + let noteid = $("#notesSaveButton").data('noteid') + + // If we're editing, delete the old note first + if (mode === 'edit') { + $.ajax({ + method: "POST", + url: "/" + username + "/deleteNote", + data: { "id": noteid } + }) + } $.ajax({ method: "POST", url: "/profile/addNote", @@ -218,6 +235,13 @@ $(document).ready(function(){ }); $(".deleteNoteButton").click(function() { + $("#confirmDeleteNote").data('username', $(this).data('username')) + $("#confirmDeleteNote").data('noteid', $(this).data('noteid')) + $("#deleteNoteWarning").modal("show") + + }); + + $("#confirmDeleteNote").click(function() { let username = $(this).data('username') let noteid = $(this).data('noteid') $.ajax({ @@ -225,11 +249,44 @@ $(document).ready(function(){ url: "/" + username + "/deleteNote", data: {"id": noteid}, success: function(response) { + msgFlash("Successfully deleted note", "success", 1300, true) reloadWithAccordion("notes") } }); }); + + $(".editNoteButton").click(function() { + let noteText = $(this).data('notetext') + let visibility = $(this).data('visibility') + let isBonner = $(this).data('bonner') + let noteid = $(this).data('noteid') + + + $("#addNoteTextArea").val(noteText) + $("#noteDropdown").val(visibility) + + if (isBonner === 'yes') { + bonnerNoteOn() + } else { + bonnerNoteOff() + } + + $("#notesSaveButton").data('noteid', $(this).data('noteid')) + $("#notesSaveButton").data('mode', 'edit') + + + $("#noteModal").modal("toggle") +}); + $.ajax({ + method: "POST", + url: "/" + username + "/editNote", + data: {"id": noteid}, + success: function(response) { + reloadWithAccordion("notes") + } + }); + }); /* * Background Check Functionality */ @@ -355,8 +412,8 @@ $(document).ready(function(){ typingTimer = setTimeout(saveDiet, saveInterval); }); }); + // end document.ready() -}); // end document.ready() // Update program manager status function updateManagers(el, volunteerUsername ) { diff --git a/app/templates/main/userProfile.html b/app/templates/main/userProfile.html index 0e587712e..e29db4895 100644 --- a/app/templates/main/userProfile.html +++ b/app/templates/main/userProfile.html @@ -432,12 +432,13 @@

{% else %} {{ "Bonner Scholar " if row.isBonnerNote else "Everyone"}} {% endif %} - - + {% if (g.current_user == row.note.createdBy) or g.current_user.isCeltsAdmin%} - + + {% else %} - + + {% endif %} @@ -493,7 +494,19 @@

Notes
{% if bonnerNotes|length %}
{% for row in profileNotes|selectattr("isBonnerNote") %} -
{{row.note.noteContent}} +
{{row.note.noteContent}} + + +
{{row.note.createdBy.fullName}} {{row.note.createdOn.strftime('%m/%d/%Y')}} {% endfor %}
@@ -531,7 +544,7 @@
Requirement Progress
+ + + + + +