1
00:00:00,780 --> 00:00:07,620
So this time around, we want to make one change here on the search for availability page to prevent

2
00:00:07,620 --> 00:00:09,820
people from choosing dates in the past.

3
00:00:09,840 --> 00:00:13,280
So as I'm recording this, it is November the 20th, 2020.

4
00:00:13,290 --> 00:00:18,420
Therefore, I should not be able to make a reservation from, let's say, will allow them to do it for

5
00:00:18,420 --> 00:00:20,730
today, but not for any day in the past.

6
00:00:21,180 --> 00:00:23,270
And there's a really simple way to do that.

7
00:00:23,280 --> 00:00:26,940
So let's go look at the template for this page, which is right here.

8
00:00:26,970 --> 00:00:28,890
This is the search availability page.

9
00:00:29,190 --> 00:00:34,810
And I have at the bottom the JavaScript that actually gives us our dice date picture.

10
00:00:34,890 --> 00:00:36,860
So that was our vanilla just date picture.

11
00:00:36,870 --> 00:00:42,230
So let's go look at the documentation for that which is right here, and that's the URL.

12
00:00:43,440 --> 00:00:50,130
So on the left hand side, we have options and one of those options is actually mindstate.

13
00:00:50,820 --> 00:00:55,920
And if we look at that, it says this is a type of string date or no, it'll take any of those.

14
00:00:56,280 --> 00:01:00,780
It defaults to no minimum limit to selectable date, no limit is applied.

15
00:01:00,780 --> 00:01:03,300
If null is set, incents null is the default.

16
00:01:03,300 --> 00:01:04,860
And we didn't specify anything else.

17
00:01:05,190 --> 00:01:11,100
It lets us choose any date, but it looks like all I have to do is go back to my JavaScript and give

18
00:01:11,100 --> 00:01:12,780
it another option Monday.

19
00:01:13,020 --> 00:01:14,820
And I want that to be today's date.

20
00:01:14,820 --> 00:01:17,610
So I'll just use the built in JavaScript that says new.

21
00:01:19,430 --> 00:01:26,090
Date and put a comma after it, so it satisfies the syntax requirements and that is today's date and

22
00:01:26,090 --> 00:01:26,470
time.

23
00:01:26,480 --> 00:01:34,640
So if we put this in here and go back and reload this page over here, that should prevent me from choosing

24
00:01:34,640 --> 00:01:36,380
yesterday or anything before that.

25
00:01:37,010 --> 00:01:37,840
And it does.

26
00:01:38,000 --> 00:01:39,020
They're all great out.

27
00:01:39,020 --> 00:01:43,720
I can still choose today or any date in the future, but I can't I can't choose a date in the past.

28
00:01:43,730 --> 00:01:46,730
These are great out, not because they're disabled, but because it's the next month.

29
00:01:46,730 --> 00:01:51,790
If I go to December now, they're all lit up and January is great, but still selectable.

30
00:01:51,800 --> 00:01:52,880
And that's exactly what I want.

31
00:01:53,210 --> 00:01:55,330
And it does the same thing in the departure date.

32
00:01:55,340 --> 00:01:55,820
Perfect.

33
00:01:55,980 --> 00:01:57,640
So that's the first thing we wanted to do.

34
00:01:58,130 --> 00:01:59,600
The next thing we wanted to do.

35
00:01:59,600 --> 00:02:05,060
And I'll just choose a date in January, January the 4th to January the 5th, because I know there's

36
00:02:05,060 --> 00:02:06,080
no restrictions there.

37
00:02:06,080 --> 00:02:08,120
I don't think there is any way we're about to find out.

38
00:02:08,900 --> 00:02:13,670
The next thing we want to fix is this part where I fill out some information here.

39
00:02:17,630 --> 00:02:22,910
This screen I need to show the arrival date and the departure date, which is no problem, I have that

40
00:02:22,910 --> 00:02:26,300
information and I also want to display the wrong name.

