Update index table
This commit is contained in:
parent
17f373a265
commit
aedb0690ce
|
@ -4,55 +4,22 @@ class Admin::WebResourcesController < OrbitAdminController
|
|||
|
||||
def index
|
||||
@tags = @module_app.tags
|
||||
@categories = @module_app.categories
|
||||
|
||||
@filter_fields = {
|
||||
: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 []
|
||||
@categories = @module_app.categories.enabled
|
||||
@filter_fields = filter_fields(@categories, @tags)
|
||||
@table_fields = [:status, :category, :title]
|
||||
|
||||
@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)
|
||||
|
||||
@table_fields = [:status, :category, :title]
|
||||
render :layout => false
|
||||
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'}
|
||||
if request.xhr?
|
||||
render :partial => "index"
|
||||
end
|
||||
@sort
|
||||
end
|
||||
|
||||
def new
|
||||
@tags =@module_app.tags
|
||||
@categories = @module_app.categories
|
||||
@categories = @module_app.categories.enabled
|
||||
@statuses = []
|
||||
@link = WebLink.new
|
||||
end
|
||||
|
@ -67,7 +34,7 @@ class Admin::WebResourcesController < OrbitAdminController
|
|||
|
||||
def edit
|
||||
@tags =@module_app.tags
|
||||
@categories = @module_app.categories
|
||||
@categories = @module_app.categories.enabled
|
||||
@statuses = []
|
||||
end
|
||||
|
||||
|
|
|
@ -12,7 +12,7 @@
|
|||
<td><%= link.status_for_table %></td>
|
||||
<td><%= link.category.title %></td>
|
||||
<td>
|
||||
<a href="#" target="_blank"><%= link.title %></a>
|
||||
<a href="<%= link.url %>" target="_blank"><%= link.title %></a>
|
||||
<div class="quick-edit">
|
||||
<ul class="nav nav-pills">
|
||||
<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-inner pagination-right" data-toggle="buttons-checkbox">
|
||||
<% @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 %>
|
||||
</div>
|
||||
<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>
|
||||
<% end %>
|
||||
|
@ -25,65 +25,57 @@
|
|||
<% end %>
|
||||
|
||||
<span id="index_table">
|
||||
<%= render 'index'%>
|
||||
</span>
|
||||
|
||||
<%= render 'layouts/delete_modal', delete_options: @delete_options %>
|
||||
|
||||
<script type="text/javascript">
|
||||
filters=[];
|
||||
table_url="";
|
||||
|
||||
$(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 Filter = function(dom){
|
||||
var makeFilters = function(){
|
||||
return (window.location.search ? window.location.search.replace('?','').split('&') : []);
|
||||
}
|
||||
};
|
||||
|
||||
var update_table = function(url){
|
||||
if(url==null){
|
||||
if(filters.length==0){
|
||||
url = table_url;
|
||||
}else{
|
||||
url = table_url+'?'+filters.join('&');
|
||||
}
|
||||
var filters = makeFilters(),
|
||||
dom = $(dom),
|
||||
mainUrl = window.location.pathname;
|
||||
var updateTable = function(url){
|
||||
xurl = (url == null ? ( filters.length ? mainUrl + "?" + filters.join('&') : mainUrl ) : null);
|
||||
$.ajax({
|
||||
url : xurl,
|
||||
type : "get",
|
||||
dataType : "html"
|
||||
}).done(function(data){
|
||||
history.pushState(null, null, decodeURIComponent(xurl));
|
||||
filters = makeFilters();
|
||||
dom.html(data);
|
||||
$(".pagination a").click(function(){
|
||||
updateTable($(this).attr('href'));
|
||||
return false;
|
||||
});
|
||||
})
|
||||
}
|
||||
|
||||
$.get(url,function(data){
|
||||
history.pushState(null, null, decodeURIComponent(url.replace('/index_table','')) );
|
||||
init();
|
||||
$("#index_table").html(data);
|
||||
|
||||
$(".pagination a").click(function(){
|
||||
update_table($(this).attr('href'));
|
||||
return false;
|
||||
this.addFilter = function(filter){
|
||||
$.each(filters,function(idx,data){
|
||||
if(data.indexOf("page=")>-1) filters.splice(idx,1);
|
||||
});
|
||||
});
|
||||
};
|
||||
|
||||
var addFilter = function(filter){
|
||||
url = "";
|
||||
$.each(filters,function(idx,data){
|
||||
if(data.indexOf("page=")>-1) filters.splice(idx,1);
|
||||
});
|
||||
if( (index = filters.indexOf(filter) ) > -1){
|
||||
mainUrl = mainUrl.replace(filter,'');
|
||||
filters.splice(index,1);
|
||||
}else{
|
||||
filters.push(filter);
|
||||
}
|
||||
|
||||
if( (index = filters.indexOf(filter) ) > -1){
|
||||
table_url = table_url.replace(filter,'');
|
||||
filters.splice(index,1);
|
||||
}else{
|
||||
filters.push(filter);
|
||||
updateTable();
|
||||
return false;
|
||||
};
|
||||
|
||||
this.clearFilter = function(){
|
||||
$(".filter-group a.active").removeClass("active");
|
||||
filters = [];
|
||||
updateTable();
|
||||
return false;
|
||||
}
|
||||
|
||||
update_table();
|
||||
return false;
|
||||
};
|
||||
}
|
||||
var filter = new Filter("#index_table");
|
||||
</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
|
||||
namespace :admin do
|
||||
get 'web_resources/index_table' => 'web_resources#index_table'
|
||||
resources :web_resources
|
||||
end
|
||||
end
|
||||
|
|
Loading…
Reference in New Issue