Commit 8c852567 authored by Ian De La Cruz's avatar Ian De La Cruz

Fixed many things

parent b786686d
<!DOCTYPE html>
<html lang="en">
<head>
<title>uBus | Admin System</title>
<meta charset="utf-8">
<meta name="description" content="uBus Ticket Reservation System administrator tools.">
<link rel="icon" type="image/x-icon" href="img/favicon.ico">
<link rel="stylesheet" type="text/css" href="css/font-awesome.min.css">
<link rel="stylesheet" type="text/css" href="css/rolling.css">
<link rel="stylesheet" type="text/css" href="css/style.css">
<script type="text/javascript" src="js/jquery-2.1.4.js"></script>
<script src="js/parse-1.6.7.js"></script>
<script type="text/javascript" src="js/app.js"></script>
</head>
<body>
<header class="header">
<a href="index.html" class="header__logo"><img src="img/logo.png" width="40px"></a>
<nav class="header__nav" id="navigation">
<a href=""></a>
<a href=""></a>
</nav>
</header>
<main class="container">
<p><a href="index.html"><span class="fa fa-arrow-left fa-2x"></span>&nbsp;Go back</a></p>
<h1>Company Management</h1>
<div id="loader" style="position: fixed; z-index: 100; width: 100%; height: 100%; display: block; background-color: gray;top: 80px;left: 0;-webkit-opacity: 0.5;">
<div class='uil-rolling-css' style='margin:20vh auto; -webkit-transform:scale(0.6);'><div><div></div><div></div></div></div>
</div>
<div class="card">
<h2>Add a new Schedule</h2>
<form class="createSked" id="createSked">
<label for="skedTime">
<span>Schedule Time (in 24:00) </span>
<input type="text" id="skedTime" placeholder="22:00">
</label>
<label for="skedDay">
<span>Schedule Day</span>
<select id="skedDay">
<option>--</option>
<option>Sunday</option>
<option>Monday</option>
<option>Tuesday</option>
<option>Wednesday</option>
<option>Thursday</option>
<option>Friday</option>
<option>Saturday</option>
</select>
</label>
<label for="originTerminal">
<select id="originTerminal">
<option>--</option>
</select>
</label>
<label for="destinationTerminal">
<select id="destinationTerminal">
<option>--</option>
</select>
</label>
<button class="createSked__btn" id="createSked__btn">Create Schedule</button>
</form>
</div>
<div class="card">
<h2>Delete A Schedule</h2>
<form id="deleteSchedule">
<!-- Search for Schedule using Time and Day -->
<label for="deleteDay">
<span>Day of Schedule</span>
<select id="availableDay">
<option>--</option>
<option>Sunday</option>
<option>Monday</option>
<option>Tuesday</option>
<option>Wednesday</option>
<option>Thursday</option>
<option>Friday</option>
<option>Saturday</option>
</select>
</label>
<label for="deleteTime">
<span>Time to be deleted</span>
<select id="availableTime">
<option>--</option>
</select>
</label>
<button class="deleteSked__btn" id="deleteSked__btn">Delete Schedule</button>
</form>
</div>
<!-- <div class="card">
<h2>Add Bus</h2>
<form class="addBus" id="addBus">
<label for="plateInput">
<span>Plate Number: </span>
<input type="text" id="plateInput" placeholder="UVA XXXX">
</label>
<label for="typeInput">
<span>Bus Type: </span>
<select id="typeInput">
<option>R</option>
<option>D</option>
</select>
</label>
<label for="seatNumber">
<span>Seat Number</span>
<input type="number" value="0" id="seatNumber">
</label>
<button class="addBus__btn" id="addBus__btn">Add Bus</button>
</form>
</div>
<div class="card">
<h2>Delete Bus</h2>
<form class="delBus" id="delBus">
<label for="plateInput">
<span>Plate Number: </span>
<input type="text" id="delPlate" placeholder="UVA XXXX">
</label>
<button class="delBus__btn" id="delBus_btn">Add Bus</button>
</form>
</div> -->
</main>
</body>
</html>
<!DOCTYPE html>
<html lang="en">
<head>
<title>uBus | Admin System</title>
<meta charset="utf-8">
<meta name="description" content="uBus Ticket Reservation System administrator tools.">
<link rel="icon" type="image/x-icon" href="img/favicon.ico">
<link rel="stylesheet" type="text/css" href="css/font-awesome.min.css">
<link rel="stylesheet" type="text/css" href="css/style.css">
<script type="text/javascript" src="js/jquery-2.1.4.js"></script>
<script src="js/parse-1.6.7.js"></script>
<script type="text/javascript" src="js/app.js"></script>
</head>
<body>
<header class="header">
<a href="index.html" class="header__logo"><img src="img/logo.png" width="40px"></a>
<nav class="header__nav" id="navigation">
<a href=""></a>
<a href=""></a>
</nav>
</header>
<main class="container">
<div class="card">
<form class="generateTrips">
<label for="startTime">
<input type="time" id="startTime">
</label>
<label for="startDate">
<input type="date" id="startDate">
</label>
<button class="generateTrips__btn">Generate Trips</button>
</form>
</div>
</main>
</body>
</html>
......@@ -26,14 +26,13 @@
<div class='uil-rolling-css' style='margin:20vh auto; -webkit-transform:scale(0.6);'><div><div></div><div></div></div></div>
</div>
<p id="successMessage" style="display:none; color: white; font-weight: 500; background-color:darkgreen; padding: 20px;">Trip created successfully!</p>
<p><a href="index.html"><span class="fa fa-arrow-left fa-2x"></span>&nbsp;Go back</a></p>
<div class="createTrip card">
<form class="createTrip__form">
<h1 class="createTrip__header">Create Trip</h1>
<label class="createTrip__selectLabel">
<span>Day: </span>
<select class="createTrip__select" id="selectScheduleDay">
<option>--</option>
</select>
<span>Date: </span>
<input type="date" id="selectTripDate">
</label>
<label class="createTrip__selectLabel">
<span>Time: </span>
......@@ -42,6 +41,18 @@
</select>
</label>
<hr>
<label class="createTrip__selectLabel">
<span>Origin: </span>
<select class="createTrip__select" id="tripOrigin">
<option>--</option>
</select>
</label>
<label class="createTrip__selectLabel">
<span>Destination: </span>
<select class="createTrip__select" id="tripDestination">
<option>--</option>
</select>
</label>
<hr>
<label class="createTrip__selectLabel">
<span>Plate Number: </span>
......@@ -58,7 +69,9 @@
</label>
</form>
</div>
<div class="card">
<div class="card" style="padding: 2rem 6rem;">
<h2>Autogenerate Trips</h2>
<form class="createTrip__form">
<label for="startDate">
<span>Start Date</span>
<input type="month" id="startDate">
......
......@@ -33,6 +33,14 @@ body {
font-family: Helvetica, Arial, sans-serif;
}
a {
text-decoration: none;
color: #124E78;
}
a:hover, a:visited {
color: #124E78;
}
/* General Style Classes */
.card {
box-shadow:0 1px 2px #aaa;
......@@ -45,8 +53,15 @@ body {
.header {
display: block;
width: 100%;
height: 80px;
/*height: 80px;*/
background-color: #124E78;
padding: 20px;
}
#logout {
position: absolute;
right: 20px;
top: 25px;
}
.container {
......
......@@ -33,17 +33,15 @@
</div>
<div class="actionbox card" id="scheduleManagement" style="display:none;">
<!-- This is not available when user is a Clerk user -->
<h1 class="actionbox__header">Schedule Management</h1>
<h2>Schedules contain information on the specifics, ie. day, time and terminals</h2>
<h1 class="actionbox__header">Company Management</h1>
<h2>Add Schedule templates and buses</h2>
<ul class="actionbox__list">
<li class="actionbox__listitem"><a href="createSchedule.html">Create Schedules</a></li>
<li class="actionbox__listitem"><a href="viewSchedules.html">View All Schedules</a></li>
<li class="actionbox__listitem"><a href="companyMgmt.html">Company Management</a></li>
</ul>
</div>
<div class="actionbox card" id="customerManagement">
<h1 class="actionbox__header">Customer Management</h1>
<ul class="actionbox__list">
<li class="actionbox__listitem"><a href="register.html">Register New User</a></li>
<li class="actionbox__listitem"><a href="reload.html">Reload User Credits</a></li>
</ul>
</div>
......
......@@ -5,6 +5,9 @@ var helper = {
pointerTo : function(objectId, klass) {
return { __type:"Pointer", className:klass, objectId:objectId };
},
/*
* Append to parent
*/
appendUsingID : function( parentID, elementName, elementClass, content ) {
var parent = document.getElementById(parentID);
var child = document.createElement(elementName);
......@@ -50,7 +53,7 @@ var helper = {
}
var app = {
login : function(){
login : function(event){
event.preventDefault();
var uname = document.getElementById("login_uname").value,
......@@ -118,7 +121,7 @@ var app = {
error : function(err){}
});
},
logout : function() {
logout : function(event) {
event.preventDefault();
Parse.User.logOut();
location.href="login.html";
......@@ -137,13 +140,36 @@ var app = {
error: function(error){ console.log(error.code); }
});
},
searchTrip : function(busCompany) {
searchTrip : function(busCompany, searchByParameter, searchTerm) {
var tripQuery = new Parse.Query("Trip");
var busQuery = new Parse.Query("Bus_Company");
busQuery.equalTo('objectId', busCompany);
tripQuery.include('assignedBus');
tripQuery.matchesQuery('busCompany', busQuery);
tripQuery.ascending('dateAndTime');
switch(searchByParameter){
case "Day":
var subQuery = new Parse.Query("Schedule");
subQuery.equalTo("day", searchTerm);
tripQuery.matchesQuery("assignedSchedule", subQuery);
break;
case "Date":
var searchArr = searchTerm.split(",");
var minTerm = new Date(searchArr[0]);
console.log(minTerm);
var maxTerm = new Date(searchArr[1]);
console.log(maxTerm);
tripQuery.greaterThanOrEqualTo("dateAndTime", minTerm);
tripQuery.lessThanOrEqualTo("dateAndTime", maxTerm);
break;
case "Time":
var subQuery = new Parse.Query("Schedule");
subQuery.equalTo("departureTime", searchTerm);
tripQuery.matchesQuery("assignedSchedule", subQuery);
break;
}
tripQuery.find({
success : function(results){
var listParent = document.getElementsByClassName("tripList")[0];
......@@ -151,6 +177,7 @@ var app = {
var plateNumber = results[i].get("assignedBus").get("plateNumber");
var busType = results[i].get("assignedBus").get("busType");
var date = moment(results[i].get("dateAndTime")).format("DD MMM YYYY hh:mm A ddd");
console.log(typeof results[i].get("dateAndTime"));
var listItem = document.createElement("li");
listItem.setAttribute("class", "tripList__item card");
......@@ -158,6 +185,7 @@ var app = {
var listItemSpan1 = document.createElement("span");
listItemSpan1.setAttribute("class", "tripList__itemInfo");
listItemSpan1.innerHTML = "Date: " + date;
console.log(date);
listItem.appendChild(listItemSpan1);
listParent.appendChild(listItem);
......@@ -175,12 +203,35 @@ var app = {
}
},
error : function(error){ console.log(error.code); }
error : function(err){ console.log("Error " + err.code + " : " + err.message); }
});
},
createTrip : function( currUserAffiliation ) {
// Steps
createTrip : function( currUserAffiliation, skedID, dateAndTimeValue, busID ) {
var busQuery = new Parse.Query("Bus");
busQuery.equalTo("objectId", busID);
busQuery.first()
.then(function(response){
console.log(busID);
var seats = response.get("seatNumber");
var skedQuery = new Parse.Query("Schedule");
skedQuery.equalTo("objectId", skedID);
skedQuery.first()
.then(function(response){
var chosenSked = response.id;
var Trip = new Parse.Object.extend("Trip")
var createTrip = new Trip();
createTrip.set("busCompany", helper.pointerTo(currUserAffiliation, "Bus_Company"));
createTrip.set("assignedBus", helper.pointerTo(busID, "Bus"));
createTrip.set("assignedSchedule", helper.pointerTo(chosenSked, "Schedule"));
createTrip.set("dateAndTime", moment(dateAndTimeValue).toDate());
createTrip.set("seatNumber", seats);
createTrip.save({
success: function(res){ console.log( "Success!" ); var loader = document.getElementById("loader"); loader.style.display = "none"; },
error: function(err){ console.log("Error " + err.code + " : " + err.message ); }
});
});
});
},
generateScheduleOptions : function( busCompany, parentNodeID, childClass, key ) {
// To be used in tne onload event
......@@ -298,22 +349,47 @@ var app = {
console.log(Parse.User.current());
});
},
createSchedule : function(){},
createSchedule : function(skedDay, skedTime, originTerminal, destinationTerminal, busCompany){
var Schedule = new Parse.Object.extend("Schedule");
var createdSked = new Schedule();
createdSked.set("day", skedDay);
createdSked.set("departureTime", skedTime);
createdSked.set("origin", helper.pointerTo(originTerminal, "Terminal"));
createdSked.set("destination", helper.pointerTo(destinationTerminal, "Terminal"));
createdSked.set("busCompany", helper.pointerTo(busCompany, "Bus_Company"));
createdSked.save({
success: function(res){ console.log("SUCCESS!"); },
error: function(err){ console.log( "Error " + err.code + " : " + err.message ); }
});
// Get Time
// Get Origin
// Get Destination
// Get Bus Company
// Create 4 pointers for the above
// Save
},
viewSchedule : function(){},
deleteSchedule : function(scheduleDay, scheduleTime){
var sked;
var skedQuery = new Parse.Query("Schedule");
skedQuery.equalTo("departureTime", scheduleTime);
skedQuery.equalTo("day", scheduleDay);
skedQuery.first()
.then(function(res){
sked = res;
console.log(res);
sked.destroy({
success: function(response){ console.log("Success") },
error: function(err){ console.log("Error " + err.code + " : " + err.message); }
})
})
},
autoGenerateSchedule : function(currUserAffiliation){
// var mondayTimes = [8:00, 10:00, 12:00, 14:00, 16:00, 18:00, 20:00];
var startDate = moment(document.getElementById("startDate").value, "YYYY-MM");
var endDate = moment(document.getElementById("endDate").value, "YYYY-MM");
console.log(document.getElementById("startDate").value);
// Parse.Cloud.run("generateTrip", {
// startDate: startDate,
// endDate: endDate,
// currUserAffiliation: currUserAffiliation
// },{
// success: function(res){ console.log(res); },
// error: function(err){ console.log(err);}
// });
var currUserAffID = currUserAffiliation;
var numberOfMonths = endDate.diff(startDate, 'months');
// number of months should be: endDATE - startDate
......@@ -370,7 +446,7 @@ var app = {
break;
}
console.log("Weekday: " + currentWeekday);
console.log("Date: " + currentDate.format("YYYY-MM-DD ddd") + " Day: " + currentWeekday);
console.log("Date: " + currentDate.format("YYYY-MM-DD HH:mm ddd") + " Day: " + currentWeekday + "Hour: " + currentDate.hour());
(function(busCompanyQuery, busCompanyValue, weekdayValue, dateAndTimeValue){
if(busPointer > busArray.length){ busPointer = 0; }
......@@ -378,13 +454,17 @@ var app = {
var skedQuery = new Parse.Query("Schedule");
skedQuery.matchesQuery("busCompany", busCompanyQuery);
skedQuery.equalTo("day", weekdayValue);
var dateAndTimeValueClone = dateAndTimeValue.clone();
skedQuery.find({
success: function(res){
// console.log("Start " + dateAndTimeValue.format("HH:mm"));
for(var k = 0; k < res.length; k++){
var timeArr = res[k].get("departureTime").split(":");
var dateAndTimeStr = dateAndTimeValue.add(timeArr[0],"h").add(timeArr[1],"m");
// console.log("Day: " + weekdayValue + " " + timeArr[0] + " " + dateAndTimeValue.hour());
var dateAndTimeStr = dateAndTimeValueClone.add(parseInt(timeArr[0]),"h").add(parseInt(timeArr[1]),"m");
dateAndTimeValueClone = dateAndTimeValue.clone();
var dateAndTimeMoment = moment(dateAndTimeStr);
console.log(dateAndTimeStr);
var Trip = new Parse.Object.extend("Trip");
var tempTrip = new Trip();
tempTrip.set("assignedSchedule", helper.pointerTo(res[k].id, "Schedule"));
......@@ -398,7 +478,7 @@ var app = {
},
error:function(err){ console.log(err); }});
}
// console.log("End " + dateAndTimeValue.format("HH:mm"));
},
error: function(err){ console.log(err.code);}
});
......@@ -407,6 +487,41 @@ var app = {
monthMoment = monthMoment.add(1, 'months');
}
}, function(err){ console.log("Error " + err.code + ": " + err.message); });
},
generateOptions : function( busCompany, parentNodeID, childClass, parseObject, objectKey ){
var objQuery = new Parse.Query(parseObject);
var busQuery = new Parse.Query("Bus_Company");
busQuery.equalTo('objectId', busCompany);
objQuery.matchesQuery("busCompany", busQuery);
objQuery.find({
success: function(res){
for (var i = res.length - 1; i >= 0; i--) {
var content = res[i].get(objectKey);
helper.appendUsingID(parentNodeID, "option", "", content);
};
},
error: function(err){ console.log("Error " + err.code + " : " + err.message ) }
});
},
addBus : function( currUserAffiliation, plateNumber, busType, seatNumber, seatCost ){
var addBus = new Parse.Object("Bus");
addBus.set("operator", helper.pointerTo(currUserAffiliation, "Bus_Company"));
console.log("I AM IN APP 1");
addBus.set("plateNumber", plateNumber);
console.log("I AM IN APP 2");
addBus.set("busType", busType);
console.log("I AM IN APP 3");
addBus.set("seatNumber", seatNumber);
console.log("I AM IN APP 4");
addBus.set("seatCost", seatCost);
console.log(addBus);
addBus.save(null,{
success: function(){
alert("Bus with plate number: " + plateNumber + " scucessfully added!");
},
error: function(err){ console.log("Error " + err.code + " : " + err.message ); }
});
}
};
......@@ -415,14 +530,19 @@ window.onload = function(){
var currLoc = location.href;
var currUserAffiliation;
if ( currLoc.indexOf("index.html") > -1) {
if ( currLoc.indexOf("index.html") > -1 ||
currLoc.indexOf("createTrip.html") > -1 ||
currLoc.indexOf("viewTrip.html") > -1 ||
currLoc.indexOf("companyMgmt.html") > -1 ||
currLoc.indexOf("viewSchedules.html") > -1 ||
currLoc.indexOf("reload.html") > -1 ) {
if( currentUser == null ){
location.href = "login.html";
} else {
var parent = document.getElementById("navigation");
var outBtn = document.createElement("button");
outBtn.setAttribute("id", "logout");
outBtn.setAttribute("onclick", "app.logout()");
outBtn.setAttribute("onclick", "app.logout(event)");
outBtn.innerHTML = "Logout";
parent.appendChild(outBtn);
}
......@@ -479,14 +599,147 @@ window.onload = function(){
if( currLoc.indexOf("viewTrip.html") != -1 ){
app.searchTrip(currUserAffiliation);
var tempDrop = document.getElementById("searchOptions");
tempDrop.onchange = function(){
var searchBox = document.getElementById("tripSearch");
var temp = helper.getSelectedOption("searchOptions");
switch( temp ){
case "Day":
searchBox.setAttribute("placeholder", "Format: Monday");
break;
case "Date":
searchBox.setAttribute("placeholder", "Format: December 1, 2015");
break;
case "Time":
searchBox.setAttribute("placeholder", "Format: 01:00 AM");
break;
}
}
var searchBtn = document.getElementById("searchBtn");
searchBtn.addEventListener("click", function(event){
event.preventDefault();
var searchByParameter = helper.getSelectedOption("searchOptions");
var searchTerm = document.getElementById("tripSearch").value;
var tripList = document.getElementById("tripList");
if( tripList.length != 0 ){
while( tripList.firstChild ){
tripList.removeChild(tripList.firstChild);
}
}
switch( searchByParameter ){
case "Day":
// app.searchTrip(currUserAffiliation, searchByParameter, searchTerm);
break;
case "Date":
var date = new Date( searchTerm );
var dateMoment = moment(date);
console.log(dateMoment);
var dateMomentMax = dateMoment.clone();
dateMomentMax.add(23, "h").add(59, 'm');
console.log(dateMomentMax);
searchTerm = dateMoment.toISOString() + "," + dateMomentMax.toISOString();
// app.searchTrip(currUserAffiliation, searchByParameter, searchTerm);
break;
case "Time":
var message = document.getElementById("timeError");
if (!searchTerm.match(/^(0?[1-9]|1[012])(:[0-5]\d) [APap][mM]$/)){
message.style.display = "block";
} else {
message.style.display = "none";
var searchArr = searchTerm.split(" ");
if (searchArr[1] == "PM" || searchArr[1] == "pm"){
var time = searchArr[0].split(":");
var hour = parseInt(time[0]) + 12;
searchTerm = hour+":"+time[1];
console.log(searchTerm);
} else {
searchTerm = searchArr[0];
}
}
break;
}
app.searchTrip(currUserAffiliation, searchByParameter, searchTerm);
});
}
if( currLoc.indexOf("createTrip.html") != -1 ){
/* Loader Settings */
var loader = document.getElementById("loader");
loader.style.display = "block";
var timeoutID = window.setTimeout(function(){ loader.style.display = "none"; }, 2000);
/* Create Trip */
var dayCreate = document.getElementById("selectScheduleDay"),
timeCreate = document.getElementById("selectScheduleTime"),
dateCreate = document.getElementById("selectTripDate"),
tripOrigin = document.getElementById("tripOrigin"),
tripDest = document.getElementById("tripDestination"),
createTripBtn = document.getElementById("createTrip__btn");
var chosenDay, chosenTime, busID, dateValue, origin, destination;
app.generateTerminalOptions("tripOrigin", "");
app.generateTerminalOptions("tripDestination", "");
app.generatePlateOptions( currUserAffiliation, "selectPlate", "" );
dateCreate.onchange = function(){
dateValue = dateCreate.value;
var dateValueClone = moment(dateValue).clone();
var dateDay = dateValueClone.day();
switch( dateDay ){
case 1:
chosenDay = "Monday";
break;
case 2:
chosenDay = "Tuesday";
break;
case 3:
chosenDay = "Wednesday";
break;
case 4:
chosenDay = "Thursday";
break;
case 5:
chosenDay = "Friday";
break;
case 6:
chosenDay = "Saturday";
break;
case 7:
chosenDay = "Sunday";
break;
}
// console.log(chosenDay)
if( timeCreate.length != 0 ){
while( timeCreate.firstChild ){
timeCreate.removeChild(timeCreate.firstChild);
}
}
// console.log(scheduleDay)
var skedQuery = new Parse.Query("Schedule");
skedQuery.equalTo("day", chosenDay);
skedQuery.descending("departureTime");
skedQuery.find({
success: function(res){
for (var i = res.length - 1; i >= 0; i--) {
var content = res[i].get("departureTime");
helper.appendUsingID("selectScheduleTime", "option", "", content);
};
},
error: function(err){ console.log("Error " + err.code + " : " + err.message ); }
});
timeCreate.onchange = function(){
chosenTime = helper.getSelectedOption("selectScheduleTime");
}
}
var busSelect = document.getElementById("selectPlate");
busSelect.onchange = function(){
var typeOutput = document.getElementById("busType"),
......@@ -494,23 +747,58 @@ window.onload = function(){
var busQuery = new Parse.Query("Bus");
busQuery.equalTo("plateNumber", value);
busQuery.first({
success : function(res){ typeOutput.value = res.get("busType"); },
success : function(res){ typeOutput.value = res.get("busType"); busID = res.id; },
error : function(err){ console.log(err.code); }
});
};
};
var submitBtn = document.getElementById("createTrip__btn");
// submitBtn.onclick = app.createTrip(currUserAffiliation);
submitBtn.addEventListener("click", function(){
submitBtn.addEventListener("click", function(event){
event.preventDefault();
console.log(busID);
origin = helper.getSelectedOption("tripOrigin");
destination = helper.getSelectedOption("tripDestination");
var originQuery = new Parse.Query("Terminal");
originQuery.equalTo("location", origin);
originQuery.find().then(function(res){ console.log(res); });
var destinationQuery = new Parse.Query("Terminal");
destinationQuery.equalTo("location", destination);
destinationQuery.find().then(function(res){ console.log(res); });
var idQuery = new Parse.Query("Schedule");
idQuery.equalTo("day", chosenDay);
idQuery.equalTo("departureTime", chosenTime);
idQuery.matchesQuery("origin", originQuery);
idQuery.matchesQuery("destination", destinationQuery);
idQuery.first({
success: function(res){
var loader = document.getElementById("loader");
loader.style.display = "block";
app.createTrip(currUserAffiliation);
var dateAndTimeValue = dateValue + " " + chosenTime;
// console.log(res);
if ( res == undefined ){
alert("No schedule with the given parameters exist.");
loader.style.display = "none";
} else {
app.createTrip(currUserAffiliation, res.id , dateAndTimeValue, busID);
}
},
error: function(err){
console.log("Error " + err.code + " : " + err.message );
}
});
});
/* Auto Generate */
var autoGenerate = document.getElementsByClassName("generateTrips__btn")[0];
autoGenerate.addEventListener("click", function(){
autoGenerate.addEventListener("click", function(event){
event.preventDefault();
app.autoGenerateSchedule(currUserAffiliation);
});
......@@ -519,24 +807,126 @@ window.onload = function(){
if ( currLoc.indexOf("reload.html") > -1 ) {
var searchBtn = document.getElementById("searchBtn");
searchBtn.addEventListener("click", function(){
event.preventDefault();
// var list = document.getElementById("searchResults");
// list.removeChild(list.firstChild);
// var num = document.getElementById("cellNum").value;
// var userQuery = new Parse.Query(Parse.User);
// // userQuery.equalTo("mobileNumber", num);
// userQuery.equalTo("cellPhone", num);
// userQuery.find({
// success : function(res){
// var item = document.createElement("li");
// item.innerHTML = "Username: " + res[0].get("username") + " Credits: " + res[0].get("creditsRemaining");
// // item.innerHTML = res[0].get("creditsRemaining");
// list.appendChild(item);
// },
// error : function(err){ console.log(err.code); }
// })
searchBtn.addEventListener("click", function(event){
event.preventDefault(event);
app.reload(currentUser.id);
});
}
if ( currLoc.indexOf("companyMgmt.html") > -1 ) {
var loader = document.getElementById("loader");
loader.style.display = "block";
app.generateTerminalOptions("originTerminal", "terminalOption");
app.generateTerminalOptions("destinationTerminal", "terminalOption");
var daySelect = document.getElementById("availableDay");
var timeSelect = document.getElementById("availableTime");
var scheduleDay, scheduleTime;
daySelect.onchange = function(){
scheduleDay = helper.getSelectedOption("availableDay");
if( timeSelect.length != 0 ){
while( timeSelect.firstChild ){
timeSelect.removeChild(timeSelect.firstChild);
}
}
console.log(scheduleDay)
var skedQuery = new Parse.Query("Schedule");
skedQuery.equalTo("day", scheduleDay);
skedQuery.descending("departureTime");
skedQuery.find({
success: function(res){
for (var i = res.length - 1; i >= 0; i--) {
var content = res[i].get("departureTime");
helper.appendUsingID("availableTime", "option", "", content);
};
},
error: function(err){ console.log("Error " + err.code + " : " + err.message ); }
});
timeSelect.onchange = function(){
scheduleTime = helper.getSelectedOption("availableTime");
}
var delSkedBtn = document.getElementById("deleteSked__btn");
delSkedBtn.addEventListener("click", function(event){
event.preventDefault();
app.deleteSchedule(scheduleDay, scheduleTime);
});
}
var timeoutID = window.setTimeout(function(){ loader.style.display = "none"; }, 2000);
// CREATE SCHEDULE
var skedInput = document.getElementById("skedTime"),
skedSelect = document.getElementById("skedDay"),
originSelect = document.getElementById("originTerminal"),
destinationSelect = document.getElementById("destinationTerminal"),
skedDay,
originSelectValue,
destinationSelectValue;
var createSkedBtn = document.getElementById("createSked__btn");
skedSelect.onchange = function(){
skedDay = helper.getSelectedOption("skedDay");
}
originSelect.onchange = function(){
originSelectValue = helper.getSelectedOption("originTerminal");
}
destinationSelect.onchange = function(){
destinationSelectValue = helper.getSelectedOption("destinationTerminal");
}
createSkedBtn.addEventListener("click", function(event){
event.preventDefault();
var originTerminal, destinationTerminal;
var skedTime = skedInput.value;
helper.getParseObjectID("location", originSelectValue, "Terminal")
.then(function(response){
originTerminal = response;
return helper.getParseObjectID("location", destinationSelectValue, "Terminal");
})
.then(function(response){
destinationTerminal = response;
app.createSchedule(
skedDay,
skedTime,
originTerminal,
destinationTerminal,
currUserAffiliation
);
});
});
// ADD BUS
var addBusTypeSelect = document.getElementById("typeInput");
var addBusBtn = document.getElementById("addBus__btn");
var addBusType, addBusCost;
// addBusTypeSelect.onchange = function(){
// addBusType = helper.getSelectedOption("typeInput");
// }
// addBusBtn.addEventListener("click", function(event){
// event.preventDefault();
// var addBusPlate = document.getElementById("plateInput").value,
// addBusSeat = document.getElementById("seatNumber");
// switch( addBusType ){
// case "R":
// console.log("HI")
// addBusCost = 50;
// break;
// case "D":
// addBusCost = 80;
// break;
// }
// app.addBus( currUserAffiliation, addBusPlate, addBusType, addBusSeat, addBusCost );
// })
}
}
\ No newline at end of file
......@@ -29,7 +29,7 @@
<label class="fa fa-unlock fa-2x login__pass">
<input type="password" id="login_pass" placeholder="Password"></label>
<label class="login__submit" >
<button id="login__btn" onclick="app.login()">Login</button>
<button id="login__btn" onclick="app.login(event)">Login</button>
</label>
</form>
</div>
......
......@@ -21,6 +21,24 @@
</nav>
</header>
<main class="container">
<p><a href="index.html"><span class="fa fa-arrow-left fa-2x"></span>&nbsp;Go back</a></p>
<h2>Search for Trips</h2>
<form class="tripSearch">
<label>
<span>Search by: </span>
<select id="searchOptions" >
<option>--</option>
<option>Day</option>
<option>Date</option>
<option>Time</option>
</select>
</label>
<label>
<span id="timeError" style="display:none; color: red;">Please follow the format 12:00 AM/PM</span>
<input type="text" id="tripSearch" placeholder="Search">
</label>
<button id="searchBtn"><span class="fa fa-search"></span></button>
</form>
<ul class="tripList" id="tripList">
</ul>
</main>
......
Markdown is supported
0% or
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment