Refactor debates order select using js-location-changer
This commit is contained in:
@@ -21,7 +21,6 @@
|
||||
//= require d3
|
||||
//= require c3
|
||||
//= require c3ext
|
||||
//= require qp
|
||||
//= require app
|
||||
//= require_tree .
|
||||
|
||||
@@ -32,7 +31,6 @@ var initialize_modules = function() {
|
||||
App.Tags.initialize();
|
||||
App.Stats.initialize();
|
||||
App.LocationChanger.initialize();
|
||||
App.DebatesOrderSelector.initialize();
|
||||
};
|
||||
|
||||
$(function(){
|
||||
|
||||
@@ -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))
|
||||
|
||||
@@ -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},{});
|
||||
};
|
||||
@@ -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
|
||||
@@ -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>
|
||||
@@ -4,7 +4,16 @@
|
||||
<div class="filters row">
|
||||
<div class="small-12 column">
|
||||
<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>
|
||||
<!-- /. Filters -->
|
||||
|
||||
Reference in New Issue
Block a user