Skip to content

Commit

Permalink
Company and Supplier ready.
Browse files Browse the repository at this point in the history
  • Loading branch information
jskno committed Sep 6, 2015
1 parent 359aaf1 commit 666c6af
Show file tree
Hide file tree
Showing 28 changed files with 687 additions and 292 deletions.
113 changes: 113 additions & 0 deletions WebContent/js/checkTaxIDCompany.js
Original file line number Diff line number Diff line change
@@ -0,0 +1,113 @@
/**
*
*/
var taxID;
var xmlhttp;
var responseXML;

var companyAdded;
var supplierAdded;

var companyId;
var companyName;
var companyTelephone;
var companyEmail;

var addCompanyUrl = "notes/addElement";
var closeCompanyUrl = "notes";
var addCompanyNextStep = "addCompany";
var closeCompanyNextStep = "newCompany";


$('#taxID').change(function() {
clearForm();
taxID = $(this).val(); // get the current value of the input field.
xmlhttp = initRequest();
sendMessageToServer();

});

function initRequest() {

if (window.XMLHttpRequest) {// code for IE7+, Firefox, Chrome, Opera, Safari
xmlhttp=new XMLHttpRequest();
} else {// code for IE6, IE5
xmlhttp=new ActiveXObject("Microsoft.XMLHTTP");
}
return xmlhttp;
}

function sendMessageToServer() {
var url = "notes/ajax?action=checkCompany&taxID=" + taxID;
xmlhttp.open("GET",url,true);
xmlhttp.onreadystatechange = callback;
xmlhttp.send();
}

function callback() {
if (xmlhttp.readyState==4 && xmlhttp.status==200) {
responseXML = xmlhttp.responseXML
process(responseXML);
}
}

function process(responseXML) {
if (responseXML == null) {
alert("There is no answer from the Server.");
return false;
} else {

companyAdded = responseXML.getElementsByTagName("companyAdded")[0].childNodes[0].nodeValue;

if (companyAdded == 1) {
populateCompanyForm();
disableCompanyForm(true);
setSubmitForm("Close", closeCompanyUrl, closeCompanyNextStep);
alert("The company already exists.");
} else {

}
}
}

function populateCompanyForm() {
companyId = responseXML.getElementsByTagName("companyId")[0].childNodes[0].nodeValue;
companyName = responseXML.getElementsByTagName("companyName")[0].childNodes[0].nodeValue;
companyTelephone = responseXML.getElementsByTagName("companyTelephone")[0].childNodes[0].nodeValue;
companyEmail = responseXML.getElementsByTagName("companyEmail")[0].childNodes[0].nodeValue;
document.getElementById("companyId").value = companyId;
document.getElementById("companyName").value = companyName;
document.getElementById("companyTelephone").value = companyTelephone;
document.getElementById("companyEmail").value = companyEmail;
}

function disableCompanyForm(value) {
document.getElementById('companyName').disabled = value;
document.getElementById('companyTelephone').disabled = value;
document.getElementById('companyEmail').disabled = value;
}

function setSubmitForm(textButton, url, step) {
// Modify the button label
var submitButton = document.getElementById("submitButton");
submitButton.innerHTML = textButton;

// Modify the url that calls the appropiate Servlet
$("#newCompany").attr("action", url);

// Modify the nextStep parameter that indicates which way to follow in the Servlet.
document.getElementById("nextStep").value = step;
}

function clearForm() {
disableCompanyForm(false);
clearFields();
setSubmitForm("Submit", addCompanyUrl, addCompanyNextStep);
}

function clearFields() {
document.getElementById("companyId").value = "";
document.getElementById("companyName").value = "";
document.getElementById("companyTelephone").value = "";
document.getElementById("companyEmail").value = "";
}
Original file line number Diff line number Diff line change
Expand Up @@ -72,7 +72,7 @@ function initRequest() {
}

