refactors javascript
This commit is contained in:
37
app/assets/javascripts/advanced_search.js.coffee
Normal file
37
app/assets/javascripts/advanced_search.js.coffee
Normal file
@@ -0,0 +1,37 @@
|
|||||||
|
App.AdvancedSearch =
|
||||||
|
|
||||||
|
advanced_search_terms: ->
|
||||||
|
$('#advanced-search').data('advanced-search-terms')
|
||||||
|
|
||||||
|
decorate_link: (id) ->
|
||||||
|
$('.advanced-search-title').addClass 'blue'
|
||||||
|
|
||||||
|
undecorate_link: (id) ->
|
||||||
|
$('.advanced-search-title').removeClass 'blue'
|
||||||
|
|
||||||
|
toggle_form: ->
|
||||||
|
$('#advanced-search').slideToggle()
|
||||||
|
|
||||||
|
toggle_date_options: ->
|
||||||
|
if $('#advanced_search_date_min').val() == 'custom'
|
||||||
|
$('.customized-date').show()
|
||||||
|
$('.customized-date input').prop 'disabled', false
|
||||||
|
else
|
||||||
|
$('.customized-date').hide()
|
||||||
|
$('.customized-date input').prop 'disabled', true
|
||||||
|
|
||||||
|
initialize: ->
|
||||||
|
if App.AdvancedSearch.advanced_search_terms()
|
||||||
|
$('#advanced-search').show()
|
||||||
|
|
||||||
|
$('.advanced-search-title').on
|
||||||
|
click: ->
|
||||||
|
App.AdvancedSearch.toggle_form()
|
||||||
|
mouseenter: ->
|
||||||
|
App.AdvancedSearch.decorate_link()
|
||||||
|
mouseleave: ->
|
||||||
|
App.AdvancedSearch.undecorate_link()
|
||||||
|
|
||||||
|
$('#advanced_search_date_min').on
|
||||||
|
change: ->
|
||||||
|
App.AdvancedSearch.toggle_date_options()
|
||||||
@@ -35,6 +35,7 @@
|
|||||||
//= require users
|
//= require users
|
||||||
//= require votes
|
//= require votes
|
||||||
//= require annotatable
|
//= require annotatable
|
||||||
|
//= require advanced_search
|
||||||
|
|
||||||
|
|
||||||
var initialize_modules = function() {
|
var initialize_modules = function() {
|
||||||
@@ -48,6 +49,7 @@ var initialize_modules = function() {
|
|||||||
App.PreventDoubleSubmission.initialize();
|
App.PreventDoubleSubmission.initialize();
|
||||||
App.IeAlert.initialize();
|
App.IeAlert.initialize();
|
||||||
App.Annotatable.initialize();
|
App.Annotatable.initialize();
|
||||||
|
App.AdvancedSearch.initialize();
|
||||||
};
|
};
|
||||||
|
|
||||||
$(function(){
|
$(function(){
|
||||||
|
|||||||
@@ -3,7 +3,9 @@
|
|||||||
</div>
|
</div>
|
||||||
|
|
||||||
<%= form_tag search_path, method: :get do %>
|
<%= form_tag search_path, method: :get do %>
|
||||||
<div id='advanced-search'>
|
<div id='advanced-search'
|
||||||
|
data-advanced-search-terms=<%= @advanced_search_terms.present? %>
|
||||||
|
style="display: none">
|
||||||
|
|
||||||
<div class="small-12 medium-12 advanced-search columns">
|
<div class="small-12 medium-12 advanced-search columns">
|
||||||
<h5 class='search-option inline-block'><%= t("shared.advanced_search.general") %></h5>
|
<h5 class='search-option inline-block'><%= t("shared.advanced_search.general") %></h5>
|
||||||
@@ -28,7 +30,7 @@
|
|||||||
<%= select_tag('advanced_search[date_min]', date_range_options,
|
<%= select_tag('advanced_search[date_min]', date_range_options,
|
||||||
include_blank: 'Elige una fecha') %>
|
include_blank: 'Elige una fecha') %>
|
||||||
|
|
||||||
<div class='customized-date inline-block'>
|
<div class='customized-date inline-block' style="display: none">
|
||||||
|
|
||||||
<%= t("shared.advanced_search.from") %>:
|
<%= t("shared.advanced_search.from") %>:
|
||||||
<div class='inline-block'>
|
<div class='inline-block'>
|
||||||
@@ -42,7 +44,6 @@
|
|||||||
</div>
|
</div>
|
||||||
</div>
|
</div>
|
||||||
|
|
||||||
|
|
||||||
<div class="small-6 medium-3 offset advanced-search columns">
|
<div class="small-6 medium-3 offset advanced-search columns">
|
||||||
<%= submit_tag t("shared.advanced_search.search"), class: 'button postfix' %>
|
<%= submit_tag t("shared.advanced_search.search"), class: 'button postfix' %>
|
||||||
</div>
|
</div>
|
||||||
@@ -51,45 +52,4 @@
|
|||||||
|
|
||||||
<% end %>
|
<% end %>
|
||||||
|
|
||||||
<hr>
|
<hr>
|
||||||
|
|
||||||
<script type="text/javascript">
|
|
||||||
|
|
||||||
//open advantage options menu
|
|
||||||
|
|
||||||
var open = <%= raw @advanced_search_terms.to_json.html_safe %>;
|
|
||||||
|
|
||||||
if(!open) $('#advanced-search').hide();
|
|
||||||
|
|
||||||
$('.advanced-search-title').on({
|
|
||||||
click: function(){
|
|
||||||
$('#advanced-search').slideToggle();
|
|
||||||
},
|
|
||||||
mouseenter: function(){
|
|
||||||
$(this).addClass('blue');
|
|
||||||
},
|
|
||||||
mouseleave: function(){
|
|
||||||
$(this).removeClass('blue');
|
|
||||||
}
|
|
||||||
});
|
|
||||||
|
|
||||||
//hide customized-date if it is not selected
|
|
||||||
|
|
||||||
if($('#advanced_search_date_min').val() != 'custom'){
|
|
||||||
$('.customized-date').hide();
|
|
||||||
$('.customized-date input').prop('disabled', true);
|
|
||||||
}
|
|
||||||
|
|
||||||
$('#advanced_search_date_min').on('change',function(e){
|
|
||||||
var next = $(e.target).next();
|
|
||||||
if($(this).val() == 'custom'){
|
|
||||||
next.show();
|
|
||||||
$('.customized-date input').prop('disabled', false);
|
|
||||||
}
|
|
||||||
else{
|
|
||||||
next.hide();
|
|
||||||
}
|
|
||||||
|
|
||||||
});
|
|
||||||
|
|
||||||
</script>
|
|
||||||
Reference in New Issue
Block a user