41
00:02:26,300 --> 00:02:30,920
And later on, we're going to send some e-mail notifications, one to the property owner to indicate

42
00:02:30,920 --> 00:02:36,620
to him or her that there is, in fact, a new reservation and a receipt off to the person making the

43
00:02:36,620 --> 00:02:37,220
reservation.

44
00:02:37,250 --> 00:02:38,990
But we won't get to that until we get to email.

45
00:02:38,990 --> 00:02:40,030
And that's a little ways away.

46
00:02:40,250 --> 00:02:41,090
We will get there.

47
00:02:41,840 --> 00:02:42,110
All right.

48
00:02:42,120 --> 00:02:43,460
So how am I going to fix this?

49
00:02:43,490 --> 00:02:46,850
Well, let's go back to our code and let's look at the reservation summary page.

50
00:02:47,630 --> 00:02:48,240
Here it is.

51
00:02:48,260 --> 00:02:50,210
This is the template for the reservation summary.

52
00:02:50,210 --> 00:02:53,600
And currently I'm displaying arrival and departure, but not putting anything in there.

53
00:02:53,690 --> 00:02:54,090
OK.

54
00:02:54,830 --> 00:02:58,280
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

55
00:02:58,280 --> 00:02:58,790
right here.

56
00:02:58,880 --> 00:03:05,270
So I'll put in a neuro for the table, a new column room, and I'll just leave this empty for right

57
00:03:05,270 --> 00:03:05,570
now.

58
00:03:06,410 --> 00:03:11,390
So we need to somehow get information for arrival and departure.

59
00:03:11,420 --> 00:03:16,520
Well, we already have the reservation, so I could put the reservation start date and the reservation

60
00:03:16,520 --> 00:03:17,750
and date down here.

61
00:03:17,960 --> 00:03:19,670
But again, they're not in the right format.

62
00:03:19,670 --> 00:03:22,170
So let's go back to our handlers.

63
00:03:22,190 --> 00:03:26,730
I'll just find the correct handler by displaying the route.

64
00:03:28,070 --> 00:03:30,770
So here's the reservation summary function.

65
00:03:31,370 --> 00:03:34,480
And what I'm doing here is pulling the reservation out of the session.

66
00:03:34,700 --> 00:03:38,120
So what's in the session right now?

67
00:03:38,120 --> 00:03:41,010
What's the step right before reservation summary.

68
00:03:41,030 --> 00:03:46,810
Let's go back here and make sure we have the correct information in the the session.

69
00:03:46,820 --> 00:03:49,870
So I'm just gonna go back here and look at post reservation.

70
00:03:50,000 --> 00:03:56,930
So what I do the post reservation, I'm actually pulling I'm pulling nothing out of the session here.

71
00:03:56,930 --> 00:04:01,430
And actually I'm actually doing is at some point before this, I have a reservation in the session,

72
00:04:02,030 --> 00:04:08,260
but I seem to be rebuilding it from the ground up, which is probably not the best idea.

73
00:04:08,720 --> 00:04:17,150
So let me go to the step before this one, which is actually reservation when I make this reservation

74
00:04:18,230 --> 00:04:18,890
here.

75
00:04:21,710 --> 00:04:24,020
I'm pulling a reservation out of the session.

76
00:04:25,670 --> 00:04:31,790
I'm getting the Rambhai ID, I'm storing the name of the room in the reservation.

77
00:04:33,640 --> 00:04:39,250
OK, so at this point, it would seem to make more sense to since we've already updated our reservation

78
00:04:39,250 --> 00:04:45,310
model, why don't we store that in the session with the room name attached to it?

79
00:04:45,460 --> 00:04:46,270
So let's do that.

80
00:04:47,590 --> 00:04:56,510
So what I'm going to do is say M dot app, dot session, dot put and I'll put in the context, argt

81
00:04:56,530 --> 00:04:57,220
context.

82
00:04:58,420 --> 00:05:03,400
Then I need my, my key for the session and I'll use exactly what I'm using up here reservation.

