New Function : convertCurrency

This commit is contained in:
Divlo
2019-09-13 21:56:36 +02:00
parent 04b95d8988
commit c5c167a806
10 changed files with 94 additions and 7 deletions

View File

@ -37,7 +37,7 @@ function weatherRequest(url,toDo) {
},
statusCode: {
404: function() {
document.location.replace("../error404.php");
document.location.replace("../error404Weather");
}
}
});
@ -170,13 +170,38 @@ function filterStudents(filteredLetter, students)
}
}
// Génère aléatoirement une citation ou un proverbe.
// Génère aléatoirement une citation ou un proverbe
function getRandomQuote() {
let randomNbr = randomNumber(0, (quotes.length - 1));
let randomQuotes = quotes[randomNbr];
return '" ' + randomQuotes["quote"] + ' " <br> <br> - ' + randomQuotes["source"];
}
// Convertis des euros (€) dans une autre devise
function convertCurrency(urlFixerIO, currency, euroValue) {
$.ajax({
url : urlFixerIO,
dataType : "jsonp",
success: function (jsonFixer) {
switch(currency) {
case '$':
$('.results').html(formatNumberResult(euroValue) + ' € = ' + (formatNumberResult(parseFloat(jsonFixer.rates.USD) * euroValue)).toFixed(2) + ' ' + currency);
break;
case '£':
$('.results').html(formatNumberResult(euroValue) + ' € = ' + (formatNumberResult(parseFloat(jsonFixer.rates.GBP) * euroValue)).toFixed(2) + ' ' + currency);
break;
default:
$('.results').html(formatNumberResult(euroValue) + ' €');
break;
}
},
statusCode: {
404: function() {
document.location.replace("../404.php");
}
}
});
}
/////////////////////////////////////////////////////////////////
/* Fonctions Annexes */

View File

@ -21,7 +21,7 @@ $(function () {
}
else
{
let url = "https://api.openweathermap.org/data/2.5/weather?q=" + cityName + "&lang=fr&units=metric&appid=" + config.APIkey + "";
let url = "https://api.openweathermap.org/data/2.5/weather?q=" + cityName + "&lang=fr&units=metric&appid=" + config.APIkeyWeather + "";
weatherRequest(url, 'weather');
}
});
@ -161,6 +161,25 @@ $(function () {
}
}
$("#submitConvertCurrency").click(function()
{
let euroValue = $('#euroValue').val();
let euroToCurrency = $("#euroToCurrency option:selected").val();
if(isEmptyValue(euroValue) || isNaN(parseFloat(euroValue)))
{
$('.results').html(emptyMessageError);
$("#euroValue, #submitConvertCurrency").click(function() {
document.location.replace("../function-views/convertCurrency.php");
});
}
else
{
euroValue = parseFloat(euroValue);
let urlFixer = 'http://data.fixer.io/api/latest?access_key=' + config.APIkeyFixer;
convertCurrency(urlFixer, euroToCurrency, euroValue);
}
});
/* Permet d'afficher l'heure en temps réel sur le footer */
window.onload = realDateTime('realDateTime');