2012-11-13 20:56:00 +01:00
|
|
|
var settingsForm;
|
|
|
|
|
2012-11-13 15:54:52 +01:00
|
|
|
Template.settings.generate_settings_form = function (setting) {
|
|
|
|
Meteor.defer(function() {
|
2012-11-13 22:13:11 +01:00
|
|
|
form().generateFor(setting);
|
|
|
|
})
|
|
|
|
}
|
|
|
|
|
|
|
|
function form() {
|
|
|
|
settingsForm = new ModelForm(Settings, settingsFormOptions());
|
|
|
|
return settingsForm;
|
2012-11-13 13:14:50 +01:00
|
|
|
}
|
|
|
|
|
2012-09-06 19:42:11 +09:00
|
|
|
Template.settings.events = {
|
2012-11-13 22:13:11 +01:00
|
|
|
'click input[type=submit]': function(e){
|
|
|
|
e.preventDefault();
|
|
|
|
if(!Meteor.user()) throw 'You must be logged in.';
|
2012-10-05 11:39:33 +09:00
|
|
|
|
2012-11-13 22:13:11 +01:00
|
|
|
settingsForm.submit(
|
2012-11-13 21:09:22 +01:00
|
|
|
function(){
|
2012-11-13 22:13:11 +01:00
|
|
|
throwError("Settings have been created");
|
2012-11-13 21:09:22 +01:00
|
|
|
},
|
|
|
|
function(error) {
|
|
|
|
if(error) console.log(error);
|
2012-11-13 22:13:11 +01:00
|
|
|
throwError("Settings have been updated");
|
2012-11-13 21:09:22 +01:00
|
|
|
});
|
2012-11-13 22:13:11 +01:00
|
|
|
}
|
2012-09-06 19:42:11 +09:00
|
|
|
};
|
|
|
|
|
|
|
|
Template.settings.no_settings = function(){
|
2012-11-13 22:13:11 +01:00
|
|
|
if (Settings.findOne()) {
|
|
|
|
return false;
|
|
|
|
}
|
|
|
|
return true;
|
2012-09-06 19:42:11 +09:00
|
|
|
}
|
|
|
|
|
|
|
|
Template.settings.setting = function(){
|
2012-11-13 22:13:11 +01:00
|
|
|
var setting = Settings.find().fetch()[0];
|
|
|
|
return new Setting(setting) || new Setting();
|
2012-09-06 19:42:11 +09:00
|
|
|
};
|
|
|
|
|
|
|
|
Template.settings.is_theme = function(theme){
|
2012-11-13 22:13:11 +01:00
|
|
|
if(theme==this.setting.theme){
|
|
|
|
return true;
|
|
|
|
}
|
|
|
|
return false;
|
2012-09-06 19:42:11 +09:00
|
|
|
};
|
|
|
|
|
2012-11-13 22:13:11 +01:00
|
|
|
Template.settings.is_ascndr = function() { return this.theme=="ascndr" ? true : false; }
|
|
|
|
Template.settings.is_telescope = function() { return this.theme=="telescope" ? true : false; }
|
2012-11-17 13:24:19 +09:00
|
|
|
Template.settings.is_default = function() { return this.theme=="default" ? true : false; }
|