Skip to content

Commit

Permalink
Supported deleting grouped as well as one Note(s) on manage Notes page
Browse files Browse the repository at this point in the history
  • Loading branch information
k-joseph committed Jun 18, 2015
1 parent 6b427fd commit ec7e80e
Show file tree
Hide file tree
Showing 3 changed files with 110 additions and 6 deletions.
Expand Up @@ -396,7 +396,7 @@ public JSONArray fetchAllNotesForManageUI(boolean wholePageIsToBeLoaded) {

for (ChartSearchNote note : allNotes) {
JSONObject json = new JSONObject();
if (note.getNoteOwner().getUserId().equals(Context.getAuthenticatedUser().getUserId())) {//manage owned notes only
if (note.getNoteOwner().getUserId().equals(Context.getAuthenticatedUser().getUserId()) && null != note) {//manage owned notes only

This comment has been minimized.

Copy link
@dkayiwa

dkayiwa Jun 18, 2015

Member

why don't you say note != null?

This comment has been minimized.

Copy link
@k-joseph

k-joseph Jun 18, 2015

Author Member

I have changed this,

json.put("uuid", note.getUuid());
json.put("createdOrLastModifiedAt", note.getCreatedOrLastModifiedAt().getTime());
json.put("backgroundColor", note.getDisplayColor());
Expand All @@ -415,6 +415,18 @@ public JSONArray fetchAllNotesForManageUI(boolean wholePageIsToBeLoaded) {
return jsonArr;
}

public JSONArray deleteSelectedNotes(String[] uuids) {

This comment has been minimized.

Copy link
@dkayiwa

dkayiwa Jun 18, 2015

Member

Can you add some javadoc to the new methods?

This comment has been minimized.

Copy link
@k-joseph

k-joseph Jun 18, 2015

Author Member

Alright, i will go through them adding some java-docs later-on, i tried as much i could to make the methods and variables easy to understand on-reading to limit having to write so many javadocs

This comment has been minimized.

Copy link
@dkayiwa

dkayiwa via email Jun 18, 2015

Member
if (uuids != null && uuids.length != 0) {
for (int i = 0; i < uuids.length; i++) {
ChartSearchNote note = chartSearchService.getSearchNoteByUuid(uuids[i]);
if (note != null) {
chartSearchService.deleteSearchNote(note);
}
}
}
return fetchAllNotesForManageUI(false);
}

private <T> T getComponent(Class<T> clazz) {
List<T> list = Context.getRegisteredComponents(clazz);
if (list == null || list.size() == 0)
Expand Down
Expand Up @@ -9,8 +9,11 @@
*/
package org.openmrs.module.chartsearch.fragment.controller;

import net.sf.json.JSONArray;

import org.openmrs.module.chartsearch.ChartSearchCache;
import org.openmrs.ui.framework.fragment.FragmentModel;
import org.springframework.web.bind.annotation.RequestParam;

public class ManageNotesFragmentController {

Expand All @@ -20,4 +23,7 @@ public void controller(FragmentModel fragmentModel) {
fragmentModel.addAttribute("allFoundNotes", cache.fetchAllNotesForManageUI(true).toString());
}

public JSONArray deleteSelectedNotes(@RequestParam("selectedUuids[]") String[] selectedUuids) {
return cache.deleteSelectedNotes(selectedUuids);
}
}
96 changes: 91 additions & 5 deletions omod/src/main/webapp/fragments/manageNotes.gsp
@@ -1,5 +1,12 @@
<style type="text/css">
#notes-grouped-functionality {
float:right;
}
.m-notes-actions {
cursor:pointer;
}
</style>


Expand All @@ -10,22 +17,54 @@
jq(document).ready(function(event) {
displayExistingNotes();
jq("body").on("click", "#manage-notes-display", function(event) {
if(event.target.id === "select-all-notes") {
checkOrUnAllOtherCheckBoxesInADiv("#manage-notes-display", "select-all-notes");
}
if(event.target.className.indexOf("m-notes-actions") >= 0) {
//TODO either purform a delete or a save functionality here
if(event.target.id) {
if(confirm("Do you really want to delete this Note?")) {
deleteSelectedNotes(event.target.id);
} else {
//Do nothing
}
} else {
if(confirm("Have you finished Editing?")) {
//TODO save the edited Note
}
}
}
});
jq("table").on('mouseenter', 'tr', function(event) {
if(event.delegateTarget.id === "manage-notes-display-table" && event.target.localName !== "th") {
jq(this).css('background', '#F0EAEA');
}
}).on('mouseleave', 'tr', function () {
jq(this).css('background', '');
});
jq("#delete-selected-notes").click(function(event) {
deleteSelectedNotes();
});
function displayExistingNotes() {
var displayNotes;
if(notesAfterparse && notesAfterparse.length !== 0) {
displayNotes = "<tr><th><input type='checkbox' id='select-all-notes' style='width:55%;height:1.5em;'/>Patient</th><th>Search Phrase</th><th>Comment/Note</th><th>Priority</th><th>Last Updated</th></tr>";
displayNotes = "<tr><th><input type='checkbox' id='select-all-notes' style='width:55%;height:1.5em;'/>Patient</th><th>Search Phrase</th><th>Comment/Note</th><th>Priority</th><th>Last Updated</th><th>Action</th></tr>";
for(i = 0; i < notesAfterparse.length; i++) {
var note = notesAfterparse[i];
if(note) {
if(note && note.searchPhrase) {
var uuid = note.uuid;
var patient = "<td><input type='checkbox' class='select-this-note' id='" + uuid + "' style='width:55%;height:1.5em;'/>" + note.patientFName + "</td>";
var phrase = "<td>" + note.searchPhrase + "</td>";
var comment = "<td><textarea class='m-notes-comment' style='width: 488px;'>" + note.comment + "</textarea></td>";
var comment = "<td><textarea class='m-notes-comment' style='width: 488px;height:80px;'>" + note.comment + "</textarea></td>";
var priority = setPriorityDisplay(note.priority);
var date = new Date(note.createdOrLastModifiedAt);
displayNotes += "<tr>" + patient + phrase + comment + priority + "<td>" + date.toString() + "</td></tr>";
displayNotes += "<tr>" + patient + phrase + comment + priority + "<td>" + date.toString() + "</td><td><i class='icon-remove medium m-notes-actions' id='" + uuid + "'><i class='icon-save medium m-notes-actions'></td></tr>";
}
}
}
Expand All @@ -49,6 +88,50 @@
return priorityDisplay;
}
function deleteSelectedNotes(onlyOneNoteUuid) {
var selectedUuids = returnUuidsOfSeletedNotes(onlyOneNoteUuid);
if(selectedUuids.length !== 0) {
if(onlyOneNoteUuid || (!onlyOneNoteUuid && confirm("Are you sure you want to delete " + selectedUuids.length + " items?"))) {
jq.ajax({
type: "POST",
url: "${ ui.actionLink('deleteSelectedNotes') }",
data: {"selectedUuids":selectedUuids},
dataType: "json",
success: function(remainingNotes) {
notesAfterparse = remainingNotes;
displayExistingNotes();
alert("Successfully Saved Note");
},
error: function(e) {
}
});
} else {
//do nothing
}
} else {
alert("No selected Note to be Deleted");
}
}
function returnUuidsOfSeletedNotes(onlyOneNoteUuid) {
var selectedUuids = [];
if(onlyOneNoteUuid) {
selectedUuids.push(onlyOneNoteUuid);
} else {
jq('#manage-notes-display input:checked').each(function() {
var selectedId = jq(this).attr("id");
if(selectedId !== "select-all-notes") {
selectedUuids.push(selectedId);
}
});
}
return selectedUuids;
}
});
</script>
Expand All @@ -61,6 +144,9 @@


<h1>Manage Notes</h1>
<div id="notes-grouped-functionality">
<input type="button" id="delete-selected-notes" value="Delete Selected"/>
</div><br /><br />
<div id="manage-notes-display">
<table id="manage-notes-display-table"></table>
</div>

0 comments on commit ec7e80e

Please sign in to comment.