Skip to content
GitLab
Menu
Projects
Groups
Snippets
Help
Help
Support
Community forum
Keyboard shortcuts
?
Submit feedback
Sign in
Toggle navigation
Menu
Open sidebar
jkerr
Assignment 1
Commits
2837097d
Commit
2837097d
authored
Aug 21, 2019
by
jkerr
Browse files
Added localStorage
parent
4f423545
Changes
3
Hide whitespace changes
Inline
Side-by-side
index.html
View file @
2837097d
...
...
@@ -7,6 +7,7 @@
<script
src=
"scripts/jquery-3.3.1.min.js"
></script>
<script
src=
"scripts/switchbooking.js"
></script>
<script
src=
"scripts/filterSites.js"
></script>
<script
src=
"scripts/setbooking.js"
></script>
<link
rel=
"stylesheet"
href=
"scripts/leaflet/leaflet.css"
/>
<script
src=
"scripts/leaflet/leaflet.js"
></script>
...
...
scripts/filterSites.js
View file @
2837097d
var
FilterSites
=
(
function
()
{
pub
=
{};
/** A simple input validator **/
function
pad
(
str
)
{
if
(
str
.
len
<
2
)
{
return
str
.
padStart
(
2
,
"
0
"
);
}
}
/** When the search button is pushed**/
pub
.
searchPushed
=
function
()
{
function
searchPushed
()
{
fullName
=
$
(
"
#name
"
).
val
();
checkIn
=
$
(
"
#checkIn
"
).
val
().
replace
(
new
RegExp
(
"
-
"
,
'
g
'
),
""
);
checkOut
=
$
(
"
#checkOut
"
).
val
().
replace
(
new
RegExp
(
"
-
"
,
'
g
'
),
""
);
...
...
@@ -34,17 +26,15 @@ var FilterSites = (function () {
cOutMonth
=
cBook
.
checkin
.
month
.
padStart
(
2
,
"
0
"
);
cOutYear
=
cBook
.
checkin
.
year
;
cOutDate
=
cOutYear
+
cOutMonth
+
cOutDay
;
if
((
c
In
Date
<
checkIn
&&
checkIn
<
cOutDate
)
||
(
cInDate
<
checkOut
&&
checkOut
<
c
Out
Date
))
{
if
((
c
Out
Date
<
=
checkIn
)
||
(
checkOut
<
=
c
In
Date
))
{
continue
;
}
//Search for site and add
console
.
log
(
"
Added:
"
+
cBook
.
number
);
takenSites
.
push
(
cBook
.
number
);
}
console
.
log
(
"
TakenSites1:
"
+
takenSites
);
},
error
:
function
(
data
)
{
alert
(
"
ERROR
"
);
alert
(
data
);
}
});
//Clears all sites from table
...
...
@@ -57,19 +47,18 @@ var FilterSites = (function () {
cache
:
false
,
success
:
function
(
data
)
{
sites
=
data
.
campSites
.
site
;
console
.
log
(
"
TakenSites2:
"
+
takenSites
);
top
:
for
(
i
=
0
;
i
<
sites
.
length
;
i
++
)
{
if
(
sites
[
i
].
siteType
.
toLowerCase
()
===
type
||
type
===
"
any
"
)
{
if
(
takenSites
.
includes
(
sites
[
i
].
number
))
{
continue
top
;
}
tableAdd
(
sites
[
i
]);
for
(
i
=
0
;
i
<
sites
.
length
;
i
++
)
{
if
(
sites
[
i
].
siteType
.
toLowerCase
()
===
type
||
type
===
"
any
"
)
{
if
(
takenSites
.
includes
(
sites
[
i
].
number
))
{
continue
;
}
tableAdd
(
sites
[
i
]);
}
}
SetBooking
.
updateButtons
();
},
error
:
function
(
data
)
{
alert
(
"
ERROR
"
);
alert
(
data
);
}
});
return
false
;
...
...
@@ -82,32 +71,21 @@ var FilterSites = (function () {
"
<td>
"
+
site
.
siteType
+
"
</td>
"
+
"
<td>
"
+
site
.
description
+
"
</td>
"
+
"
<td>$
"
+
site
.
pricePerNight
+
"
</td>
"
+
"
<td><input type='button' value='Book'></td>
"
+
"
<td><input
class='bookButton'
type='button' value='Book'></td>
"
+
"
</tr>
"
);
}
/** Setup function **/
pub
.
setup
=
function
()
{
/** Adds click event for submit button **/
$
(
"
#submit
"
).
click
(
pub
.
searchPushed
);
$
(
"
#submit
"
).
click
(
searchPushed
);
/** Gets all sites from json and adds them to the table**/
address
=
"
scripts/data/campsites.json
"
;
$
.
ajax
({
type
:
"
GET
"
,
url
:
address
,
cache
:
false
,
success
:
function
(
data
)
{
sites
=
data
.
campSites
.
site
;
for
(
i
=
0
;
i
<
sites
.
length
;
i
++
)
{
tableAdd
(
sites
[
i
]);
}
},
error
:
function
(
data
)
{
alert
(
"
ERROR
"
);
}
});
}
searchPushed
();
};
pub
.
searchPushed
=
function
()
{
searchPushed
();
};
return
pub
;
})();
$
(
document
).
ready
(
FilterSites
.
setup
);
\ No newline at end of file
scripts/setbooking.js
View file @
2837097d
var
changeType
=
(
function
()
{
var
SetBooking
=
(
function
()
{
pub
=
{};
function
setBooking
()
{
booking
=
{};
booking
.
siteId
=
$
(
this
).
parent
().
parent
().
find
(
"
td
"
)[
0
].
textContent
;
booking
.
checkIn
=
$
(
"
#checkIn
"
).
val
();
booking
.
checkOut
=
$
(
"
#checkOut
"
).
val
();
console
.
log
(
booking
);
localStorage
.
setItem
(
"
savedQuickCampBooking
"
,
JSON
.
stringify
(
booking
))
}
pub
.
updateButtons
=
function
()
{
bookButtons
=
$
(
"
.bookButton
"
);
console
.
log
(
"
Length:
"
+
bookButtons
.
length
);
for
(
i
=
0
;
i
<
bookButtons
.
length
;
i
++
)
{
bookButtons
[
i
].
onclick
=
setBooking
;
}
}
return
pub
;
})();
$
(
document
).
ready
(
changeType
.
setup
);
\ No newline at end of file
})();
\ No newline at end of file
Write
Preview
Markdown
is supported
0%
Try again
or
attach a new file
.
Attach a file
Cancel
You are about to add
0
people
to the discussion. Proceed with caution.
Finish editing this message first!
Cancel
Please
register
or
sign in
to comment