Skip to content

Commit

Permalink
Merge branch 'dev' into 491_Event_list_date_bug
Browse files Browse the repository at this point in the history
  • Loading branch information
philipp-bode committed Feb 3, 2017
2 parents 7bfe080 + f64012c commit 27457dc
Show file tree
Hide file tree
Showing 9 changed files with 99 additions and 45 deletions.
22 changes: 20 additions & 2 deletions app/assets/javascripts/emails.js
Expand Up @@ -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');
Expand All @@ -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);
});
});
48 changes: 39 additions & 9 deletions app/assets/javascripts/events.js
Expand Up @@ -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');
Expand Down
7 changes: 4 additions & 3 deletions app/views/emails/_templates.erb
@@ -1,9 +1,10 @@
<h3><%= t('.templates') %></h3>
<div class="list-group">
<% @templates.each do |template| %>
<a href="#" class="list-group-item">
<h4 class="list-group-item-heading"><%= template[:subject] %></h4>
<p class="list-group-item-text"><%= template[:content] %></p>
<a href="" class="email-template list-group-item">
<p class="template-hide_recipients hidden"><%= template[:hide_recipients] %></p>
<h4 class="template-subject list-group-item-heading"><%= template[:subject] %></h4>
<p class="template-content list-group-item-text"><%= template[:content] %></p>
</a>
<% end %>
</div>
17 changes: 2 additions & 15 deletions app/views/events/_form.html.erb
Expand Up @@ -41,22 +41,9 @@
<div class="form-group">
<%= f.label :description, :class => 'control-label col-lg-2' %>
<div class="col-lg-10">
<%= 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" %>
<script>
var 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';
$("#description").attr('placeholder', placeholder);

$("#description").focus(function(){
if($(this).val() === placeholder){
$(this).attr('placeholder', '');
}
});

$("#description").blur(function(){
if($(this).val() ===''){
$(this).attr('placeholder', placeholder);
}
});
var EVENT_DESCRIPTION_PLACEHOLDER = '<%= I18n.t "events.description_placeholder" %>';
</script>
<%=f.error_span(:description) %>
Dieser Editor unterstüzt <a href="https://daringfireball.net/projects/markdown/syntax">Markdown</a>
Expand Down
3 changes: 3 additions & 0 deletions config/locales/de.events.yml
Expand Up @@ -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"
Expand Down
4 changes: 2 additions & 2 deletions spec/controllers/email_controller_spec.rb
Expand Up @@ -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
Expand All @@ -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
Expand Down
18 changes: 9 additions & 9 deletions spec/factories/email_templates.rb
Expand Up @@ -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
15 changes: 15 additions & 0 deletions spec/features/email_spec.rb
Expand Up @@ -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
Expand Down
10 changes: 5 additions & 5 deletions spec/models/email_template_spec.rb
Expand Up @@ -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
Expand All @@ -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
Expand Down

0 comments on commit 27457dc

Please sign in to comment.