Last active
August 29, 2015 14:04
-
-
Save jarrettmeyer/bcfa0548bda0b5543e12 to your computer and use it in GitHub Desktop.
Login View Example
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
LoginService = (function () { | |
function LoginService() { | |
if (!$) { | |
throw Error("jQuery is not defined!"); | |
} | |
} | |
LoginService.prototype.login = function (data, callback) { | |
$.post("/login", function(result) { | |
if (result.isValid) { | |
callback(null, result); | |
} else { | |
callback({ message: "Invalid credentials!" }, result); | |
} | |
}); | |
}; | |
return LoginService; | |
}).call(this); |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
LoginView = (function () { | |
function LoginView() { | |
this.initializeBindings(); | |
this.loginService = new LoginService(); | |
} | |
LoginView.prototype.initializeBindings = function () { | |
$("#login-button").on("click", function () { | |
this.login(); | |
}.bind(this)); | |
}; | |
LoginView.prototype.login = function () { | |
var data = getLoginData(); | |
this.loginService.login(function (error, result) { | |
}); | |
}; | |
function getLoginData() { | |
return { | |
username: $("#username").val(), | |
password: $("#password").val() | |
}; | |
} | |
return LoginView; | |
}).call(this); |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment