Commit 4cde789a authored by Alex Moore's avatar Alex Moore

final code update

parents d88480e2 9321a650
......@@ -2,5 +2,5 @@
var div = document.getElementById("ActionMessage");
var msg = div.getElementsByTagName("td")[0].innerHTML.trim().replace(",", "-");
return msg.replace(/<br>/g, ",");
return msg.replace(/<br>/g, ",");
})();
\ 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" : [';
(function () {
var scannedDiv = document.getElementById("ScannedListDiv");
var scannedTB = scannedDiv.children[0].children[0];
var allRows = scannedTB.children;
var scannedRows = [];
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];
}
}
for (var i = 1; i < allRows.length; i++) {
if (allRows[i].childElementCount !== 0) {
scannedRows[scannedRows.length] = allRows[i];
}
}
for (var j = 0; j < scannedRows.length; j++) {
var curRow = scannedRows[j].children;
// 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
for (var k = 0; k < curRow.length; k++) {
if (curRow[k].hasAttribute("title")) {
var bookProp = curRow[k].title;
// Go through each td element in a row
for (var k = 0; k < rowChildren.length; k++) { // k is col num
if (rowChildren[k].hasAttribute("title")) {
var bookProp = rowChildren[k].title; // Information desired
switch (k) {
case 1:
scannedBooks += '{"barcode":"' + bookProp.trim() + '", ';
break;
case 2:
scannedBooks += '"callnum":"' + bookProp.trim() + '", ';
break;
case 3:
scannedBooks += '"title":"' + bookProp.trim() + '"},';
break;
}
}
}
}
scannedBooks = scannedBooks.substring(0, scannedBooks.length - 1);
switch (k) {
case 1:
scannedBooks += '{"barcode":"' + bookProp.trim() + '", ';
break;
case 2:
scannedBooks += '"callnum":"' + bookProp.trim() + '", ';
break;
case 3:
scannedBooks += '"title":"' + bookProp.trim() + '"},';
break;
}
}
// 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
return scannedBooks + ']}';
})();
\ No newline at end of file
......@@ -2,6 +2,5 @@
var barcode = document.getElementById("BarcodeInput");
barcode.value = code;
// TODO: Think this is good enough to call function present
recordBarcode();
})();
\ No newline at end of file
# Error Page JavaScript
The JS functions specified below are run only on the Error Page.
\ No newline at end of file
The JS functions specified below are run only on the Error Page.
### [GetError.js](/WAMI/WAMI/GetError.js)
GetError is designed built to retrieve the particular error message displayed on the Scan Error page. To do this it will first get the element that holds the error message by its ID, `ActionMessage`. With this element it will retrieve the message by getting the inner HTML content of the first HTML column element, `td` elements, replacing all commas with the '-' character and replacing html line break tags with commas to make parsing of the message simpler for the application, and then returning the error message.
```javascript
var div = document.getElementById("ActionMessage");
var msg = div.getElementsByTagName("td")[0].innerHTML.trim().replace(",", "-");
return msg.replace(/<br>/g, ",");
```
**Note that layout or aesthetic changes to the Scan Error Page can cause unpredictable behavior.**
### [GoToScan.js](/WAMI/WAMI/GoToScan.js)
The GoToScan function is another very simple function, only consisting of one line of JavaScript. This function is used to proceed from the Scan Error page back to the Scan Page, it does this by calling the Scan Error Page `onContinue` function, which is internal to that page and directs the user back to the Scan Page.
---
#### References/See Also
* [JavaScript Strings](http://www.w3schools.com/jsref/jsref_obj_string.asp)
* [HTML ELement](http://www.w3schools.com/jsref/dom_obj_all.asp)
\ No newline at end of file
......@@ -33,6 +33,6 @@ Function will return 0 through 3 depending upon the step of the inventory proces
---
#### References/See Also
[URL property](http://www.w3schools.com/jsref/prop_doc_url.asp)
[Document object](http://www.w3schools.com/jsref/dom_obj_document.asp)
[String search](http://www.w3schools.com/jsref/jsref_search.asp)
\ No newline at end of file
* [URL property](http://www.w3schools.com/jsref/prop_doc_url.asp)
* [Document object](http://www.w3schools.com/jsref/dom_obj_document.asp)
* [String search](http://www.w3schools.com/jsref/jsref_search.asp)
\ No newline at end of file
......@@ -35,7 +35,7 @@ doLogin();
---
#### References/See Also
[getElementyById Method](http://www.w3schools.com/jsref/met_document_getelementbyid.asp)
[Select Element](http://www.w3schools.com/jsref/dom_obj_select.asp)
[Checkbox Element](http://www.w3schools.com/jsref/dom_obj_checkbox.asp)
* [getElementyById Method](http://www.w3schools.com/jsref/met_document_getelementbyid.asp)
* [Select Element](http://www.w3schools.com/jsref/dom_obj_select.asp)
* [Checkbox Element](http://www.w3schools.com/jsref/dom_obj_checkbox.asp)
# Scan Page JavaScript
The JS functions specified below are run only on the Scan Page.
\ No newline at end of file
The JS functions specified below are run only on the Scan Page.
### [GetScanned.js](/WAMI/WAMI/GetScanned.js)
Scanned book information is stored in a table on the scan page. Each row of the table corresponds to a single scan record. In each row the information desired (in the order of ID number, call number, and title) is stored in column elements. This file is used to retrieve the information mentioned by crawling through the table and inspecting each element encountered.
GetSanned.js will only return scanned items contained in the table on the page, as it will ignore empty rows and columns. It does this by iterate through all rows in scan table, ignoring the first header rows and empty spacing rows, saving only the rows containing scan records.
```javascript
for (var i = 1; i < allRows.length; i++) {
// Row is spacing if it doesn't have any children (i.e. columns, etc.)
if (allRows[i].childElementCount !== 0) {
scannedRows[scannedRows.length] = allRows[i]; // Store all non-spacing rows
}
}
```
Header rows are ignored by starting at the 2nd row, index 1, rather than the first, index 0. Empty rows are ignored by checking if the row has any child elements.
After retrieving all scan rows, the script will iterate through each of these rows and then go through every column in a row looking for the information desired. If the information is encountered put it into the JSON formatted list of books declared earlier in the function in a format as specified below.
```javascript
// Scanned Records JSON format
{ "books":
[
{
"barcode": "barcodeValue",
"callnum": "callnumValue",
"title": "titleValue"
},
{...},...
]
}
```
**Note that whitespace is largely irrelevant for a JSON string.**
```javascript
// From scanned rows stored apart from all rows, all rows containing records
for (var j = 0; j < scannedRows.length; j++) {
var curRow = scannedRows[j].children; // Array of tds (columns)
// Go through each column in the row
for (var k = 0; k < rowChildren.length; k++) {
if (rowChildren[k].hasAttribute("title")) { // Info desired is held in column title attribute
var bookProp = rowChildren[k].title;
// Determine what the information is and add it to the scanned books JSON list
switch (k) {
case 1: // Start at second column as numbering starts at 0 and the first is spacing
scannedBooks += '{"barcode":"' + bookProp.trim() + '", ';
break;
case 2:
scannedBooks += '"callnum":"' + bookProp.trim() + '", ';
break;
case 3:
scannedBooks += '"title":"' + bookProp.trim() + '"},';
break;
}
}
}
}
```
**Note that layout or aesthetic changes to the scanned list table can cause unpredictable behavior.**
The function is dependent on encountering information in an expected order of barcode number, callnumber, and title while iterating through the columns of a row, with any scan error information stored in the callnumber. If this order changes the script will incorrectly identify certain properties or not save others if they are pushed out of it's range.
Once all rows have been scoured for scanned records, remove the last comma and return the JSON string capped with a bracket and a brace to end the JSON string.
```javascript
scannedBooks = scannedBooks.substring(0, scannedBooks.length - 1); // Trim last comma
return scannedBooks + ']}'; // Cap end of string and return
```
### [ScanBarcode.js](/WAMI/WAMI/ScanBarcode.js)
Scan barcode is a very short function that is designed to, as the name suggests, simulate the scanning of a barcode. Before the function can be called it needs a JavaScript variable, `code`, to be declared and its value to be set to that of the item which was scanned. Once this is complete and the function is executed it will get the barcode input field of the page, `BarcodeInput`, and set that value to the barcode stored in the variable code. The function will then call the page's internal function to save that code, `recordCode`, at which point the function has completed its procedure.
```javascript
var barcode = document.getElementById("BarcodeInput");
barcode.value = code;
recordBarcode();
```
### ~~[FinishScan.js](/WAMI/WAMI/FinishScan.js)~~
This function is not currently used by the WAMI application as the Library Staff felt it would be advantageous to remove the change of clicking Finish before completing a scan, requiring another inventory of those sections to correctly mark books as missing or not. Finish scan is designed to finish an inventory scan, by emulating the Finish button on the RTI scan page. This ends up being very simple one line procedure to call the internal function that finishes a scan, `finishedScanning`, that the finish button on the page calls. This behavior can be added by following the pattern set forth by the other application buttons which call JavaScript functions.
---
#### References/See Also
* [JavaScript JSON](http://www.w3schools.com/js/js_json.asp)
* [HTML ELement](http://www.w3schools.com/jsref/dom_obj_all.asp)
* [Text Input Element](http://www.w3schools.com/jsref/dom_obj_text.asp)
* [JavaScript Strings](http://www.w3schools.com/jsref/jsref_obj_string.asp)
\ No newline at end of file
......@@ -82,7 +82,7 @@ OnOk(returnObjById("CollectionList2"), collectionsArray, CheckShelfOrder, Ignore
---
#### References/See Also
[Select Element](http://www.w3schools.com/jsref/dom_obj_select.asp)
[JavaScript Strings](http://www.w3schools.com/jsref/jsref_obj_string.asp)
[Checkbox Element](http://www.w3schools.com/jsref/dom_obj_checkbox.asp)
[JavaScript JSON](http://www.w3schools.com/js/js_json.asp)
* [Select Element](http://www.w3schools.com/jsref/dom_obj_select.asp)
* [JavaScript Strings](http://www.w3schools.com/jsref/jsref_obj_string.asp)
* [Checkbox Element](http://www.w3schools.com/jsref/dom_obj_checkbox.asp)
* [JavaScript JSON](http://www.w3schools.com/js/js_json.asp)
\ 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