Last active
August 29, 2015 14:01
-
-
Save marcodejongh/c2056ab5b5f7a360cb0a to your computer and use it in GitHub Desktop.
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
var formCollection = new Meteor.Collection(null); | |
var itemId = 'SEDatkPtyfAKvGgpj'; | |
Template.form.rendered = function () { | |
}; | |
Template.form.changed = function () { | |
var form = formCollection.findOne(itemId); | |
return !collections.wave.find(form).count();r | |
} | |
Template.form.created = function () { | |
}; | |
Template.form.data = function () { | |
var ready = Meteor.subscribe('wave').ready(), | |
form; | |
if(ready) { | |
form = formCollection.findOne(itemId) || {}; | |
if (!_.size(form)) { //No form exists yet | |
var wave = collections.wave.findOne(itemId); | |
if(!wave) { | |
router.go(currentRoute, {itemId: formCollection.insert(collections.wave.template())}); | |
} | |
form = formCollection.findOne(formCollection.insert(wave)); | |
} | |
} | |
return form; | |
}; | |
Template.form.destroyed = function () { | |
}; | |
Template.form.events({ | |
'submit': function (event, template) { | |
event.preventDefault(); | |
var modifier = {}; | |
modifier['$set'] = {}; | |
$(template.findAll('input')).each(function () { | |
var field = $(this); | |
modifier['$set'][field.attr('name')] = field.val(); | |
}); | |
formCollection.update(this._id, modifier); | |
collections.wave.update(itemId, formCollection.findOne(itemId)); | |
} | |
}); |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment