Refactor debates order select using js-location-changer

This commit is contained in:
kikito
2015-08-28 17:17:21 +02:00
parent 934512ad7a
commit 088144dcd1
6 changed files with 10 additions and 49 deletions

View File

@@ -21,7 +21,6 @@
//= require d3 //= require d3
//= require c3 //= require c3
//= require c3ext //= require c3ext
//= require qp
//= require app //= require app
//= require_tree . //= require_tree .
@@ -32,7 +31,6 @@ var initialize_modules = function() {
App.Tags.initialize(); App.Tags.initialize();
App.Stats.initialize(); App.Stats.initialize();
App.LocationChanger.initialize(); App.LocationChanger.initialize();
App.DebatesOrderSelector.initialize();
}; };
$(function(){ $(function(){

View File

@@ -1,17 +0,0 @@
App.DebatesOrderSelector =
href_with_params: (query_params) ->
loc = window.location
loc.protocol + "//" + loc.hostname +
(if loc.port then ':' + loc.port else '') +
loc.pathname +
loc.hash +
'?' + $.param(query_params)
initialize: ->
$('.js-order-selector').on 'change', ->
query_params = window.getQueryParameters()
query_params['order'] = $(this).val()
window.location.assign(App.DebatesOrderSelector.href_with_params(query_params))

View File

@@ -1,12 +0,0 @@
/*
* getQueryParameters.js
* Copyright (c) 2014 Nicholas Ortenzio
* The MIT License (MIT)
*
*/
window.getQueryParameters = function(str) {
str = (str || document.location.search).replace(/(^\?)/,'');
if(!str) { return {}; }
return str.split("&").reduce(function(o,n){n=n.split('=');o[n[0]]=n[1];return o},{});
};

View File

@@ -1,12 +0,0 @@
module DebatesHelper
def available_options_for_order_selector(valid_orders, current_order)
options_for_select(available_order_filters_array(valid_orders), current_order)
end
private
def available_order_filters_array(orders)
orders.map { |f| [t("debates.index.orders.#{f}"), f] }
end
end

View File

@@ -1,5 +0,0 @@
<form class="inline-block">
<select class="js-order-selector" name="order-selector">
<%= available_options_for_order_selector(@valid_orders, @order) %>
</select>
</form>

View File

@@ -4,7 +4,16 @@
<div class="filters row"> <div class="filters row">
<div class="small-12 column"> <div class="small-12 column">
<h2><%= t("debates.index.showing") %></h2> <h2><%= t("debates.index.showing") %></h2>
<%= render 'order_selector' %> <form class="inline-block">
<select class="js-location-changer" name="order-selector">
<% @valid_orders.each do |order| %>
<option <%= 'selected' if order == @order %>
value='<%= url_for(request.query_parameters.merge(order: order))%>'>
<%= t("debates.index.orders.#{order}") %>
</option>
<% end %>
</select>
</form>
</div> </div>
</div> </div>
<!-- /. Filters --> <!-- /. Filters -->