Connect productive_time and timer.js, add validation

parent 6f647ebd
......@@ -142,7 +142,9 @@ Array.from(workTimeBtns).map(btn => {
// let's calc time for #work_time input
let workTime = parseInt(btn.dataset["time"]);
let workTimeValue = Math.ceil(workTime / 60 * 100) / 100;
let productiveTimeValue = Math.ceil(parseInt(document.querySelector('#ProductTime').value) / 60 * 100) / 100;
document.querySelector("#work_time").value = workTimeValue;
document.querySelector("#productive_time").value = productiveTimeValue;
// now we ready for submiting all forms
let mainCommitBtn = document.querySelector("#commit_top");
......@@ -172,6 +174,35 @@ Array.from(workTimeBtns).map(btn => {
});
});
});
// let's validate!
function validate(evt) {
let theEvent = evt || window.event;
let key = theEvent.keyCode || theEvent.which;
key = String.fromCharCode( key );
let regex = /[0-9\s]/;
if( !regex.test(key) ) {
theEvent.returnValue = false;
if(theEvent.preventDefault) theEvent.preventDefault();
}
}
document.querySelector('#realworktime').onkeypress = function() {
validate(event);
}
document.querySelector('#realworktime').onpaste = function() {
validate(event);
}
document.querySelector('#ProductTime').onkeypress = function() {
validate(event);
}
document.querySelector('#ProductTime').onpaste = function() {
validate(event);
}
//////////////////////////////////////////////////////////////
if (typeof window.addEventListener != "undefined") {
......
//Номер баги
var bugId = getIdFromUrl() || getBugIdFromField();
// Если id нет, то мы имеем дело с новой багой
if (!bugId) {
// Присвоим текущее время, чтобы при создании следующей баги значения не сохранились
bugId = "c" + new Date().getTime();
}
var protocol = window.location.protocol;
//Изменение баги
var changed_remain = 0;
//Создание баги
var etersoft_create = 0;
// Объект таймера, создается при инициализации
// Подробнее про таймер см. timer_common.js
var timer;
// Интервал обновления таймера в мс, на точность не влияет
var UPDATE_INTERVAL = 1000;
function initTimer() {
// Показываем время только сотрудникам Etersoft
if (!isetersoft()) return;
document.getElementById("timerblock").style.display = "block";
timer = new Timer("bug:" + protocol + bugId, updateTimer);
timer.setAutoUpdate(UPDATE_INTERVAL);
}
// this при вызове - объект таймера
function updateTimer() {
setPauseDisplay(this.isPaused());
document.querySelector("#timespent").value = this.getFormattedString();
}
//Установка в поле отработанного времени в минутах
function setWorkTime(manualTime) {
var minutes = Math.ceil(timer.getElapsedSeconds() / 60);
document.querySelector("#realworktime").value = manualTime
? manualTime
: minutes;
}
function setPauseDisplay(pause) {
document.querySelector("#timespent").style.color = pause ? "gray" : "black";
document.querySelector("#timer_pause").style.visibility = pause
? "hidden"
: "visible";
document.querySelector("#timer_play").style.visibility = pause
? "visible"
: "hidden";
}
/////////////////////////////////////////////////////
function showDiv() {
document.querySelector("#timeQuestionDiv").style.display = "block";
document.querySelector("#realworktime").focus();
}
function closeDiv() {
document.querySelector("#timeQuestionDiv").style.display = "none";
}
/* Получение номера баги из поля */
function getBugIdFromField() {
var field = document.querySelector("#changeform input[name=id]");
if (field) {
return parseInt(field.value);
}
return false;
}
////////////////////////////////////////////
//Является ли пользователь сотрудником Etersoft
function isetersoft() {
var email = document.getElementById("useremail").className;
if (!email) return false;
var domain = email.split("@")[1];
return domain === "etersoft.ru";
}
//Является ли пользователь ответственным
function isworker() {
var useremail = document.getElementById("useremail");
var assigntoemail = document.getElementById("assigntoemail");
var email = useremail.className;
var assignemail = assigntoemail.className;
return email == assignemail;
}
window.addEventListener('load', function () {
function getTimespentValue() {
let timespent = document.querySelector("#timespent").value;
let timespentValue = timespent.split(":");
// let's calc how many time is spent in minutes
let hours = parseInt(timespentValue[0]) * 60;
let minutes = parseInt(timespentValue[1]);
let seconds = Math.round(parseInt(timespentValue[2]) / 60);
timespentValue = hours + minutes + seconds;
return timespentValue;
}
// add listener for comment commit
let commitBtn = document.querySelector("#commit");
commitBtn.addEventListener("click", function(event) {
// cancel form submiting
event.preventDefault();
let timespentValue = getTimespentValue();
document.querySelector("#timeQuestionDiv").style.display = "block";
// write work time in input value
document.querySelector("#realworktime").value = timespentValue;
document.querySelector("#saveTime").dataset['time'] = document.querySelector("#realworktime").value !== timespentValue ? document.querySelector("#realworktime").value : timespentValue;
console.log(document.querySelector("#saveTime").dataset['time']);
});
// add listener for time commit
let workTimeBtns = document.querySelectorAll(".workTime__button");
Array.from(workTimeBtns).map(btn => {
btn.addEventListener("click", function(event) {
// cancel form submiting
event.preventDefault();
// let's calc time for #work_time input
let workTime = parseInt(btn.dataset["time"]);
let workTimeValue = Math.ceil(workTime / 60 * 100) / 100;
document.querySelector("#work_time").value = workTimeValue;
// now we ready for submiting all forms
let mainCommitBtn = document.querySelector("#commit_top");
// check comment before submit
let comment = document.querySelector("#comment").value;
if (comment.length !== 0) {
if (comment.length < 9) {
alert("Слишком короткий комментарий");
}
else if (workTimeValue > 3) {
alert("Вы указали отработанное время более 3 часов. Правильным следованием рабочему процессу было бы выполнение работы по частям, о каждой из которых будет написано отдельно.");
}
else if (workTimeValue > 2 && comment.length < workTimeValue * 60) {
alert("Недопустимо коротко комментировать длительные работы. Мы ожидаем не менее 60 символов на каждый указанный час.");
}
else if (workTimeValue > 8) {
alert("Вы указали отработанное время более 8 часов. Нужно обязательно разбивать комментирование своей работы за день на отдельные части.");
}
else {
mainCommitBtn.click();
timer.clear();
}
} else {
alert("Поле комментария не может быть пустым!");
}
});
});
});
//////////////////////////////////////////////////////////////
if (typeof window.addEventListener != "undefined") {
//gecko, safari, konqueror and standard
window.addEventListener("load", initTimer, false);
} else if (typeof document.addEventListener != "undefined") {
//opera 7
document.addEventListener("load", initTimer, false);
} else if (typeof window.attachEvent != "undefined") {
//win/ie
window.attachEvent("onload", initTimer);
}
Markdown is supported
0% or
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment