refactors javascript

This commit is contained in:
rgarcia
2016-01-13 16:16:23 +01:00
parent 9ff3b1dd2f
commit afca5c2b90
3 changed files with 44 additions and 45 deletions

View 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()

View File

@@ -35,6 +35,7 @@
//= require users
//= require votes
//= require annotatable
//= require advanced_search
var initialize_modules = function() {
@@ -48,6 +49,7 @@ var initialize_modules = function() {
App.PreventDoubleSubmission.initialize();
App.IeAlert.initialize();
App.Annotatable.initialize();
App.AdvancedSearch.initialize();
};
$(function(){

View File

@@ -3,7 +3,9 @@
</div>
<%= 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">
<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,
include_blank: 'Elige una fecha') %>
<div class='customized-date inline-block'>
<div class='customized-date inline-block' style="display: none">
&nbsp;&nbsp;
<%= t("shared.advanced_search.from") %>:
<div class='inline-block'>
@@ -42,7 +44,6 @@
</div>
</div>
<div class="small-6 medium-3 offset advanced-search columns">
<%= submit_tag t("shared.advanced_search.search"), class: 'button postfix' %>
</div>
@@ -52,44 +53,3 @@
<% end %>
<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>