fix bugs chọn được mốc thời gian chồng chéo

This commit is contained in:
2020-11-13 11:33:18 +07:00
parent 463fa90f8a
commit aa1144da08
3 changed files with 36 additions and 3 deletions

View File

@@ -74,6 +74,10 @@ function saveCurrentPos() {
alert("Mốc thời gian lựa chọn chưa đúng!");
return false;
}
if (!checkTime(currentID)) {
alert("Các mốc thời gian trong ngày không được phép chồng chéo!");
return false;
}
if (f !== "00:00" || t !== "00:00") {
var html = `<span style="cursor: pointer;" onclick="openFormTimePicker(this);" data-id="` + currentID + `">` + f + ` - ` + t + `</span>`;
$("#data-" + currentID).html(html);
@@ -87,6 +91,35 @@ function saveCurrentPos() {
return true;
}
function checkTime(currentID) {
var fCheck = convertTime($("input[name='From" + currentID + "']").val());
var tCheck = convertTime($("input[name='To" + currentID + "']").val());
var currentDay = currentID.substring(0, 3);
var currentIdx = currentID.substring(3);
var others = [];
if (currentIdx == 1)
others = [2, 3];
if (currentIdx == 2)
others = [1, 3];
if (currentIdx == 3)
others = [1, 2];
for (var i = 0; i < others.length; i++) {
var f = convertTime($("input[name='From" + currentDay + others[i] + "']").val());
var t = convertTime($("input[name='To" + currentDay + others[i] + "']").val());
if (fCheck > f && fCheck < t)
return false;
if (tCheck > f && tCheck < t)
return false;
if (f > fCheck && f < tCheck)
return false;
if (t > fCheck && t < tCheck)
return false;
}
return true;
}
function convertTime(time) {
var split = time.split(":");
return parseInt(split[0]) * 60 + parseInt(split[1]);