From b04a7450a070ee8961fd5f063781d3c1fd3f6fcc Mon Sep 17 00:00:00 2001 From: Corinna Jaschek Date: Fri, 3 Feb 2017 11:35:54 +0100 Subject: [PATCH 1/2] fixes #238 event description textfield (#412) * changed event description to textarea, added placeholder * added multiline placeholder * fixed whitespaces and placeholder * added multiline placeholder support for other browser and refactored * fixed javascript reference error * added requested changes * clear field before submit if it only contains the placeholder --- app/assets/javascripts/events.js | 48 ++++++++++++++++++++++++++------ app/views/events/_form.html.erb | 17 ++--------- config/locales/de.events.yml | 3 ++ 3 files changed, 44 insertions(+), 24 deletions(-) diff --git a/app/assets/javascripts/events.js b/app/assets/javascripts/events.js index af3a056f..2a001ea8 100644 --- a/app/assets/javascripts/events.js +++ b/app/assets/javascripts/events.js @@ -3,17 +3,47 @@ jQuery(function() { - $('#send-emails-modal').on('show.bs.modal', function (event) { - var button = $(event.relatedTarget); - var header = button.data('title'); - var list = button.data('list'); - var modal = $(this); - modal.find('.modal-title').text(header); - modal.find('#send-emails-mailto').attr('href', 'mailto:' + list); - modal.find('#send-emails-list').val(list); - }); + $('#send-emails-modal').on('show.bs.modal', function (event) { + var button = $(event.relatedTarget); + var header = button.data('title'); + var list = button.data('list'); + var modal = $(this); + modal.find('.modal-title').text(header); + modal.find('#send-emails-mailto').attr('href', 'mailto:' + list); + modal.find('#send-emails-list').val(list); + }); }); +function enableMultilinePlaceholder(){ + // work around so that we can have a multiline placeholder + $("#description") + .val(function(index, oldVal) { + if (!oldVal) { + $(this).css('color', '#bbb'); + return EVENT_DESCRIPTION_PLACEHOLDER; + } + return oldVal; + }) + .focus(function(){ + if($(this).val() === EVENT_DESCRIPTION_PLACEHOLDER){ + $(this).val('').css('color', '#000'); + } + }) + .blur(function(){ + if($(this).val() ===''){ + $(this).val(EVENT_DESCRIPTION_PLACEHOLDER).css('color', '#bbb'); + } + }) + .parents("form").on("submit", function() { + $("#description").val(function(index, oldVal) { + return oldVal == EVENT_DESCRIPTION_PLACEHOLDER ? '' : oldVal; + }); + }); +} +// make sure multiline placeholders also work if the page is called via turbolink +$(document).on('turbolinks:load', enableMultilinePlaceholder); +jQuery(enableMultilinePlaceholder); + function addCustomApplicationField() { $(CUSTOM_APPLICATION_FIELD_TEMPLATE) .insertBefore('#add-custom-application-fields'); diff --git a/app/views/events/_form.html.erb b/app/views/events/_form.html.erb index ae5203c4..2125b27d 100644 --- a/app/views/events/_form.html.erb +++ b/app/views/events/_form.html.erb @@ -41,22 +41,9 @@
<%= f.label :description, :class => 'control-label col-lg-2' %>
- <%= f.text_area :description, :class => 'form-control', :id => 'description', :placeholder => '', :rows => 20 %> + <%= f.text_area :description, :class => 'form-control', :id => 'description', :placeholder => '', :rows => 20, :spellcheck => "false" %> <%=f.error_span(:description) %> Dieser Editor unterstüzt Markdown diff --git a/config/locales/de.events.yml b/config/locales/de.events.yml index f115aff0..fbfe2b2d 100644 --- a/config/locales/de.events.yml +++ b/config/locales/de.events.yml @@ -2,8 +2,11 @@ de: events: + intro_text: "Lorem ipsum dolor sit amet, consectetur adipisicing elit, sed do eiusmod tempor incididunt ut labore et dolore magna aliqua. Ut enim ad minim veniam, quis nostrud exercitation ullamco laboris nisi ut aliquip ex ea commodo consequat." + description_placeholder: "## Untertitel\\nLorem ipsum dolor sit amet, consectetur adipiscing elit, sed do eiusmod tempor incididunt ut labore et dolore magna aliqua. Ut enim ad minim veniam, quis nostrud exercitation ullamco laboris nisi ut aliquip ex ea commodo consequat. Duis aute irure dolor in reprehenderit in voluptate velit esse cillum dolore eu fugiat nulla pariatur. Excepteur sint occaecat cupidatat non proident, sunt in culpa qui officia deserunt mollit anim id est laborum.\\n \\n ## Lernziele\\n* a\\n* b\\n* c\\n\\n## Hinweise\\n* a\\n* b\\n* c" archive: "Veranstaltungs-Archiv" all_events: "Alle Events" + applicants_overview: title: "Bewerber für %{title}" participations: "Anzahl der Bewerbungen" From f64012c9812e4309bbfb9542dddce609a8332560 Mon Sep 17 00:00:00 2001 From: Instinct5Mint Date: Fri, 3 Feb 2017 13:09:34 +0100 Subject: [PATCH 2/2] 53 3.13 load email drafts (#375) * Featured Issue #55 added initial views * Featured Issue #55 Added failing tests * Featured Issue #55 added new routes,controller actions, views and locals * Featured Issue #55 added emails controller and email model * Featured Issue #55 Added more tests, improved UI * Featured Issue #55 fixed failing tests * Featured Issue #55 fixed merging commit error * Integrated Email Backend with UI * Add Copy Button to Email Page * Add Tests for Email Partial * Extended acceptance/rejection feature tests * Failing tests for #55 avoid bcc * Implement bcc avoiding for #55 * Failing tests for #55 avoid bcc * Implement avoid bcc with strings for #55 * Make send_email a class method #55 * Integrated updated Email Backend * Fixed changes that where missing after merge * Removed DB-Table for Emails * Renamed TO and BCC in Email UI * Renamed TO and BCC in Email UI * Updated test of email sending * Updated test of email sending * Updated Email UI, refactored naming scheme and tests * Removed unused test file * Fix for not registered Button Click * Fix broken show/hide recipients option for Email * Fixed double Negation of hide_recipients * Simplified Radio Buttons to fix email visibility bug * Featured Issue #55: Added tests * Featured Issue #55: Fixed added tests * Fixed new lines in Emails and truncation of event_details * Standardize the layout of event_details * Refactored Email, improved routes, template saving * Refactored Tests * Finished refactoring of email service and tests. * Merge branches '38_3.10_SaveEmailDrafts' and 'dev' of https://github.com/hpi-swt2/workshop-portal into 38_3.10_SaveEmailDrafts * Fixed Changes to the Gemfile.lock * Fixed authentication for email page, updated validation to show error messages * Added Support for default Templates, when no other status is set * Fixed Test Name * Fixed broken variable * Fixed accidently deleted copy recipients button and added a view test * Fixed naming of css file * Fixed multiple issues found in code review - Renamed Templates to Vorlagen in I18n - Added ability tests * Fixed paranthesis * Added invalid testcase * Removed duplicate tests + moved invalid testcases to own test * Load Templates via JS * Fixed email copy + refactored things annoted in PR * Fixed merged, by adding deleted route and removing old tests * Fixed controller method in model ;) * Fixed controller method in model ;) * That was strange * Added setting of hide_recipients status saved in template * Fix whitespace * Issue #53: Refactored emails.js * Remove duplicated tests * Refactored to email_template traits, and featuretest * Renamed email_template trait names to be consistend with the data * Added test for setting hide_recipients * Changed order of not * Fixed syntax error with not and ! --- app/assets/javascripts/emails.js | 22 ++++++++++++++++++++-- app/views/emails/_templates.erb | 7 ++++--- spec/controllers/email_controller_spec.rb | 4 ++-- spec/factories/email_templates.rb | 18 +++++++++--------- spec/features/email_spec.rb | 15 +++++++++++++++ spec/models/email_template_spec.rb | 10 +++++----- 6 files changed, 55 insertions(+), 21 deletions(-) diff --git a/app/assets/javascripts/emails.js b/app/assets/javascripts/emails.js index 120d1255..ddaf2324 100644 --- a/app/assets/javascripts/emails.js +++ b/app/assets/javascripts/emails.js @@ -2,9 +2,9 @@ // All this logic will automatically be available in application.js. jQuery(function() { - $(document).on('click', "#send-emails-clipboard", function() { + $('#send-emails-clipboard').click(function () { var recipients = $('#email_recipients') - if(recipients.val.length > 0) { + if(recipients.val().length > 0) { recipients.select(); try { document.execCommand('copy'); @@ -13,4 +13,22 @@ jQuery(function() { } } }); + + $('.email-template.list-group-item').click(function (e) { + e.preventDefault(); + var subject = $(this).children('.template-subject')[0].innerHTML; + var content = $(this).children('.template-content')[0].innerHTML; + var hide_recipients = $(this).children('.template-hide_recipients')[0].innerHTML == "true"; + + $('#email_subject').val(subject); + $('#email_content').val(content); + + var show_recipients_button = $('#email_hide_recipients_false'); + var hide_recipients_button = $('#email_hide_recipients_true'); + + show_recipients_button.attr('checked', !hide_recipients); + show_recipients_button.parent().toggleClass('active', !hide_recipients); + hide_recipients_button.attr('checked', hide_recipients); + hide_recipients_button.parent().toggleClass('active', hide_recipients); + }); }); \ No newline at end of file diff --git a/app/views/emails/_templates.erb b/app/views/emails/_templates.erb index a4f9ff73..9655e513 100644 --- a/app/views/emails/_templates.erb +++ b/app/views/emails/_templates.erb @@ -1,9 +1,10 @@

<%= t('.templates') %>

\ No newline at end of file diff --git a/spec/controllers/email_controller_spec.rb b/spec/controllers/email_controller_spec.rb index 6896a742..db2d23e9 100644 --- a/spec/controllers/email_controller_spec.rb +++ b/spec/controllers/email_controller_spec.rb @@ -16,7 +16,7 @@ context "with valid accepted applications" do before :each do @application = FactoryGirl.create(:application_letter_accepted, event: @event, user: FactoryGirl.build(:user)) - @template = FactoryGirl.create(:email_template_acceptance) + @template = FactoryGirl.create(:email_template, :acceptance) end it "sets @email with the email of the accepted application" do @@ -34,7 +34,7 @@ context "with valid rejected applications" do before :each do @application = FactoryGirl.create(:application_letter_rejected, event: @event, user: FactoryGirl.build(:user)) - @template = FactoryGirl.create(:email_template_rejection) + @template = FactoryGirl.create(:email_template, :rejection) end it "sets @email with the email of the rejected application" do diff --git a/spec/factories/email_templates.rb b/spec/factories/email_templates.rb index 1d106453..92531149 100644 --- a/spec/factories/email_templates.rb +++ b/spec/factories/email_templates.rb @@ -14,17 +14,17 @@ hide_recipients false subject "EmailTemplate-Subject" content "EmailTemplate-Content" - end - factory :email_template_acceptance, parent: :email_template do - status :acceptance - end + trait :default do + status :default + end - factory :email_template_rejection, parent: :email_template do - status :rejection - end + trait :acceptance do + status :acceptance + end - factory :email_template_default, parent: :email_template do - status :default + trait :rejection do + status :rejection + end end end \ No newline at end of file diff --git a/spec/features/email_spec.rb b/spec/features/email_spec.rb index da607d4a..45ace636 100644 --- a/spec/features/email_spec.rb +++ b/spec/features/email_spec.rb @@ -56,6 +56,21 @@ expect(page).to have_text(@template_content) end + scenario "logged in as Organizer I can load an email template", js: true do + login(:organizer) + @template = FactoryGirl.create(:email_template, :acceptance) + + visit event_email_show_path(@event, status: :acceptance) + first('.email-template').click + + + expect(find('#email_hide_recipients_true', visible: false).checked?).to eq(@template.hide_recipients) + expect(find('#email_hide_recipients_false', visible: false).checked?).to eq(!@template.hide_recipients) + expect(page.find('#email_subject').value).to eq(@template.subject) + expect(page.find('#email_content').value).to eq(@template.content) + end + + def login(role) @profile = FactoryGirl.create(:profile) @profile.user.role = role diff --git a/spec/models/email_template_spec.rb b/spec/models/email_template_spec.rb index 71df4a8d..eaf98e2f 100644 --- a/spec/models/email_template_spec.rb +++ b/spec/models/email_template_spec.rb @@ -22,9 +22,9 @@ end it "accepts valid status values" do - expect(FactoryGirl.build(:email_template_acceptance)).to be_valid - expect(FactoryGirl.build(:email_template_rejection)).to be_valid - expect(FactoryGirl.build(:email_template_default)).to be_valid + expect(FactoryGirl.build(:email_template, :acceptance)).to be_valid + expect(FactoryGirl.build(:email_template, :rejection)).to be_valid + expect(FactoryGirl.build(:email_template, :default)).to be_valid end it "rejects invalid status values" do @@ -34,8 +34,8 @@ end it "returns correct templates by status" do - @accepted_template = FactoryGirl.create(:email_template_acceptance) - @rejected_template = FactoryGirl.create(:email_template_rejection) + @accepted_template = FactoryGirl.create(:email_template, :acceptance) + @rejected_template = FactoryGirl.create(:email_template, :rejection) expect(EmailTemplate.with_status(:acceptance)).to eq([@accepted_template]) expect(EmailTemplate.with_status(:rejection)).to eq([@rejected_template]) end