211:4b03f725cb69
Anton Shestakov <av6@dwimlabs.net>, Thu, 07 Jul 2016 00:12:35 +0800
provision: update tasks to use more YAMLy syntax

next change 247:fcca53a2f523
previous change 169:4cebef28d40b

js/forms.js

Permissions: -rw-r--r--

Other formats: Feeds:
// Generated by CoffeeScript 1.10.0
(function() {
var extend = function(child, parent) { for (var key in parent) { if (hasProp.call(parent, key)) child[key] = parent[key]; } function ctor() { this.constructor = child; } ctor.prototype = parent.prototype; child.prototype = new ctor(); child.__super__ = parent.prototype; return child; },
hasProp = {}.hasOwnProperty;
Tram.RegistrationForm = (function(superClass) {
extend(RegistrationForm, superClass);
function RegistrationForm() {
return RegistrationForm.__super__.constructor.apply(this, arguments);
}
RegistrationForm.prototype.defaults = {
username: '',
password1: '',
password2: ''
};
RegistrationForm.prototype.validate = function(attrs, options) {
var ref, ref1, ref2, ref3, ref4;
this.unset('username-errors');
this.unset('password1-errors');
this.unset('password2-errors');
if (((ref = attrs.username) != null ? ref : '').trim() === '') {
this.set('username-errors', ['This field is required.']);
}
if (((ref1 = attrs.password1) != null ? ref1 : '') === '') {
this.set('password1-errors', ['This field is required.']);
}
if (((ref2 = attrs.password1) != null ? ref2 : '') !== ((ref3 = attrs.password2) != null ? ref3 : '')) {
this.set('password2-errors', ['Passwords must match.']);
} else if (((ref4 = attrs.password2) != null ? ref4 : '') === '') {
this.set('password2-errors', ['This field is required.']);
}
return this.has('username-errors') || this.has('password1-errors') || this.has('password2-errors');
};
return RegistrationForm;
})(Backbone.Model);
Tram.ProfileForm = (function(superClass) {
extend(ProfileForm, superClass);
function ProfileForm() {
return ProfileForm.__super__.constructor.apply(this, arguments);
}
ProfileForm.prototype.defaults = {
fullname: '',
nickname: '',
avatar: ''
};
ProfileForm.prototype.validate = function(attrs, options) {
var ae, file;
this.unset('avatar-errors');
ae = [];
file = $('#avatar').get(0).files[0];
if (file != null) {
if (file.type.match('image/.*') == null) {
ae.push("File doesn't look like an image.");
}
if (file.size > 64 * 1024) {
ae.push('File is too big.');
}
}
if (ae.length > 0) {
this.set('avatar-errors', ae);
}
return this.has('avatar-errors');
};
return ProfileForm;
})(Backbone.Model);
Tram.ConnectionForm = (function(superClass) {
extend(ConnectionForm, superClass);
function ConnectionForm() {
return ConnectionForm.__super__.constructor.apply(this, arguments);
}
ConnectionForm.prototype.defaults = {
username: '',
password: ''
};
ConnectionForm.prototype.validate = function(attrs, options) {
var ref, ref1;
this.unset('username-errors');
this.unset('password-errors');
this.unset('auth-errors');
if (((ref = attrs.username) != null ? ref : '').trim() === '') {
this.set('username-errors', ['This field is required.']);
}
if (((ref1 = attrs.password) != null ? ref1 : '') === '') {
this.set('password-errors', ['This field is required.']);
}
return this.has('username-errors') || this.has('password-errors');
};
return ConnectionForm;
})(Backbone.Model);
$.fn.streamline = function() {
return this.each(function() {
var $form;
$form = $(this);
return $form.find('input').on('keydown', function(e) {
var $next, index;
if ((!this.required || this.value !== '') && e.keyCode === 13) {
e.preventDefault();
index = $form.find('input').index(this);
$next = $form.find('input').eq(index + 1);
if ($next.length !== 0) {
return $next.focus();
} else {
return $form.find('button').trigger('click');
}
}
});
});
};
}).call(this);
//# sourceMappingURL=forms.js.map