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 @@
<%= template[:content] %>
+ +<%= template[:content] %>
<% end %> +