Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Templates fixes #1600

Merged
merged 8 commits into from
Dec 6, 2016
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
22 changes: 5 additions & 17 deletions imports/plugins/core/templates/client/templates/email.html
Original file line number Diff line number Diff line change
Expand Up @@ -4,12 +4,10 @@
<table class="table table-striped">
<thead>
<tr class="info">
<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="addEmailTemplateMethod"></i></th> -->
<th>Actions</th>
<th>{{i18n "templates.templateName" "Template Name"}}</th>
<th>{{i18n "templates.type" "Type"}}</th>
<th>{{i18n "templates.language" "Language"}}</th>
<th class="textAlignRight">{{i18n "templates.actions" "Actions"}}</th>
</tr>
</thead>
<tbody>
Expand All @@ -18,17 +16,8 @@
<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}}
Expand All @@ -45,7 +34,7 @@
schema=emailTemplateSchema
id="email-template-edit-form"
template="bootstrap3-inline"
doc=this
doc=template
}}

<div class="panel panel-default">
Expand All @@ -54,7 +43,6 @@
<div class="col-md-12 form-group">
{{>afQuickField name="title" class="form-control"}}
{{>afQuickField name="name" class="form-control" disabled=true}}
{{>afQuickField name="enabled"}}
{{>afQuickField name="language" class="form-control" disabled=true}}
{{>afQuickField name="subject" class="form-control"}}
{{>afQuickField name="template" label="HTML" class="form-control" type="textarea" rows="15"}}
Expand Down
62 changes: 19 additions & 43 deletions imports/plugins/core/templates/client/templates/email.js
Original file line number Diff line number Diff line change
Expand Up @@ -37,49 +37,6 @@ Template.emailTemplatesDashboard.helpers({
* template emailTemplatesDashboard events
*/
Template.emailTemplatesDashboard.events({
// "click [data-event-action=addEmailTemplate]"(event) {
// event.preventDefault();
//
// Reaction.showActionView({
// label: i18next.t("shipping.addShippingMethod"),
// template: "addEmailTemplate"
// });
// }

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

Alerts.alert({
title: i18next.t("templates.alerts.removeEmailTemplateTitle"),
type: "warning",
showCancelButton: true,
confirmButtonText: i18next.t("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("templates.alerts.duplicateEmailTemplateTitle"),
// type: "warning",
// showCancelButton: true,
// confirmButtonText: i18next.t("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();

Expand All @@ -96,10 +53,29 @@ Template.emailTemplatesDashboard.events({
});


/*
* Template emailTemplatesSettings Helpers
*/
Template.emailTemplateSettings.onCreated(function () {
this.state = new ReactiveDict();

this.autorun(() => {
const currentData = Template.currentData();
const currentTemplate = Templates.findOne(currentData._id);

this.state.set("template", currentTemplate);
});
});


/*
* Template emailTemplatesSettings Helpers
*/
Template.emailTemplateSettings.helpers({
template() {
return Template.instance().state.get("template");
},

emailTemplateSchema() {
return EmailTemplates;
}
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -14,7 +14,8 @@ export const EmailTemplates = new SimpleSchema({
label: "Template ShopId"
},
name: {
type: String
type: String,
optional: true
},
priority: {
type: Number,
Expand Down
5 changes: 0 additions & 5 deletions imports/plugins/core/templates/register.js
Original file line number Diff line number Diff line change
Expand Up @@ -19,11 +19,6 @@ Reaction.registerPackage({
priority: 1,
container: "appearance",
template: "emailTemplatesDashboard"
}, {
label: "Edit Email Template",
name: "templates/email",
provides: "settings",
template: "emailTemplateSettings"
}],
layout: [{
layout: "coreLayout",
Expand Down
17 changes: 9 additions & 8 deletions imports/plugins/core/templates/server/i18n/en.json
Original file line number Diff line number Diff line change
Expand Up @@ -5,21 +5,22 @@
"translation": {
"reaction-templates": {
"templates": {
"edit": "Edit email template",
"actions": "Actions",
"edit": "Edit template",
"editingTemplate": "Editing {{name}} template",
"duplicate": "Duplicate email template",
"delete": "Delete email template",
"duplicate": "Duplicate template",
"delete": "Delete template",
"method": "Method",
"templateName": "Template Name",
"type": "Type",
"language": "Language",
"enabled": "Enabled",
"addTemplate": "Add email template",
"addTemplate": "Add template",
"alerts": {
"removeEmailTemplateConfirm": "Are you sure you want to deleted {{title}}?",
"removeEmailTemplateTitle": "Remove Email Template",
"duplicateEmailTemplateConfirm": "Are you sure you want to duplicate {{title}}?",
"duplicateEmailTemplateTitle": "Duplicate Email Template",
"removeTemplateConfirm": "Confirm",
"removeTemplateTitle": "Remove Template",
"duplicateTemplateConfirm": "Are you sure you want to duplicate {{title}}?",
"duplicateTemplateTitle": "Duplicate Template",
"failedToUpdate": "Failed to update template: {{err}}"
}
}
Expand Down
103 changes: 0 additions & 103 deletions imports/plugins/core/templates/server/methods.js
Original file line number Diff line number Diff line change
@@ -1,31 +1,12 @@
import { Templates } from "/lib/collections";
import { Reaction } from "/server/api";

export const methods = {

/**
* templates/email/remove
* @summary removes email template from Templates collection
* @param {String} templateId - id of template to remove
* @return {Number} remove template
* TODO: change return type? is number correct?
*/
"templates/email/remove": function (templateId) {
check(templateId, String);
// TODO: add permissions
// if (!Reaction.hasPermission("shipping")) {
// throw new Meteor.Error(403, "Access Denied");
// }
return Templates.remove(templateId);
},

/**
* templates/email/update
* @summary updates email template in Templates collection
* @param {String} templateId - id of template to remove
* @param {Object} doc - data to update
* @return {Number} remove template
* TODO: change return type? is number correct?
*/
"templates/email/update": function (templateId, doc) {
check(templateId, String);
Expand All @@ -48,90 +29,6 @@ export const methods = {
}
});
}


// TODO: Cleanup functions below

// /**
// * add new shipping methods
// * @summary insert Shipping methods for a provider
// * @param {String} insertDoc shipping method
// * @param {String} currentDoc current providerId
// * @return {Number} insert result
// */
// "shipping/methods/add": function (insertDoc, currentDoc) {
// check(insertDoc, Object);
// check(currentDoc, Match.Optional(String));
// // if no currentDoc we need to insert a default provider.
// const id = currentDoc || Random.id();
//
// if (!Reaction.hasPermission("shipping")) {
// throw new Meteor.Error(403, "Access Denied");
// }
//
// return Shipping.update({
// _id: id
// }, {
// $addToSet: {
// methods: insertDoc
// }
// });
// },
//
// /**
// * updateShippingMethods
// * @summary update Shipping methods for a provider
// * @param {String} providerId providerId
// * @param {String} methodId methodId
// * @param {Object} updateMethod - updated method itself
// * @return {Number} update result
// */

//
//
// /*
// * add / insert shipping provider
// */
// "shipping/provider/add": function (doc) {
// check(doc, Object);
// if (!Reaction.hasPermission("shipping")) {
// throw new Meteor.Error(403, "Access Denied");
// }
// return Shipping.insert(doc);
// },
//
// /*
// * update shipping provider
// */
// "shipping/provider/update": function (updateDoc, currentDoc) {
// check(updateDoc, Object);
// check(currentDoc, String);
// if (!Reaction.hasPermission("shipping")) {
// throw new Meteor.Error(403, "Access Denied");
// }
// return Shipping.update({
// _id: currentDoc
// }, updateDoc);
// },

//
//
// "templates/email/duplicate": function (templateId, doc) {
// check(templateId, String);
// check(doc, Object);
// // if (!Reaction.hasPermission("shipping")) {
// // throw new Meteor.Error(403, "Access Denied");
// // }
// // return Templates.remove(templateId);
// console.log("------templateId-----", templateId);
// console.log("------doc-----", doc);
// return Templates.insert({
// $unset: { _id: "" }
// }, doc);
// },

// const variantNewId = Random.id();

};

Meteor.methods(methods);