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/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/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') %>

<% @templates.each do |template| %> - -

<%= template[:subject] %>

-

<%= template[:content] %>

+
+ +

<%= template[:subject] %>

+

<%= template[:content] %>

<% end %>
\ No newline at end of file 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" 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