From 42bfbb9b83f912637b070e9200250ee16269be43 Mon Sep 17 00:00:00 2001 From: Yibing Chen Date: Thu, 1 Dec 2016 23:09:57 -0800 Subject: [PATCH 1/4] add check all --- app/views/users/show.html.haml | 5 +++++ 1 file changed, 5 insertions(+) diff --git a/app/views/users/show.html.haml b/app/views/users/show.html.haml index 157003a..09ff7d8 100644 --- a/app/views/users/show.html.haml +++ b/app/views/users/show.html.haml @@ -1,6 +1,11 @@ +:javascript + $('#check_all').on("click", function(){ $('input[type="checkbox"]').click(); }); %h1 Preference Settings = form_tag user_path, :method => :put do %div#project-preference-list + %div + = check_box_tag "check_all", 0, true + = label_tag "check_all", "Check all" %h4 Check projects to monitor: - @all_projects.each do |project| %div From 051279ba322922146bb5cc30bc9f1995df159a52 Mon Sep 17 00:00:00 2001 From: DrakeW Date: Mon, 5 Dec 2016 00:24:02 -0800 Subject: [PATCH 2/4] updated checkbox --- app/assets/javascripts/users.coffee | 3 --- app/assets/javascripts/users.js | 18 ++++++++++++++++++ app/views/users/show.html.haml | 12 +++++------- 3 files changed, 23 insertions(+), 10 deletions(-) delete mode 100644 app/assets/javascripts/users.coffee create mode 100644 app/assets/javascripts/users.js 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..472191e --- /dev/null +++ b/app/assets/javascripts/users.js @@ -0,0 +1,18 @@ +$(document).ready(function() { + $('#check_all').on("click", function(){ + var project_checkboxes = $('.project_checkbox') + var metric_checkboxes = $('.metric_checkbox') + if (this.checked) { + $.each(project_checkboxes, function(index, el) { + if (el.checked !== true) { + el.click(); + } + }); + $.each(metric_checkboxes, function(index, el) { + if (el.checked !== true) { + el.click(); + } + }); + } + }); +}); \ No newline at end of file diff --git a/app/views/users/show.html.haml b/app/views/users/show.html.haml index 09ff7d8..067fc5d 100644 --- a/app/views/users/show.html.haml +++ b/app/views/users/show.html.haml @@ -1,21 +1,19 @@ -:javascript - $('#check_all').on("click", function(){ $('input[type="checkbox"]').click(); }); %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 - %div - = check_box_tag "check_all", 0, true - = label_tag "check_all", "Check all" %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" From ce03657dcbd74b69bd701023e6ba3d0d2ed30aeb Mon Sep 17 00:00:00 2001 From: DrakeW Date: Mon, 5 Dec 2016 00:26:53 -0800 Subject: [PATCH 3/4] fixed turbolinks --- app/assets/javascripts/users.js | 11 +++++++---- 1 file changed, 7 insertions(+), 4 deletions(-) diff --git a/app/assets/javascripts/users.js b/app/assets/javascripts/users.js index 472191e..94e96fb 100644 --- a/app/assets/javascripts/users.js +++ b/app/assets/javascripts/users.js @@ -1,7 +1,7 @@ -$(document).ready(function() { +var ready = function() { $('#check_all').on("click", function(){ - var project_checkboxes = $('.project_checkbox') - var metric_checkboxes = $('.metric_checkbox') + var project_checkboxes = $('.project_checkbox'); + var metric_checkboxes = $('.metric_checkbox'); if (this.checked) { $.each(project_checkboxes, function(index, el) { if (el.checked !== true) { @@ -15,4 +15,7 @@ $(document).ready(function() { }); } }); -}); \ No newline at end of file +}; + +$(document).on('turbolinks:load', ready); +$(document).ready(ready); \ No newline at end of file From b714f54c08ae9aa9e6355538a595ef26ce1ea210 Mon Sep 17 00:00:00 2001 From: DrakeW Date: Mon, 5 Dec 2016 00:29:44 -0800 Subject: [PATCH 4/4] codeclimate --- app/assets/javascripts/users.js | 20 ++++++++++---------- 1 file changed, 10 insertions(+), 10 deletions(-) diff --git a/app/assets/javascripts/users.js b/app/assets/javascripts/users.js index 94e96fb..885042d 100644 --- a/app/assets/javascripts/users.js +++ b/app/assets/javascripts/users.js @@ -3,19 +3,19 @@ var ready = function() { var project_checkboxes = $('.project_checkbox'); var metric_checkboxes = $('.metric_checkbox'); if (this.checked) { - $.each(project_checkboxes, function(index, el) { - if (el.checked !== true) { - el.click(); - } - }); - $.each(metric_checkboxes, function(index, el) { - if (el.checked !== true) { - el.click(); - } - }); + 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