Advertisement
Not a member of Pastebin yet?
Sign Up,
it unlocks many cool features!
- (function() {
- var base,
- bind = function(fn, me){ return function(){ return fn.apply(me, arguments); }; },
- 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;
- (base = Swap.Views).UserSessions || (base.UserSessions = {});
- Swap.Views.UserSessions.LoginView = (function(superClass) {
- extend(LoginView, superClass);
- function LoginView() {
- this.onClose = bind(this.onClose, this);
- this.onShow = bind(this.onShow, this);
- return LoginView.__super__.constructor.apply(this, arguments);
- }
- LoginView.prototype.template = JST["backbone/templates/user_sessions/login"];
- LoginView.prototype.className = 'modal fade hide';
- LoginView.prototype.id = 'login';
- LoginView.prototype.attributes = {
- tabindex: '-1',
- role: 'dialog'
- };
- LoginView.prototype.events = {
- 'submit form': 'login',
- 'click .eyes': 'togglePassword',
- 'focusin input': 'clearError'
- };
- LoginView.prototype.bindings = {
- "input#user_email": "email",
- "input#user_password": "password",
- "input[type='email'], input[type='password'], input[type='text']": {
- attributes: [
- {
- name: 'class',
- observe: 'error',
- onGet: function(val) {
- if (val && !_.isEmpty(val)) {
- return 'error';
- }
- }
- }
- ]
- },
- '.error_message': {
- observe: 'error',
- onGet: function(val) {
- if (val && !_.isEmpty(val)) {
- return val;
- }
- }
- }
- };
- LoginView.prototype.render = function() {
- this.model = new Swap.Models.UserSession();
- $('.modal').modal('hide');
- this.$el.html(this.template());
- this.$el.on('shown.bs.modal', this.onShow);
- this.$el.on('hidden.bs.modal', this.onClose);
- this.stickit();
- this.$el.modal({
- keyboard: false,
- backdrop: true
- });
- return this;
- };
- LoginView.prototype.onShow = function(e) {
- return this.$el.find('a, span, i, div').tooltip();
- };
- LoginView.prototype.login = function(e) {
- if (e) {
- e.preventDefault();
- }
- return this.model.save(this.model.attributes, {
- success: (function(_this) {
- return function(userSession, response) {
- var csrf;
- csrf = _.pick(response, 'csrf_token', 'csrf_param');
- if (_.has(csrf, 'csrf_token')) {
- $('meta[name="csrf-token"]').attr('content', response.csrf_token);
- }
- Swap.currentUser = new Swap.Models.User(_.omit(response, 'csrf_token', 'csrf_param'));
- Swap.vent.trigger('authentication:logged_in');
- _this.$el.modal('hide');
- };
- })(this),
- error: (function(_this) {
- return function(userSession, response) {
- var result;
- result = $.parseJSON(response.responseText);
- _this.model.set(result);
- };
- })(this)
- });
- };
- LoginView.prototype.onClose = function(e) {
- var view;
- view = this;
- return setTimeout((function() {
- view.$el.modal('hide');
- view.remove();
- }), 25);
- };
- LoginView.prototype.togglePassword = function(e) {
- if ($('input#user_password').prop('type') === 'password') {
- return $('input#user_password').prop('type', 'text');
- } else {
- return $('input#user_password').prop('type', 'password');
- }
- };
- LoginView.prototype.clearError = function(e) {
- var block, input, message;
- input = $(e.target);
- if (input.hasClass('error')) {
- block = input.closest('form');
- if (block.length > 0) {
- message = block.find('.error_message');
- }
- if (message) {
- return message.fadeOut('slow', (function(_this) {
- return function() {
- message.html();
- message.show();
- return _this.model.set({
- error: {}
- });
- };
- })(this));
- }
- }
- };
- return LoginView;
- })(Backbone.View);
- }).call(this);
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement