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-04-24 09:28:50 +09:00
|
|
|
Posts.registerField(
|
2015-04-22 07:50:11 +09:00
|
|
|
{
|
|
|
|
propertyName: 'scheduledAt',
|
|
|
|
propertySchema: {
|
|
|
|
type: Date,
|
|
|
|
optional: true,
|
|
|
|
autoform: {
|
|
|
|
omit: true
|
|
|
|
}
|
|
|
|
}
|
|
|
|
}
|
|
|
|
);
|
|
|
|
|
|
|
|
// Settings
|
|
|
|
|
|
|
|
var enableNewsletter = {
|
|
|
|
propertyName: 'enableNewsletter',
|
|
|
|
propertySchema: {
|
|
|
|
type: Boolean,
|
|
|
|
optional: true,
|
|
|
|
autoform: {
|
|
|
|
group: 'newsletter',
|
|
|
|
instructions: 'Enable newsletter (requires restart).'
|
|
|
|
}
|
|
|
|
}
|
2015-05-01 18:22:00 +02:00
|
|
|
};
|
2015-04-25 13:11:28 +09:00
|
|
|
Settings.registerField(enableNewsletter);
|
2015-04-22 07:50:11 +09:00
|
|
|
|
|
|
|
var showBanner = {
|
|
|
|
propertyName: 'showBanner',
|
|
|
|
propertySchema: {
|
|
|
|
type: Boolean,
|
|
|
|
optional: true,
|
|
|
|
label: 'Newsletter banner',
|
|
|
|
autoform: {
|
|
|
|
group: 'newsletter',
|
|
|
|
instructions: 'Show newsletter sign-up form on the front page.'
|
|
|
|
}
|
|
|
|
}
|
2015-05-01 18:22:00 +02:00
|
|
|
};
|
2015-04-25 13:11:28 +09:00
|
|
|
Settings.registerField(showBanner);
|
2015-04-22 07:50:11 +09:00
|
|
|
|
|
|
|
var mailChimpAPIKey = {
|
2015-04-25 12:39:07 +09:00
|
|
|
propertyName: "mailChimpAPIKey",
|
2015-04-22 07:50:11 +09:00
|
|
|
propertySchema: {
|
|
|
|
type: String,
|
|
|
|
optional: true,
|
2015-04-25 12:39:07 +09:00
|
|
|
private: true,
|
2015-04-22 07:50:11 +09:00
|
|
|
autoform: {
|
2015-04-25 12:39:07 +09:00
|
|
|
group: "newsletter",
|
|
|
|
class: "private-field"
|
2015-04-22 07:50:11 +09:00
|
|
|
}
|
|
|
|
}
|
2015-05-01 18:22:00 +02:00
|
|
|
};
|
2015-04-25 13:11:28 +09:00
|
|
|
Settings.registerField(mailChimpAPIKey);
|
2015-04-22 07:50:11 +09:00
|
|
|
|
|
|
|
var mailChimpListId = {
|
|
|
|
propertyName: 'mailChimpListId',
|
|
|
|
propertySchema: {
|
|
|
|
type: String,
|
|
|
|
optional: true,
|
2015-04-25 12:39:07 +09:00
|
|
|
private: true,
|
2015-04-22 07:50:11 +09:00
|
|
|
autoform: {
|
|
|
|
group: 'newsletter',
|
|
|
|
instructions: 'The ID of the list you want to send to.',
|
2015-04-25 12:39:07 +09:00
|
|
|
class: "private-field"
|
2015-04-22 07:50:11 +09:00
|
|
|
}
|
|
|
|
}
|
2015-05-01 18:22:00 +02:00
|
|
|
};
|
2015-04-25 13:11:28 +09:00
|
|
|
Settings.registerField(mailChimpListId);
|
2015-04-22 07:50:11 +09:00
|
|
|
|
|
|
|
var postsPerNewsletter = {
|
|
|
|
propertyName: 'postsPerNewsletter',
|
|
|
|
propertySchema: {
|
|
|
|
type: Number,
|
|
|
|
optional: true,
|
|
|
|
autoform: {
|
|
|
|
group: 'newsletter'
|
|
|
|
}
|
|
|
|
}
|
2015-05-01 18:22:00 +02:00
|
|
|
};
|
2015-04-25 13:11:28 +09:00
|
|
|
Settings.registerField(postsPerNewsletter);
|
2015-04-22 07:50:11 +09:00
|
|
|
|
|
|
|
var newsletterFrequency = {
|
|
|
|
propertyName: 'newsletterFrequency',
|
|
|
|
propertySchema: {
|
|
|
|
type: Number,
|
|
|
|
optional: true,
|
|
|
|
autoform: {
|
|
|
|
group: 'newsletter',
|
|
|
|
instructions: 'Defaults to once a week. Changes require restarting your app to take effect.',
|
|
|
|
options: [
|
|
|
|
{
|
|
|
|
value: 1,
|
|
|
|
label: 'Every Day'
|
|
|
|
},
|
|
|
|
{
|
|
|
|
value: 2,
|
|
|
|
label: 'Mondays, Wednesdays, Fridays'
|
|
|
|
},
|
|
|
|
{
|
|
|
|
value: 3,
|
|
|
|
label: 'Mondays & Thursdays'
|
|
|
|
},
|
|
|
|
{
|
|
|
|
value: 7,
|
|
|
|
label: 'Once a week (Mondays)'
|
|
|
|
}
|
|
|
|
]
|
|
|
|
}
|
|
|
|
}
|
2015-05-01 18:22:00 +02:00
|
|
|
};
|
2015-04-25 13:11:28 +09:00
|
|
|
Settings.registerField(newsletterFrequency);
|
2015-04-22 07:50:11 +09:00
|
|
|
|
|
|
|
var newsletterTime = {
|
|
|
|
propertyName: 'newsletterTime',
|
|
|
|
propertySchema: {
|
|
|
|
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'
|
|
|
|
}
|
|
|
|
}
|
2015-05-01 18:22:00 +02:00
|
|
|
};
|
2015-04-25 13:11:28 +09:00
|
|
|
Settings.registerField(newsletterTime);
|
2015-04-22 07:50:11 +09:00
|
|
|
|
|
|
|
var autoSubscribe = {
|
|
|
|
propertyName: 'autoSubscribe',
|
|
|
|
propertySchema: {
|
|
|
|
type: Boolean,
|
|
|
|
optional: true,
|
|
|
|
autoform: {
|
|
|
|
group: 'newsletter',
|
|
|
|
instructions: 'Automatically subscribe new users on sign-up.'
|
|
|
|
}
|
|
|
|
}
|
2015-05-01 18:22:00 +02:00
|
|
|
};
|
2015-04-25 13:11:28 +09:00
|
|
|
Settings.registerField(autoSubscribe);
|
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-04-27 10:35:06 +09:00
|
|
|
Telescope.viewParameters.campaign = function (terms) {
|
2015-04-22 07:50:11 +09:00
|
|
|
return {
|
|
|
|
find: {
|
|
|
|
scheduledAt: {$exists: false},
|
|
|
|
postedAt: {
|
|
|
|
$gte: terms.after
|
|
|
|
}
|
|
|
|
},
|
|
|
|
options: {sort: {sticky: -1, score: -1}}
|
|
|
|
};
|
2015-05-01 18:22:00 +02:00
|
|
|
};
|
2015-04-22 07:50:11 +09:00
|
|
|
|
2015-04-24 09:48:36 +09:00
|
|
|
Telescope.modules.register("hero", {
|
2015-04-22 07:50:11 +09:00
|
|
|
template: 'newsletterBanner',
|
|
|
|
order: 10
|
|
|
|
});
|
|
|
|
|
|
|
|
function subscribeUserOnCreation (user) {
|
|
|
|
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-04-24 09:48:36 +09:00
|
|
|
Telescope.callbacks.register("userCreated", subscribeUserOnCreation);
|