Commit c47f0edd authored by Jake Mylet's avatar Jake Mylet

Updating GetScanned page. Now will also return a JSON string with error...

Updating GetScanned page. Now will also return a JSON string with error specified as true or false depending on the background color of the td element.
parent e1ad6e13
(function() {
var scannedDiv = document.getElementById("ScannedListDiv");
var scannedTB = scannedDiv.children[0].children[0];
var allRows = scannedTB.children;
var scannedRows = []; // Array of tr elements
var scannedBooks = '{ "books" : [';
// Go through all rows, except header, to get all scanned rows
for (var i = 1; i < allRows.length; i++) {
if (allRows[i].childElementCount !== 0) { // Ignore empty spacing rows
scannedRows[scannedRows.length] = allRows[i];
}
}
// Go through scanned rows
for (var j = 0; j < scannedRows.length; j++) {
if (scannedRows[j].children.length !== 0) {
// Scanned rows is a tr element with td children
var rowChildren = scannedRows[j].children; // Array of tds
// Go through each td element in a row
for (var k = 0; k < rowChildren.length; k++) { // k is col num
if (rowChildren[k].childElementCount !== 0) { // If the td has children (font)
var bookProp = rowChildren[k].children[0]; // font element
// If the col isn't empty
var a = bookProp.innerHTML;
if (bookProp.innerHTML != "&nbsp;" && bookProp.innerHTML !== "") {
switch(k) {
case 1: // ID Prop - called barcode for later JSON processing (so as not
//to interfere with "id" keyword
scannedBooks += '{"barcode":"' + bookProp.innerHTML.trim() + '", ';
break;
case 2: // Call Num
scannedBooks += '"callnum":"' + bookProp.innerHTML.trim() + '", ';
break;
case 3: // Title
scannedBooks += '"title":"' + bookProp.innerHTML.trim() + '"},';
break;
}
}
}
}
}
}
scannedBooks = scannedBooks.substring(0, scannedBooks.length-1);
return scannedBooks + ']}';
})();
\ No newline at end of file
(function () {
var scannedDiv = document.getElementById("ScannedListDiv");
var scannedTB = scannedDiv.children[0].children[0];
var allRows = scannedTB.children;
var scannedRows = []; // Array of tr elements
var scannedBooks = '{ "books" : [';
// Go through all rows, except header, to get all scanned rows
for (var i = 1; i < allRows.length; i++) {
if (allRows[i].childElementCount !== 0) { // Ignore empty spacing rows
scannedRows[scannedRows.length] = allRows[i];
}
}
// Go through scanned rows
for (var j = 0; j < scannedRows.length; j++) {
if (scannedRows[j].children.length !== 0) {
// Scanned rows is a tr element with td children
var rowChildren = scannedRows[j].children; // Array of tds
// Go through each td element in a row
for (var k = 0; k < rowChildren.length; k++) { // k is col num
if (rowChildren[k].childElementCount !== 0) { // If the td has children (font)
var bookProp = rowChildren[k].children[0]; // font element
var tdElement = rowChildren[k];
// Contents of font element
var contents = bookProp.innerHTML;
if (bookProp.innerHTML != "&nbsp;" && contents !== "") {
switch (k) {
case 1:
scannedBooks += '{"barcode":"' + contents.trim() + '", ';
// Look for error bgcolor contained in first td element
if (tdElement.bgColor == "#ffffcc") {
scannedBooks += '"error":"true", ';
}
else {
scannedBooks += '"error":"false", ';
}
break;
case 2: // Call Num
scannedBooks += '"callnum":"' + contents.trim() + '", ';
break;
case 3: // Title
scannedBooks += '"title":"' + contents.trim() + '"},';
break;
}
}
}
}
}
}
scannedBooks = scannedBooks.substring(0, scannedBooks.length - 1);
return scannedBooks + ']}';
})();
\ 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