Skip to content

Instantly share code, notes, and snippets.

@czbaker
Created November 3, 2015 16:09
Show Gist options
  • Select an option

  • Save czbaker/6d2a0cf3fed4bdf4a376 to your computer and use it in GitHub Desktop.

Select an option

Save czbaker/6d2a0cf3fed4bdf4a376 to your computer and use it in GitHub Desktop.
Template.adminSystem.events({
"submit form": function(event) {
event.preventDefault();
// Fetch current settings
CurrentSettings = Settings.findOne();
theID = CurrentSettings._id;
// Check options set.
var timeSlots = $('#timeSlots').prop('checked');
//CurrentSettings.timeSlots = timeSlots;
// var bDate = new Date($('.form').form('get value', 'beginDateTime'));
// var eDate = new Date($('.form').form('get value', 'endDateTime'));
var beginDateTime = moment($('.form').form('get value', 'beginDateTime'), "MM/DD/YYYY h:mm a");
var endDateTime = moment($('.form').form('get value', 'endDateTime'), "MM/DD/YYYY h:mm a");
console.log("Begin Date: " + beginDateTime.isValid());
console.log("End Date: " + endDateTime.isValid());
// If both fields are filled in
if (beginDateTime && endDateTime) {
if (!endDateTime.isAfter()) {
// This is in the past!
$('ui.basic.modal.error1').modal('show');
}
if (endDateTime.isAfter(beginDateTime)) {
console.log(theID);
// Settings.update(theID, { $set: {timeSlots: timeSlots, start: beginDateTime, end: endDateTime} });
settingsDoc = {
start: beginDateTime,
end: endDateTime,
timeSlots: timeSlots
};
console.log(settingsDoc);
Meteor.call('changeSettings', settingsDoc, function(err, result) {
if (err && err.error === "not-admin") {
console.log("Unable to update settings, not an admin!");
} else {
console.log(result);
}
});
}
}
}
});
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment