Now let's allow our users to update Songs. We're going to create a new modal to do this. That means, now might be a good time to take a look at the bootstrap modal documentation.
We'll create another modal in index.html
. Each time someone clicks a button to edit songs we'll populate it with the current songs' information. This won't be too hard since we're just going to replace the modal body. (on the sample: #editSongsModalBody
)
Here's a rough idea of what it could look like:
Make sure your modal's elements don't use the same ids as the other modal does. id in html must be unique!
Objectives:
- allow songs to be edited
- allow songs to be deleted
- practice more with bootstrap modal's
- Add a new modal to the page. You can build your own OR use the sample provided.
If you're using the sample, take a look at the unique ids created on the elements. We'll be using those later on.
-
Add a new button 'Edit Songs' in the panel-footer of each album row.
-
When 'Edit Songs' is clicked open the modal!
opening a modal with js
$('#fooModal').modal('show');
-
Develop a form for editing the song list. It should be able to (1) delete a song (2) edit each song. Your form will need to be put into an HTML string (write a function for this).
-
Remember that in order to do a
DELETE /api/albums/:album_id/songs/:id
or aPUT /api/albums/:album_id/songs/:id
you'll need thoseid
s. Embed them indata-
attributes in your form. -
You may want to use a
GET /api/albums/:album_id/songs
index route to get all songs for a particular album. This is likely easier than retrieving incomplete data from the page.
A sample HTML string for the form is provided for you.
-
Create the server-side routes for
DELETE /api/albums/:album_id/songs/:id
andPUT /api/albums/:album_id/songs/:id
. -
Write client-side AJAX to delete items when the delete button is clicked.
-
Make sure the deleted input is removed as well.
-
Test delete for songs.
-
Ensure that the song list on the page (the main album row that contains this song) is updated as well.
You may want to re-retrieve the songs rather than trying to parse the current album
<li>
content. It would be a good idea to make a function for this, it'll be useful in the next step.
Let's allow users to save their edits.
-
After the user clicks a 'Save' button, make an AJAX
PUT
request for the edited song. -
Update the page with the changed song.
-
Make sure you test everything.
-
Make sure the modal closes when the close button is clicked.
- Add functionality so that the user can create new songs and have them added to the list from within the modal.
-
Add a saving spinner or animation for each song when it is saving.
-
Save each song when the user leaves the input box.
-
Client-side validations: make sure trackNumbers are numbers & unique. In the form sort them by trackNumber.
-
Consider using a Bootstrap theme.
-
Consider using Font Awesome.
-
Server-side validations: make sure track-numbers are unique per album.