2015-05-01 18:22:00 +02:00
|
|
|
var campaignSchema = new SimpleSchema({
|
2015-04-22 07:50:11 +09:00
|
|
|
_id: {
|
|
|
|
type: String,
|
|
|
|
optional: true
|
|
|
|
},
|
|
|
|
createdAt: {
|
|
|
|
type: Date,
|
|
|
|
optional: true
|
|
|
|
},
|
|
|
|
sentAt: {
|
|
|
|
type: String,
|
|
|
|
optional: true
|
|
|
|
},
|
|
|
|
status: {
|
|
|
|
type: String,
|
|
|
|
optional: true
|
|
|
|
},
|
|
|
|
posts: {
|
|
|
|
type: [String],
|
|
|
|
optional: true
|
|
|
|
},
|
|
|
|
webHits: {
|
|
|
|
type: Number,
|
|
|
|
optional: true
|
|
|
|
},
|
|
|
|
});
|
|
|
|
|
|
|
|
Campaigns = new Meteor.Collection("campaigns", {
|
|
|
|
schema: campaignSchema
|
|
|
|
});
|
|
|
|
|
2015-05-19 10:29:36 +09:00
|
|
|
Posts.addField({
|
|
|
|
fieldName: 'scheduledAt',
|
2015-05-10 14:36:47 +09:00
|
|
|
fieldSchema: {
|
2015-05-19 10:29:36 +09:00
|
|
|
type: Date,
|
2015-04-22 07:50:11 +09:00
|
|
|
optional: true,
|
|
|
|
autoform: {
|
2015-05-19 10:29:36 +09:00
|
|
|
omit: true
|
2015-04-22 07:50:11 +09:00
|
|
|
}
|
|
|
|
}
|
2015-05-19 10:29:36 +09:00
|
|
|
});
|
2015-04-22 07:50:11 +09:00
|
|
|
|
2015-06-08 08:52:41 +09:00
|
|
|
Users.addField([
|
|
|
|
{
|
|
|
|
fieldName: 'telescope.newsletter.showBanner',
|
|
|
|
fieldSchema: {
|
|
|
|
label: 'Show banner',
|
|
|
|
type: Boolean,
|
|
|
|
optional: true,
|
|
|
|
editableBy: ['admin', 'member'],
|
|
|
|
autoform: {
|
|
|
|
omit: true
|
|
|
|
}
|
|
|
|
}
|
|
|
|
},
|
|
|
|
{
|
|
|
|
fieldName: 'telescope.newsletter.subscribeToNewsletter',
|
|
|
|
fieldSchema: {
|
|
|
|
label: 'Subscribe to newsletter',
|
|
|
|
type: Boolean,
|
|
|
|
optional: true,
|
|
|
|
editableBy: ['admin', 'member'],
|
|
|
|
autoform: {
|
2015-06-09 10:49:59 +09:00
|
|
|
omit: true
|
2015-06-08 08:52:41 +09:00
|
|
|
}
|
|
|
|
}
|
|
|
|
}
|
|
|
|
]);
|
2015-04-22 07:50:11 +09:00
|
|
|
|
2015-05-19 10:29:36 +09:00
|
|
|
// Settings
|
2015-04-22 07:50:11 +09:00
|
|
|
|
2015-05-19 10:29:36 +09:00
|
|
|
Settings.addField([
|
|
|
|
{
|
|
|
|
fieldName: 'enableNewsletter',
|
|
|
|
fieldSchema: {
|
|
|
|
type: Boolean,
|
|
|
|
optional: true,
|
|
|
|
autoform: {
|
|
|
|
group: 'newsletter',
|
|
|
|
instructions: 'Enable newsletter (requires restart).'
|
|
|
|
}
|
2015-04-22 07:50:11 +09:00
|
|
|
}
|
2015-05-19 10:29:36 +09:00
|
|
|
},
|
|
|
|
{
|
|
|
|
fieldName: 'showBanner',
|
|
|
|
fieldSchema: {
|
|
|
|
type: Boolean,
|
|
|
|
optional: true,
|
|
|
|
label: 'Newsletter banner',
|
|
|
|
autoform: {
|
|
|
|
group: 'newsletter',
|
|
|
|
instructions: 'Show newsletter sign-up form on the front page.'
|
|
|
|
}
|
2015-04-22 07:50:11 +09:00
|
|
|
}
|
2015-05-19 10:29:36 +09:00
|
|
|
},
|
|
|
|
{
|
|
|
|
fieldName: "mailChimpAPIKey",
|
|
|
|
fieldSchema: {
|
|
|
|
type: String,
|
|
|
|
optional: true,
|
|
|
|
private: true,
|
|
|
|
autoform: {
|
|
|
|
group: "newsletter",
|
|
|
|
class: "private-field"
|
|
|
|
}
|
2015-04-22 07:50:11 +09:00
|
|
|
}
|
2015-05-19 10:29:36 +09:00
|
|
|
},
|
|
|
|
{
|
|
|
|
fieldName: 'mailChimpListId',
|
|
|
|
fieldSchema: {
|
|
|
|
type: String,
|
|
|
|
optional: true,
|
|
|
|
private: true,
|
|
|
|
autoform: {
|
|
|
|
group: 'newsletter',
|
|
|
|
instructions: 'The ID of the list you want to send to.',
|
|
|
|
class: "private-field"
|
|
|
|
}
|
|
|
|
}
|
|
|
|
},
|
|
|
|
{
|
|
|
|
fieldName: 'postsPerNewsletter',
|
|
|
|
fieldSchema: {
|
|
|
|
type: Number,
|
|
|
|
optional: true,
|
|
|
|
autoform: {
|
|
|
|
group: 'newsletter'
|
|
|
|
}
|
|
|
|
}
|
|
|
|
},
|
|
|
|
{
|
|
|
|
fieldName: 'newsletterFrequency',
|
|
|
|
fieldSchema: {
|
2015-06-23 22:40:43 -04:00
|
|
|
type: [Number],
|
2015-05-19 10:29:36 +09:00
|
|
|
optional: true,
|
|
|
|
autoform: {
|
|
|
|
group: 'newsletter',
|
2015-06-23 22:40:43 -04:00
|
|
|
instructions: 'Defaults to once a week on Monday. Changes require restarting your app to take effect.',
|
|
|
|
noselect: true,
|
2015-05-19 10:29:36 +09:00
|
|
|
options: [
|
|
|
|
{
|
|
|
|
value: 1,
|
2015-06-23 22:40:43 -04:00
|
|
|
label: 'Sunday'
|
2015-05-19 10:29:36 +09:00
|
|
|
},
|
|
|
|
{
|
|
|
|
value: 2,
|
2015-06-23 22:40:43 -04:00
|
|
|
label: 'Monday'
|
2015-05-19 10:29:36 +09:00
|
|
|
},
|
|
|
|
{
|
|
|
|
value: 3,
|
2015-06-23 22:40:43 -04:00
|
|
|
label: 'Tuesday'
|
|
|
|
},
|
|
|
|
{
|
|
|
|
value: 4,
|
|
|
|
label: 'Wednesday'
|
|
|
|
},
|
|
|
|
{
|
|
|
|
value: 5,
|
|
|
|
label: 'Thursday'
|
|
|
|
},
|
|
|
|
{
|
|
|
|
value: 6,
|
|
|
|
label: 'Friday'
|
2015-05-19 10:29:36 +09:00
|
|
|
},
|
|
|
|
{
|
|
|
|
value: 7,
|
2015-06-23 22:40:43 -04:00
|
|
|
label: 'Saturday'
|
2015-05-19 10:29:36 +09:00
|
|
|
}
|
|
|
|
]
|
|
|
|
}
|
|
|
|
}
|
|
|
|
},
|
|
|
|
{
|
|
|
|
fieldName: 'newsletterTime',
|
|
|
|
fieldSchema: {
|
|
|
|
type: String,
|
|
|
|
optional: true,
|
|
|
|
defaultValue: '00:00',
|
|
|
|
autoform: {
|
|
|
|
group: 'newsletter',
|
|
|
|
instructions: 'Defaults to 00:00/12:00 AM. Time to send out newsletter if enabled.',
|
|
|
|
type: 'time'
|
|
|
|
}
|
|
|
|
}
|
|
|
|
},
|
|
|
|
{
|
|
|
|
fieldName: 'autoSubscribe',
|
|
|
|
fieldSchema: {
|
|
|
|
type: Boolean,
|
|
|
|
optional: true,
|
|
|
|
autoform: {
|
|
|
|
group: 'newsletter',
|
|
|
|
instructions: 'Automatically subscribe new users on sign-up.'
|
|
|
|
}
|
2015-04-22 07:50:11 +09:00
|
|
|
}
|
|
|
|
}
|
2015-05-19 10:29:36 +09:00
|
|
|
]);
|
2015-04-22 07:50:11 +09:00
|
|
|
|
|
|
|
// create new "campaign" lens for all posts from the past X days that haven't been scheduled yet
|
2015-05-17 15:38:02 +09:00
|
|
|
Posts.views.add("campaign", function (terms) {
|
2015-04-22 07:50:11 +09:00
|
|
|
return {
|
|
|
|
find: {
|
|
|
|
scheduledAt: {$exists: false},
|
|
|
|
postedAt: {
|
|
|
|
$gte: terms.after
|
|
|
|
}
|
|
|
|
},
|
2015-07-28 11:48:32 +09:00
|
|
|
options: {sort: {baseScore: -1}}
|
2015-04-22 07:50:11 +09:00
|
|
|
};
|
2015-05-06 17:38:19 +09:00
|
|
|
});
|
2015-04-22 07:50:11 +09:00
|
|
|
|
2015-05-17 15:38:02 +09:00
|
|
|
Telescope.modules.add("hero", {
|
2015-05-18 10:12:48 +09:00
|
|
|
template: 'newsletter_banner',
|
2015-04-22 07:50:11 +09:00
|
|
|
order: 10
|
|
|
|
});
|
|
|
|
|
2015-05-19 12:34:27 +09:00
|
|
|
function subscribeUserOnProfileCompletion (user) {
|
2015-04-22 07:50:11 +09:00
|
|
|
if (!!Settings.get('autoSubscribe') && !!Users.getEmail(user)) {
|
|
|
|
addToMailChimpList(user, false, function (error, result) {
|
2015-05-01 18:22:00 +02:00
|
|
|
console.log(error);
|
|
|
|
console.log(result);
|
2015-04-22 07:50:11 +09:00
|
|
|
});
|
|
|
|
}
|
|
|
|
return user;
|
|
|
|
}
|
2015-05-19 12:34:27 +09:00
|
|
|
Telescope.callbacks.add("profileCompletedAsync", subscribeUserOnProfileCompletion);
|