Skip to content
Browse files

Including email previews

  • Loading branch information...
1 parent de58df1 commit d8e63b22fd042a913c1af5bfa95765dbeb1176b5 @nahurst committed Mar 17, 2013
Showing with 13 additions and 0 deletions.
  1. +13 −0 app/assets/javascripts/application.js
View
13 app/assets/javascripts/application.js
@@ -22,17 +22,24 @@ APP = {
callback: APP.mail_merges.display,
simpleSheet: true } );
});
+
+ $("#mail_merge_body_template").keyup(
+ APP.mail_merges.updatePreview);
},
'display': function(data, tabletop) {
if (!data || data.length === 0) {
alert("No spreadsheet found. Please make sure it's published.");
}
else {
+ APP.google_spreadsheet_data = data;
$("#mail_merge_data").val(JSON.stringify(data));
var table = $("#pulled_data");
var thead = table.find("thead");
var tbody = table.find("tbody");
+
+ thead.find("th").remove();
+ tbody.find("tr").remove();
for (var key in data[0]) {
thead.append("<th>" + key + "</th");
@@ -48,6 +55,12 @@ APP = {
table.slideDown();
}
+ },
+ 'updatePreview': function() {
+ var template = $("#mail_merge_body_template").val();
+ var message = Mustache.render(template,
+ APP.google_spreadsheet_data[0]);
+ $("#preview").html(message);
}
},
}

0 comments on commit d8e63b2

Please sign in to comment.
Something went wrong with that request. Please try again.