function sendMessageToServer() {
var url = "notes/ajax?action=checkCompany&taxID=" + taxID;
var url = "notes/ajax?action=checkCompanyCustomer&taxID=" + taxID;
xmlhttp.open("GET",url,true);
xmlhttp.onreadystatechange = callback;
xmlhttp.send();
Expand Down Expand Up @@ -184,7 +184,8 @@ function clearForm() {
disableCustomerForm(false);
clearFields();
setSubmitForm("Submit", addCustomerUrl, addCustomerNextStep);

}

function clearFields() {
document.getElementById("companyId").value = "";
document.getElementById("companyName").value = "";
Expand All @@ -196,7 +197,6 @@ function clearFields() {
document.getElementById("customerDiscount").value = "";
}

}
function fillInFields() {
// document.getElementById("companyNameLabel").innerHTML = customerAdded2;
}
146 changes: 146 additions & 0 deletions WebContent/js/checkTaxIDSupplier.js
Original file line number Diff line number Diff line change
@@ -0,0 +1,146 @@
/**
*
*/
var taxID;
var xmlhttp;
var responseXML;
var string = "come on";

var companyAdded;
var supplierAdded;

var companyId;
var companyName;
var companyTelephone;
var companyEmail;

var roleId;
var contactName;
var contactTelephone;
var deliveryDays;
var supplierAdded;

var addSupplierUrl = "notes/addElement";
var closeSupplierUrl = "notes";
var addSupplierNextStep = "addSupplier";
var closeSupplierNextStep = "newSupplier";


$('#taxID').change(function() {
clearForm();
taxID = $(this).val(); // get the current value of the input field.
xmlhttp = initRequest();
sendMessageToServer();

});

function initRequest() {

if (window.XMLHttpRequest) {// code for IE7+, Firefox, Chrome, Opera, Safari
xmlhttp=new XMLHttpRequest();
} else {// code for IE6, IE5
xmlhttp=new ActiveXObject("Microsoft.XMLHTTP");
}
return xmlhttp;
}

function sendMessageToServer() {
var url = "notes/ajax?action=checkCompanySupplier&taxID=" + taxID;
xmlhttp.open("GET",url,true);
xmlhttp.onreadystatechange = callback;
xmlhttp.send();
}

function callback() {
if (xmlhttp.readyState==4 && xmlhttp.status==200) {
responseXML = xmlhttp.responseXML
process(responseXML);
}
}

function process(responseXML) {
if (responseXML == null) {
alert("There is no answer from the Server.");
return false;
} else {

supplierAdded = responseXML.getElementsByTagName("supplierAdded")[0].childNodes[0].nodeValue;
companyAdded = responseXML.getElementsByTagName("companyAdded")[0].childNodes[0].nodeValue;

if (companyAdded == 1) {
populateCompanyForm();
disableCompanyForm(true);

if (supplierAdded == 1) {
populateSupplierForm();
disableSupplierForm(true);
setSubmitForm("Close", closeSupplierUrl, closeSupplierNextStep);
alert("The supplier already exists.");
}
} else {

}
}
}

function populateCompanyForm() {
companyId = responseXML.getElementsByTagName("companyId")[0].childNodes[0].nodeValue;
companyName = responseXML.getElementsByTagName("companyName")[0].childNodes[0].nodeValue;
companyTelephone = responseXML.getElementsByTagName("companyTelephone")[0].childNodes[0].nodeValue;
companyEmail = responseXML.getElementsByTagName("companyEmail")[0].childNodes[0].nodeValue;
document.getElementById("companyId").value = companyId;
document.getElementById("companyName").value = companyName;
document.getElementById("companyTelephone").value = companyTelephone;
document.getElementById("companyEmail").value = companyEmail;

}

function populateSupplierForm() {
contactName = responseXML.getElementsByTagName("contactName")[0].childNodes[0].nodeValue;
contactTelephone = responseXML.getElementsByTagName("contactTelephone")[0].childNodes[0].nodeValue;
deliveryDays = responseXML.getElementsByTagName("deliveryDays")[0].childNodes[0].nodeValue;
document.getElementById("contactName").value = contactName;
document.getElementById("contactTelephone").value = contactTelephone;
document.getElementById("deliveryDays").value = deliveryDays;
}

function disableCompanyForm(value) {
document.getElementById('companyName').disabled = value;
document.getElementById('companyTelephone').disabled = value;
document.getElementById('companyEmail').disabled = value;
}

function disableSupplierForm(value) {
document.getElementById('contactName').disabled = value;
document.getElementById('contactTelephone').disabled = value;
document.getElementById('deliveryDays').disabled = value;
}

function setSubmitForm(textButton, url, step) {
// Modify the button label
var submitButton = document.getElementById("submitButton");
submitButton.innerHTML = textButton;

// Modify the url that calls the appropiate Servlet
$("#newSupplier").attr("action", url);

// Modify the nextStep parameter that indicates which way to follow in the Servlet.
document.getElementById("nextStep").value = step;
}

function clearForm() {
disableCompanyForm(false);
disableSupplierForm(false);
clearFields();
setSubmitForm("Submit", addSupplierUrl, addSupplierNextStep);
}

function clearFields() {
document.getElementById("companyId").value = "";
document.getElementById("companyName").value = "";
document.getElementById("companyTelephone").value = "";
document.getElementById("companyEmail").value = "";
document.getElementById("contactName").value = "";
document.getElementById("contactTelephone").value = "";
document.getElementById("deliveryDays").value = "";
}
Loading

0 comments on commit 666c6af

Please sign in to comment.