Update index table
This commit is contained in:
parent
17f373a265
commit
aedb0690ce
|
@ -4,55 +4,22 @@ class Admin::WebResourcesController < OrbitAdminController
|
||||||
|
|
||||||
def index
|
def index
|
||||||
@tags = @module_app.tags
|
@tags = @module_app.tags
|
||||||
@categories = @module_app.categories
|
@categories = @module_app.categories.enabled
|
||||||
|
@filter_fields = filter_fields(@categories, @tags)
|
||||||
@filter_fields = {
|
@table_fields = [:status, :category, :title]
|
||||||
:status=>[{:title=>"is_top",:id=>"is_top"},{:title=>"is_hot",:id=>"is_hot"},{:title=>"is_hidden",:id=>"is_hidden"}],
|
|
||||||
:category=>@categories.map{|c| {:title=>c.title, :id=>c.id}},
|
|
||||||
:tags=>@tags.map{|tag| {:title=>tag.name, :id=>tag.id}}
|
|
||||||
}
|
|
||||||
end
|
|
||||||
|
|
||||||
def index_table
|
|
||||||
status = params[:filters][:status].blank? ? [] : params[:filters][:status] rescue []
|
|
||||||
categories = params[:filters][:category].blank? ? [] : params[:filters][:category] rescue []
|
|
||||||
tags = params[:filters][:tags].blank? ? [] : params[:filters][:tags] rescue []
|
|
||||||
|
|
||||||
@links = Kaminari.paginate_array(
|
@links = Kaminari.paginate_array(
|
||||||
WebLink.order_by(sort).with_categories(categories).with_tags(tags).with_status(status)
|
WebLink.order_by(sort).with_categories(filters("category")).with_tags(filters("tag")).with_status(filters("status"))
|
||||||
).page(params[:page]).per(10)
|
).page(params[:page]).per(10)
|
||||||
|
|
||||||
@table_fields = [:status, :category, :title]
|
if request.xhr?
|
||||||
render :layout => false
|
render :partial => "index"
|
||||||
end
|
end
|
||||||
|
|
||||||
def sort
|
|
||||||
unless params[:sort].blank?
|
|
||||||
case params[:sort]
|
|
||||||
when "status"
|
|
||||||
@sort = [[:is_top, params[:order]],
|
|
||||||
[:is_hot, params[:order]],
|
|
||||||
[:is_hidden,params[:order]]]
|
|
||||||
when "category"
|
|
||||||
@sort = {:category_id=>params[:order]}
|
|
||||||
when "title"
|
|
||||||
@sort = {:title=>params[:order]}
|
|
||||||
when "start_date"
|
|
||||||
@sort = {:postdate=>params[:order]}
|
|
||||||
when "end_date"
|
|
||||||
@sort = {:deadline=>params[:order]}
|
|
||||||
when "last_modified"
|
|
||||||
@sort = {:update_user_id=>params[:order]}
|
|
||||||
end
|
|
||||||
else
|
|
||||||
@sort = {:created_at=>'desc'}
|
|
||||||
end
|
|
||||||
@sort
|
|
||||||
end
|
end
|
||||||
|
|
||||||
def new
|
def new
|
||||||
@tags =@module_app.tags
|
@tags =@module_app.tags
|
||||||
@categories = @module_app.categories
|
@categories = @module_app.categories.enabled
|
||||||
@statuses = []
|
@statuses = []
|
||||||
@link = WebLink.new
|
@link = WebLink.new
|
||||||
end
|
end
|
||||||
|
@ -67,7 +34,7 @@ class Admin::WebResourcesController < OrbitAdminController
|
||||||
|
|
||||||
def edit
|
def edit
|
||||||
@tags =@module_app.tags
|
@tags =@module_app.tags
|
||||||
@categories = @module_app.categories
|
@categories = @module_app.categories.enabled
|
||||||
@statuses = []
|
@statuses = []
|
||||||
end
|
end
|
||||||
|
|
||||||
|
|
|
@ -12,7 +12,7 @@
|
||||||
<td><%= link.status_for_table %></td>
|
<td><%= link.status_for_table %></td>
|
||||||
<td><%= link.category.title %></td>
|
<td><%= link.category.title %></td>
|
||||||
<td>
|
<td>
|
||||||
<a href="#" target="_blank"><%= link.title %></a>
|
<a href="<%= link.url %>" target="_blank"><%= link.title %></a>
|
||||||
<div class="quick-edit">
|
<div class="quick-edit">
|
||||||
<ul class="nav nav-pills">
|
<ul class="nav nav-pills">
|
||||||
<li><a href="/admin/web_resources/<%=link.id.to_s%>/edit"><%= t(:edit) %></a></li>
|
<li><a href="/admin/web_resources/<%=link.id.to_s%>/edit"><%= t(:edit) %></a></li>
|
|
@ -13,11 +13,11 @@
|
||||||
<div class="accordion-body collapse" id="collapse-<%= field %>">
|
<div class="accordion-body collapse" id="collapse-<%= field %>">
|
||||||
<div class="accordion-inner pagination-right" data-toggle="buttons-checkbox">
|
<div class="accordion-inner pagination-right" data-toggle="buttons-checkbox">
|
||||||
<% @filter_fields[field].each do |val| %>
|
<% @filter_fields[field].each do |val| %>
|
||||||
<%= link_to t(val[:title]), "#", :onclick => "addFilter('filters[#{field}][]=#{val[:id]}')", :class => "btn btn-small #{is_filter_active?(field, val[:id])}" %>
|
<%= link_to t(val[:title]), "#", :onclick => "filter.addFilter('filters[#{field}][]=#{val[:id]}')", :class => "btn btn-small #{is_filter_active?(field, val[:id])}" %>
|
||||||
<% end %>
|
<% end %>
|
||||||
</div>
|
</div>
|
||||||
<div class="filter-clear">
|
<div class="filter-clear">
|
||||||
<a href="" class="btn btn-link btn-small"><i class="icons-cycle"></i> <%= t(:clear) %></a>
|
<a href="#" onclick="filter.clearFilter();" class="btn btn-link btn-small"><i class="icons-cycle"></i> <%= t(:clear) %></a>
|
||||||
</div>
|
</div>
|
||||||
</div>
|
</div>
|
||||||
<% end %>
|
<% end %>
|
||||||
|
@ -25,65 +25,57 @@
|
||||||
<% end %>
|
<% end %>
|
||||||
|
|
||||||
<span id="index_table">
|
<span id="index_table">
|
||||||
|
<%= render 'index'%>
|
||||||
</span>
|
</span>
|
||||||
|
|
||||||
<%= render 'layouts/delete_modal', delete_options: @delete_options %>
|
<%= render 'layouts/delete_modal', delete_options: @delete_options %>
|
||||||
|
|
||||||
<script type="text/javascript">
|
<script type="text/javascript">
|
||||||
filters=[];
|
var Filter = function(dom){
|
||||||
table_url="";
|
var makeFilters = function(){
|
||||||
|
return (window.location.search ? window.location.search.replace('?','').split('&') : []);
|
||||||
$(function(){
|
|
||||||
init();
|
|
||||||
update_table();
|
|
||||||
});
|
|
||||||
|
|
||||||
var init = function(){
|
|
||||||
filters = window.location.search.replace('?','').split('&');
|
|
||||||
table_url = "";
|
|
||||||
if(window.location.search==""){
|
|
||||||
filters = [];
|
|
||||||
table_url = window.location.pathname+'/index_table';
|
|
||||||
}else{
|
|
||||||
table_url = window.location.pathname+'/index_table';
|
|
||||||
}
|
}
|
||||||
};
|
var filters = makeFilters(),
|
||||||
|
dom = $(dom),
|
||||||
var update_table = function(url){
|
mainUrl = window.location.pathname;
|
||||||
if(url==null){
|
var updateTable = function(url){
|
||||||
if(filters.length==0){
|
xurl = (url == null ? ( filters.length ? mainUrl + "?" + filters.join('&') : mainUrl ) : null);
|
||||||
url = table_url;
|
$.ajax({
|
||||||
}else{
|
url : xurl,
|
||||||
url = table_url+'?'+filters.join('&');
|
type : "get",
|
||||||
}
|
dataType : "html"
|
||||||
}
|
}).done(function(data){
|
||||||
|
history.pushState(null, null, decodeURIComponent(xurl));
|
||||||
$.get(url,function(data){
|
filters = makeFilters();
|
||||||
history.pushState(null, null, decodeURIComponent(url.replace('/index_table','')) );
|
dom.html(data);
|
||||||
init();
|
|
||||||
$("#index_table").html(data);
|
|
||||||
|
|
||||||
$(".pagination a").click(function(){
|
$(".pagination a").click(function(){
|
||||||
update_table($(this).attr('href'));
|
updateTable($(this).attr('href'));
|
||||||
return false;
|
return false;
|
||||||
});
|
});
|
||||||
});
|
})
|
||||||
};
|
}
|
||||||
|
this.addFilter = function(filter){
|
||||||
var addFilter = function(filter){
|
|
||||||
url = "";
|
|
||||||
$.each(filters,function(idx,data){
|
$.each(filters,function(idx,data){
|
||||||
if(data.indexOf("page=")>-1) filters.splice(idx,1);
|
if(data.indexOf("page=")>-1) filters.splice(idx,1);
|
||||||
});
|
});
|
||||||
|
|
||||||
if( (index = filters.indexOf(filter) ) > -1){
|
if( (index = filters.indexOf(filter) ) > -1){
|
||||||
table_url = table_url.replace(filter,'');
|
mainUrl = mainUrl.replace(filter,'');
|
||||||
filters.splice(index,1);
|
filters.splice(index,1);
|
||||||
}else{
|
}else{
|
||||||
filters.push(filter);
|
filters.push(filter);
|
||||||
}
|
}
|
||||||
|
|
||||||
update_table();
|
updateTable();
|
||||||
return false;
|
return false;
|
||||||
};
|
};
|
||||||
|
|
||||||
|
this.clearFilter = function(){
|
||||||
|
$(".filter-group a.active").removeClass("active");
|
||||||
|
filters = [];
|
||||||
|
updateTable();
|
||||||
|
return false;
|
||||||
|
}
|
||||||
|
}
|
||||||
|
var filter = new Filter("#index_table");
|
||||||
</script>
|
</script>
|
|
@ -4,7 +4,6 @@ locales = Site.find_by(site_active: true).in_use_locales rescue I18n.available_l
|
||||||
|
|
||||||
scope "(:locale)", locale: Regexp.new(locales.join("|")) do
|
scope "(:locale)", locale: Regexp.new(locales.join("|")) do
|
||||||
namespace :admin do
|
namespace :admin do
|
||||||
get 'web_resources/index_table' => 'web_resources#index_table'
|
|
||||||
resources :web_resources
|
resources :web_resources
|
||||||
end
|
end
|
||||||
end
|
end
|
||||||
|
|
Loading…
Reference in New Issue