Skip to content
Browse files

Showing the data pulled (will need to allow multiple clicks on the pu…

…ll data button eventually)
  • Loading branch information...
1 parent 625cb29 commit 62b45a946a6e920cbbd642156ddd07db12595b36 @nahurst committed Mar 17, 2013
Showing with 33 additions and 4 deletions.
  1. +24 −1 app/assets/javascripts/application.js
  2. +9 −3 app/views/mail_merges/_form.html.erb
View
25 app/assets/javascripts/application.js
@@ -24,7 +24,30 @@ APP = {
});
},
'display': function(data, tabletop) {
- $("#mail_merge_data").val(JSON.stringify(data));
+ if (!data || data.length === 0) {
+ alert("No spreadsheet found. Please make sure it's published.");
+ }
+ else {
+ $("#mail_merge_data").val(JSON.stringify(data));
+
+ var table = $("#pulled_data");
+ var thead = table.find("thead");
+ var tbody = table.find("tbody");
+
+ for (var key in data[0]) {
+ thead.append("<th>" + key + "</th");
+ }
+
+ for (var row in data) {
+ var cells = "";
+ for (var key in data[row]) {
+ cells += "<td>" + data[row][key] + "</td>";
+ }
+ tbody.append("<tr>" + cells + "</tr>");
+ }
+
+ table.slideDown();
+ }
}
},
}
View
12 app/views/mail_merges/_form.html.erb
@@ -13,17 +13,23 @@
<%= f.hidden_field :data %>
+ <table id="pulled_data" style="display: none">
+ <thead>
+ </thead>
+ <tbody>
+ </tbody>
+ </table>
<div class="field">
- <%= f.label :from %><br />
+ <%= f.label :from %>
<%= f.text_field :from %>
</div>
<div class="field">
- <%= f.label :subject_template %><br />
+ <%= f.label :subject_template %>
<%= f.text_field :subject_template %>
</div>
<div class="field">
- <%= f.label :body_template %><br />
+ <%= f.label :body_template %>
<%= f.text_area :body_template %>
</div>
<div class="actions">

0 comments on commit 62b45a9

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