So we have our display of new reservations and of all reservations working properly, but we're not
quite done yet.
So if I look at an individual reservation, the first thing I need to do is to put a button here.
I'm going to put it right here that will allow us to make a reservation as processed, but only if it
hasn't been processed already.
And I'm also going to want to add a button and I'll stick it way over here so it's not clicked on accidentally
that allows us to delete a reservation.
Somebody calls to cancel, says they can't make it.
So I need to delete that reservation and make sure that room is available for booking by someone else.
So to make that happen, there's a few things we need to do.
But the very first thing I'm going to be concerned with is ensuring that I have a means of displaying
messages to the user.
So we did that on the public site with our Attention and Nottie and Sweet Alert, but we never copied
the necessary JavaScript libraries or JavaScript code into our admin template.
So let's do that first just to get that out of the way.
So I'll go back to my ID and I will open the base layout.
And at the very top, first thing I'll grab is this Nottie Min.
So I'll grab that CSC file and then I'll open my admin layout and make sure I put that in here.
So I'll put it right here.
Right.
Here.
And then back in our other page, which is basically let's open that up, let's get the necessary JavaScript
libraries, we're going to need abcess, we're going to need suite alert and we're going to need Nottie.
So let's copy those and go back to admin layout and down on the JavaScript section.
We'll put that right here.
And then finally, we're going to need this code right here.
So I'll copy the first part here.
And put that right here and give it a closing script tag.
And then let's get the rest of it, the bit that gives us our notifications right here all the way down
to here.
And we'll put that right in there.
So now we have the necessary JavaScript that allows us to use our prompt JavaScript module to called
notified to give us a Nottie, alert, to give us a model, to give us an error message as success message
or a warning message.
Now, there is one other change I need to make, and that is an app jass.
And if we look at the part where we're doing a custom notification, we have this pre confirmed bid
and we don't need that anymore.
I'm going to get rid of that entirely.
We don't need it.
And that will actually cause us JavaScript errors, because every time I try to call a custom JavaScript
alert a notification of some sort, it will always look for a start an element in the model that has
an idea of start at an idiot and I'm going to get rid of those because I don't need those right in here
anymore.
So we've built that.
Now let's open our admin reservations show page and put a necessary button and I'll just set up the
buttons first and then I will put in the necessary JavaScript and handlers and everything else afterwards.
So we already have two buttons, we have a save button and we have the cancel button.
And those look like this save and cancel.
And I want a button here that's called marked as processed.
So let's put a button first.
HSF equals and I'll make it go nowhere with you using hash bang, which still makes it an active link.
But when clicking on it has no effect.
I'll get a class of button and button info and I want an unclick handler.
When I, when I click on this, I want to execute a JavaScript function which doesn't exist yet, but
we'll make it in a minute and I'll call it process revs and it will take one parameter, which will
be the reservation ID.
And I'll give it some text mark as processed, so there now I need to create the necessary JavaScript
and I'll just use the define G.S. that section we have set up in our admin template layout.
And inside of that, I'll have a script tag.
And inside that make a function.
And the function will be process rose, and it takes one parameter, which I'll call it.
Now, what do we want to do in this function?
I don't want someone to actually let's just reload the page and see what it looks like.
It looks OK when someone clicks on this.
I don't want it to just automatically mark that as processed because they might have clicked on that
button by mistake so we can take advantage of our attention, which we defined in our base and our admin
layer, which is right here.
We defined attention, which is our prompt JavaScript library or module.
So we can just say attention, custom.
And custom take some settings and icon, which I will make warning because this is a warning and then
has a message which will be something as simple as are you sure?
And then the callback.
What do I want to have happen when someone clicks the OK button but not the council button?
Well, that's going to be a function, an anonymous function which takes result, whatever they clicked
on as an argument.
And that's passed to us by Sweedler, hour by hour, hour, library.
And if they actually click on that, but not on the cancel button, if the result is not exactly equal
to faults, then I just want to take them to another URL and the URL I'm going to take them to doesn't
exist yet, but we can create window dot, location, dot, rev that says change the browser's location,
take them to this address and I'll take them to a euro admin process reservation and then I'm going
to put the source in there and we we used it up here.
If you recall, we have this source.
So I'll copy this.
This this takes the argument as passed to the JavaScript, to the goal line template and says, where
did you come from?
The Sarsae, in other words.
So I'll just put this in here.
So we have access to it in this library or in this this block of our function.
And I'll just put SIRC and then slash and then plus ID, which is the parameter pass to this JavaScript
function.
So if someone clicks on the button here, Mark is processed, it should fire an alert that has an E
message with a warning icon.
And if they click OK, it should take them to this URL, which doesn't exist yet, but we can try it
out and make sure it works.
So let's reload the page and open up the JavaScript console just to make sure we don't have any errors.
And let's see what happens.
Mark is processed, so that looks good.
Counsel should make this go away and it does.
And clicking it again, but clicking OK, should give us a page not found error because we're taking
them to a u r l that doesn't exist yet and it does.
Perfect.
So that looks good.
So this is are you, are we now we need to set that up in our roots and create the necessary handler.
So let's go back to our roots file.
And let's put this in and we got to put it in the right place, remember, are you are all that we're
trying to go to is admin's process reservations, news six.
So I want to make sure that it's actually hit.
So I'll put it right here.
Mux, don't get.
Process reservation, I don't need the admin part because that's added automatically and then the source,
which can be all or new at the moment, and then the ID and we're going to take this to a handler,
which doesn't exist yet, were created at the moment.
Handlers thought repo dot and I'll call this process reservation.
Actually, I'll call it admin process reservation just for consistency.
All right.
Now let's go create that handler.
So I'll just create it right here and I'll just copy this and change it to make it a little faster.
And I want this one to be called that mean process reservation, which should fix the problem in our
reads file.
And it does.
So now we can find it at least.
Let's give it a comment.
Marks a reservation as processed.
OK, and what do we want to do here?
We don't want to render a template, so let's delete that.
First thing we want to do is get those two things that are being passed as part of the route, the source
and the ID.
And that's easy enough.
We know how to do that.
We can just say ID and then I'll ignore the error for now is equal to this needs to be an input.
So I'll use the str conv package a Twohy and it requires a couple of requires one thing and that is
what is the string that you want to convert to anent.
So I'll just use the built in function czi Eurail Perram and it requires the RR variable which is our
request and it also requires what's the name of the key.
And in this case it's ID and then I'll duplicate this changes to SIRC.
We're not converting it to a string because it's coming as a string.
So I don't need the STR convert and this one is called SIRC and remember that ID and SIRC are these
things right here, ID NRC.
So that should give us those two pieces of information.
So now that we have those we can just call that database function that we set up in lecture ago called
update process for reservation.
So again, I'll ignore the error rate.
Now that's equal to my DB dot update process for reservation.
That requires two things the ID, which we know we already have, that we just grabbed it and what do
we want to change it to?
And here I just want to change it to one, because I'm going to mark this preservation, this reservation
as processed so I can just hard code the one.
And that's fine for our purposes right now.
Next, we want to give them some kind of feedback.
So let's put something in the session.
M dot app, dot session dot put.
And it requires the context, our context.
And what are we going to call it?
It will be a flash message because it's a success message and we'll just say reservation marked as processed
and then take them somewhere.
And here's where we use the source bit.
If they've come from the new reservations, if they got to that reservation from the new reservations
page or only reservations, we want to take them back to their if they came from all reservations,
we want to take them back there.
So htp dot redirect.
And that requires the response right to the point here, to the request and the euro.
And here all use format is print F because I want to use that source tag.
We'll take them to slash admin's reservations, dash my placeholder and substitute SIRC for that and
then give them the appropriate status http dot status c other and that should work.
So let's try this out so we'll go back and stop our application.
If it's running it is clear the screen run this.
It compiled and what I'm going to do now is go back to this screen Reloaded and I'm going to clear this
and I'm going to turn on the inspector and I'm going to turn that on for a particular reason.
OK, we're looking at this, the screen right now.
Watch this little bit and see if I can get this a little actually show up.
We should when I mark as processed, if we got everything right, it should give us a nodi alert.
So let's see if it does.
So there it is showing up here.
This is great that that's been added, that's the.
Are you sure?
I'll click, OK.
And it actually gave us that Nodi alert and then it disappeared, as it should, but it was there,
but we never saw it.
Why was that?
Well, there's a very simple reason for that.
It actually did display the Nodi Alert and hopefully you saw that flash in and out.
If not, roll back the video a little bit and you'll see that a little d'Hiv appeared and then it disappeared.
And we need to actually change in our admin layout page a little bit of success because it showed that
Sweedler are that that Nodi alert, but it showed it behind everything else.
The Z index needs to be changed so we can do that easily enough.
All we need to do is go back to our success for the admin layout.
So let's open this up.
And at the very top where we have this little bit, we need to add another directive here and it's going
to be for anything with a Class of Nottie container, which I saw from that little thing that popped
up.
Let's just change it Z index to something really high and I'll put 50000.
And that should do it.
So now if I come back here and reload this page, we're going to click on the link, which is a new
reservation ID for Lois Lane.
We're going to mark this as processed and we'll say, OK, and now it shows up properly, except that
I have a zero ID in the word reservation, so I'm going to go fix that.
And Lane disappeared from new reservations, but should still show up in all reservations.
And there it is.
So this seems to be working really well.
Let's just go fix that one typo I had in my handler, which was right here.
Reservation, get rid of the zero.
Good.
OK, so that's all set up in the next lecture.
We'll do the same thing for the delete a reservation bit.
And that's pretty straightforward.