Commit b4dd9a09 authored by System Administrator's avatar System Administrator

[etersoft] Cherry-pick 222af203

parent 0427d730
//Номер баги
var bugId = getIdFromUrl() || getBugIdFromField();
// Если id нет, то мы имеем дело с новой багой
if (!bugId) {
// Присвоим текущее время, чтобы при создании следующей баги значения не сохранились
bugId = "c" + new Date().getTime();
}
var protocol = window.location.protocol;
//Изменение баги
var changed_remain = 0;
//Создание баги
var etersoft_create = window.location.href.search("enter") !== -1 ? 1 : 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 openButton = document.querySelector("#commit");
let closeButton = document.querySelectorAll("#timeQuestionDiv .close");
let dialog = document.querySelector("#timeQuestionDiv");
openButton.addEventListener("click", function(event) {
// cancel form submiting
event.preventDefault();
let timespentValue = getTimespentValue();
dialog.style.display = "block";
focusManager.capture(dialog);
// write work time in input value
document.querySelector("#realworktime").value =
localStorage.time === undefined ? timespentValue : localStorage.time;
document.querySelector("#saveTime").dataset["time"] = timespentValue;
});
let openButtonTop = document.querySelector("#commit_top");
openButtonTop.addEventListener("click", function(event) {
// cancel form submiting
event.preventDefault();
let timespentValue = getTimespentValue();
dialog.style.display = "block";
focusManager.capture(dialog);
// write work time in input value
document.querySelector("#realworktime").value =
localStorage.time === undefined ? timespentValue : localStorage.time;
document.querySelector("#saveTime").dataset["time"] = timespentValue;
});
document
.querySelector("#realworktime")
.addEventListener("change", function() {
document.querySelector("#saveTime").dataset["time"] = this.value;
localStorage.time = this.value;
console.log(
"time changed:",
document.querySelector("#saveTime").dataset["time"]
);
});
document.querySelector("#realworktime").addEventListener("paste", function() {
document.querySelector("#saveTime").dataset["time"] = this.value;
localStorage.time = this.value;
console.log(
"time changed:",
document.querySelector("#saveTime").dataset["time"]
);
});
// add listener for time commit
let btn = document.querySelector("#saveTime");
btn.addEventListener("click", function(event) {
// cancel form submiting
event.preventDefault();
// let's calc time for #work_time input
let workTime = parseInt(document.querySelector("#realworktime").value);
workTime =
workTime === parseInt(btn.dataset["time"])
? parseInt(btn.dataset["time"])
: workTime;
workTime = workTime > 0 ? workTime : 1;
let workTimeValue = Math.ceil((workTime / 60) * 100) / 100;
let productiveTime = parseInt(document.querySelector("#ProductTime").value);
productiveTime = productiveTime > 0 ? productiveTime : 1;
let productiveTimeValue = Math.ceil((productiveTime / 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");
// check comment before submit
let comment = document.querySelector("#comment").value;
if (comment.length !== 0) {
if (comment.length < 9) {
alert("Слишком короткий комментарий");
} else if (productiveTimeValue > 8 || workTimeValue > 8) {
alert(
"Недопустимо указывать отработанное/продуктивное время более восьми часов. Правильным следованием рабочему процессу было бы выполнение работы по частям, о каждой из которых будет написано отдельно."
);
} else if (
productiveTimeValue > 2 &&
comment.length < productiveTimeValue * 60
) {
alert(
"Недопустимо коротко комментировать длительные работы. Мы ожидаем не менее 60 символов на каждый указанный час."
);
} else if (productiveTimeValue > workTimeValue) {
alert("Продуктивное время не может быть больше отработанного!");
} else {
let bugForm = etersoft_create === 1 ? "#Create" : "#changeform";
document.querySelector(bugForm).submit();
timer.clear();
localStorage.removeItem("time");
}
} else {
alert("Поле комментария не может быть пустым!");
}
});
});
// 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") {
//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);
}
<link rel="stylesheet" type="text/css" href="js/etersoft/timersplash.css?15_04_2020" />
<div style="display: none;" id="useremail" class="[% user.email FILTER html %]"></div>
<div style="display: none;" id="assigntoemail" class="[% bug.assigned_to.email FILTER html %]"></div>
<!-- Таймер -->
<div id="timerblock" title="Время на странице">
<img src="js/etersoft/control_pause.gif" id="timer_pause" onclick="timer.togglePause()" title="Пауза" />
<img src="js/etersoft/control_right.gif" id="timer_play" onclick="timer.togglePause()" title="Продолжить" />
<img src="js/etersoft/control_stop.gif" id="timer_stop" onclick="if (confirm('Вы точно хотите сбросить таймер?')) {timer.reset();}" title="Сбросить таймер" />
<input type="text" size="10" title="Время на странице" id='timespent' name="timespent" value="" readonly="readonly">
</div>
<!-- Сохранение времени -->
<div id="timeQuestionDiv">
<div class="container">
<div class="workTime">
<h3>Укажите отработанное время</h3>
<fieldset>
Отработанное время:
<div class="workTimeInner">
<input class="workTime__input" id="realworktime" name="realworktime" data-time="" placeholder="в минутах" title="Общее время, потраченное на задачу." type="text" tabindex="1" required autofocus>
<button class="workTime__button" data-time="1" onclick="document.querySelector('#realworktime').value=this.dataset['time']" tabindex="2">1</button>
<button class="workTime__button" data-time="5" onclick="document.querySelector('#realworktime').value=this.dataset['time']" tabindex="3">5</button>
<button class="workTime__button" data-time="15" onclick="document.querySelector('#realworktime').value=this.dataset['time']" tabindex="4">15</button>
<button class="workTime__button" data-time="30" onclick="document.querySelector('#realworktime').value=this.dataset['time']" tabindex="5">30</button>
</div>
</fieldset>
<fieldset>
Продуктивное время:
<div class="workTimeInner">
<input class="workTime__input" id="ProductTime" placeholder="в минутах" title="Время, которое вы бы потратили на задачу, зная как её решать." type="text" tabindex="6" required>
<button class="workTime__button" data-time="1" onclick="document.querySelector('#ProductTime').value=this.dataset['time']" tabindex="7">1</button>
<button class="workTime__button" data-time="5" onclick="document.querySelector('#ProductTime').value=this.dataset['time']" tabindex="8">5</button>
<button class="workTime__button" data-time="15" onclick="document.querySelector('#ProductTime').value=this.dataset['time']" tabindex="9">15</button>
<button class="workTime__button" data-time="30" onclick="document.querySelector('#ProductTime').value=this.dataset['time']" tabindex="10">30</button>
</div>
</fieldset>
<fieldset>
<button class="workTime__button--save" id="saveTime" tabindex="11">Сохранить</button>
</fieldset>
<button onclick="closeDiv();" class="close" tabindex="12">&times;</button>
</div>
</div>
</div>
<script language="javascript" type="text/javascript" src="js/etersoft/focusManager.js"></script>
<script language="javascript" type="text/javascript" src="js/etersoft/timer_common.js?25_10_2017"></script>
<script language="javascript" type="text/javascript" src="js/etersoft/timer.js?10_09_2020"></script>
<link rel="stylesheet" type="text/css" href="js/etersoft/timersplash.css?15_04_2020" />
<div style="display: none;" id="useremail" class="[% user.email FILTER html %]"></div>
<div style="display: none;" id="assigntoemail" class="[% bug.assigned_to.email FILTER html %]"></div>
<!-- Таймер -->
<div id="timerblock" title="Время на странице">
<img src="js/etersoft/control_pause.gif" id="timer_pause" onclick="timer.togglePause()" title="Пауза" />
<img src="js/etersoft/control_right.gif" id="timer_play" onclick="timer.togglePause()" title="Продолжить" />
<img src="js/etersoft/control_stop.gif" id="timer_stop" onclick="if (confirm('Вы точно хотите сбросить таймер?')) {timer.reset();}" title="Сбросить таймер" />
<input type="text" size="10" title="Время на странице" id='timespent' name="timespent" value="" readonly="readonly">
</div>
<!-- Сохранение времени -->
<div id="timeQuestionDiv">
<div class="container">
<div class="workTime">
<h3>Укажите отработанное время</h3>
<fieldset>
Отработанное время:
<div class="workTimeInner">
<input class="workTime__input" id="realworktime" name="realworktime" data-time="" placeholder="в минутах" title="Общее время, потраченное на задачу." type="text" tabindex="1" required>
<button class="workTime__button" data-time="1" onclick="document.querySelector('#realworktime').value=this.dataset['time']" tabindex="2">1</button>
<button class="workTime__button" data-time="5" onclick="document.querySelector('#realworktime').value=this.dataset['time']" tabindex="3">5</button>
<button class="workTime__button" data-time="15" onclick="document.querySelector('#realworktime').value=this.dataset['time']" tabindex="4">15</button>
<button class="workTime__button" data-time="30" onclick="document.querySelector('#realworktime').value=this.dataset['time']" tabindex="5">30</button>
</div>
</fieldset>
<fieldset>
Продуктивное время:
<div class="workTimeInner">
<input class="workTime__input" id="ProductTime" placeholder="в минутах" title="Время, которое вы бы потратили на задачу, зная как её решать." type="text" tabindex="6" required>
<button class="workTime__button" data-time="1" onclick="document.querySelector('#ProductTime').value=this.dataset['time']" tabindex="7">1</button>
<button class="workTime__button" data-time="5" onclick="document.querySelector('#ProductTime').value=this.dataset['time']" tabindex="8">5</button>
<button class="workTime__button" data-time="15" onclick="document.querySelector('#ProductTime').value=this.dataset['time']" tabindex="9">15</button>
<button class="workTime__button" data-time="30" onclick="document.querySelector('#ProductTime').value=this.dataset['time']" tabindex="10">30</button>
</div>
</fieldset>
<fieldset>
<button class="workTime__button--save" id="saveTime" tabindex="11">Сохранить</button>
</fieldset>
<button onclick="closeDiv();" class="close" tabindex="12">&times;</button>
</div>
</div>
</div>
<script language="javascript" type="text/javascript" src="js/etersoft/focusManager.js"></script>
<script language="javascript" type="text/javascript" src="js/etersoft/timer_common.js?25_10_2017"></script>
<script language="javascript" type="text/javascript" src="js/etersoft/timer.js?10_09_2020"></script>
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