Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Refactor jquery selectors #32

Open
wants to merge 5 commits into
base: remove-js-from-views
Choose a base branch
from
Open
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
2 changes: 2 additions & 0 deletions app/assets/javascripts/application.js
Original file line number Diff line number Diff line change
Expand Up @@ -27,4 +27,6 @@
//= require_tree ./utils
//= require_tree ./components/users
//= require_tree ./components/questionnaires
//= require_tree ./components/loop_items
//= require_tree ./components/loop_sources
//= require_tree ./application
1 change: 1 addition & 0 deletions app/assets/javascripts/components/loop_items.js
Original file line number Diff line number Diff line change
@@ -0,0 +1 @@
//require loop_items/base
24 changes: 24 additions & 0 deletions app/assets/javascripts/components/loop_items/base.js.coffee
Original file line number Diff line number Diff line change
@@ -0,0 +1,24 @@
window.LoopItemsComponent = class LoopItemsComponent
@initialize: ->
@addEventListeners()

@addEventListeners: ->
@itemNamesTable()

@itemNamesTable: ->
$("#item_names_table").on("click","#add_item_name_other_languages", (e) ->
e.preventDefault()
$("#add_extra").hide('slow').empty()
$("#add_extra_source").hide('slow').empty()
$("#add_loop_item_names_source").show('slow')
)
$("#hide_add_translations").click( (e) ->
e.preventDefault()
$("#add_loop_item_names_source").hide('slow')
)
$("#item_names_table").tablesorter({
sortList: [[0,0]],
widgets: ['zebra']
})

$(document).ready -> LoopItemsComponent.initialize()
1 change: 1 addition & 0 deletions app/assets/javascripts/components/loop_sources.js
Original file line number Diff line number Diff line change
@@ -0,0 +1 @@
//require loop_sources/base
14 changes: 14 additions & 0 deletions app/assets/javascripts/components/loop_sources/base.js.coffee
Original file line number Diff line number Diff line change
@@ -0,0 +1,14 @@
window.LoopSourcesComponent = class LoopSourcesComponent
@initialize: ->
@addEventListeners()

@addEventListeners: ->
@updateSource()

@updateSource: ->
$("#update_source").click( (e) ->
e.preventDefault()
$("#edit_source").toggle('slow')
)

$(document).ready -> LoopSourcesComponent.initialize()
17 changes: 17 additions & 0 deletions app/assets/javascripts/components/questionnaires/base.js.coffee
Original file line number Diff line number Diff line change
Expand Up @@ -9,6 +9,7 @@ window.QuestionnairesComponent = class QuestionnairesComponent
@hideInfoContent()
@addCloseEvent()
@addHideInfoEvent()
@slideDuplicateQuestionnaire()

@hideInfoContent: ->
$('.app-content').on('click', '.info-toggle-header', (ev) ->
Expand Down Expand Up @@ -52,5 +53,21 @@ window.QuestionnairesComponent = class QuestionnairesComponent
toggle_info.text("Show")
)

@slideDuplicateQuestionnaire: ->
$("#questionnaire_original_id").change( ->
val = $(@).val()
closedAny = false
$(".questionnaires_info").each( ->
if($(@).is(":visible"))
$(@).slideUp("slow", ->
$("#questionnaire_"+val).slideDown("slow")
)
closedAny = true
)
if(!closedAny)
$("#questionnaire_"+val).slideDown("slow")
)


$(document).ready -> QuestionnairesComponent.initialize()

1 change: 1 addition & 0 deletions app/assets/javascripts/components/users/base.js.coffee
Original file line number Diff line number Diff line change
@@ -1,5 +1,6 @@
window.UsersComponent = class UsersComponent
@initialize: ->
UsersComponent.UserDelegates.initialize()
@addEventListeners()

@addEventListeners: ->
Expand Down
21 changes: 21 additions & 0 deletions app/assets/javascripts/components/users/user_delegates.js.coffee
Original file line number Diff line number Diff line change
@@ -0,0 +1,21 @@
window.UsersComponent.UserDelegates = class UsersComponent.UserDelegates
@initialize: ->
@addEventListeners()

@addEventListeners: ->
@showDetails()
@delegatedTasksTable()

@showDetails: ->
$(".show-details").click( (e) ->
e.preventDefault()
$(@).parent().siblings('.delegation-details').toggle('slow')
)

@delegatedTasksTable: ->
$("#delegated_tasks_table").tablesorter({
sortList: [[0,0]],
widgets: ['zebra']
})


