pagecontent/app/views/admin/page_contents/_index.html.erb

77 lines
2.5 KiB
Plaintext
Raw Normal View History

2014-08-07 10:48:51 +00:00
<table class="table table-striped table-hover main-list">
<thead>
<tr class="sort-header">
<% @table_fields.each do |f| %>
<%= thead(f) %>
<% end %>
</tr>
</thead>
<tbody>
<% @pages.each do |page| %>
<tr>
<td><%= page.page_id %></td>
<td>
<a href="/<%= I18n.locale %><%= page.url %>" target="_blank"><%= page.name %></a>
<div class="quick-edit">
<ul class="nav nav-pills">
<% if can_edit_or_delete?(page) %>
<li><a href="/admin/page_contents/new?page_id=<%= page.id.to_s %>"><%= t(:edit) %></a></li>
<% end %>
</ul>
</div>
</td>
<td><a href="/admin/page_contents/<%= page.id.to_s %>/view" ><%= page.page_contexts.last.version rescue nil %></a></td>
<td><%= format_value page.page_contexts.last.updated_at rescue nil %></td>
<td><%= User.find(page.page_contexts.last.update_user_id).user_name rescue nil %></td>
2014-12-01 10:06:31 +00:00
<td>
2014-12-01 13:07:00 +00:00
<% if can_edit_or_delete?(page) %>
2014-12-01 11:12:18 +00:00
<%= select_tag("category_id",options_for_select(@categories, (page.category_id.to_s rescue "")), prompt: "Select a category", class: "category_select", style: "margin-bottom:0; width:150px;") %>
<button <%= !page.category_id.nil? ? "data-page-category-id=#{page.category_id.to_s}" : "" %> data-page-id="<%= page.id.to_s %>" class="btn btn-primary save_category hide">Save</button>
2014-12-01 13:07:00 +00:00
<% end %>
2014-12-01 10:06:31 +00:00
</td>
2014-08-07 10:48:51 +00:00
</tr>
<% end %>
</tbody>
</table>
<%=
content_tag :div, class: "bottomnav clearfix" do
content_tag :div, paginate(@pages), class: "pagination pagination-centered"
end
2014-12-01 10:06:31 +00:00
%>
<script type="text/javascript">
(function(){
var category_id = null,
2014-12-01 11:12:18 +00:00
buttons = $("button.save_category");
2014-12-01 10:06:31 +00:00
$("select.category_select").on("change",function(){
2014-12-01 11:12:18 +00:00
category_id = $(this).val();
button = $(this).parent().find("button");
2014-12-01 10:06:31 +00:00
if(category_id != ""){
if(button.data("page-category-id") != category_id){
2014-12-01 11:12:18 +00:00
button.removeClass("hide");
2014-12-01 10:06:31 +00:00
}else{
2014-12-01 11:12:18 +00:00
button.addClass("hide");
2014-12-01 10:06:31 +00:00
}
}else{
2014-12-01 11:12:18 +00:00
button.addClass("hide");
2014-12-01 10:06:31 +00:00
}
})
2014-12-01 11:12:18 +00:00
buttons.on("click",function(){
var page_id = $(this).data("page-id"),
button = $(this);
2014-12-01 10:06:31 +00:00
if(category_id != null){
$.ajax({
url : "/admin/page_contents/save_category",
dataType : "json",
type: "post",
data : {"category_id" : category_id, "page_id" : page_id}
}).done(function(data){
if(data.success){
button.addClass("hide");
}
})
}
})
})();
</script>