ask/app/views/admin/asks/ticket_status.html.erb

115 lines
4.0 KiB
Plaintext
Raw Normal View History

<div id="pageslide">
<div class="page-title clearfix">
<a class="pull-right" href="javascript:$.pageslide.close()">
<i class="icons-arrow-left-2"></i>
</a>
<span></span>
</div>
<div class="view-page">
<div class="nano">
<div class="content">
<%= form_for :ask_ticket_status, url: update_ticket_status_admin_asks_path, remote: true, :html=>{id: "ask_ticket_status_form"} do |f| %>
<fieldset>
<%= hidden_field_tag :id, "", {:id=>'hidden_id_field'} %>
<%= f.fields_for :title_translations do |f| %>
<% @site_in_use_locales.each do |locale| %>
<div class="control-group">
<label class="control-label"><%= "#{t('ask.status')} (#{t(locale)})" %></label>
<div class="controls">
<input class="input-large" id="<%=locale%>" name="<%=f.object_name%>[<%=locale%>]" placeholder="<%=t('ask.status')%>" type="text">
</div>
</div>
<% end %>
<% end %>
<div class="form-actions">
<a href="javascript:$.pageslide.close()" class="btn btn-small"><%= t(:cancel) %></a>
<%= f.submit t(:submit), class: 'btn btn-primary btn-small', id: "ask_ticket_status_submit" %>
</div>
</fieldset>
<% end %>
</div>
</div>
</div>
</div>
<table class="table main-list" id="status_table">
<thead>
<tr>
<th><%= t('ask.status') %></th>
<th><%= t('ask.action') %></th>
</tr>
</thead>
<tbody>
<% @ticket_statuses.each do |ticket_status| %>
<tr>
<td><%= ticket_status.title %></td>
<td>
<a href="#" class="btn btn-primary edit_ticket open-slide" data-id="<%=ticket_status.id%>"><%= t(:edit) %></a>
<% unless ticket_status.is_default %>
<button class="btn btn-danger delete_ticket" data-id="<%=ticket_status.id%>"><%= t(:delete_) %></button>
<% end %>
</td>
</tr>
<% end %>
</tbody>
</table>
<a href="#" class="btn btn-primary new_ticket open-slide" data-title="<%=t("ask.new_status")%>"><%= t(:add) %></a>
<script>
function reload_page(){
$.get(window.location.href).done(function(data){
$('#status_table').html($(data).filter('#status_table').html());
openSlide();
})
}
$(document).ready(function(){
openSlide();
$('form#ask_ticket_status_form').bind('ajax:success', function(evt, data, status, xhr){
window.setTimeout(function(){
reload_page();
$.pageslide.close();
}, 500);
})
$.pageslide.closeCallback(function(pageslide, item) {
$('.filter-item').removeClass("active");
});
$.pageslide.loadComplete(function(pageslide, item) {
var id = item.data('id');
var form = pageslide.find('form');
$.post('<%= get_ticket_status_admin_asks_path %>', {id: id}).done(function(data){
form.find('#hidden_id_field').val(id);
Object.keys(data).forEach(function(k){
var v = data[k];
if(v instanceof Object){
console.log(v);
var tmp = Object.keys(v);
if(tmp.length){
tmp.forEach(function(kk){
form.find('[name*="ask_ticket_status['+k+']['+kk+']"').val(v[kk]);
});
}else{
form.find('[name*="ask_ticket_status['+k+']"').val('');
}
}else{
form.find('[name*="ask_ticket_status['+k+']"').val(v);
}
})
})
});
$(document).on('click', '.delete_ticket', function(){
var id = $(this).data('id');
var tr = $(this).parents('tr');
var sure_text = "<%=t(:are_you_sure_to_delete)%>";
if(window.confirm(sure_text)){
if(window.confirm(sure_text)){
$.ajax({
url : '<%=delete_ticket_status_admin_asks_path%>',
type : 'DELETE',
data: {id: id},
success: function(){
tr.remove();
}
});
}
}
})
})
</script>