Skip to content

final mod exercise1 #37

New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Open
wants to merge 1 commit into
base: master
Choose a base branch
from
Open
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
41 changes: 32 additions & 9 deletions assets/js/quote.js
Original file line number Diff line number Diff line change
Expand Up @@ -13,8 +13,11 @@ $(document).ready(function () {
});


$('#standart, #premium, #excelium').on('click', function () {
document.getElementById('elevPriceUnit').value = (7565).toFixed(2) + " $";
$('#standard, #premium, #excelium').on('click', function () {

var prodRange = getProdRange();

document.getElementById('elevPriceUnit').value = (prodRange.price).toFixed(2) + " $";
doCalc();
});

Expand Down Expand Up @@ -49,6 +52,7 @@ $(document).ready(function () {
};

function getProdRange() {

if ($('#standard').is(':checked')) {
prodRange.type = "standard";
prodRange.price = parseFloat(7565);
Expand All @@ -57,7 +61,7 @@ $(document).ready(function () {

} else if ($('#premium').is(':checked')) {
prodRange.type = "premium";
prodRange.price = parseFloat(123456);
prodRange.price = parseFloat(12345);
prodRange.installationFeePercentage = 0.13;
return prodRange;

Expand All @@ -68,13 +72,14 @@ $(document).ready(function () {
return prodRange;
} else {
prodRange.type = null,
prodRange.price = null,
prodRange.installationFeePercentage = null
prodRange.price = null,
prodRange.installationFeePercentage = null
return prodRange;
}
};

function GetInfos() {
getInfoNumApp();
getInfoNumFloors();
getInfoNumBase();
getInfoNumElev();
Expand All @@ -93,18 +98,21 @@ $(document).ready(function () {
};

function emptyElevatorsNumberAndPricesFields() {
$('#numElev_2').val('');
$('#numElev_3').val('');
$('.priceField').val('');
};

function createFormData(projectType) {

return {
numberApp: numApp,
numberFloors: numFloors,
numberBase: numBase,
maximumOcc: maxOcc,
productRange: prodRange,
projectType: projectType
projectType: projectType,
numberElev: numElev
}
};

Expand All @@ -115,6 +123,12 @@ $(document).ready(function () {
$('#numApp').val('');
return true

} else if ($('#numFloors').val() < 0) {

alert("Please enter a positive number!");
$('#numFloors').val('');
return true

} else if ($('#numBase').val() < 0) {

alert("Please enter a positive number!");
Expand Down Expand Up @@ -162,6 +176,8 @@ $(document).ready(function () {
//Preparing data for Api call
formData = createFormData(projectType)

console.log(formData);

$.ajax({
type: "POST",
// url: 'http://localhost:3000/api/quoteCalculation/', //for local testing
Expand All @@ -170,21 +186,28 @@ $(document).ready(function () {
contentType: "application/json; charset=utf-8",
dataType: "json",
success: function (data) {

console.log(data);
console.log(data.finalNumElev);

setRequiredElevatorsResult(data.finalNumElev);
if (prodRange.type != null) {
setPricesResults(data.finalNumElev, data.subTotal, data.installationFee, data.grandTotal);
}
}
});
}

function doCalc() {

if ($('#residential').hasClass('active') && !negativeValues() && $('#numApp').val() && $('#numFloors').val()) {
apiCall('residential')
} else if ($('#commercial').hasClass('active') && !negativeValues() && $('#numElev').val() && $('#numPark').val()) {
} else if ($('#commercial').hasClass('active') && !negativeValues() && $('#numElev').val()) {
apiCall('commercial')
} else if ($('#corporate').hasClass('active') && !negativeValues() && $('#numFloors').val() && $('#numBase').val() && $('#maxOcc').val()) {
apiCall('commercial')
apiCall('corporate')
} else if ($('#hybrid').hasClass('active') && !negativeValues() && $('#numFloors').val() && $('#numBase').val() && $('#maxOcc').val()) {
apiCall('hybrid')
} else {
emptyElevatorsNumberAndPricesFields();
};
Expand Down
9 changes: 6 additions & 3 deletions quote.html
Original file line number Diff line number Diff line change
Expand Up @@ -214,17 +214,20 @@ <h2 class="card-title">Select a range</h2>

<!-- radio -->
<label class="radio">
<input type="radio" name="radio-btn" value="1" id="standard" class="productRangeBtn">
<input type="radio" name="radio-btn" value="1" id="standard"
class="productRangeBtn">
<i></i> Standard
</label>

<label class="radio">
<input type="radio" name="radio-btn" value="1" id="premium" class="productRangeBtn">
<input type="radio" name="radio-btn" value="1" id="premium"
class="productRangeBtn">
<i></i> Premium
</label>

<label class="radio">
<input type="radio" name="radio-btn" value="1" id="excelium" class="productRangeBtn">
<input type="radio" name="radio-btn" value="1" id="excelium"
class="productRangeBtn">
<i></i> Excelium
</label>

Expand Down