Let's allow users to edit album information.
This sprint we will:
- make it so users can edit each album
- add a
PUT /api/albums/:id
route to the server
Note: if you get stuck going through this, make use of the hints, your neighbors, and the solutions for sprint 5.
You must complete all of the previous sprint before starting this sprint (excluding stretch challenges).
In this sprint, you will probably notice the instructions are more succinct; we're hoping that you're starting to feel more comfortable and developing more resourcefulness and independence. Still, if you get stuck, it's ok to ask for help.
We're going to add a button that allows our users to edit an album.
- Add a new button to each
panel-footer
in the album template string.
<button class='btn btn-info edit-album'>Edit Album</button>
-
Use jQuery to react to clicks on these buttons and determine the correct
album-id
. Thenconsole.log
it. -
When the
Edit
button is clicked, replace it with aSave Changes
button. Remember to reverse this change when the edit is finished. -
Also replace the major fields on the album with
input
elements.
Hint: you could have 2 buttons in place already, 1) "Edit", 2) "Save changes" and simply toggle their visibility with $.toggle
Note: this step could be a little tricky, especially if you want to display the current values in the input fields. You'll have to get the text from the page, then replace the text with input elements.
-
When
Save Changes
is clicked, handle that event on the client side. -
Prepare an AJAX call to the server at
PUT /api/albums/:id
.
-
Add the
app.put
method for the/api/albums/:id
path on the server. -
Use the album controller's
update
method as the callback. Ensure that it updates the album in the database.
-
Make any final changes to your AJAX, and test everything.
-
Make sure you are removing the form fields and replacing them with updated data from the server.
- You should do this when you get a response to your PUT request.
- Use the response data from the PUT request.
Hint: you already have a render function
-
When one album edit is in progress, disable or hide the other edit buttons.
-
Add a new modal for editing instead of letting the user make changes directly in the album row.
-
Add a cancel button for the edits.