59 lines
2.1 KiB
Text
59 lines
2.1 KiB
Text
.row
|
|
.col-md-6.col-md-offset-2
|
|
.panel.panel-default
|
|
.panel-heading
|
|
%h3.panel-title
|
|
Send an email
|
|
.panel-body
|
|
%p
|
|
%b Select/Enter Emails
|
|
= text_field_tag :to, '', class: 'form-control', id: 'admin_email_to', data: { keys: @keys }
|
|
%br
|
|
%p.text-right
|
|
= link_to 'Send Email', '', class: 'btn btn-primary', id: 'send_mail'
|
|
|
|
:javascript
|
|
$(document).ready(function() {
|
|
var $select = $('#admin_email_to').selectize({
|
|
delimiter: ',',
|
|
persist: true,
|
|
plugins: ['remove_button'],
|
|
labelField: 'item',
|
|
valueField: 'item',
|
|
sortField: 'item',
|
|
searchField: 'item',
|
|
create: function(input) {
|
|
if (!/^\w+([\.-]?\w+)*@\w+([\.-]?\w+)*(\.\w{2,3})+$/.test(input)){
|
|
return {}
|
|
}
|
|
return {
|
|
item: input
|
|
}
|
|
}
|
|
})
|
|
var selectizeControl = $select[0].selectize;
|
|
var email_hash = $('#admin_email_to').data('keys')
|
|
for(var key in email_hash){
|
|
selectizeControl.addOption({item: key});
|
|
}
|
|
selectizeControl.on('change', function() {
|
|
var emails_in_to_field = selectizeControl.getValue();
|
|
var emails_array = emails_in_to_field.split(",");
|
|
var text = "mailto:".concat(emails_array.shift(), "?bcc=", emails_array.join());
|
|
document.getElementById("send_mail").href = text;
|
|
if (emails_in_to_field==''){
|
|
selectizeControl.clearOptions();
|
|
for(var key in email_hash){
|
|
selectizeControl.addOption({item: key});
|
|
}
|
|
} else if (emails_in_to_field in email_hash){
|
|
for (var i = 0, n = email_hash[emails_in_to_field].length; i < n; i++) {
|
|
selectizeControl.addOption({item: email_hash[emails_in_to_field][i]});
|
|
}
|
|
selectizeControl.setValue(email_hash[emails_in_to_field]);
|
|
selectizeControl.clearOptions();
|
|
} else {
|
|
selectizeControl.refreshOptions();
|
|
}
|
|
})
|
|
})
|