Skip to content

Instantly share code, notes, and snippets.

@ericf
Created August 5, 2010 23:02
Show Gist options
  • Select an option

  • Save ericf/510555 to your computer and use it in GitHub Desktop.

Select an option

Save ericf/510555 to your computer and use it in GitHub Desktop.
/**
* InviteWindow
*/
YUI().use('node', 'value-change', 'substitute', 'form-overlabels', 'resource', function(Y){
Y.on('domready', function(){
var inviteForm = Y.one('#invite').plug(Y.Plugin.FormOverlabels),
inviteFormInput = inviteForm.one('input'),
inviteFormControl = inviteForm.one('button'),
inviteFormMessage = inviteForm.one('#invite-message'),
inviteResource = new Y.Resource({ uri: inviteForm.get('action') }),
messageTemplate = '<p>Hmmm… <strong>{code}</strong> seems to be an invalid or already used invite code. ' +
'Let us know if this seems wrong: ' +
'<strong><a href="mailto:support@">support@</a></strong></p>';
inviteFormControl.set('disabled', inviteFormInput.get('value').length === 0);
inviteFormInput.on('valueChange', function(e){
inviteFormControl.set('disabled', e.newVal.length === 0);
inviteFormMessage.setContent(null);
});
inviteForm.on('submit', function(e){
e.preventDefault();
inviteResource.POST({
params : { code: inviteFormInput.get('value') },
on : {
success : function(e){
window.location.reload(true);
},
failure : function(e){
inviteFormMessage.setContent(Y.substitute(messageTemplate, e.request.params));
}
}
});
});
});
});
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment