ruling_timer/app/views/ruling_timers/_timer_window.html.erb

793 lines
28 KiB
Plaintext
Raw Normal View History

2021-07-21 07:37:06 +00:00
<% if (current_user rescue false)%>
<% @ruling_timer_temp.reset_all %>
<% @timer_infos = @ruling_timer_temp.get_infos %>
<div class="popup-window" id="timeman_main" style="display: none; position: fixed; left: 0; z-index: 1400 !important;">
<div class="popup-window-angly popup-window-angly-top" style="left: 130px; margin-left: 0px;"></div>
<div id="popup-window-content-timeman_main" class="popup-window-content">
<div class="tm-popup-content">
<div class="tm-popup-notice">
<span class="tm-popup-notice-text">工作日期間: </span>
<span class="tm-popup-notice-time"><%=@timer_infos["work"]%></span>
<span class="tm-popup-notice-pencil"><i class="fa fa-pencil" aria-hidden="true"></i></span>
<span class="tm-popup-notice-right"></span>
</div>
<div class="tm-popup-timeman tm-popup-timeman-buttons-mode tm-popup-timeman-change-time-mode">
<div class="tm-popup-timeman-pause" style="<%= 'display: none;' if @ruling_timer_temp.status != "rest" %>">
<span class="tm-popup-timeman-pause-timer-caption">休息時數: <span class="tm-popup-timeman-pause-time"><%=@timer_infos["rest"]%></span></span>
</div>
<table cellspacing="0" class="tm-popup-timeman-layout">
<tbody>
<tr class="timer_button working_btn_groups <%= 'hide' if @ruling_timer_temp.status == "stop" %>">
<td class="tm-popup-timeman-layout-time">
<button class="btn btn-secondary <%= @ruling_timer_temp.status == "rest" ? "tm-btn-start" : "tm-btn-pause" %>">
<span class="text-start start_timer"><i class="fa fa-play" style="margin-right: 0.5em;"></i>繼續</span>
<span class="text-pause rest_timer"><i class="fa fa-pause" style="margin-right: 0.5em;"></i>休息時數</span>
</button>
</td>
<td class="tm-popup-timeman-layout-button">
<div class="tm-popup-button-handler">
<button class="btn btn-danger stop_timer">
<span style="margin-right: 0.5em;">&#9632;</span>打卡下班
</button>
</div>
<button class="tm-popup-change-time-link <%= 'hide' if @ruling_timer_temp.status != 'stop' %>">變更下班打卡時間</button>
</td>
</tr>
<tr class="timer_button stop_btn_groups <%= 'hide' if @ruling_timer_temp.status != "stop" %>">
<td class="tm-popup-timeman-layout-button">
<button class="btn btn-success start_timer">
<i class="fa fa-play" style="margin-right: 0.5em;"></i>
<% if @ruling_timer_temp.all_work_times_seconds == 0 %>
打卡上班
<% else %>
繼續工作日
<% end %>
</button>
</td>
</tr>
<tr>
<td><a class="btn btn-primary" href="<%= admin_ruling_timers_path rescue '#' %>"><%=t("ruling_timer.view_history")%></a></td>
</tr>
</tbody>
</table>
</div>
<div class="tm-tabs-box">
<ul class="nav nav-pills tm-tabs">
<li class="tm-tab active">
<a href="#tm_plan" data-toggle="tab" aria-expanded="true">每日計劃</a>
</li>
<li class="tm-tab">
<a href="#tm_summary" data-toggle="tab" aria-expanded="true">每日摘要</a>
</li>
</ul>
<div class="tab-content tm-tabs-content">
<div class="tm-tab-content tab-pane fade active in" id="tm_plan">
<div class="bx-planner-content">
<div>
<div class="tm-popup-section tm-popup-section-tasks"><span class="tm-popup-section-text">今日任務</span><span class="tm-popup-section-right-link">從清單中選取</span>
</div>
<div class="tm-popup-tasks">
<div class="tm-task-list">
<% @ruling_timer_temp.tasks.to_a.each_with_index do |task,i| %>
<% checked = @ruling_timer_temp.tasks_finished.include?(i) %>
<div class="tm-task-item" data-task-id="<%=@ruling_timer_temp.sub_task_ids[i]%>">
<input class="tm-task-checkbox" type="checkbox" <%="checked=\"checked\"" if checked%>>
<span class="tm-task-name <%="task-finished" if checked %>"><%=task%></span>
<span class="tm-task-item-menu"><i class="fa fa-caret-down"></i></span>
</div>
<% end %>
</div>
<div class="tm-popup-task-form tm-popup-task-form-disabled">
<input type="text" class="tm-popup-task-form-textbox" placeholder="輸入新任務">
<button class="add_btn tm-popup-task-form-submit">+</button>
</div>
</div>
</div>
<div class="tm-popup-events-empty">
<div class="tm-popup-section tm-popup-section-events">
<span class="tm-popup-section-text">事項</span>
</div>
<div class="tm-popup-events">
<div class="tm-popup-event-list">
<% @ruling_timer_temp.events.to_a.each do |event| %>
<div class="tm-popup-event">
<span class="time_interval"><%=event["start"]%> - <%=event["end"]%></span><span class="tm-popup-event-name"><%=event["event"]%></span>
<button type="button" title="移除事項" class="add_btn delete_event">X</button>
</div>
<% end %>
</div>
<div class="tm-popup-event-form tm-popup-event-form-disabled">
<input type="text" class="event-start-time" value="13:00">
<input type="text" class="event-end-time" value="14:00">
<input type="text" class="event-form-textbox" placeholder="新活動">
<button class="add_btn tm-popup-event-form-submit">+</button>
<!--
<div class="tm-popup-event-form-options">
<input type="checkbox" class="checkbox" id="bx_tm_absence_0.4349872404840247">
<label for="bx_tm_absence_0.4349872404840247">不在辦公室</label>
</div> -->
</div>
</div>
</div>
</div>
</div>
<div class="tm-tab-content tab-pane fade" id="tm_summary">
<div class="tm-popup-report">
<div class="tm-popup-report-text">
<textarea class="tm-popup-report-textarea" placeholder="撰寫您工作的簡報"><%=@ruling_timer_temp.summary%></textarea>
</div>
<div class="tm-popup-report-buttons">
<button type="button" class="btn btn-success" disabled="true" id="save_summary">儲存</button>
</div>
</div>
</div>
</div>
</div>
</div>
</div>
</div>
<div class="popup-window" id="menu-popup-task"
style="display: none;position: fixed;z-index: 1500 !important;">
<div class="popup-window-content" style="padding: 0px;">
<div class="menu-popup">
<div class="menu-popup-items">
<span class="menu-popup-item menu-popup-item-decline ">
<i class="fa fa-minus-circle"></i>
<span class="menu-popup-item-text">從每日計劃移除</span>
</span>
</div>
</div>
</div>
</div>
<div class="popup-window" id="task-list-popup"
style="display: none;position: fixed;z-index: 1500 !important;">
<div class="popup-window-content" style="padding: 0px;">
<div class="task-popup">
<div class="task-popup-items">
<% %>
<% if @new_sub_tasks.count == 0 %>
無任務可添加
<% else %>
<% @new_sub_tasks.each_with_index do |sub_task,i| %>
<div class="tm-task-new-item" data-task-id="<%=sub_task.ruling_timer_task_id.to_s%>">
<%=sub_task.task_name%>
<button type="button" title="添加任務" class="add_btn add_task_from_list">+</button>
</div>
<% end %>
<% end %>
</div>
</div>
<div class="popup-window-buttons">
<button class="popup-window-button close_popup">關閉</button>
</div>
</div>
</div>
<div class="popup-window" id="timer-setting-popup"
style="display: none;position: fixed;z-index: 1500 !important;">
<div class="popup-window-content" style="padding: 0px;">
<div class="task-popup" id="timer_content">
<% work_times = @ruling_timer_temp.get_work_times(true) %>
<% work_times.each_with_index do |t,i| %>
<% if i % 2 == 0
next_t = work_times[i+1]
else
next
end %>
<span><input name="work_times[]" class="timers timer_start" value="<%=t%>"> ~ <% if next_t %><input name="work_times[]" class="timers timer_end" value="<%=next_t%>"><%else%>Now<%end%></span>
<hr>
<% end %>
</div>
<div class="popup-window-buttons">
<button class="popup-window-button save_timers">儲存</button><button class="popup-window-button close_popup">關閉</button>
</div>
</div>
</div>
<style>
.timers {
width: 5em;
}
.popup-window-buttons {
display: flex;
justify-content: center;
}
.popup-window-button{
background: transparent;
border: 0;
text-decoration: underline;
padding: 0;
margin: 0 0.2em;
}
.popup-window input{
margin-bottom: 0;
margin-top: 0;
}
.tm-popup-change-time-link{
background: transparent;
border: 0;
text-decoration: underline;
padding: 0;
}
.nav:hover {
background-color: transparent;
color: #fff;
}
.menu-popup-item-text{
cursor: pointer;
}
.tm-task-item-menu{
float: right;
cursor: pointer;
}
.add_btn{
background: #fff;
border: 1px solid #666666;
padding: 0.1em 0.5em;
text-align: center;
}
.tm-popup-notice-pencil{
cursor: pointer;
}
.popup-window{
background: #ffffff;
top: 48px;
padding: 10px;
-webkit-box-shadow: 0 7px 21px rgb(83 92 105 / 12%), 0 -1px 6px 0 rgb(83 92 105 / 6%);
box-shadow: 0 7px 21px rgb(83 92 105 / 12%), 0 -1px 6px 0 rgb(83 92 105 / 6%);
-webkit-box-orient: vertical;
-webkit-box-direction: normal;
justify-content: stretch;
display: none;
}
.popup-window.active_popup{
display: flex;
}
.tm-popup-timeman-pause-timer-caption{
background: #868d95;
color: #ffffff;
}
.timer_button{
vertical-align: top;
}
.tm-tabs-box ul{
width: 100%;
}
.popup-window-angly {
height: 22px;
position: absolute;
overflow: hidden;
width: 33px;
}
.popup-window-angly-top {
display: block;
left: 10px;
margin: 0;
top: -22px;
}
.popup-window-angly:before {
background-color: #fff;
-webkit-box-shadow: 0 0 21px rgb(83 92 105 / 13%);
box-shadow: 0 0 21px rgb(83 92 105 / 13%);
content: '';
height: 15px;
position: absolute;
left: 9px;
top: 16px;
-webkit-transform: rotate(45deg);
-ms-transform: rotate(45deg);
transform: rotate(45deg);
-webkit-transform-origin: 50% 50%;
-ms-transform-origin: 50% 50%;
transform-origin: 50% 50%;
width: 15px;
}
.text-pause,.text-start{
display: none;
}
.tm-btn-pause .text-pause{
display: initial;
}
.tm-btn-start .text-start{
display: initial;
}
.tm-btn-start .text-pause{
display: none;
}
.btn.btn-secondary{
background: #868d95;
color: #fff;
}
.btn.btn-secondary:hover{
background: #5b6573;
}
.tm-popup-report-buttons {
padding: 10px 0 0 0;
text-align: center;
}
.tm-tab-content {
background-color: #fff;
border: 1px solid #c6cdd3;
padding: 10px;
}
.tm-popup-report-textarea{
width: 100%;
min-height: 130px;
box-sizing: border-box;
}
.tm-popup-section {
border-radius: 0;
height: 39px;
}
.tm-popup-section {
white-space: nowrap;
position: relative;
background: #e8e8e8;
font: normal normal normal 12px/23px Arial,Helvetica,sans-serif;
border-radius: 2px;
}
.tm-popup-section-tasks {
background: #b9e9fa;
}
.tm-popup-section-right-link {
color: #3a8090;
font-size: 12px;
line-height: 14px;
opacity: .6;
margin-top: 12px;
text-decoration: none;
border-bottom: 1px dashed #3a8090;
-webkit-transition: opacity .2s linear;
transition: opacity .2s linear;
}
.tm-popup-section-right-link {
position: absolute;
right: 11px;
top: 0;
font-size: 11px;
line-height: 21px;
color: #949494;
text-decoration: underline;
cursor: pointer;
}
.tm-popup-section-left, .tm-popup-section-text, .tm-popup-section-right {
display: inline-block;
height: 23px;
vertical-align: top;
}
.tm-popup-section-text {
color: #535c69;
height: 39px;
font: bold 14px/39px "Helvetica Neue",Helvetica,Arial,sans-serif;
padding-left: 10px;
vertical-align: middle;
}
.tm-popup-section-text {
padding: 0 8px;
color: #000;
}
.tm-popup-section-events {
background: #ffe75e;
}
.tm-popup-event-form-options {
width: auto;
padding: 2px 0 0 110px;
text-align: left;
color: #555;
}
.tm-popup-event-form .tm-popup-event-start-time-textbox, .tm-popup-event-form .tm-popup-event-end-time-textbox {
padding: 0 4px !important;
text-align: center;
width: 55px;
}
.tm-popup-event-form-options input {
vertical-align: middle;
margin: 0;
display: inline;
}
.tm-popup-tasks {
margin: 15px 0;
}
.tm-popup-event-form {
margin: 10px 0 0 0;
}
.tm-task-name{
text-decoration: none;
}
.tm-task-name.task-finished{
text-decoration: line-through;
}
.tm-popup-event-form input{
width: auto;
}
.tm-popup-event-form .event-start-time,.tm-popup-event-form .event-end-time{
width: 3em;
}
.delete_event {
margin-left: 1em;
color: red;
font-weight: bold;
border-color: red;
}
.tm-popup-event-name{
margin-left: 0.5em;
}
.wrong_timer{
border: 2px solid red;
}
</style>
<script>
function update_timer_inputs(){
$.post("/xhr/ruling_timer/get_work_times").done(function(work_times){
var input_html = "";
work_times.forEach(function(t,i){
var next_t;
if(i % 2 == 0){
next_t = work_times[i+1];
}else{
return;
}
var tmp = "";
tmp += ('<span><input name="work_times[]" class="timers timer_start" value="'+t+'"> ~ ');
if(next_t){
tmp += ('<input name="work_times[]" class="timers timer_end" value="'+next_t+'">');
}else{
tmp += "Now";
}
tmp += "</span><hr>";
input_html += tmp;
})
$("#timer_content").html(input_html);
})
}
$(document).ajaxSend(function(e, xhr, options) {
var token = $("meta[name='csrf-token']").attr('content');
xhr.setRequestHeader('X-CSRF-Token', token);
});
time_tracker.timer_id = null;
time_tracker.set_data = function(data){
this.work_seconds = data.work;
this.rest_seconds = data.rest;
}
time_tracker.start_timer = function(field){
var now = Date.now();
if(this[field+"start"] == undefined){
this[field+"start"] = now;
}
var temp = this[field] + Math.round((now - this[field+"start"]) / 1000);
this.field = field;
if(field == "work_seconds"){
$(".tm-popup-notice-time").text(this.transform_second_to_time(temp));
}else{
$(".tm-popup-timeman-pause-time").text(this.transform_second_to_time(temp));
}
if(time_tracker.timer_id){
window.clearTimeout(time_tracker.timer_id);
}
time_tracker.timer_id = window.setTimeout($.proxy(function (){
this.start_timer(field)
},this),1000);
return;
}
time_tracker.stop_timer = function(){
if(time_tracker.timer_id){
window.clearTimeout(time_tracker.timer_id);
}
var now = Date.now();
var field = this.field;
if(time_tracker[field+"start"] == undefined){
time_tracker[field+"start"] = now;
}
time_tracker[field] = time_tracker[field] + Math.round((now - time_tracker[field+"start"]) / 1000);
delete time_tracker[field+"start"];
}
if(time_tracker.status == "working"){
time_tracker.start_timer("work_seconds");
}else if(time_tracker.status == "rest"){
time_tracker.start_timer("rest_seconds");
}
$(".start_timer").click(function(){
var _this = $(this);
$.post("/xhr/ruling_timer/start",{"timer_offset": window.timer_offset}).done(
function(data){
$('.tm-popup-notice-time').text(time_tracker.transform_second_to_time(data.work));
$('.tm-popup-timeman-pause-time').text(time_tracker.transform_second_to_time(data.rest));
time_tracker.status = "working";
$(".stop_btn_groups").addClass("hide");
$(".working_btn_groups").removeClass("hide");
_this.parent().removeClass("tm-btn-start").addClass("tm-btn-pause");
time_tracker.set_data(data);
time_tracker.start_timer("work_seconds");
$(".tm-popup-timeman-pause").css("display","none");
$(".tm-popup-change-time-link").addClass("hide");
$('#timeman-status-block').html('<i class="fa fa-stop-circle"></i><span id="timeman-status" class="timeman-status"><%=t("ruling_timer.working")%></span>');
update_timer_inputs();
}
)
})
$(".stop_timer").click(function(){
var _this = $(this);
$.post("/xhr/ruling_timer/stop",{"timer_offset": window.timer_offset}).done(
function(data){
$('.tm-popup-notice-time').text(time_tracker.transform_second_to_time(data.work));
$('.tm-popup-timeman-pause-time').text(time_tracker.transform_second_to_time(data.rest));
time_tracker.status = "stop";
$(".stop_btn_groups").removeClass("hide");
$(".working_btn_groups").addClass("hide");
time_tracker.stop_timer();
time_tracker.set_data(data);
$(".tm-popup-change-time-link").removeClass("hide");
$('#timeman-status-block').html('<i class="fa fa-play-circle"></i><span id="timeman-status" class="timeman-status">記錄的下班時間</span>');
update_timer_inputs();
}
)
})
$(".rest_timer").click(function(){
var _this = $(this);
$.post("/xhr/ruling_timer/rest",{"timer_offset": window.timer_offset}).done(
function(data){
$('.tm-popup-notice-time').text(time_tracker.transform_second_to_time(data.work));
$('.tm-popup-timeman-pause-time').text(time_tracker.transform_second_to_time(data.rest));
time_tracker.status = "rest";
$(".stop_btn_groups").addClass("hide");
$(".working_btn_groups").removeClass("hide");
_this.parent().addClass("tm-btn-start").removeClass("tm-btn-pause");
time_tracker.set_data(data);
time_tracker.start_timer("rest_seconds");
$(".tm-popup-timeman-pause").css("display","");
$('#timeman-status-block').html('<i class="fa fa-play-circle"></i><span id="timeman-status" class="timeman-status"><%=t("ruling_timer.rest")%></span>');
update_timer_inputs();
}
)
})
$(".tm-popup-report-textarea").on("input",function(){
$("#save_summary").removeAttr("disabled");
})
$("#save_summary").click(function(){
var summary = $(".tm-popup-report-textarea").val();
$.post("/xhr/ruling_timer/set_summary",{"summary": summary}).done(function(data){
if(data.success){
$("#save_summary").attr("disabled","true");
}else{
alert("Cannot save summary!\nPlease refresh web and login!");
}
})
})
$(window).on("load",function(){
$('.popup-window-content input').off('focus');
})
$(".tm-popup-task-form-textbox").on("keyup",function(){
event.preventDefault();
var keyCode = event.which ? event.which : event.keyCode;
if( keyCode == 13 ){
$(".tm-popup-task-form-submit").click();
}
})
$(".tm-popup-task-form-submit").click(function(){
var task = $(".tm-popup-task-form-textbox").val();
if(task != ""){
$.post("/xhr/ruling_timer/add_task",{"task": task}).done(function(data){
if(data.success){
var task_id = data["task-id"];
var task_item = $("<div class=\"tm-task-item\" data-task-id=\""+task_id+"\"></div>");
task_item.append("<input class=\"tm-task-checkbox\" type=\"checkbox\">"+"<span class=\"tm-task-name\">"+task+"</span>");
task_item.append("<span class=\"tm-task-item-menu\"><i class=\"fa fa-caret-down\"></i></span>");
$(".tm-task-list").append(task_item);
$(".tm-popup-task-form-textbox").val("");
}else{
alert("Cannot save task!\nPlease refresh web and login!");
}
})
}
})
$(".tm-task-checkbox").click(function(){
var task_name = $(this).siblings(".tm-task-name");
var task_id = $(this).parent().data("task-id");
var status = $(this).is(":checked") ? 1 : 0;
if(task_id){
$.post("/xhr/ruling_timer/set_task_status",{"task_id": task_id, "status": status}).done(function(data){
if(data.success){
if(status == 1)
task_name.addClass("task-finished");
else
task_name.removeClass("task-finished");
}else{
alert("Cannot save task!\nPlease refresh web and login!");
}
})
}
})
$(document).on("click",".tm-task-item-menu",function(){
var offset = $(this).offset();
var task_id = $(this).parent().data("task-id");
if($("#menu-popup-task").hasClass("popup")){
$("#menu-popup-task").css("display","none").removeClass("popup");
}else{
$("#menu-popup-task").css("display","block").addClass("popup");
var popup_width = $("#menu-popup-task").width();
offset.top = offset.top + $(this).height();
var window_width = $(window).width();
var padding_right = 20;
var left = Math.min(offset.left - popup_width / 2 - padding_right, window_width - popup_width - padding_right);
offset.left = left;
$("#menu-popup-task").offset(offset)
$(".menu-popup-item-text").data("task-id",task_id);
$(".menu-popup-item-text").data("task_item",$(this).parent());
}
})
$(document).on("click",".menu-popup-item-text",function(){
var task_id = $(this).data("task-id");
var _this = $(this);
if( task_id ){
$.post("/xhr/ruling_timer/remove_task",{"task_id": task_id}).done(function(data){
if(data.success){
_this.data("task_item").remove();
$("#menu-popup-task").removeClass("popup").css("display","none");
}else{
alert("Cannot remove task!\nPlease refresh web and login!");
}
})
}
})
window.show_timer_task_list = function(){
var _this = $(".tm-popup-section-right-link");
var popup = $("#task-list-popup");
popup.css("display","block");
var offset = _this.offset();
var item_width = _this.width();
offset.left += item_width / 2;
var popup_width = popup.width();
offset.top = offset.top + _this.height();
var window_width = $(window).width();
var padding_right = 20;
var left = Math.min(offset.left - popup_width / 2 - padding_right, window_width - popup_width - padding_right);
offset.left = left;
popup.offset(offset);
}
window.show_timer_setting = function(){
var _this = $(".tm-popup-notice-pencil");
var popup = $("#timer-setting-popup");
popup.css("display","block");
var offset = _this.offset();
var item_width = _this.width();
offset.left += item_width / 2;
var popup_width = popup.width();
offset.top = offset.top + _this.height();
var window_width = $(window).width();
var padding_right = 20;
var left = Math.min(offset.left - popup_width / 2 - padding_right, window_width - popup_width - padding_right);
offset.left = left;
popup.offset(offset);
}
$(".tm-popup-section-right-link").click(window.show_timer_task_list);
$(document).on("click",".close_popup",function(){
$(this).parents(".popup-window").eq(0).css("display","none");
})
$(".tm-popup-event-form-submit").click(function(){
var event = $(".tm-popup-event-form input").map(function(i,v){return v.value}).toArray();
if(event[2].trim() != ""){
$.post("/xhr/ruling_timer/add_event",{"event": event}).done(function(data){
if(data.success){
var event_item = $('<div class="tm-popup-event"></div>')
event_item.append('<span class="time_interval">'+ event[0] +' - '+ event[1] +'</span><span class="tm-popup-event-name">'+ event[2] +'</span>');
event_item.append('<button type="button" title="移除事項" class="add_btn delete_event">X</button>');
$(".tm-popup-event-list").append(event_item);
var next_event_time = time_calc.get_next_hour_only(event[1]);
$(".event-start-time").val(next_event_time);
$(".event-end-time").val(time_calc.get_next_hour_only(next_event_time));
$(".event-form-textbox").val("");
if(window.can_notify){
var notify_title = event[0] + " ~ " + event[1] + " : " + event[2];
if (Notification.permission === 'default' || Notification.permission === 'undefined') {
Notification.requestPermission(function(permission){
add_notify(permission,event[0],event[1],notify_title)
});
}else{
add_notify(Notification.permission,event[0],event[1],notify_title)
}
}
}else{
alert("Cannot add event!\nPlease refresh web and login!");
}
})
}
})
$(document).on("click",".delete_event",function(){
var event_idx = $(this).parent().index();
var _this = $(this);
$.post("/xhr/ruling_timer/delete_event",{"event_idx": event_idx}).done(function(data){
if(data.success){
_this.parent().remove();
}else{
alert("Cannot remove event!\nPlease refresh web and login!");
}
})
})
$(".add_task_from_list").click(function(){
var task_id = $(this).parent().data("task-id");
var _this = $(this);
$.post("/xhr/ruling_timer/add_task_from_list",{"task_id": task_id}).done(function(data){
if(data.success){
_this.parent().remove();
if($(".task-popup-items > *").length == 0){
$("#task-list-popup").css("display","none");
}
var task_id = data["task-id"];
var task_item = $("<div class=\"tm-task-item\" data-task-id=\""+task_id+"\"></div>");
task_item.append("<input class=\"tm-task-checkbox\" type=\"checkbox\">"+"<span class=\"tm-task-name\">"+data.task+"</span>");
task_item.append("<span class=\"tm-task-item-menu\"><i class=\"fa fa-caret-down\"></i></span>");
$(".tm-task-list").append(task_item);
}else{
alert("Cannot add task!\nPlease refresh web and login!");
}
})
})
$('.event-start-time,.event-end-time').click(function(){
$(this).not('.hasDatepicker').ui_timepicker({timeFormat: 'H:mm'});
$(this).trigger('focus');
})
$(document).on('click','.timers',function(){
$(this).not('.hasDatepicker').ui_timepicker({timeFormat: 'HH:mm:ss'});
$(this).trigger('focus');
})
$(".tm-popup-notice-pencil").click(show_timer_setting);
$(".save_timers").click(function(){
var _this = $(this);
var work_times = $('.timers').map(function(i,v){return v.value}).toArray();
var wrong_index = -1;
work_times.forEach(function(v,i){
work_times.slice(i+1,work_times.length).forEach(function(vv,j){
if(v > vv){
wrong_index = i;
}
})
})
if(wrong_index != -1){
var min = work_times[wrong_index-1];
var max = work_times[wrong_index+1];
var title = "";
if(min){
title += decodeURIComponent("<%=t('ruling_timer.please_input_larger_than_value')%>").replace("{{value}}",min) + "\n";
}
if(max){
title += decodeURIComponent("<%=t('ruling_timer.please_input_smaller_than_value')%>").replace("{{value}}",max) + "\n";
}
$('.timers').eq(wrong_index).addClass("wrong_timer").data({"min": min,"max": max}).attr("title",title);
}else{
$.post("/xhr/ruling_timer/save_work_times",{"work_times": work_times}).done(function(data){
var field = time_tracker.field;
time_tracker.stop_timer();
time_tracker.set_data(data);
time_tracker.start_timer(field);
_this.parents(".popup-window").eq(0).css("display","none");
})
}
})
$(document).on("input change",".wrong_timer",function(){
var min = $(this).data("min");
var max = $(this).data("max");
var val = $(this).val();
var correct = true;
if(min && val < min){
correct = false;
}
if(max && val > max){
correct = false;
}
if(correct){
$(this).removeClass("wrong_timer").attr("title","");
}
})
$(document).ready(function(){
<% if @ruling_timer_temp.events.count == 0 %>
var next_event_time = time_calc.get_next_hour_only(time_tracker.now_str);
<% else %>
var next_event_time = time_calc.get_next_hour_only("<%=@ruling_timer_temp.events.last["end"]%>");
<% end %>
$(".event-start-time").val(next_event_time);
$(".event-end-time").val(time_calc.get_next_hour_only(next_event_time));
$(".display_task_list").click(function(){
show_timer_window(true);
window.setTimeout(show_timer_task_list,100);
})
})
</script>
<% end %>