So our task this time around is to make this button check availability on the major sweep page work
the same way that it does on the generals quarters page.
And that's really easy.
So let's get started.
So the simplest thing to do, I'm going to look at the Generals Quarters page, which is right here.
This has a section at the very bottom of the template called Defined Jass.
If you think about it, everything I have in here, with the exception of one character, is exactly
what I need on the major, major sweet page.
And the one character that has to change is this number one, where we append room ID to our form data
that needs to be a two.
So this will work.
I can go over here now to the Majors page, major story page tampoe and replace what's there by pasting
over top of it.
What I just copied from looks that I get it all.
I get an extra character up here that I missed that when I selected it to replace it.
So now this is correct, except for this one, which becomes a two.
So if I save that and go back over to my major sweep page, reload the page and check availability,
this should work now.
So I'll choose from the 27th to the 28th, which is a date I have verified beforehand is available.
This should show rooms available and it does.
And that works really well.
Now, at least some of you, at least hopefully some of you have thought about this in this page Meijers
page.
I have all this JavaScript, which is pretty much identical except for one character to what I have
here on the majors, on the general page.
Wouldn't it make more sense to take the contents of this, everything from say here all the way down
to here and create a function just by wrapping all of that with a function tag, giving it a name,
putting it somewhere where it's available to all of the pages that need it and then just call that function.
And when I'm calling it from the generals page, I could call it with an idea of one one I'm calling
it from the majors page, I can call it with a remedy of two.
And that is absolutely right.
And I encourage you to do that.
As a matter of fact, I'm going to leave that as an exercise for you.
But to get you started, there is one change I'm going to make right now, and this will point you in
the right direction.
This is my base layout and base layout has this prompt I'm going to add prompt doesn't need to be part
of the layout.
I said a while ago you typically import JavaScript modules.
This is quite a while ago when we were talking about JavaScript.
What I'm going to do now is I'm going to create over in my static folder a new directory.
I'm going to call that JS for JavaScript.
Inside of that, I'll create a new file, which I will call Abdah Jazz, OK, and I will add that to
my git repository and I'm going to paste in.
Oops, I got the wrong thing there.
I am going to copy my entire prompt JavaScript module.
I'll cut it out of there.
I'll cut it out of my base layout.
I don't want to copy it and only two versions of it and paste it into ABC's and save this.
And then instead of having it written right into the base template, I'll just import it like I do.
All these other JavaScript libraries script source equals and it's static jazz act jazz and close my
script tag.
And if I did everything right, when I go back to my web browser, I can reload this page and it should
work and it appears to so 27 to 28 and the room is available.
Perfect.
So what I've given you or what I've pointed you in the direction of is application javascript that I
want available to every page of my application, at least every public page.
We might have a different one for a back end.
When we get to the back end, we'll look at that.
But right now, here is a place where you could take this everything that you see at the bottom of the
page and everything that you see at the bottom of the majors page starting right after the opening script
tag.
Take that and or at least as much of it as you need and create a function that you can call in a much
smaller amount of JavaScript from the majors page and from the generals page.
And since everything is the same on these two pages, except for this one character right here, it's
a one four generals quarters and a two for the major suite.
You know, you only have to pass one parameter.
So if you want to do that, I encourage you to do it.
It will be great practice and great exercise.
I'm not going to do it for you right now.
I might do it later in the course.
But at the moment, I think it's time to move on and work on our testing a bit more to update our tests
because they are starting to get out of date.