Szablon:Edycja: Różnice pomiędzy wersjami
Nie podano opisu zmian |
Nie podano opisu zmian |
||
(Nie pokazano 3 wersji utworzonych przez 2 użytkowników) | |||
Linia 2: | Linia 2: | ||
<html> | <html> | ||
<body> | <body> | ||
<div class="form-group"> | <div class="form-group"> | ||
Linia 34: | Linia 30: | ||
</div> | </div> | ||
<div class="form-group"> | <div class="form-group"> | ||
<label for="targetLevel">Wybierz docelowy poziom:</label> | <label for="targetLevel" id="targetLevelLabel">Wybierz docelowy poziom:</label> | ||
<select class="form-control" id="targetLevel"> | <select class="form-control" id="targetLevel"> | ||
</select> | </select> | ||
Linia 41: | Linia 37: | ||
<button onclick="calculatePoints()" class="btn btn-primary">Oblicz</button> | <button onclick="calculatePoints()" class="btn btn-primary">Oblicz</button> | ||
</div> | </div> | ||
<p id="pointsNeeded" class="font-weight-bold | <p id="pointsNeeded" class="font-weight-bold text-center"> | ||
</p> | </p> | ||
</div> | </div> | ||
Linia 47: | Linia 43: | ||
<script> | <script> | ||
document.addEventListener("DOMContentLoaded",function(){ | |||
const currentLevelSelect = document.querySelector('#currentLevel'); | |||
const targetLevelSelect = document.querySelector('#targetLevel'); | |||
const professionInput = document.getElementById("profession"); | |||
const abilityInput = document.getElementById("ability"); | |||
const updateLevels = function() { | |||
currentLevelSelect.innerHTML = ''; | |||
targetLevelSelect.innerHTML = ''; | |||
const limit = !!this.Altaron ? Altaron.getSkillLimit(professionInput.value, abilityInput.value) : 200; | |||
for (let i = 1; i <= limit; i++) { | |||
const option1 = document.createElement('option'); | |||
option1.value = i; | |||
option1.textContent = i; | |||
targetLevelSelect.appendChild(option1); | |||
var ability = | const option2 = document.createElement('option'); | ||
option2.value = i; | |||
option2.textContent = i; | |||
currentLevelSelect.appendChild(option2); | |||
} | |||
}; | |||
updateLevels(); | |||
const clearInputErrors = function() { | |||
document.getElementById("targetLevel").classList.remove("is-invalid"); | |||
document.getElementById("targetLevelLabel").classList.remove("text-danger"); | |||
}; | |||
professionInput.addEventListener('change', function(){ | |||
updateLevels(); | |||
clearInputErrors(); | |||
}); | |||
abilityInput.addEventListener('change', function(){ | |||
updateLevels(); | |||
clearInputErrors(); | |||
}); | |||
window.calculatePoints = function() { | |||
var profession = professionInput.value; | |||
var ability = abilityInput.value; | |||
var currentLevel = parseInt(currentLevelSelect.value); | |||
var targetLevel = parseInt(targetLevelSelect.value); | |||
var pointsNeeded = 0; | var pointsNeeded = 0; | ||
var limit = Altaron.getSkillLimit(profession, ability); | var limit = Altaron.getSkillLimit(profession, ability); | ||
clearInputErrors(); | |||
if (targetLevel > limit) { | |||
document.getElementById("pointsNeeded").innerHTML ="Docelowy poziom jest większy niż maksymalny poziom " + limit + "."; | |||
document.getElementById("targetLevel").classList.add("is-invalid"); | |||
document.getElementById("targetLevelLabel").classList.add("text-danger") | |||
return; | |||
} | |||
else if (targetLevel < currentLevel) { | |||
document.getElementById("pointsNeeded").innerHTML ="Docelowy poziom " + targetLevel + " nie może być mniejszy od obecnego " + currentLevel + "."; | |||
document.getElementById("targetLevel").classList.add("is-invalid"); | |||
document.getElementById("targetLevelLabel").classList.add("text-danger") | |||
return; | |||
} | |||
for(var i = currentLevel; i < targetLevel; i++) { | for(var i = currentLevel; i < targetLevel; i++) { | ||
pointsNeeded += Altaron.getLearnPointsForLevel(profession, ability, i); | |||
} | } | ||
document.getElementById("pointsNeeded").innerHTML = "Brakuje Ci " + pointsNeeded + " punktów nauki."; | |||
}; | |||
}); | |||
</script> | </script> | ||
</html> | </html> | ||
</altaronpanel> | </altaronpanel> |