// Generated by github.com/steida/coffee2closure 0.1.12
goog.provide('spark.widgets.SignUp');
goog.require('spark.core.View');
goog.require('spark.components.Form');
/**
Ready to use customizable user sign up widget of Spark Framework.
@constructor
@export
@param {Object=} options Class options.
@param {*=} data Class data
@extends {spark.core.View}
*/
spark.widgets.SignUp = function(options, data) {
var _ref;
if (options == null) {
options = {};
}
if (options.withImage == null) {
options.withImage = (_ref = options['withImage']) != null ? _ref : true;
}
options.imageUrl || (options.imageUrl = options['imageUrl'] || 'http://lorempixel.com/460/144/city/4');
options.title || (options.title = options['title'] || 'Sign Up');
options.buttonTitle || (options.buttonTitle = options['buttonTitle'] || 'Sign Up');
options.buttonColor || (options.buttonColor = options['buttonColor'] || 'green');
options.callback || (options.callback = options['callback'] || null);
options.forgotPasswordCallback || (options.forgotPasswordCallback = options['forgotPasswordCallback'] || null);
options.alreadyRegisteredCallback || (options.alreadyRegisteredCallback = options['alreadyRegisteredCallback'] || null);
this.getCssClass(options, 'sign-up-widget');
spark.widgets.SignUp.superClass_.constructor.call(this, options, data);
if (options.withImage) {
this.createImage_();
}
this.createTitle_();
this.form = new spark.components.Form(this.getFormOptions_());
this.appendView(this.form);
this.createLinks_();
}
goog.inherits(spark.widgets.SignUp, spark.core.View);
/**
Creates form title element.
*/
spark.widgets.SignUp.prototype.createTitle_ = function() {
var title;
title = new spark.core.View({
template: this.getOptions().title,
cssClass: 'title'
});
return this.appendView(title);
};
/**
Creates form header image if `withImage` option is set to true.
*/
spark.widgets.SignUp.prototype.createImage_ = function() {
var image;
image = new spark.core.View({
tagName: 'img',
attributes: {
src: this.getOptions().imageUrl
}
});
this.appendView(image);
return this.addClass('with-image');
};
/**
Creates Forgot Password and Already Registered links.
*/
spark.widgets.SignUp.prototype.createLinks_ = function() {
var alreadyRegisteredCallback, forgotPassword, forgotPasswordCallback, registered, _ref;
_ref = this.getOptions(), forgotPasswordCallback = _ref.forgotPasswordCallback, alreadyRegisteredCallback = _ref.alreadyRegisteredCallback;
registered = new spark.core.View({
tagName: 'a',
template: 'Already Registered?',
cssClass: 'already-registered',
attributes: {
href: '#'
},
events: {
click: (function(_this) {
return function() {
if (alreadyRegisteredCallback) {
alreadyRegisteredCallback.call(_this);
}
return _this.emit('AlreadyRegisteredLinkClicked');
};
})(this)
}
});
forgotPassword = new spark.core.View({
tagName: 'a',
template: 'Forgot password?',
cssClass: 'forgot-password',
attributes: {
href: '#'
},
events: {
click: (function(_this) {
return function() {
if (forgotPasswordCallback) {
forgotPasswordCallback.call(_this);
}
return _this.emit('ForgotPasswordLinkClicked');
};
})(this)
}
});
this.appendView(registered);
return this.form.getInputsContainer().appendView(forgotPassword);
};
/**
Returns form options.
@private
@return {Object} Form options.
*/
spark.widgets.SignUp.prototype.getFormOptions_ = function() {
var formOptions, options;
options = this.getOptions();
formOptions = {
inputs: [
{
type: 'text',
placeholder: 'Email or username',
name: 'username'
}, {
type: 'password',
placeholder: 'Password',
name: 'password'
}
],
buttons: [
{
title: options.buttonTitle,
cssClass: options.buttonColor,
callback: (function(_this) {
return function() {
if (options.callback) {
options.callback.call(_this);
}
return _this.emit('SignUpFormPosted');
};
})(this)
}
]
};
return formOptions;
};
/**
Returns form instance.
@export
@return {spark.components.Form}
*/
spark.widgets.SignUp.prototype.getForm = function() {
return this.form;
};