Skip to content

Instantly share code, notes, and snippets.

@ericf
Created May 14, 2013 17:46
Show Gist options
  • Star 0 You must be signed in to star a gist
  • Fork 0 You must be signed in to fork a gist
  • Save ericf/5577957 to your computer and use it in GitHub Desktop.
Save ericf/5577957 to your computer and use it in GitHub Desktop.
A snippet from rsvp.js from my wedding site.
Y.Model.prototype.promiseSave = function (options) {
var model = this;
return new Y.Promise(function (resolve, reject) {
model.save(options, function (err, res) {
return err ? reject(err) : resolve(res);
});
});
};
var app = new Y.App({
container : '#main',
viewContainer : '#main',
contentSelector: '#main',
linkSelector : null,
transitions: true,
root : '/rsvp/',
views: {
rsvp : {type: Y.RsvpView},
attending : {type: Y.AttendingView},
notAttending: {type: Y.NotAttendingView}
}
});
app.invitation = new Y.Invitation(YUI.Env.LE.invitation);
app.initialContent = Y.one('#main > [data-view]');
app.rsvp = function (isAttending) {
var guests = this.invitation.get('guests'),
saves = [app.updateInvitation({rsvpd: true, send_paper: false})];
guests.invoke('set', 'is_attending', isAttending);
saves.push.apply(saves, guests.invoke('promiseSave'));
Y.batch.apply(null, saves).then(function () {
app.replace('');
});
};
app.updateInvitation = function (updates) {
this.invitation.setAttrs(updates);
if (this.invitation.isModified()) {
return this.invitation.promiseSave();
}
return Y.when(true);
};
app.on('*:rsvp', function (e) {
this.rsvp(e.isAttending);
});
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment