So this time around, we want to make one change here on the search for availability page to prevent
people from choosing dates in the past.
So as I'm recording this, it is November the 20th, 2020.
Therefore, I should not be able to make a reservation from, let's say, will allow them to do it for
today, but not for any day in the past.
And there's a really simple way to do that.
So let's go look at the template for this page, which is right here.
This is the search availability page.
And I have at the bottom the JavaScript that actually gives us our dice date picture.
So that was our vanilla just date picture.
So let's go look at the documentation for that which is right here, and that's the URL.
So on the left hand side, we have options and one of those options is actually mindstate.
And if we look at that, it says this is a type of string date or no, it'll take any of those.
It defaults to no minimum limit to selectable date, no limit is applied.
If null is set, incents null is the default.
And we didn't specify anything else.
It lets us choose any date, but it looks like all I have to do is go back to my JavaScript and give
it another option Monday.
And I want that to be today's date.
So I'll just use the built in JavaScript that says new.
Date and put a comma after it, so it satisfies the syntax requirements and that is today's date and
time.
So if we put this in here and go back and reload this page over here, that should prevent me from choosing
yesterday or anything before that.
And it does.
They're all great out.
I can still choose today or any date in the future, but I can't I can't choose a date in the past.
These are great out, not because they're disabled, but because it's the next month.
If I go to December now, they're all lit up and January is great, but still selectable.
And that's exactly what I want.
And it does the same thing in the departure date.
Perfect.
So that's the first thing we wanted to do.
The next thing we wanted to do.
And I'll just choose a date in January, January the 4th to January the 5th, because I know there's
no restrictions there.
I don't think there is any way we're about to find out.
The next thing we want to fix is this part where I fill out some information here.
This screen I need to show the arrival date and the departure date, which is no problem, I have that
information and I also want to display the wrong name.
And later on, we're going to send some e-mail notifications, one to the property owner to indicate
to him or her that there is, in fact, a new reservation and a receipt off to the person making the
reservation.
But we won't get to that until we get to email.
And that's a little ways away.
We will get there.
All right.
So how am I going to fix this?
Well, let's go back to our code and let's look at the reservation summary page.
Here it is.
This is the template for the reservation summary.
And currently I'm displaying arrival and departure, but not putting anything in there.
OK.
The second thing I'm going to do or the next thing I'm going to do is I'll just put in the room name
right here.
So I'll put in a neuro for the table, a new column room, and I'll just leave this empty for right
now.
So we need to somehow get information for arrival and departure.
Well, we already have the reservation, so I could put the reservation start date and the reservation
and date down here.
But again, they're not in the right format.
So let's go back to our handlers.
I'll just find the correct handler by displaying the route.
So here's the reservation summary function.
And what I'm doing here is pulling the reservation out of the session.
So what's in the session right now?
What's the step right before reservation summary.
Let's go back here and make sure we have the correct information in the the session.
So I'm just gonna go back here and look at post reservation.
So what I do the post reservation, I'm actually pulling I'm pulling nothing out of the session here.
And actually I'm actually doing is at some point before this, I have a reservation in the session,
but I seem to be rebuilding it from the ground up, which is probably not the best idea.
So let me go to the step before this one, which is actually reservation when I make this reservation
here.
I'm pulling a reservation out of the session.
I'm getting the Rambhai ID, I'm storing the name of the room in the reservation.
OK, so at this point, it would seem to make more sense to since we've already updated our reservation
model, why don't we store that in the session with the room name attached to it?
So let's do that.
So what I'm going to do is say M dot app, dot session, dot put and I'll put in the context, argt
context.
Then I need my, my key for the session and I'll use exactly what I'm using up here reservation.
And now I'll store my updated reservation, which I called Redds.
So now that's in the session.
So this one will have the start date, it will have the end date and it will have the room name and
I probably should put the remedy in there as well.
Yeah, let me just put the remedy in there, because I'm actually searching for I've got the remedy.
So the Reds remedies already in there.
Good.
So that's good.
So now I have an updated version of the session of the reservation model in the session.
So let's go back to post reservation and here let's pull that out of the session.
So, Rez.
And OK, are assigned the value of M dot app, dot session dot yet and the context are context and the
key, which is reservation.
And then cast that to type models dot reservation, if not OK.
And right now, I'll just say helper's server error error.
We're going to clean this.
We're doing this and a lot of places, this helper server error errors, new errors and you can't get
from session.
We're doing this helper's dot server error and quite a few places.
And when we get our next past testing, when we update our tests, you take advantage of all the things
we've been doing since the last time we worked on them.
We're actually going to change this.
But for right now, let's just put it in here just so we can get this part done.
So now I have a reservation and that's got the remedy, the wrong name, the start date and the end
date.
So when I come down here, I formed a start date are formed again.
I think this is in the wrong spot post reservation.
Actually don't need those at this point, do I?
Let's just keep going and find out so we have our start date, we have our end date and down here we
have a reservation.
So the only thing I want to do here is update my reservation.
So let's just leave this one alone for right now and just update our reservation.
We want to update our reservation with first name is equal to our form.
Get first name.
And then last name,
which will make last name.
And then foam, which is foam.
And then email.
Which is email.
Everything else should be good to go, so I don't even need this anymore, so let's just hide that and
change the name of this to.
Reservation.
So here reservation and down here will change this to reservation as well, I'll just copy and paste
reservation, reservation, reservation, reservation and do I need all of this?
All I'm doing here is parsing those dates, but I've already got those dates, Daury.
I think so let's comment this out, and I don't need this right now, so let's comment that a.
OK, so let's see if we've got this right, we have a reservation, we pull it from the session, that
reservation has the start date, the end date, the remedy in the room name.
OK, then down here I update my reservation model to have the first name, the last name, the phone
in the email.
Perfect.
And there should be needs to be commented to and then we do our validation.
If it is valid, we insert the reservation and now let's put in our our reservation back in the session.
Emden Apte session dot put our on context.
Reservation, reservation, I think that'll work.
And now here for this restriction, we don't want this start date.
We want to go to the reservation start date.
And this one, we want reservation and date.
And now we can get a remedy from that model as well.
Reservation dot remedy that seems cleaner.
All right.
And then we insert our reservation and I see I already did the reservation down here so I can pull it
out of here.
We don't see no sense in putting in this session twice.
I think that'll work.
So if that works, then there's only one other thing left to do.
Let's just see up here where I commented some things out.
I'm going to take this.
Where is it?
No, it's all right, let's just go with that.
OK, so from here now, I want to go.
So this is the handler that actually post the reservation.
Great.
So I've now posted my reservation.
I've entered my restriction into the database.
I've entered my my reservation into the database.
I've updated my reservation and stuck it in the session.
So now I want to display my reservation summary page.
So let's go back to our roots, find the reservation summary page here.
I pulled my reservation out.
That's great.
The only other thing left to do is to create a street map and put dates in a format that we can display.
And we know how to do that.
So we can say start date, which is just going to be a string, is going to be equal to reservation
start date dot format 2006, 01 02.
I think that's what it was.
And then end date will be Eddie and this becomes end date.
And now we make our string map.
String map is a sign the value of make a map string string and put our start and end date formatted
in this format into that string map.
String map start date is equal to SD for start date and I'll duplicate that and change this one to end
date and make that the end date and then pass my string that.
And that's string wrap.
All right, so that should work for this.
Now we go update a reservation summary page and now I can just go because I have the reservation.
I'm getting it right here.
I can just go rez, dot room, dot room name and arrival is from the string map index dot index dot
string map start underscore date and I'll copy that.
And pasted in here and change that to end it.
All right, let's see if it compiles.
So open our terminal, clear the screen
run.
It comp. Let's go back to our Web browser and choose some other date, and I'll choose a date in March
because I know there's nothing in March there, so.
March the 9th to March the 10th search, major suite and first last email at email, dotcom and some
phone number and hopefully this'll work and it did.
There's the correct date, March the 9th to March the 10th, and there's the major suite.
Perfect.
All right.
Now let's go back and clean up a little bit and get rid of all the stuff I've commented out.
So that would be under handlers.
And somewhere in here, I have a whole bunch of comments, so I'll just get it this way.
Let's go to post reservation.
There it is.
So I don't need any of this anymore.
I don't need any of this anymore.
And I think that might be it, it is all right, so now we have the ability to make a reservation by
searching availability for all rooms.
So the next step is to go back to our site and look at the individual rooms.
And right now, I have this check check availability, but that doesn't do very much.
It fires off a request in the background using Ajax to our server, and it just returns a hardcoded
value right now.
So we need to modify the handler that is called by that AJAX to actually perform a search by room using
the database function we already have.
And we need to modify our JavaScript on this page to determine what to do based upon the nature of the
response that comes in.
So we'll do that in the next lecture or two.