83
00:05:05,110 --> 00:05:08,250
And now I'll store my updated reservation, which I called Redds.

84
00:05:08,260 --> 00:05:09,680
So now that's in the session.

85
00:05:09,940 --> 00:05:17,860
So this one will have the start date, it will have the end date and it will have the room name and

86
00:05:17,860 --> 00:05:20,640
I probably should put the remedy in there as well.

87
00:05:23,890 --> 00:05:28,750
Yeah, let me just put the remedy in there, because I'm actually searching for I've got the remedy.

88
00:05:28,750 --> 00:05:30,310
So the Reds remedies already in there.

89
00:05:30,320 --> 00:05:30,550
Good.

90
00:05:30,560 --> 00:05:31,040
So that's good.

91
00:05:31,060 --> 00:05:35,710
So now I have an updated version of the session of the reservation model in the session.

92
00:05:35,710 --> 00:05:40,840
So let's go back to post reservation and here let's pull that out of the session.

93
00:05:41,320 --> 00:05:43,240
So, Rez.

94
00:05:44,650 --> 00:05:58,090
And OK, are assigned the value of M dot app, dot session dot yet and the context are context and the

95
00:05:58,090 --> 00:05:59,710
key, which is reservation.

96
00:06:02,420 --> 00:06:10,110
And then cast that to type models dot reservation, if not OK.

97
00:06:11,060 --> 00:06:15,980
And right now, I'll just say helper's server error error.

98
00:06:16,370 --> 00:06:17,270
We're going to clean this.

99
00:06:17,630 --> 00:06:26,570
We're doing this and a lot of places, this helper server error errors, new errors and you can't get

100
00:06:26,570 --> 00:06:27,530
from session.

101
00:06:27,890 --> 00:06:30,590
We're doing this helper's dot server error and quite a few places.

102
00:06:30,590 --> 00:06:35,510
And when we get our next past testing, when we update our tests, you take advantage of all the things

103
00:06:35,510 --> 00:06:37,430
we've been doing since the last time we worked on them.

104
00:06:37,880 --> 00:06:39,110
We're actually going to change this.

105
00:06:39,320 --> 00:06:42,740
But for right now, let's just put it in here just so we can get this part done.

106
00:06:43,130 --> 00:06:47,270
So now I have a reservation and that's got the remedy, the wrong name, the start date and the end

107
00:06:47,270 --> 00:06:47,500
date.

108
00:06:48,110 --> 00:06:54,240
So when I come down here, I formed a start date are formed again.

109
00:06:54,390 --> 00:06:56,990
I think this is in the wrong spot post reservation.

110
00:06:59,340 --> 00:07:01,740
Actually don't need those at this point, do I?

111
00:07:02,160 --> 00:07:07,590
Let's just keep going and find out so we have our start date, we have our end date and down here we

112
00:07:07,590 --> 00:07:08,490
have a reservation.

113
00:07:08,490 --> 00:07:11,790
So the only thing I want to do here is update my reservation.

114
00:07:13,410 --> 00:07:17,510
So let's just leave this one alone for right now and just update our reservation.

115
00:07:17,520 --> 00:07:23,190
We want to update our reservation with first name is equal to our form.

116
00:07:23,400 --> 00:07:24,600
Get first name.

117
00:07:27,690 --> 00:07:28,770
And then last name,

118
00:07:32,160 --> 00:07:33,240
which will make last name.

119
00:07:35,830 --> 00:07:39,100
And then foam, which is foam.

120
00:07:42,050 --> 00:07:43,100
And then email.

121
00:07:45,710 --> 00:07:46,400
Which is email.

122
00:07:48,510 --> 00:07:58,530
Everything else should be good to go, so I don't even need this anymore, so let's just hide that and

123
00:07:58,530 --> 00:08:01,650
change the name of this to.

124
00:08:02,700 --> 00:08:03,450
Reservation.

125
00:08:07,430 --> 00:08:13,550
So here reservation and down here will change this to reservation as well, I'll just copy and paste

