ruling_timer/app/views/admin/ruling_timers/add_history.html.erb

78 lines
3.2 KiB
Plaintext
Raw Normal View History

2021-07-21 07:37:06 +00:00
<style type="text/css">
.timer_block input{
width: 5em;
}
.remove_btn{
color: red;
margin-right: 0.3em;
background: transparent;
border: 1px solid red;
}
.remove_btn:hover{
font-weight: bold;
}
</style>
<h3><%=@user.name%></h3>
<%= form_for @history, url: create_history_admin_ruling_timers_path(@history), html: {class: "form-horizontal main-forms previewable"} do |f| %>
<fieldset>
<%= f.hidden_field :user_id%>
<%= f.hidden_field :time_offset, :id=>"history_timeoffset" %>
<div class="control-group">
<label class="control-label muted" for="ruling_timer_history_date" ><%= t("ruling_timer.date") %></label>
<div class="controls">
<%= f.datetime_picker :date, {:picker_type=>"date",:no_label=>true,:format=>"yyyy/MM/dd"} %>
</div>
</div>
<div class="control-group">
<label class="control-label muted" for="edit_summary" ><%= t("ruling_timer.summary") %></label>
<div class="controls">
<%= f.text_area :summary,:id=>"edit_summary" %>
</div>
</div>
<div class="control-group">
<label class="control-label muted"><%=t("ruling_timer.work_time")%></label>
<div class="controls timer_block">
<% work_times = @history.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><button class="remove_btn" type="button">X</button><%= f.text_field_tag "#{f.object_name}[work_times][]", t ,:id=>nil %> ~ <%= f.text_field_tag "#{f.object_name}[work_times][]", next_t ,:id=>nil %></span>
<hr>
<% end %>
<div class="add_target"></div>
<button type="button" class="btn btn-primary" id="add_timer"><%=t(:add)%></button>
</div>
</div>
<!-- Form Actions -->
<div class="form-actions">
<% referer = request.referer rescue nil %>
<% referer = get_referer_url if referer.blank? || request.host != URI.parse(URI.encode(referer)).host %>
<%= f.submit t('submit'), class: 'btn btn-primary' %>
<input type="hidden" name="referer_url" value="<%= referer %>">
<%= link_to t('cancel'), referer, :class=>"btn" %>
</div>
</fieldset>
<script>
window.timer_offset = (new Date().getTimezoneOffset() / -60).toString();
if(window.timer_offset[0] != "-"){
window.timer_offset = "+" + window.timer_offset;
}
$(document).ready(function(){
$("#history_timeoffset").val(window.timer_offset);
$('.timer_block input').ui_timepicker({timeFormat: 'H:mm:ss'});
$("#add_timer").click(function(){
var timer_html = $('<span><button class="remove_btn" type="button">X</button><%= f.text_field_tag "#{f.object_name}[work_times][]",nil,:id=>nil %> ~ <%= f.text_field_tag "#{f.object_name}[work_times][]",nil,:id=>nil %></span><hr>');
$(".add_target").append(timer_html);
timer_html.find("input").ui_timepicker({timeFormat: 'H:mm:ss'});
})
$(document).on("click",".remove_btn",function(){
var item = $(this).parent();
item.next("hr").remove();
item.remove();
})
})
</script>
<% end %>