Vulcan/client/views/admin/settings.js

172 lines
5 KiB
JavaScript
Raw Normal View History

2012-10-22 14:00:47 +09:00
// note: this is some horrible code, I know
var StringUtils = {
humanize: function(string) {
return this.capitalize(this.convertCamelToSpaces(string));
},
capitalize: function(string) {
return string.charAt(0).toUpperCase() + string.slice(1);
},
convertCamelToSpaces: function(string) {
return string.replace(/([A-Z])/g, function(match) {
return ' ' + match;
});
}
}
var ModelForm = function (model, formOptions) {
this.model = model;
this.formOptions = formOptions;
this.generate = function () {
var formSchema = {};
for (var field in model) {
if (field != '_id') {
formSchema[field] = {
type: (formOptions[field] && formOptions[field]['type']) || model[field].constructor.name.toLowerCase(),
title: (formOptions[field] && formOptions[field]['title']) || StringUtils.humanize(field),
id: field
}
}
}
$('#json-form').jsonForm({
schema: formSchema
});
}
}
Template.settings.generate_settings_form = function (setting) {
Meteor.defer(function() {
var options = {
'requireViewInvite': {
title: 'Require Invite to view?'
},
'requirePostInvite': {
title: 'Require Invite to post?'
},
'requirePostsApproval': {
title: 'Posts must be approved by admin?'
},
'title': {
title: 'Site Title'
}
};
new ModelForm(setting, options).generate();
})
}
2012-09-06 19:42:11 +09:00
Template.settings.events = {
'click input[type=submit]': function(e){
e.preventDefault();
if(!Meteor.user()) throw 'You must be logged in.';
2012-10-05 14:21:16 +09:00
var requireViewInvite=!!$('#requireViewInvite').attr('checked');
var requirePostInvite=!!$('#requirePostInvite').attr('checked');
2012-10-24 11:04:42 +09:00
var requirePostsApproval=!!$('#requirePostsApproval').attr('checked');
2012-09-06 19:42:11 +09:00
var title= $('#title').val();
var theme = $('#theme').val();
2012-10-05 10:34:34 +09:00
var footerCode=$("#footerCode").val();
var analyticsCode = $('#analyticsCode').val();
var tlkioChannel = $('#tlkioChannel').val();
var mixpanelId= $('#mixpanelId').val();
var proxinoKey=$('#proxinoKey').val();
var goSquaredId=$('#goSquaredId').val();
var logoUrl=$('#logoUrl').val();
var logoHeight=$('#logoHeight').val();
var logoWidth=$('#logoWidth').val();
var veroAPIKey=$('#veroAPIKey').val();
var veroSecret=$('#veroSecret').val();
var intercomId=$('#intercomId').val();
2012-10-22 14:00:47 +09:00
var scoreInterval=$('#scoreInterval').val();
2012-10-08 17:54:37 +09:00
var landingPageText=$('#landingPageText').val();
var afterSignupText=$('#afterSignupText').val();
var notes=$('#notes').val();
2012-10-05 11:39:33 +09:00
2012-09-06 19:42:11 +09:00
var prevSetting=Settings.find().fetch()[0];
2012-09-24 15:36:37 +09:00
2012-09-06 19:42:11 +09:00
if(prevSetting){
Settings.update(prevSetting._id,{
$set: {
2012-10-05 14:21:16 +09:00
requireViewInvite:requireViewInvite,
2012-10-24 11:04:42 +09:00
requirePostInvite:requirePostInvite,
requirePostsApproval: requirePostsApproval,
2012-09-06 19:42:11 +09:00
title: title,
theme: theme,
2012-09-24 15:36:37 +09:00
footerCode: footerCode,
analyticsCode: analyticsCode,
tlkioChannel: tlkioChannel,
mixpanelId: mixpanelId,
2012-09-29 12:28:51 +09:00
proxinoKey: proxinoKey,
2012-10-01 12:23:35 +09:00
goSquaredId: goSquaredId,
2012-10-05 10:34:34 +09:00
intercomId: intercomId,
2012-09-29 12:28:51 +09:00
logoUrl: logoUrl,
logoHeight: logoHeight,
2012-10-01 11:59:53 +09:00
logoWidth: logoWidth,
veroAPIKey: veroAPIKey,
veroSecret:veroSecret,
2012-10-08 17:54:37 +09:00
landingPageText:landingPageText,
afterSignupText:afterSignupText,
2012-10-22 14:00:47 +09:00
scoreInterval: scoreInterval,
2012-10-01 11:59:53 +09:00
notes: notes
2012-09-06 19:42:11 +09:00
}
2012-10-05 11:39:33 +09:00
}, function(error){
if(error)
console.log(error);
throwError("Settings have been updated");
2012-09-06 19:42:11 +09:00
});
}else{
var settingId = Settings.insert({
2012-10-05 14:21:16 +09:00
requireViewInvite:requireViewInvite,
2012-10-24 11:04:42 +09:00
requirePostInvite:requirePostInvite,
requirePostsApproval:requirePostsApproval,
2012-09-24 15:36:37 +09:00
title: title,
theme: theme,
footerCode: footerCode,
analyticsCode: analyticsCode,
tlkioChannel: tlkioChannel,
mixpanelId: mixpanelId,
2012-09-29 12:28:51 +09:00
proxinoKey: proxinoKey,
2012-10-01 12:23:35 +09:00
goSquaredId: goSquaredId,
2012-10-05 11:39:33 +09:00
intercomId: intercomId,
2012-09-29 12:28:51 +09:00
logoUrl: logoUrl,
logoHeight: logoHeight,
2012-10-01 11:59:53 +09:00
logoWidth: logoWidth,
veroAPIKey: veroAPIKey,
veroSecret:veroSecret,
2012-10-08 17:54:37 +09:00
landingPageText:landingPageText,
afterSignupText:afterSignupText,
2012-10-22 14:00:47 +09:00
scoreInterval:scoreInterval,
2012-10-01 11:59:53 +09:00
notes:notes
}, function(){
throwError("Settings have been created");
});
2012-09-06 19:42:11 +09:00
}
}
};
Template.settings.no_settings = function(){
if(Settings.find().fetch()[0]){
return false;
}
return true;
}
Template.settings.setting = function(){
var setting = Settings.find().fetch()[0];
return setting;
};
Template.settings.is_theme = function(theme){
if(theme==this.setting.theme){
return true;
}
return false;
};
Template.settings.is_ascndr = function(){return this.theme=="ascndr" ? true : false;}
Template.settings.is_telescope = function(){return this.theme=="telescope" ? true : false;}
Template.settings.is_default = function(){return this.theme=="default" ? true : false;}