I am writing a program that will deal with formatting the text in a text area.
The user will use Ctrl + A, Ctrl + C to copy the entirety of a web page, then paste that text into a text area. The program will take the text area, remove the junk, and output the important information to then be copied and pasted into a different system.
The concept is simple, but based on my education in programming I need a little help with the pseudocode to make sure I write this correctly and efficiently. I know this website is about code review and refactoring, so I've waited to post until I had some code written. I have already spent about three weeks on this project and I am moving too slowly. Any help would be greatly appreciated.
Here's what I know (or think I know) needs to be done: - The program will use a loop to pass through the text box contents one time, extracting the important information and putting it into the appropriate variables - There will be a two dimensional array, or rather, an array of objects. The objects will be the account lines, each with information like account number, device type, phone number, etc. - The system needs to be able to identify certain fields that can be blank. I will give an example:
Text that will be in the text box:
Account Number - Account Name - Product - Phone - Extension - Equipment - Status - Start Date - Order ID
ER4402 - testaccount - Unlimited Product - 1234567890 - 987 - FRZ142 - Active - 12-12-12 - ABC12345 ER4403 - testaccount2 - Unlimited Product - - - - Active - 12-12-12 - ABC12345
Notice the second has empty fields. I think they would be /t in the text box.
Edit: I pressed enter too soon... writing more info now
Here are the objects I've made
// Customer "class"
var customer = {
name: "",
phone: "",
compName: "",
email: "",
getInfo: function () {
return "Details: " + this.name + ", " + this.phone + ", " + this.compName + ", " + this.email;
}
}
// Account lines "class"
var account = {
checked: 0,
number: "",
ipbx: "",
product: "",
phoneNumb: "",
ext: "",
equip: "",
status: "",
startDate: "",
order: "",
getInfo: function () {
return "Details: " + this.number + ", " + this.ipbx + ", " + this.product + ", " + this.phoneNumb + ", " + this.ext + ", " + this.equip + ", " + this.status + ", " + this.startDate + ", " + this.order;
}
}
The code:
// Parse the input box into an array
var inputArr = document.getElementById("inputBox").value.split(/[ ]/);
var contNameBool = new Boolean();
var compNameBool = new Boolean();
var emailBool = new Boolean();
var accountsBool = new Boolean();
var accountLinesArray = new Array();
var marker = 1;
var arrayNumb = 0;
for(i = 0; i < inputArr.length; i++) {
switch(inputArr[i]) {
case "Name":
if(inputArr[i - 1] == "Summary") {
contNameBool = true;
break;
}
break;
case "Details":
if(contNameBool == true) {
contNameBool = false;
break;
} else if(contNameBool == false && compNameBool == true) {
compNameBool = false;
break;
}
break;
case "Customer":
if(inputArr[i - 1] == "Details") {
contNameBool = false;
compNameBool = true;
break;
}
break;
case "Address":
if(inputArr[i - 1] == "Profile") {
compNameBool = false;
emailBool = true;
break;
}
break;
case ("VISA" || "MASTERCARD" || "AMERICAN" || "DISCOVER"):
emailBool = false;
break;
case "Show":
if(inputArr[i + 1] == "next" && inputArr[1 + 2] == "row") {
accountLinesArray.length = custDet[i - 1];
break;
}
break;
case "Order":
if(inputArr[i + 1] == "ID" && inputArr[i + 2] == "MRC") {
accountsBool = true;
break;
}
break;
}
if(contNameBool == true && inputArr[i] != "Name") {
if(inputArr[i].search(",") != -1) {
var temp = inputArr[i].split(/[,]/);
temp.reverse();
if(customer.name == "") {
customer.name = temp.join(" ");
} else {
customer.name = customer.name + " " + temp.join(" ");
}
} else {
if(customer.name == "") {
customer.name = inputArr[i];
} else {
customer.name = customer.name + " " + inputArr[i];
}
}
} else if(compNameBool == true) {
if (customer.compName == "") {
customer.compName = inputArr[i + 1] + " ";
} else if(inputArr[i + 1] == "Details") {
void(0);
} else {
customer.compName = customer.compName + inputArr[i + 1] + " ";
}
} else if(emailBool == true) {
if(customer.email == "") {
customer.email = inputArr[i + 1];
} else if(inputArr[i + 1] == "VISA" || "MASTERCARD" || "AMERICAN" || "DISCOVER") {
void(0);
} else {
customer.email = customer.email + " " + inputArr[i + 1];
}
} else if(accountsBool == true) {
if(inputArr[i].replace(/[\t]/))
switch(marker) {
case 1:
accountLinesArray[arrayNumb] = new account;
break;
case 2:
break;
case 3:
break;
case 4:
break;
case 5:
break;
case 6:
break;
case 7:
break;
case 8:
break;
case 9:
break;
}
if (marker == 9) {
marker = 1;
} else {
marker++;
}
}
}
/*
customer.name = prompt("Error: Could not locate a valid Contact Name. Please input Contact Name.");
customer.compName = prompt("Error: Could not locate a valid Company Name. Please input Company Name.");
customer.email = prompt("Error: Could not locate a valid Email Address. Please input Email Address.");
*/
document.getElementById("contactNameOutput").innerHTML = customer.name;
// document.getElementById("contactNameOutput").innerHTML = inputArr;
document.getElementById("companyNameOutput").innerHTML = customer.compName;
document.getElementById("emailAddressOutput").innerHTML = customer.email;
}
The problem I'm having is figuring out how to get the program to identify when one account line has ended and a new one has begun.
I've made a marker to have the program go back to the first part of the array, but I can't wrap my head around how to get it to identify if a field is blank and how to move on to the next field and reach the end of the account line in the right order.
I realize I just asked a lot, but I don't know where to go or how to proceed with this. I admit that it's a bit over my head, but due to my frustration and level of completion, I really thought I should post it before I put the project on a hiatus. Any feedback or help would be appreciated.
Thank you.