Skip to content

Commit

Permalink
More email templates (#1557)
Browse files Browse the repository at this point in the history
* added some comments to break up html table

* reorganized data for email template

removed all [0]. type variables from new.html email template, so all
variables are set in orders.js for easy manipulation

* welcome to the shop email template

* extract social from template, add on/off switch

* invite shop member email

* shopName variable updates

* update reaction address

This was driving me crazy seeing the wrong address in all these emails
being tested.

* add Collections imports for Accounts, Cart, Shopts

* password reset emails

* update subject of order confirmation email

* lint fix

* renamed file for email template

* removed test text

* path file organization

* mail -> SMTP for clarification

* Merge branch 'release-0.18.0' into email-template-expansion-v2

# Conflicts:
#	imports/plugins/included/email-templates/lib/paths.js

* i18n for email template admin

* publication for Templates

* conflict fix

* add email subject into saved DB data

* add server methods for deleting email templates

* Add a duplicate, editable template to the template collection (#1548)

Mark one of those templates and an original, which can be used to
revert editable templates.

* server methods for updating email templates

* added check for original template

* new translations

* Merge branch 'release-0.18.0' into email-template-expansion-v2

* core workflow emails - processing & completed

* test - new workflow email exports

* Update email schema

* shipping email

* conflict fixes

* removed comments

* removed comments

* import new email schema

* template updates

* removed commented code

* organize templates

* added todo to schema

* updated comments

* cleanup methods file

* updated error messaging

* schema update

* update comments

* i18n updates

* removed testing alerts

* i18n updates

* file organization
  • Loading branch information
kieckhafer authored Nov 10, 2016
1 parent 68dca93 commit bca6752
Show file tree
Hide file tree
Showing 24 changed files with 2,111 additions and 937 deletions.
4 changes: 3 additions & 1 deletion imports/plugins/core/orders/client/templates/orders.js
Original file line number Diff line number Diff line change
@@ -1,7 +1,7 @@
import _ from "lodash";
import { Meteor } from "meteor/meteor";
import { Template } from "meteor/templating";
import { Reaction, i18next } from "/client/api";
import { Reaction, i18next, Logger } from "/client/api";
import { Orders, Shops } from "/lib/collections";

const orderFilters = [{
Expand Down Expand Up @@ -193,9 +193,11 @@ Template.ordersListItem.events({
const isActionViewOpen = Reaction.isActionViewOpen();
const { order } = instance.data;


if (order.workflow.status === "new") {
Meteor.call("workflow/pushOrderWorkflow", "coreOrderWorkflow", "processing", order);
}

// toggle detail views
if (isActionViewOpen === false) {
Reaction.showActionView({
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -2,6 +2,7 @@ import _ from "lodash";
import { Meteor } from "meteor/meteor";
import { Tracker } from "meteor/tracker";
import { Template } from "meteor/templating";
import { i18next } from "/client/api";
import { Orders } from "/lib/collections";

Template.coreOrderShippingTracking.onCreated(() => {
Expand Down Expand Up @@ -37,11 +38,11 @@ Template.coreOrderShippingTracking.events({

"click [data-event-action=resendNotification]": function () {
const template = Template.instance();
Meteor.call("orders/sendNotification", template.order, (err) => {
Meteor.call("orders/sendNotification", template.order, "shipped", (err) => {
if (err) {
Alerts.toast("Server Error: Can't send email notification.", "error");
Alerts.toast(i18next.t("mail.alerts.cantSendEmail"), "error");
} else {
Alerts.toast("Email notification sent.", "success");
Alerts.toast(i18next.t("mail.alerts.emailSent"), "success");
}
});
},
Expand Down
2 changes: 2 additions & 0 deletions imports/plugins/core/templates/client/index.js
Original file line number Diff line number Diff line change
@@ -0,0 +1,2 @@
import "./templates/email.html";
import "./templates/email.js";
76 changes: 76 additions & 0 deletions imports/plugins/core/templates/client/templates/email.html
Original file line number Diff line number Diff line change
@@ -0,0 +1,76 @@
<template name="emailTemplatesDashboard">
<div class="panel panel-default">
<div class="panel-body">
<table class="table table-striped">
<thead>
<tr class="info">
<th>{{i18n "mail.templates.method" "Method"}}</th>
<th>{{i18n "mail.templates.templateName" "Template Name"}}</th>
<th>{{i18n "mail.templates.type" "Type"}}</th>
<th>{{i18n "mail.templates.language" "Language"}}</th>
<th>{{i18n "mail.templates.enabled" "Enabled"}}</th>
<th><i class="fa fa-plus pull-right add-shipping-method" title="{{i18n 'mail.templates.addTemplate' 'Add email template'}}" data-event-action="addShippingMethod"></i></th>
</tr>
</thead>
<tbody>
{{#each emailTemplate}}
<tr class="edit-shipping-method" data-event-action="editEmailTemplate">
<td>{{name}}</td>
<td>{{title}}</td>
<td>{{type}}</td>
<td>{{language}}</td>
<td>
{{#if enabled}}
<i class="fa fa-check text-success" title="Enabled"></i>
{{else}}
<i class="fa fa-ban text-danger" title="Disabled"></i>
{{/if}}
</td>
<td class="text-right">
<i class="fa fa-pencil" data-template-id="{{_id}}" title="{{i18n 'mail.templates.edit' 'Edit email template'}}" data-event-action="editEmailTemplate"></i>
<i class="fa fa-files-o" data-template-id="{{_id}}" title="{{i18n 'mail.templates.duplicate' 'Duplicate email template'}}" data-event-action="duplicateEmailTemplate"></i>
<i class="fa fa-trash" data-template-id="{{_id}}" title="{{i18n 'mail.templates.delete' 'Delete email template'}}" data-event-action="deleteEmailTemplate"></i>
</td>
</tr>
{{/each}}
</tbody>
</table>
</div>
</div>
</template>


<template name="emailTemplateSettings">
{{#autoForm
collection=Collections.Templates
schema=emailTemplateSchema
id="email-template-edit-form"
template="bootstrap3-inline"
doc=this
}}

<div class="panel panel-default">
<div class="panel-heading">Update {{name}} template</div>
<div class="panel-body">
<div class="col-md-12 form-group">
{{>afQuickField name='subject' class="form-control"}}
{{>afQuickField name='name' class="form-control"}}
{{>afQuickField name='title' class="form-control"}}
{{>afQuickField name='language' class="form-control"}}
{{>afQuickField name='template' label='HTML' class="form-control" type="textarea" rows="10"}}
{{>afQuickField name='enabled'}}
{{>afQuickField name='type' class="form-control"}}
{{>afQuickField name='parser' class="form-control"}}
{{>afQuickField name='_id' class="form-control"}}
</div>
</div>

<div class="panel-footer">
<div class="right">
<button type="submit" class="btn btn-primary">Update</button>
</div>
</div>
</div>

{{/autoForm}}
</template>
141 changes: 141 additions & 0 deletions imports/plugins/core/templates/client/templates/email.js
Original file line number Diff line number Diff line change
@@ -0,0 +1,141 @@
import { Meteor } from "meteor/meteor";
import { Session } from "meteor/session";
import { Template } from "meteor/templating";
import { Blaze } from "meteor/blaze";
import { AutoForm } from "meteor/aldeed:autoform";
import { Reaction, i18next } from "/client/api";
import { Templates } from "/lib/collections";
import { EmailTemplates } from "../../lib/collections/schemas";

/*
* Subscribe to Templates collections
*/
Template.emailTemplatesDashboard.onCreated(function () {
this.autorun(() => {
this.subscribe("Templates");
});
});


/*
* template emailTemplatesDashboard helpers
*/
Template.emailTemplatesDashboard.helpers({
emailTemplate() {
const instance = Template.instance();
if (instance.subscriptionsReady()) {
return Templates.find({
shopId: Reaction.getShopId(),
type: "email",
isOriginalTemplate: false
});
}
}
});


/*
* template emailTemplatesDashboard events
*/
Template.emailTemplatesDashboard.events({
// "click [data-event-action=addShippingMethod]"(event) {
// event.preventDefault();
//
// Reaction.showActionView({
// label: i18next.t("shipping.addShippingMethod"),
// template: "addShippingMethod"
// });
// }

"click [data-event-action=deleteEmailTemplate]"(event) {
event.preventDefault();
event.stopPropagation();

Alerts.alert({
title: i18next.t("mail.templates.alerts.removeEmailTemplateTitle"),
type: "warning",
showCancelButton: true,
confirmButtonText: i18next.t("mail.templates.alerts.removeEmailTemplateConfirm", { title: this.title })
}, (isConfirm) => {
if (isConfirm) {
Meteor.call("templates/email/remove", $(event.currentTarget).data("template-id"));
Reaction.hideActionView();
}
});
},

// "click [data-event-action=duplicateEmailTemplate]"(event) {
// event.preventDefault();
// event.stopPropagation();
//
// Alerts.alert({
// title: i18next.t("mail.templates.alerts.duplicateEmailTemplateTitle"),
// type: "warning",
// showCancelButton: true,
// confirmButtonText: i18next.t("mail.templates.alerts.duplicateEmailTemplateConfirm", { title: this.title })
// }, (isConfirm) => {
// if (isConfirm) {
// Meteor.call("templates/email/duplicate", $(event.currentTarget).data("template-id"), this);
// Reaction.hideActionView();
// }
// });
// },

"click [data-event-action=editEmailTemplate]"(event) {
event.preventDefault();

Reaction.showActionView({
label: i18next.t("mail.templates.edit"),
data: this,
template: "emailTemplateSettings"
});

// TODO: What does this do?
Session.set("updatedMethodObj", "");
Session.set("selectedMethodObj", this);
}
});


/*
* Template emailTemplatesSettings Helpers
*/
Template.emailTemplateSettings.helpers({
emailTemplateSchema() {
return EmailTemplates;
}
});


AutoForm.hooks({
"email-template-edit-form": {
onSubmit: function (insertDoc) {
this.event.preventDefault();

const templateId = this.docId;

Meteor.call("templates/email/update", templateId, insertDoc, (error, result) => {
if (error) {
Alerts.toast(i18next.t("mail.templates.alerts.failedToUpdate", { err: error.message }), "error");
this.done(new Error("Failed to update template: ", error));
return false;
}
if (result) {
this.done();
}
});
}
}
});


Blaze.TemplateInstance.prototype.parentTemplate = function (levels = 1) {
let view = Blaze.currentView;
let numLevel = levels;
while (view) {
if (view.name.substring(0, 9) === "Template." && !numLevel--) {
return view.templateInstance();
}
view = view.parentView;
}
};
Original file line number Diff line number Diff line change
@@ -0,0 +1,78 @@
import { SimpleSchema } from "meteor/aldeed:simple-schema";
import { Templates } from "/lib/collections";


/**
* EmailTemplates Schema
* TODO: Update schema with final fields when known
*/

export const EmailTemplates = new SimpleSchema({
name: {
type: String
},
isOriginalTemplate: {
type: Boolean,
optional: true,
defaultValue: false
},
priority: {
type: Number,
optional: true,
defaultValue: 1
},
enabled: {
type: Boolean,
defaultValue: true
},
route: {
type: String,
optional: true
},
audience: {
type: [String],
optional: true
},
type: {
type: String,
defaultValue: "email"
},
provides: {
type: String,
defaultValue: "template"
},
block: {
type: String,
optional: true
},
defaultData: {
type: Object,
blackbox: true,
optional: true
},
template: {
type: String,
optional: true
},
parser: {
type: String
},
language: {
type: String,
optional: true,
defaultValue: "en"
},
source: {
type: String,
optional: true
},
title: {
type: String
},
subject: {
type: String,
optional: true
}
});

Templates.attachSchema(EmailTemplates, { selector: { type: "email" } });
Original file line number Diff line number Diff line change
@@ -0,0 +1 @@
export * from "./emailtemplates";
44 changes: 44 additions & 0 deletions imports/plugins/core/templates/register.js
Original file line number Diff line number Diff line change
@@ -0,0 +1,44 @@
import { Reaction } from "/server/api";

Reaction.registerPackage({
label: "Email",
name: "reaction-templates",
icon: "fa fa-columns",
autoEnable: true,
settings: {
name: "Templates"
},
registry: [{
route: "/dashboard/templates",
provides: "dashboard",
workflow: "coreEmailWorkflow",
name: "Templates",
label: "Templates",
description: "App Templates",
icon: "fa fa-columns",
priority: 1,
container: "appearance",
template: "emailTemplatesDashboard"
}, {
label: "Edit Email Template",
name: "templates/email",
provides: "settings",
template: "emailTemplateSettings"
}],
layout: [{
layout: "coreLayout",
workflow: "coreEmailWorkflow",
theme: "default",
enabled: true,
structure: {
template: "email",
layoutHeader: "layoutHeader",
layoutFooter: "",
notFound: "notFound",
dashboardHeader: "dashboardHeader",
// dashboardHeaderControls: "emailDashboardTabs", // removed until needed for nav tabs
dashboardControls: "dashboardControls",
adminControlsFooter: "adminControlsFooter"
}
}]
});
2 changes: 2 additions & 0 deletions imports/plugins/core/templates/server/index.js
Original file line number Diff line number Diff line change
@@ -0,0 +1,2 @@
import "./methods";
import "../lib/collections/schemas/emailtemplates";
Loading

0 comments on commit bca6752

Please sign in to comment.