12 changes: 12 additions & 0 deletions app/assets/javascripts/utils/layout.js.coffee
Original file line number Diff line number Diff line change
@@ -0,0 +1,12 @@
window.Layout = class Layout
@initialize: ->
@addEventListeners()

@addEventListeners: ->
$("#display_language").change( ->
selected_lang = $(@).val()
if(selected_lang != "")
window.location = "?lang=#{selected_lang}"
)

$(document).ready -> Layout.initialize()
11 changes: 1 addition & 10 deletions app/views/layouts/_authentication.html.erb
Original file line number Diff line number Diff line change
Expand Up @@ -9,15 +9,6 @@
<%= link_to t("login_menu.login"), root_path(:lang => (params[:lang]||"en")) %>
</p>
<p style="float: right">
<%= select :display, :language, [["English","en"], ["Français","fr"]], {:selected => (params[:lang] || "en")} %>
<%= select :display, :language, [["English","en"], ["Français","fr"]], {:selected => (params[:lang] || "en")} %>
</p>
<script type="text/javascript">
$("#display_language").change(function(){
var selected_lang = $(this).val();
if(selected_lang != "")
{
window.location = "?lang="+selected_lang;
}
});
</script>
<% end -%>
8 changes: 0 additions & 8 deletions app/views/layouts/_header.html.erb
Original file line number Diff line number Diff line change
Expand Up @@ -13,14 +13,6 @@
<% end %>
<%= link_to t("login_menu.login"), root_path(:lang => (params[:lang]||"en")) %>
| <%= select :display, :language, [["English","en"], ["Français","fr"], ["Español","es"]], {:selected => (params[:lang] || "en")} %>
<script type="text/javascript">
$("#display_language").change(function(){
var selected_lang = $(this).val();
if(selected_lang != ""){
window.location = "?lang="+selected_lang;
}
});
</script>
<% end %>
</p>
</div>
Expand Down
16 changes: 0 additions & 16 deletions app/views/loop_item_types/show.html.erb
Original file line number Diff line number Diff line change
Expand Up @@ -143,19 +143,3 @@
</table>
</div>
</div>
<script type="text/javascript">
$("#item_names_table").on("click","#add_item_name_other_languages", function(e){
e.preventDefault();
$("#add_extra").hide('slow').empty();
$("#add_extra_source").hide('slow').empty();
$("#add_loop_item_names_source").show('slow');
});
$("#hide_add_translations").click(function(e){
e.preventDefault();
$("#add_loop_item_names_source").hide('slow');
});
$("#item_names_table").tablesorter({
sortList: [[0,0]],
widgets: ['zebra']
});
</script>
19 changes: 0 additions & 19 deletions app/views/questionnaires/duplicate.html.erb
Original file line number Diff line number Diff line change
Expand Up @@ -71,22 +71,3 @@
<% end -%>
</div>
</div>
<script type="text/javascript">
$(function(){
$("#questionnaire_original_id").change(function(){
var val = $(this).val();
var closedAny = false;
$(".questionnaires_info").each(function(){
if($(this).is(":visible"))
{
$(this).slideUp("slow", function(){
$("#questionnaire_"+val).slideDown("slow");
});
closedAny = true;
}
});
if(!closedAny)
$("#questionnaire_"+val).slideDown("slow");
})
})
</script>
6 changes: 0 additions & 6 deletions app/views/source_files/edit.html.erb
Original file line number Diff line number Diff line change
Expand Up @@ -49,9 +49,3 @@
<% end -%>
</div>
</div>
<script type="text/javascript">
$("#update_source").click(function(e){
e.preventDefault();
$("#edit_source").toggle('slow');
})
</script>
14 changes: 1 addition & 13 deletions app/views/user_delegates/show.html.erb
Original file line number Diff line number Diff line change
Expand Up @@ -62,7 +62,7 @@
<% if delegation.sections.present? %>
<div class="delegation-details hide" id="delegation_details_<%= delegation.id %>">
<table>
<thead>
<thead
<tr>
<th><%= t('generic.section')%></th>
<th><%= t('delegation_details.root_section_th')%></th>
Expand All @@ -87,15 +87,3 @@
</div>
<% end %>
</div><!-- /content -->
<script type="text/javascript">
$(function(){
$(".show-details").click(function(e){
e.preventDefault();
$(this).parent().siblings('.delegation-details').toggle('slow');
});
$("#delegated_tasks_table").tablesorter({
sortList: [[0,0]],
widgets: ['zebra']
});
});
</script>