Skip to content
This repository

HTTPS clone URL

Subversion checkout URL

You can clone with HTTPS or Subversion.

Download ZIP
Browse code

Including email previews

  • Loading branch information...
commit d8e63b22fd042a913c1af5bfa95765dbeb1176b5 1 parent de58df1
Nathan Hurst authored

Showing 1 changed file with 13 additions and 0 deletions. Show diff stats Hide diff stats

  1. +13 0 app/assets/javascripts/application.js
13 app/assets/javascripts/application.js
@@ -22,17 +22,24 @@ APP = {
22 22 callback: APP.mail_merges.display,
23 23 simpleSheet: true } );
24 24 });
  25 +
  26 + $("#mail_merge_body_template").keyup(
  27 + APP.mail_merges.updatePreview);
25 28 },
26 29 'display': function(data, tabletop) {
27 30 if (!data || data.length === 0) {
28 31 alert("No spreadsheet found. Please make sure it's published.");
29 32 }
30 33 else {
  34 + APP.google_spreadsheet_data = data;
31 35 $("#mail_merge_data").val(JSON.stringify(data));
32 36
33 37 var table = $("#pulled_data");
34 38 var thead = table.find("thead");
35 39 var tbody = table.find("tbody");
  40 +
  41 + thead.find("th").remove();
  42 + tbody.find("tr").remove();
36 43
37 44 for (var key in data[0]) {
38 45 thead.append("<th>" + key + "</th");
@@ -48,6 +55,12 @@ APP = {
48 55
49 56 table.slideDown();
50 57 }
  58 + },
  59 + 'updatePreview': function() {
  60 + var template = $("#mail_merge_body_template").val();
  61 + var message = Mustache.render(template,
  62 + APP.google_spreadsheet_data[0]);
  63 + $("#preview").html(message);
51 64 }
52 65 },
53 66 }

0 comments on commit d8e63b2

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