2014-05-01 08:41:00 +00:00
|
|
|
<% content_for :right_nav do %>
|
|
|
|
<ul class="nav nav-pills filter-nav pull-right">
|
|
|
|
<% @filter_fields.keys.each do |field| %>
|
|
|
|
<li class="accordion-group">
|
|
|
|
<div class="accordion-heading">
|
|
|
|
<a href="#collapse-<%= field %>" data-toggle="collapse" data-parent="#filter" class="accordion-toggle"><%= t(field) %></a>
|
|
|
|
</div>
|
|
|
|
</li>
|
|
|
|
<% end %>
|
|
|
|
</ul>
|
|
|
|
<div class="filter-group accordion-group">
|
|
|
|
<% @filter_fields.keys.each do |field| %>
|
|
|
|
<div class="accordion-body collapse" id="collapse-<%= field %>">
|
|
|
|
<div class="accordion-inner pagination-right" data-toggle="buttons-checkbox">
|
|
|
|
<% @filter_fields[field].each do |val| %>
|
2014-05-14 02:58:06 +00:00
|
|
|
<%= link_to t(val[:title]), "#", :onclick => "filter.addFilter('filters[#{field}][]=#{val[:id]}')", :class => "btn btn-small #{is_filter_active?(field, val[:id])}" %>
|
2014-05-01 08:41:00 +00:00
|
|
|
<% end %>
|
|
|
|
</div>
|
|
|
|
<div class="filter-clear">
|
2014-05-14 02:58:06 +00:00
|
|
|
<a href="#" onclick="filter.clearFilter();" class="btn btn-link btn-small"><i class="icons-cycle"></i> <%= t(:clear) %></a>
|
2014-05-01 08:41:00 +00:00
|
|
|
</div>
|
|
|
|
</div>
|
|
|
|
<% end %>
|
|
|
|
</div>
|
|
|
|
<% end %>
|
|
|
|
|
2014-05-02 10:21:51 +00:00
|
|
|
<span id="index_table">
|
2014-05-14 02:58:06 +00:00
|
|
|
<%= render 'index'%>
|
2014-05-02 10:21:51 +00:00
|
|
|
</span>
|
2014-05-01 08:41:00 +00:00
|
|
|
|
2014-05-02 04:09:44 +00:00
|
|
|
<%= render 'layouts/delete_modal', delete_options: @delete_options %>
|
2014-05-02 10:21:51 +00:00
|
|
|
|
|
|
|
<script type="text/javascript">
|
2014-05-14 02:58:06 +00:00
|
|
|
var Filter = function(dom){
|
|
|
|
var makeFilters = function(){
|
|
|
|
return (window.location.search ? window.location.search.replace('?','').split('&') : []);
|
2014-05-02 10:21:51 +00:00
|
|
|
}
|
2014-05-14 02:58:06 +00:00
|
|
|
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;
|
|
|
|
});
|
|
|
|
})
|
|
|
|
}
|
|
|
|
this.addFilter = function(filter){
|
|
|
|
$.each(filters,function(idx,data){
|
|
|
|
if(data.indexOf("page=")>-1) filters.splice(idx,1);
|
|
|
|
});
|
2014-05-02 10:21:51 +00:00
|
|
|
|
2014-05-14 02:58:06 +00:00
|
|
|
if( (index = filters.indexOf(filter) ) > -1){
|
|
|
|
mainUrl = mainUrl.replace(filter,'');
|
|
|
|
filters.splice(index,1);
|
2014-05-02 10:21:51 +00:00
|
|
|
}else{
|
2014-05-14 02:58:06 +00:00
|
|
|
filters.push(filter);
|
2014-05-02 10:21:51 +00:00
|
|
|
}
|
|
|
|
|
2014-05-14 02:58:06 +00:00
|
|
|
updateTable();
|
|
|
|
return false;
|
|
|
|
};
|
2014-05-02 10:21:51 +00:00
|
|
|
|
2014-05-14 02:58:06 +00:00
|
|
|
this.clearFilter = function(){
|
|
|
|
$(".filter-group a.active").removeClass("active");
|
|
|
|
filters = [];
|
|
|
|
updateTable();
|
|
|
|
return false;
|
2014-05-02 10:21:51 +00:00
|
|
|
}
|
2014-05-14 02:58:06 +00:00
|
|
|
}
|
|
|
|
var filter = new Filter("#index_table");
|
2014-05-02 10:21:51 +00:00
|
|
|
</script>
|