Now let's allow our users to edit the Album info.
This sprint we will:
- make it so users can edit each Album
- add a
PUT /api/albums/:id
route to the server
Note: as we go through this if you get stuck make use of the hints, your neighbors and the solutions.
You must complete all of the previous sprint before starting this sprint. (excludes stretch challenges)
In this sprint you might notice that our instructions are getting a little 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 a friend or your friendly neighborhood DIR, or instructor.
We're going to add a button that allows our users to edit an album.
- Add a new button to each panel-footer
<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
.console.log
it. -
Replace the
Edit
button with aSave Changes
button when clicked. -
Also replace the major fields on the Album with
input
elements.
Confused? How about a wire-frame from the UX department to sort things out:
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. You also have to worry about swapping
-
When
Save Changes
is clicked, react to it. -
Prepare an AJAX call to the server at
PUT /api/albums/:id
.
-
Add the
app.put
method on the server. -
Connect it to 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, ね(ne)?
-
When an edit is in progress disable or hide the other buttons.
-
Add a new modal instead of making changes directly in the album row.
-
Add a cancel button for the edits