diff --git a/app/assets/javascripts/users.coffee b/app/assets/javascripts/users.coffee deleted file mode 100644 index 24f83d1..0000000 --- a/app/assets/javascripts/users.coffee +++ /dev/null @@ -1,3 +0,0 @@ -# Place all the behaviors and hooks related to the matching controller here. -# All this logic will automatically be available in application.js. -# You can use CoffeeScript in this file: http://coffeescript.org/ diff --git a/app/assets/javascripts/users.js b/app/assets/javascripts/users.js new file mode 100644 index 0000000..885042d --- /dev/null +++ b/app/assets/javascripts/users.js @@ -0,0 +1,21 @@ +var ready = function() { + $('#check_all').on("click", function(){ + var project_checkboxes = $('.project_checkbox'); + var metric_checkboxes = $('.metric_checkbox'); + if (this.checked) { + check_all(project_checkboxes); + check_all(metric_checkboxes); + } + }); +}; + +var check_all = function(checkboxes) { + $.each(checkboxes, function(index, el) { + if (el.checked !== true) { + el.click(); + } + }); +} + +$(document).on('turbolinks:load', ready); +$(document).ready(ready); \ No newline at end of file diff --git a/app/views/users/show.html.haml b/app/views/users/show.html.haml index 157003a..067fc5d 100644 --- a/app/views/users/show.html.haml +++ b/app/views/users/show.html.haml @@ -1,16 +1,19 @@ %h1 Preference Settings +%div + = check_box_tag "check_all", 0, true + = label_tag "check_all", "Check all" = form_tag user_path, :method => :put do %div#project-preference-list %h4 Check projects to monitor: - @all_projects.each do |project| %div - = check_box_tag "projects[#{project.id}]", 0, (@preferred_projects.include? project) + = check_box_tag "projects[#{project.id}]", 0, (@preferred_projects.include? project), :class => "project_checkbox" = label_tag "projects_#{project.id}", project.name %div#metric-preference-list %h4 Check Metrics to monitor: - @all_metrics.each do |metric| %div - = check_box_tag "metrics[#{metric}]", 0, (@preferred_metrics.include? metric) + = check_box_tag "metrics[#{metric}]", 0, (@preferred_metrics.include? metric), :class => "metric_checkbox" = label_tag "metrics_#{metric}", metric.camelcase %br = submit_tag "Save", :id => "project_preference_submit", :class => "btn btn-default"