Implemented edit and update for entries.
- Added ts_entry:delete/1 to delete an entry from the database. - Implemented ts_api:delete_entry/3. - Added a form to facilitate editing individual entries. - Moved the small show/hide functions directly into the HTML. - Wired up the update timeline form. - Wired up the edit and update entry form.
This commit is contained in:
97
www/js/ts.js
97
www/js/ts.js
@ -25,6 +25,9 @@ $(document).ready(function(){
|
||||
buttons: { Login: function(){login()} }
|
||||
});
|
||||
|
||||
// TODO: add a hook to AJAX requests to check for 401 unauth
|
||||
// and re-display the login dialog.
|
||||
|
||||
// try to load user information for an authenticated user
|
||||
$.ajax({
|
||||
url: "/ts_api/users/",
|
||||
@ -109,6 +112,7 @@ function loadUser(username) {
|
||||
// update the timeline display
|
||||
$("#timeline-name").text(activeTimeline.timeline_id + " |");
|
||||
$("#timeline-desc").text(activeTimeline.description);
|
||||
$("#timeline-desc-input").val(activeTimeline.description);
|
||||
|
||||
// TODO: populate the drop-down list for the available timeline
|
||||
// choices
|
||||
@ -205,27 +209,12 @@ function displayOlderEntries(entries) {
|
||||
});
|
||||
}
|
||||
|
||||
/* Show/hide the editable user-info panel. */
|
||||
function toggleUserInfo(event) {
|
||||
$("#user-info").slideToggle("slow");
|
||||
event.preventDefault();
|
||||
}
|
||||
|
||||
/* Show/hide the password change controls. */
|
||||
function showChangePwd(event) { $("#change-pwd").slideToggle("slow"); }
|
||||
|
||||
/* Update the user information based on the editable user-info panel. */
|
||||
function updateUser(event) {
|
||||
alert("TODO: update user via AJAX.");
|
||||
event.preventDefault();
|
||||
}
|
||||
|
||||
/* Show/hide the editable timeline-info panel. */
|
||||
function toggleTimelineInfo(event) {
|
||||
$("#timeline-info").slideToggle("slow");
|
||||
event.preventDefault();
|
||||
}
|
||||
|
||||
/* Show the change timeline menu. */
|
||||
function showTimelineMenu(event) {
|
||||
alert("TODO: show other timelines via a popup menu");
|
||||
@ -234,22 +223,24 @@ function showTimelineMenu(event) {
|
||||
|
||||
/* Update the timeline details based on the editable timeline-info panel. */
|
||||
function updateTimeline(event) {
|
||||
alert("TODO: update timeline via AJAX.");
|
||||
event.preventDefault();
|
||||
}
|
||||
var desc = $("#timeline-desc-input").val();
|
||||
|
||||
/* Show/hide the add notes panel. */
|
||||
function showNewNotes(event) { $("#add-notes").slideToggle("slow"); }
|
||||
$.ajax({url: "/ts_api/timelines/" + user.username
|
||||
+ "/" + activeTimeline.timeline_id,
|
||||
type: "POST",
|
||||
data: JSON.stringify({desc: desc, created: activeTimeline.created}),
|
||||
|
||||
function toggleEntryNotes(event, entryId) {
|
||||
var selector = "#" + entryId + " .entry-notes";
|
||||
$(selector).slideToggle("slow");
|
||||
event.preventDefault();
|
||||
}
|
||||
error: function(jqXHR, textStatus, error) {
|
||||
// TODO: better error handling
|
||||
alert("Error updating timeline: \n" + jqXHR.responseText); },
|
||||
|
||||
success: function(data, testStatus, jqXHR) {
|
||||
// TODO: check for appropriate data.status value
|
||||
|
||||
// update display
|
||||
$("#timeline-desc").text(data.timeline.description);
|
||||
}});
|
||||
|
||||
function editEntry(event, entryId) {
|
||||
var selector = "#" + entryId;
|
||||
alert("TODO: implement edit entry. Called for '" + selector + "'");
|
||||
event.preventDefault();
|
||||
}
|
||||
|
||||
@ -293,9 +284,59 @@ function newEntry(event) {
|
||||
event.preventDefault();
|
||||
}
|
||||
|
||||
function toggleEditEntry(event, entryId) {
|
||||
$("#entry-" + entryId + " .entry-display").toggle();
|
||||
$("#entry-" + entryId + " .entry-edit").toggle();
|
||||
event.preventDefault();
|
||||
}
|
||||
|
||||
function updateEntry(event, entryId) {
|
||||
|
||||
var mark = $("#entry-" + entryId + "-mark-input").val();
|
||||
var notes = $("#entry-" + entryId + "-notes-input").val();
|
||||
var timestamp = getUTCTimestamp(); // TODO: define and read from input element
|
||||
|
||||
var payload = JSON.stringify(
|
||||
{ mark: mark, notes: notes, timestamp: timestamp });
|
||||
|
||||
$.ajax({url: "/ts_api/entries/" + user.username
|
||||
+ "/" + activeTimeline.timeline_id
|
||||
+ "/" + entryId,
|
||||
type: "POST",
|
||||
data: payload,
|
||||
|
||||
error: function(jqXHR, textStatus, error) {
|
||||
// TODO: error handling
|
||||
alert("Error updating entry: \n" + jqXHR.responseText); },
|
||||
|
||||
success: function(data, textStatus, jqXHR) {
|
||||
// TODO: check that data.status is appropriate
|
||||
|
||||
// update the entry display
|
||||
$("#entry-" + entryId + " .entry-mark").text(data.entry.mark);
|
||||
$("#entry-" + entryId + " .entry-notes").text(data.entry.notes);
|
||||
}});
|
||||
|
||||
toggleEditEntry(event, entryId);
|
||||
}
|
||||
|
||||
/* Delete an entry. */
|
||||
function deleteEntry(event, entryId) {
|
||||
$.ajax({url: "/ts_api/entries/" + user.username
|
||||
+ "/" + activeTimeline.timeline_id
|
||||
+ "/" + entryId,
|
||||
type: "DELETE",
|
||||
|
||||
error: function(jqXHR, textStatus, error) {
|
||||
// TODO: error handling
|
||||
alert("Error updating entry: \n" + jqXHR.responseText); },
|
||||
|
||||
success: function(data, textStatus, jqXHR) {
|
||||
$("#entry-" + entryId).slideUp('slow',
|
||||
function() {$("#entry-" + entryId).remove(); });
|
||||
}});
|
||||
|
||||
event.preventDefault();
|
||||
}
|
||||
|
||||
/* Generate a UTC timestamp string in ISO format.
|
||||
|
Reference in New Issue
Block a user