126
00:08:14,090 --> 00:08:24,100
reservation, reservation, reservation, reservation and do I need all of this?

127
00:08:24,620 --> 00:08:28,220
All I'm doing here is parsing those dates, but I've already got those dates, Daury.

128
00:08:31,080 --> 00:08:36,900
I think so let's comment this out, and I don't need this right now, so let's comment that a.

129
00:08:42,830 --> 00:08:47,690
OK, so let's see if we've got this right, we have a reservation, we pull it from the session, that

130
00:08:47,690 --> 00:08:51,110
reservation has the start date, the end date, the remedy in the room name.

131
00:08:51,290 --> 00:08:58,220
OK, then down here I update my reservation model to have the first name, the last name, the phone

132
00:08:58,220 --> 00:08:58,750
in the email.

133
00:08:58,820 --> 00:08:59,410
Perfect.

134
00:08:59,810 --> 00:09:05,300
And there should be needs to be commented to and then we do our validation.

135
00:09:06,080 --> 00:09:16,880
If it is valid, we insert the reservation and now let's put in our our reservation back in the session.

136
00:09:17,840 --> 00:09:23,330
Emden Apte session dot put our on context.

137
00:09:26,270 --> 00:09:30,780
Reservation, reservation, I think that'll work.

138
00:09:31,490 --> 00:09:34,990
And now here for this restriction, we don't want this start date.

139
00:09:35,090 --> 00:09:38,380
We want to go to the reservation start date.

140
00:09:39,410 --> 00:09:44,180
And this one, we want reservation and date.

141
00:09:44,690 --> 00:09:47,140
And now we can get a remedy from that model as well.

142
00:09:47,150 --> 00:09:50,540
Reservation dot remedy that seems cleaner.

143
00:09:51,170 --> 00:09:51,650
All right.

144
00:09:52,010 --> 00:09:57,410
And then we insert our reservation and I see I already did the reservation down here so I can pull it

145
00:09:57,410 --> 00:09:58,010
out of here.

146
00:10:00,140 --> 00:10:02,360
We don't see no sense in putting in this session twice.

147
00:10:02,870 --> 00:10:03,900
I think that'll work.

148
00:10:04,550 --> 00:10:09,200
So if that works, then there's only one other thing left to do.

149
00:10:09,440 --> 00:10:12,830
Let's just see up here where I commented some things out.

150
00:10:13,250 --> 00:10:15,230
I'm going to take this.

151
00:10:16,960 --> 00:10:17,680
Where is it?

152
00:10:22,340 --> 00:10:23,750
No, it's all right, let's just go with that.

153
00:10:23,890 --> 00:10:26,500
OK, so from here now, I want to go.

154
00:10:26,660 --> 00:10:29,600
So this is the handler that actually post the reservation.

155
00:10:29,600 --> 00:10:29,960
Great.

156
00:10:30,320 --> 00:10:32,110
So I've now posted my reservation.

157
00:10:32,270 --> 00:10:34,490
I've entered my restriction into the database.

158
00:10:34,490 --> 00:10:37,430
I've entered my my reservation into the database.

159
00:10:37,430 --> 00:10:39,970
I've updated my reservation and stuck it in the session.

160
00:10:39,980 --> 00:10:42,430
So now I want to display my reservation summary page.

161
00:10:42,440 --> 00:10:48,440
So let's go back to our roots, find the reservation summary page here.

162
00:10:48,440 --> 00:10:49,970
I pulled my reservation out.

163
00:10:49,970 --> 00:10:50,680
That's great.

164
00:10:51,320 --> 00:10:57,920
The only other thing left to do is to create a street map and put dates in a format that we can display.

165
00:10:57,920 --> 00:10:58,820
And we know how to do that.

166
00:10:58,820 --> 00:11:06,050
So we can say start date, which is just going to be a string, is going to be equal to reservation

167
00:11:06,460 --> 00:11:11,870
start date dot format 2006, 01 02.

168
00:11:11,870 --> 00:11:12,800
I think that's what it was.

