Commit 7e69c117 authored by Matthew Burket's avatar Matthew Burket
Browse files

Code clean up

parent 3f1dd0cc
......@@ -13,9 +13,8 @@
}
table, tr, td {
border-jlapse: jlapse;
border-style: solid;
border-width: 1px;
border-color: black;
border: 1px solid;
padding: 4px;
}
......
/**
* Created by matthewburket and David Garner on 2/22/16.
* Created by Matthew Burket and David Garner on 2/22/16.
*/
......@@ -13,35 +13,35 @@ Library.prototype.addShelf = function(shelfName) {
};
Library.prototype.getBook = function(shelf, title){
var myBooks = this.shelves[shelf].books
var myBooks = this.shelves[shelf].books;
for (var i = 0; i < myBooks.length; i++) {
if(myBooks[i].name == title){
return myBooks[i];
}
};
}
}
};
Library.prototype.isBookAvalible = function(book){
Library.prototype.isBookAvailable = function(book){
if( !(book.isCheckedOut)){
return book.shelf
return book.shelf;
}
}
};
Library.prototype.getShelves = function(book){
return this.shelves
}
return this.shelves;
};
Library.prototype.checkOutBook = function(book){
if(!(book.isCheckedOut)){
book.checkOut()
return 1
book.checkOut();
return 1;
}
return 0
}
return 0;
};
......@@ -64,15 +64,15 @@ var Book = function(name,shelf) {
Book.prototype.getCopies = function(){
return this.numCopies;
}
};
Book.prototype.checkOut = function(){
this.numCopies--
this.numCopies--;
if(this.numCopies <= 0){
this.isCheckedOut = true
}
}
};
......
......@@ -5,7 +5,7 @@
jQuery(function () {
// CSS
$("body").css('background', 'green');
$("h1").css('jor', 'white');
$("h1").css('color', 'white');
$("p").css('font-size', '20px');
$("button").css('height', '20px');
$("a").css('text-decoration', 'none');
......
......@@ -3,8 +3,8 @@
*/
jQuery(function() {
var i, j, lib, table, currentShelf, currentBook;
var lib = new Library("Iowa State Library");
var i, j, lib, table, currentShelf, currentBook, cell, bookTitleStr, topRow;
lib = new Library("Iowa State Library");
i = 0;
while (i < 3) {
......@@ -27,36 +27,28 @@ jQuery(function() {
table += "</table>";
$('body').append(table);
var bookTitleStr = "<h>Title:</h>"
bookTitleStr = bookTitleStr + "<p id=bookSelect>No title selected</p>"
$('body').append(bookTitleStr)
$('body').append("<button>Checkout</button>")
bookTitleStr = "<h3>Title: <span id=\"bookSelect\"></span></h3>";
$('body').append(table).append(bookTitleStr).append("<button>Checkout</button>");
$(function(){
$('button').on('click',function(){
var status = lib.checkOutBook(currentBook);
if(status == 1)
document.getElementById("bookSelect").innerHTML = "You checked Out: " + currentBook.name +
" " + currentBook.getCopies() + " copies left!"
" " + currentBook.getCopies() + " copies left!";
else{
document.getElementById("bookSelect").innerHTML = currentBook.name + " is unavalible"
document.getElementById("bookSelect").innerHTML = currentBook.name + " is unavailable"
}
});
});
var table = document.getElementById('myTable');
var topRow = table.insertRow(-1);
for (var i = 0; i < lib.shelves.length; i++) {
table = document.getElementById('myTable');
topRow = table.insertRow(-1);
for (i = 0; i < lib.shelves.length; i++) {
currentShelf = lib.shelves[i];
topRow.insertCell(-1).innerHTML = currentShelf.name
for (var j = 1; j < currentShelf.books.length; j++) {
topRow.insertCell(-1).innerHTML = currentShelf.name;
for (j = 1; j < currentShelf.books.length; j++) {
if(i == 0){
table.insertRow(-1);
}
......@@ -64,14 +56,15 @@ jQuery(function() {
bookTitle = currentShelf.books[j].name;
table.rows[j].insertCell(-1).innerHTML = bookTitle;
var cell = table.rows[j].cells[i]
cell.className = "styleClass"
cell.shelf = i
cell = table.rows[j].cells[i];
cell.className = "styleClass";
cell.shelf = i;
cell.addEventListener("click",
function(e){
currentBook = lib.getBook(e.target.shelf,this.innerHTML);
document.getElementById("bookSelect").innerHTML = currentBook.name + " Copies: " + currentBook.getCopies()
})
document.getElementById("bookSelect").innerHTML = currentBook.name + " Copies: " + currentBook.getCopies();
}
)
}
}
});
\ No newline at end of file
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