From 39c894dc1babb85d4095c295b2e159e708dde479 Mon Sep 17 00:00:00 2001 From: nikhilgupta1211 Date: Thu, 29 Jun 2017 18:22:01 +0530 Subject: [PATCH 1/4] Disable the select recipients dropdown when no participants are present for an event --- app/views/event_emails/new.html.haml | 11 ++++++++--- 1 file changed, 8 insertions(+), 3 deletions(-) diff --git a/app/views/event_emails/new.html.haml b/app/views/event_emails/new.html.haml index 16a53ac8..ed6f1850 100644 --- a/app/views/event_emails/new.html.haml +++ b/app/views/event_emails/new.html.haml @@ -29,7 +29,12 @@ = link_to 'Cancel', event_event_emails_path(@event) , class: 'btn btn-default' :javascript + document.addEventListener("DOMContentLoaded", function(event) { + if(#{users_for_event('all')}.length == 0 ) { + $('#select_recp').prop("disabled", true); + } + }); + function user_email(users){ - var recip = document.getElementById('event_email_to'); - recip.value = users - } + $('#event_email_to').val(users) + } \ No newline at end of file From 4a718b121f2eed65ed127d187b7b6179edd540f6 Mon Sep 17 00:00:00 2001 From: nikhilgupta1211 Date: Thu, 29 Jun 2017 18:37:30 +0530 Subject: [PATCH 2/4] Added tests in event_email spec for scenario for no participants present --- spec/features/event_email.spec.rb | 8 ++++++++ 1 file changed, 8 insertions(+) diff --git a/spec/features/event_email.spec.rb b/spec/features/event_email.spec.rb index f25945f9..0dfe9220 100644 --- a/spec/features/event_email.spec.rb +++ b/spec/features/event_email.spec.rb @@ -3,6 +3,14 @@ feature 'Email Events', '' do fixtures :all + scenario 'When there are no participants present', js: true do + sign_in_as_user(users(:tspmember)) + visit event_event_emails_path(events(:hoth_hackaton)) + click_link 'Compose' + + page.should have_button('Select recipients', disabled: true) + end + scenario 'Email the event participants', js: true do sign_in_as_user(users(:tspmember)) visit event_event_emails_path(events(:party)) From 65104bde6e6f9e1a6463259145f9de8448bf000a Mon Sep 17 00:00:00 2001 From: nikhilgupta1211 Date: Fri, 30 Jun 2017 03:11:34 +0530 Subject: [PATCH 3/4] Moved the inline javascript from events new to event_emails.js.coffee --- app/assets/javascripts/application.js.coffee | 1 + app/assets/javascripts/event_emails.js.coffee | 9 ++++++ app/views/event_emails/new.html.haml | 28 +++---------------- 3 files changed, 14 insertions(+), 24 deletions(-) create mode 100644 app/assets/javascripts/event_emails.js.coffee diff --git a/app/assets/javascripts/application.js.coffee b/app/assets/javascripts/application.js.coffee index af282227..ad16b160 100644 --- a/app/assets/javascripts/application.js.coffee +++ b/app/assets/javascripts/application.js.coffee @@ -15,6 +15,7 @@ #= require bootstrap #= require cocoon #= require additional +#= require event_emails # window.init_page = -> diff --git a/app/assets/javascripts/event_emails.js.coffee b/app/assets/javascripts/event_emails.js.coffee new file mode 100644 index 00000000..c96257a0 --- /dev/null +++ b/app/assets/javascripts/event_emails.js.coffee @@ -0,0 +1,9 @@ +if $('#select_recp').data('users') + $('#select_recp').prop("disabled", true) + +fill_email_to = (state) -> + $('#state'+state).click -> + users = $('#state'+state).data('users') + $('#event_email_to').val(users) + +fill_email_to state for state in ['All', 'Accepted', 'Incomplete', 'Submitted', 'Approved', 'Cancel'] diff --git a/app/views/event_emails/new.html.haml b/app/views/event_emails/new.html.haml index ed6f1850..239be46c 100644 --- a/app/views/event_emails/new.html.haml +++ b/app/views/event_emails/new.html.haml @@ -1,22 +1,13 @@ .col-md-10 %h2 Email the participants of #{@event.name} .dropdown.pull-right - %button#select_recp.btn.btn-default.dropdown-toggle{"aria-expanded" => "true", "aria-haspopup" => "true", "data-toggle" => "dropdown", :type => "button"} + %button#select_recp.btn.btn-default.dropdown-toggle{"aria-expanded" => "true", "aria-haspopup" => "true", "data-toggle" => "dropdown", :type => "button", "data-users" => "#{users_for_event('all').empty?}"} Select recipients %span.caret %ul.dropdown-menu{"aria-labelledby" => "select_recp"} - %li - %a{:onclick => "user_email(#{users_for_event('all')})"} All - %li - %a{:onclick => "user_email(#{users_for_event('accepted')})"} Accepted - %li - %a{:onclick => "user_email(#{users_for_event('incomplete')})"} Incomplete - %li - %a{:onclick => "user_email(#{users_for_event('submitted')})"} Submitted - %li - %a{:onclick => "user_email(#{users_for_event('approved')})"} Approved - %li - %a{:onclick => "user_email(#{users_for_event('canceled')})"} Cancel + - %w[All Accepted Incomplete Submitted Approved Cancel].each do |s| + %li + %a{id: 'state' + s, "data-users" => users_for_event(s.downcase) } #{s} %br = simple_form_for(resource, url: event_event_emails_path) do |f| = f.input :to, as: :text,readonly: true, input_html: {rows: 1} @@ -27,14 +18,3 @@ .pull-right = f.button :submit, 'Send', class: 'btn btn-primary', data: { disable_with: "Please wait..." } = link_to 'Cancel', event_event_emails_path(@event) , class: 'btn btn-default' - -:javascript - document.addEventListener("DOMContentLoaded", function(event) { - if(#{users_for_event('all')}.length == 0 ) { - $('#select_recp').prop("disabled", true); - } - }); - - function user_email(users){ - $('#event_email_to').val(users) - } \ No newline at end of file From c10438a22da8ee0e0950aa579733f853aa2f22ee Mon Sep 17 00:00:00 2001 From: nikhilgupta1211 Date: Tue, 11 Jul 2017 00:37:39 +0530 Subject: [PATCH 4/4] Added a placeholder for the event email 'to' field Added coffeescript to change the placeholder when no recipients are present Fixes #69 --- app/assets/javascripts/event_emails.js.coffee | 2 ++ app/views/event_emails/new.html.haml | 2 +- 2 files changed, 3 insertions(+), 1 deletion(-) diff --git a/app/assets/javascripts/event_emails.js.coffee b/app/assets/javascripts/event_emails.js.coffee index c96257a0..fbf17cec 100644 --- a/app/assets/javascripts/event_emails.js.coffee +++ b/app/assets/javascripts/event_emails.js.coffee @@ -5,5 +5,7 @@ fill_email_to = (state) -> $('#state'+state).click -> users = $('#state'+state).data('users') $('#event_email_to').val(users) + if users.length == 0 + $('#event_email_to').attr('placeholder', 'No recipients present for ' + state + ' state') fill_email_to state for state in ['All', 'Accepted', 'Incomplete', 'Submitted', 'Approved', 'Cancel'] diff --git a/app/views/event_emails/new.html.haml b/app/views/event_emails/new.html.haml index 239be46c..2bda7eeb 100644 --- a/app/views/event_emails/new.html.haml +++ b/app/views/event_emails/new.html.haml @@ -10,7 +10,7 @@ %a{id: 'state' + s, "data-users" => users_for_event(s.downcase) } #{s} %br = simple_form_for(resource, url: event_event_emails_path) do |f| - = f.input :to, as: :text,readonly: true, input_html: {rows: 1} + = f.input :to, as: :text,readonly: true,placeholder: 'Select the recipients', input_html: {rows: 1} = f.input :subject = f.input :body, as: :text, hint: 'This field supports markdown', input_html: {rows: 12} %a{:href => "https://daringfireball.net/projects/markdown/syntax"}