169
00:11:13,310 --> 00:11:18,320
And then end date will be Eddie and this becomes end date.

170
00:11:20,120 --> 00:11:21,650
And now we make our string map.

171
00:11:21,650 --> 00:11:31,160
String map is a sign the value of make a map string string and put our start and end date formatted

172
00:11:31,160 --> 00:11:33,500
in this format into that string map.

173
00:11:34,100 --> 00:11:42,950
String map start date is equal to SD for start date and I'll duplicate that and change this one to end

174
00:11:42,950 --> 00:11:47,630
date and make that the end date and then pass my string that.

175
00:11:49,470 --> 00:11:50,950
And that's string wrap.

176
00:11:52,470 --> 00:11:54,580
All right, so that should work for this.

177
00:11:55,170 --> 00:12:00,210
Now we go update a reservation summary page and now I can just go because I have the reservation.

178
00:12:00,210 --> 00:12:01,530
I'm getting it right here.

179
00:12:01,770 --> 00:12:12,960
I can just go rez, dot room, dot room name and arrival is from the string map index dot index dot

180
00:12:12,960 --> 00:12:17,850
string map start underscore date and I'll copy that.

181
00:12:21,600 --> 00:12:24,810
And pasted in here and change that to end it.

182
00:12:25,860 --> 00:12:27,180
All right, let's see if it compiles.

183
00:12:27,270 --> 00:12:29,250
So open our terminal, clear the screen

184
00:12:31,800 --> 00:12:32,280
run.

185
00:12:35,380 --> 00:12:41,920
It comp. Let's go back to our Web browser and choose some other date, and I'll choose a date in March

186
00:12:42,100 --> 00:12:44,170
because I know there's nothing in March there, so.

187
00:12:46,420 --> 00:12:57,430
March the 9th to March the 10th search, major suite and first last email at email, dotcom and some

188
00:12:57,430 --> 00:13:00,490
phone number and hopefully this'll work and it did.

189
00:13:01,180 --> 00:13:05,020
There's the correct date, March the 9th to March the 10th, and there's the major suite.

190
00:13:05,350 --> 00:13:05,880
Perfect.

191
00:13:06,280 --> 00:13:06,790
All right.

192
00:13:06,820 --> 00:13:10,750
Now let's go back and clean up a little bit and get rid of all the stuff I've commented out.

193
00:13:12,280 --> 00:13:14,260
So that would be under handlers.

194
00:13:14,650 --> 00:13:17,870
And somewhere in here, I have a whole bunch of comments, so I'll just get it this way.

195
00:13:17,890 --> 00:13:19,570
Let's go to post reservation.

196
00:13:19,900 --> 00:13:20,400
There it is.

197
00:13:20,980 --> 00:13:22,630
So I don't need any of this anymore.

198
00:13:25,000 --> 00:13:26,470
I don't need any of this anymore.

199
00:13:31,450 --> 00:13:37,930
And I think that might be it, it is all right, so now we have the ability to make a reservation by

200
00:13:37,930 --> 00:13:40,060
searching availability for all rooms.

201
00:13:40,430 --> 00:13:45,320
So the next step is to go back to our site and look at the individual rooms.

202
00:13:45,640 --> 00:13:50,520
And right now, I have this check check availability, but that doesn't do very much.

203
00:13:50,530 --> 00:13:57,610
It fires off a request in the background using Ajax to our server, and it just returns a hardcoded

204
00:13:57,610 --> 00:13:58,470
value right now.

205
00:13:58,480 --> 00:14:06,130
So we need to modify the handler that is called by that AJAX to actually perform a search by room using

206
00:14:06,130 --> 00:14:07,960
the database function we already have.

207
00:14:08,380 --> 00:14:14,560
And we need to modify our JavaScript on this page to determine what to do based upon the nature of the

208
00:14:14,560 --> 00:14:15,630
response that comes in.

209
00:14:16,570 --> 00:14:19,060
So we'll do that in the next lecture or two.
