Vulcan/packages/nova-settings/lib/collection.js

436 lines
11 KiB
JavaScript
Raw Normal View History

2015-05-10 13:37:42 +09:00
/**
* @summary The global namespace for Settings.
* @namespace Telescope.settings.collection
2015-05-10 13:37:42 +09:00
*/
const isInSettingsJSON = function () {
2016-04-21 15:09:03 +09:00
// settings can either be in settings json's public, or in the special object we publish only for admins for private settings
return typeof Telescope.settings.getFromJSON(this.name) !== "undefined" || typeof Telescope.settings.settingsJSON[this.name] !== "undefined";
};
const getFromJSON = function () {
return Telescope.settings.getFromJSON(this.name) || Telescope.settings.settingsJSON[this.name];
};
2016-02-16 15:08:30 +09:00
Telescope.settings.collection = new Mongo.Collection("settings");
2016-02-16 15:08:30 +09:00
Telescope.settings.schema = new SimpleSchema({
title: {
type: String,
optional: true,
2016-04-15 11:11:13 +09:00
insertableIf: Users.is.admin,
editableIf: Users.is.admin,
2016-04-21 15:09:03 +09:00
publish: true,
autoform: {
disabled: isInSettingsJSON,
2016-04-21 15:09:03 +09:00
prefill: getFromJSON,
help: "Your site's title.",
group: "01_general"
}
},
siteUrl: {
type: String,
optional: true,
2016-04-21 15:09:03 +09:00
publish: true,
// regEx: SimpleSchema.RegEx.Url,
2016-04-15 11:11:13 +09:00
insertableIf: Users.is.admin,
editableIf: Users.is.admin,
autoform: {
disabled: isInSettingsJSON,
2016-04-21 15:09:03 +09:00
prefill: getFromJSON,
group: "01_general",
type: "bootstrap-url",
help: 'Your site\'s URL (with trailing "/"). Will default to Meteor.absoluteUrl()'
}
},
tagline: {
type: String,
optional: true,
2016-04-21 15:09:03 +09:00
publish: true,
2016-04-15 11:11:13 +09:00
insertableIf: Users.is.admin,
editableIf: Users.is.admin,
autoform: {
disabled: isInSettingsJSON,
2016-04-21 15:09:03 +09:00
prefill: getFromJSON,
group: "01_general"
}
},
description: {
type: String,
optional: true,
2016-04-21 15:09:03 +09:00
publish: true,
2016-04-15 11:11:13 +09:00
insertableIf: Users.is.admin,
editableIf: Users.is.admin,
autoform: {
disabled: isInSettingsJSON,
2016-04-21 15:09:03 +09:00
prefill: getFromJSON,
group: "01_general",
rows: 5,
help: 'A short description used for SEO purposes.'
}
},
siteImage: {
type: String,
optional: true,
2016-04-21 15:09:03 +09:00
publish: true,
2016-04-15 11:11:13 +09:00
insertableIf: Users.is.admin,
editableIf: Users.is.admin,
regEx: SimpleSchema.RegEx.Url,
autoform: {
disabled: isInSettingsJSON,
2016-04-21 15:09:03 +09:00
prefill: getFromJSON,
group: "01_general",
help: "URL to an image for the open graph image tag for all pages"
}
},
requireViewInvite: {
type: Boolean,
optional: true,
2016-04-21 15:09:03 +09:00
publish: true,
2016-04-15 11:11:13 +09:00
insertableIf: Users.is.admin,
editableIf: Users.is.admin,
control: "checkbox",
autoform: {
disabled: isInSettingsJSON,
2016-04-21 15:09:03 +09:00
prefill: getFromJSON,
group: 'invites',
leftLabel: 'Require View Invite'
}
},
requirePostInvite: {
type: Boolean,
optional: true,
2016-04-21 15:09:03 +09:00
publish: true,
2016-04-15 11:11:13 +09:00
insertableIf: Users.is.admin,
editableIf: Users.is.admin,
control: "checkbox",
autoform: {
disabled: isInSettingsJSON,
2016-04-21 15:09:03 +09:00
prefill: getFromJSON,
group: 'invites',
leftLabel: 'Require Post Invite'
}
},
requirePostsApproval: {
type: Boolean,
optional: true,
2016-04-21 15:09:03 +09:00
publish: true,
2016-04-15 11:11:13 +09:00
insertableIf: Users.is.admin,
editableIf: Users.is.admin,
control: "checkbox",
autoform: {
disabled: isInSettingsJSON,
2016-04-21 15:09:03 +09:00
prefill: getFromJSON,
group: "01_general",
help: "Posts must be approved by admin",
leftLabel: "Require Posts Approval"
}
},
defaultEmail: {
type: String,
optional: true,
2016-04-15 11:11:13 +09:00
insertableIf: Users.is.admin,
editableIf: Users.is.admin,
autoform: {
disabled: isInSettingsJSON,
2016-04-21 15:09:03 +09:00
prefill: getFromJSON,
group: "06_email",
help: 'The address all outgoing emails will be sent from.',
class: "private-field"
}
},
mailUrl: {
type: String,
optional: true,
2016-04-15 11:11:13 +09:00
insertableIf: Users.is.admin,
editableIf: Users.is.admin,
autoform: {
disabled: isInSettingsJSON,
2016-04-21 15:09:03 +09:00
prefill: getFromJSON,
group: "06_email",
help: 'MAIL_URL environment variable (requires restart).',
class: "private-field"
}
},
scoreUpdateInterval: {
type: Number,
optional: true,
defaultValue: 30,
2016-04-15 11:11:13 +09:00
insertableIf: Users.is.admin,
editableIf: Users.is.admin,
autoform: {
disabled: isInSettingsJSON,
2016-04-21 15:09:03 +09:00
prefill: getFromJSON,
2015-06-18 16:46:45 +09:00
group: '01_general',
help: 'How often to recalculate scores, in seconds (default to 30)',
class: "private-field"
}
},
postInterval: {
type: Number,
optional: true,
2016-04-21 15:09:03 +09:00
publish: true,
defaultValue: 30,
2016-04-15 11:11:13 +09:00
insertableIf: Users.is.admin,
editableIf: Users.is.admin,
autoform: {
disabled: isInSettingsJSON,
2016-04-21 15:09:03 +09:00
prefill: getFromJSON,
group: "02_posts",
help: 'Minimum time between posts, in seconds (defaults to 30)'
}
},
2015-10-13 10:16:40 +09:00
RSSLinksPointTo: {
type: String,
optional: true,
2016-04-21 15:09:03 +09:00
publish: true,
2016-04-15 11:11:13 +09:00
insertableIf: Users.is.admin,
editableIf: Users.is.admin,
control: "radiogroup",
autoform: {
disabled: isInSettingsJSON,
2016-04-21 15:09:03 +09:00
prefill: getFromJSON,
group: "02_posts",
options: [
{value: 'page', label: 'Discussion page'},
{value: 'link', label: 'Outgoing link'}
]
}
},
commentInterval: {
type: Number,
optional: true,
2016-04-21 15:09:03 +09:00
publish: true,
defaultValue: 15,
2016-04-15 11:11:13 +09:00
insertableIf: Users.is.admin,
editableIf: Users.is.admin,
autoform: {
disabled: isInSettingsJSON,
2016-04-21 15:09:03 +09:00
prefill: getFromJSON,
group: "03_comments",
help: 'Minimum time between comments, in seconds (defaults to 15)'
}
},
maxPostsPerDay: {
type: Number,
optional: true,
2016-04-21 15:09:03 +09:00
publish: true,
defaultValue: 30,
2016-04-15 11:11:13 +09:00
insertableIf: Users.is.admin,
editableIf: Users.is.admin,
autoform: {
disabled: isInSettingsJSON,
2016-04-21 15:09:03 +09:00
prefill: getFromJSON,
group: "02_posts",
help: 'Maximum number of posts a user can post in a day (default to 30).'
}
},
startInvitesCount: {
type: Number,
defaultValue: 3,
optional: true,
2016-04-21 15:09:03 +09:00
publish: true,
2016-04-15 11:11:13 +09:00
insertableIf: Users.is.admin,
editableIf: Users.is.admin,
autoform: {
disabled: isInSettingsJSON,
2016-04-21 15:09:03 +09:00
prefill: getFromJSON,
group: 'invites'
}
},
postsPerPage: {
type: Number,
defaultValue: 10,
optional: true,
2016-04-21 15:09:03 +09:00
publish: true,
2016-04-15 11:11:13 +09:00
insertableIf: Users.is.admin,
editableIf: Users.is.admin,
autoform: {
disabled: isInSettingsJSON,
2016-04-21 15:09:03 +09:00
prefill: getFromJSON,
group: "02_posts"
}
},
logoUrl: {
type: String,
optional: true,
2016-04-21 15:09:03 +09:00
publish: true,
2016-04-15 11:11:13 +09:00
insertableIf: Users.is.admin,
editableIf: Users.is.admin,
autoform: {
disabled: isInSettingsJSON,
2016-04-21 15:09:03 +09:00
prefill: getFromJSON,
group: "04_logo"
}
},
logoHeight: {
type: Number,
optional: true,
2016-04-21 15:09:03 +09:00
publish: true,
2016-04-15 11:11:13 +09:00
insertableIf: Users.is.admin,
editableIf: Users.is.admin,
autoform: {
disabled: isInSettingsJSON,
2016-04-21 15:09:03 +09:00
prefill: getFromJSON,
group: "04_logo"
}
},
logoWidth: {
type: Number,
optional: true,
2016-04-21 15:09:03 +09:00
publish: true,
2016-04-15 11:11:13 +09:00
insertableIf: Users.is.admin,
editableIf: Users.is.admin,
autoform: {
disabled: isInSettingsJSON,
2016-04-21 15:09:03 +09:00
prefill: getFromJSON,
group: "04_logo"
}
},
faviconUrl: {
type: String,
optional: true,
2016-04-21 15:09:03 +09:00
publish: true,
2016-04-15 11:11:13 +09:00
insertableIf: Users.is.admin,
editableIf: Users.is.admin,
autoform: {
disabled: isInSettingsJSON,
2016-04-21 15:09:03 +09:00
prefill: getFromJSON,
group: "04_logo"
}
},
2016-04-15 11:11:13 +09:00
// language: {
// type: String,
// defaultValue: 'en',
// optional: true,
// insertableIf: Users.is.admin,
// editableIf: Users.is.admin,
// autoform: {
// group: "01_general",
// help: 'The app\'s language. Defaults to English.',
2016-04-15 11:11:13 +09:00
// options: function () {
// var languages = _.map(TAPi18n.getLanguages(), function (item, key) {
// return {
// value: key,
// label: item.name
// };
// });
// return languages;
// }
// }
// },
twitterAccount: {
type: String,
optional: true,
2016-04-21 15:09:03 +09:00
publish: true,
2016-04-15 11:11:13 +09:00
insertableIf: Users.is.admin,
editableIf: Users.is.admin,
autoform: {
disabled: isInSettingsJSON,
2016-04-21 15:09:03 +09:00
prefill: getFromJSON,
group: "07_integrations"
}
},
2015-08-03 15:43:02 +09:00
facebookPage: {
type: String,
optional: true,
2016-04-21 15:09:03 +09:00
publish: true,
2016-04-15 11:11:13 +09:00
insertableIf: Users.is.admin,
editableIf: Users.is.admin,
2015-08-03 15:43:02 +09:00
autoform: {
disabled: isInSettingsJSON,
2016-04-21 15:09:03 +09:00
prefill: getFromJSON,
2015-08-03 15:43:02 +09:00
group: "07_integrations"
}
},
googleAnalyticsId: {
type: String,
optional: true,
2016-04-21 15:09:03 +09:00
publish: true,
2016-04-15 11:11:13 +09:00
insertableIf: Users.is.admin,
editableIf: Users.is.admin,
autoform: {
disabled: isInSettingsJSON,
2016-04-21 15:09:03 +09:00
prefill: getFromJSON,
group: "07_integrations"
}
},
emailFooter: {
type: String,
optional: true,
2016-04-15 11:11:13 +09:00
insertableIf: Users.is.admin,
editableIf: Users.is.admin,
autoform: {
disabled: isInSettingsJSON,
2016-04-21 15:09:03 +09:00
prefill: getFromJSON,
group: "06_email",
help: 'Content that will appear at the bottom of outgoing emails (accepts HTML).',
rows: 5,
class: "private-field"
}
}
});
2016-02-16 15:08:30 +09:00
// Meteor.startup(function(){
// Settings.internationalize();
// });
2016-02-16 15:08:30 +09:00
Telescope.settings.collection.attachSchema(Telescope.settings.schema);
2016-02-16 15:08:30 +09:00
Telescope.subscriptions.preload("settings");
2016-02-16 15:08:30 +09:00
// Settings.get = function(setting, defaultValue) {
// var settings = Settings.find().fetch()[0];
2015-08-03 15:43:02 +09:00
2016-02-16 15:08:30 +09:00
// if(settings && (typeof settings[setting] !== 'undefined')) { // look in Settings collection first
// return settings[setting];
2016-02-16 15:08:30 +09:00
// } else if (Meteor.isServer && Meteor.settings && !!Meteor.settings[setting]) { // else if on the server, look in Meteor.settings
// return Meteor.settings[setting];
2016-02-16 15:08:30 +09:00
// } else if (Meteor.settings && Meteor.settings.public && !!Meteor.settings.public[setting]) { // look in Meteor.settings.public
// return Meteor.settings.public[setting];
2016-02-16 15:08:30 +09:00
// } else if (typeof defaultValue !== 'undefined') { // fallback to default
// return defaultValue;
2016-02-16 15:08:30 +09:00
// } else { // or return undefined
// return undefined;
// }
// };
2016-02-16 15:08:30 +09:00
// /**
// * Add trailing slash if needed on insert
// */
// Settings.before.insert(function (userId, doc) {
// if(doc.siteUrl && doc.siteUrl.match(/\//g).length === 2) {
// doc.siteUrl = doc.siteUrl + "/";
// }
// });
2016-02-16 15:08:30 +09:00
// /**
// * Add trailing slash if needed on update
// */
// Settings.before.update(function (userId, doc, fieldNames, modifier) {
// if(modifier.$set && modifier.$set.siteUrl && modifier.$set.siteUrl.match(/\//g).length === 2) {
// modifier.$set.siteUrl = modifier.$set.siteUrl + "/";
// }
// });
2016-02-16 15:08:30 +09:00
// Meteor.startup(function () {
// Settings.allow({
// insert: Users.is.adminById,
// update: Users.is.adminById,
// remove: Users.is.adminById
// });
// });
// Meteor.startup(function () {
// // override Meteor.absoluteUrl() with URL provided in settings
// Meteor.absoluteUrl.defaultOptions.rootUrl = Settings.get('siteUrl', Meteor.absoluteUrl());
// debug = Settings.get('debug', false);
// });