So now that we have all the information we need to render the information on the calendar, let's do
so and we'll start with the blocks.
So I'm going to go back to my template, which is right here, and find the part where I'm rendering
the TD with a checkbox.
So this input type equals checkbox is what appears right here on both of these rows.
And I want to display a checked checkbox if there is a block and leave it unchecked.
If there's not now, because this is a form, each of these inputs is going to have to have a meaningful
name.
And that's something I'll also take care of in this step.
So let's get started.
So right now, inside this range Rum's, I want to each time I iterate through this, pull the appropriate
values for my reservation blocks, reservations and blocks out of my data variable.
So let's do that to start with.
So we'll create a variable called blocks and that will be equal to or assign the value of index from
my data.
And I can't just go data here because I'm inside this range.
So this variable is not part of the rooms.
So I need to tell somehow, tell the template, get the value of data from outside of this loop, and
you do that by putting a dollar sign in front of it.
So from index dollar sign dot data, I want to get the block map, which is name something like this
block map.
Underscore one for the first time through.
Well actually I need to put that as a to the second time through or whatever the remedy is.
So what I really need is access to that format dot s print f function that's available to me and regular
go code.
And fortunately there is an alias for that available to us in Goldwing templates and it's just called
print F, so print F and I'm going to give it my string with a placeholder and it's a present D because
the remedy is an aunt and I need to put in the variable ID or the value of ID so that will get block
underscore map underscore one for remedy one and block block underscore map underscore two for remedy
two.
So that gets my blocks and I'll duplicate this and do the same thing for reservations.
But of course that's called reservation underscore map.
OK, so now I have this information now down here I need to make a determination and my determination
is a really simple one.
I'm doing blocks first.
If there is an entry in the blocks map for the current date that has a value of greater than zero for
a block, then display a checkmark, otherwise don't.
So I can really just kind of put my if statement right inside this input tag.
And what I want to check here is to see in my block map do I have an entry for the current date that
has a value of greater than zero.
So which is right.
And if statement if greater than and in parentheses I'm going to put index block map of blocks and I'm
looking for the value of print F.
And my string will be a string followed by a hyphen and then another string followed by a hyphen and
then an ENT, and I'm going to replace those values with no comma career, which I got from my string
map per month, which I got from my string map right up here per month and career.
And then the current index added with one added to it.
So let's count our we have one opening to opening three openings.
So one, two, three closing parentheses.
And that has to be greater than zero.
If that is true.
And I'll put in ELT's here, then give this thing a name, give this thing a value and check it.
So let's first all check it.
That's easy checked.
That will make sure it's checked and let's give it a name.
And this name is going to be because this is an existing block that I want to remove.
I will say remove.
I'm going to give it this name.
Remove block.
And I'm going to pass in the remedy.
And then an underscore and then I'm going to pass in the formatted date once again, and that will be
print F and %s %s percent D and replacing those with.
The current year.
The cur month.
And add index.
So that's its name and what's its value going to be?
Well, its value is going to be something as simple as value equals.
Index blocks.
Print F again and the same string.
And replacing those values with career per month and add index one.
So that's going to get the value for my Bloks map and the value stored for this date, which happens
to be a block, is the restriction ID for that block.
So that passes in and it and that's all I have to do for there.
Otherwise, if there is no block, I don't want to the in there.
I want the end.
Yeah I do.
What the end there.
OK, I'm going to put in the name is going to be not equal to remove block.
It'll be equal to Adblock and I got a closing tag there.
That's better.
Name equals ad block.
Underscore once again the remedy and once again an underscore and then the date which I'll just copy
and paste because I have it up here correctly.
I have something missing there.
See one, two.
I've got a missing closing parentheses.
Their ideas are so helpful for pointing out errors.
So let's copy this whole print statement.
Right here to here.
Copy that.
Pasted here, closer quotation marks, and that should do it.
So let's save this and let's make sure our application is running.
I'm going to restart it just to be sure and see if this works.
So this should, when I click on this, should show me any blocks that I have.
And it appears to let's make sure they're right.
So this is on the 8th of December.
Let's inspect that element and make sure it's got the correct name and its remove block room ID and
the date and its value is too perfect.
Let's try a different one.
Let's try this one on the 12th.
And that is remove block the 12th and its value also, too.
That doesn't seem right.
It can't have the same values for those.
Let's try one more, see what's going on on the seventh value, too.
So there's something wrong with the value.
Let's have a look at the value and see what we're doing wrong there.
This is for existing blocks and its value is index blocks.
Print F Kirker Month.
Ad index one.
Well, the only place that can come from is our handler when we actually populate that with value.
So what am I putting in there?
Restriction ID?
That's not what I want.
I want the ID.
OK, so the restriction idea is type to block the ID is the ID of the restriction itself.
OK, so let's stop.
Our application started again.
Go back to our Web browser, reload the calendar, and this time I should see the correct information.
So this is for the eighth and the name is correct and its value is 19.
That looks better.
Let's try another one.
That date is the 12th.
The 12th is correct.
And value of twenty, that looks much better.
OK, so that seems to be working the way that it's supposed to.
The next step is to display reservations if they exist.
So back in my template, let's come up here and see what we're going to do.
What I'm going to do is right after the opening TD tag and I'm going to give myself some room here,
I need to determine, is there a reservation?
If there's not, then I'm going to display either a block or an empty checkmark.
If there's a reservation, though, I want to have something that links to the actual reservations.
And I can do that pretty easily because I have my reservation map.
And I know that if there's an entry for the current date that has a reservation ID that is greater than
zero, then there is a reservation.
So we can just say if greater than and once again, index from our reservations, which is a map and
we're looking for once again, print F percent stasch percent X percent D and I'm substituting the values
of the current year.
The current month and the index with one added to it, and I have one opening parentheses to three,
so one, two, three, and this should be zero.
If it's greater than zero, then there is a reservation otherwise else just do what we just did because
we know it's either a block or something that can be blocked and that should be an end, not an ELT's.
OK, so let's just save this and reload this this calendar and what should happen is if there's a reservation
anywhere in the month of December for either of these rooms, it should just show an empty cell.
So let's see if that works.
And it does.
There's an empty cell for the second and the third there.
And there's another one over here for the 16th and 17th.
That seems correct.
So let's actually just put a link in there and link that'll take us to the appropriate reservation.
So all I'm going to put in here is an A F equals and a link to the reservations page.
And that goes to admin reservations where you're coming from, and this time I'm going to put Carl in
there because we're coming from the calendar, even though we're not doing any anything with it yet,
we will in a little while.
And then I need to get the value of the reservation, which I can get from my reservations map index
or first dollar sign reservations.
And again, I'll use my printer function and use the same string that I have all along and pass in the
courier the courier month and add index one.
OK, now let's see how many closing parentheses do I need one to.
So that should do it and close my opening ATG and in here I'll just put a red our spin class equals
text danger
and that should give me a link to the appropriate reservation and show an hour for every day of the
reservation.
Let's see what happens.
So let's reload this page by clicking on a reservation calendar.
And I have the hours and this one should take me to reservation seven for generals quarters from the
second to the third.
Second to the third, perfect.
OK, so that gives me the reservation and it takes me to the correct place.
Now what I want to fix next is this this this part right here, because I didn't click on Cancel, it's
going to take me nowhere.
So I'm going to go back and find that reservation template and just fix that one little thing, the
back button.
So let's find other bookings templates.
And we want admin show reservation right here.
So down at the cancel per.
Right here, where is it safe cancel?
So what I'm going to do here is just put an if statement if equals source Karl.
ELT's and then put an end if here.
And all I really want to do, if you're on the calendars, I want to take you back to whatever month
you were currently looking at and there's a really easy way to do that.
I'll just take advantage of the browser history.
So I'll say a traffic equals to nothing.
Don't link and don't go anywhere when you click on this, but add an unclick handler unclick equals
and I'm just going to say window dot history dot go and minus one which says go to the previous page
in your browser history and we'll give this the same class of button button warning.
Try that again.
And cancel, so now if I've got that right window history, go one class button warning, that all looks
good.
Let's try that again.
This time I will go back to my reservation or to my reservations calendar.
I'll click on this reservation on the 16th and it's showing me the correct information and cancel.
Should take me back one one page in my browser history.
And it does.
And it takes me to the correct month, which is perfect because I don't want to redirect them to the
calendar page because I want to make sure they're looking at the correct month.
So if I go ahead, I'm on January 20, 21, I click on the reservation, I click on cancel and it takes
me back to January 20 one.
That's exactly what I want.
Perfect.
All right.
So the next step is a pretty simple one.
We need to be able to check dates to block them and remove blocks.
So we need to create a post handler for a reservation calendar and we'll take care of that in the next
lecture or two.