Not a member of Pastebin yet?
Sign Up,
it unlocks many cool features!
- window.User = Backbone.Model.extend({
- urlRoot: "../api/login",
- idAttribute: "userID",
- defaults: {
- username: "",
- password: "",
- },
- validate: function(attrs) {
- if (attrs.username == "" || attrs.password == "") {
- return {responseText: "empty values are not allowed"};
- }
- },
- initialize: function() {
- this.on("error", function(model, error) {
- alert(error.responseText);
- });
- }
- });
- window.LoginView = Backbone.View.extend({
- events:{
- "click #logbut": "login"
- },
- template: _.template($('#login-temp').html()),
- render: function(eventName) {
- $(this.el).html(this.template());
- return this;
- },
- login: function () {
- //Només heu d'implementar això!
- },
- change: function() {
- app.loginView.remove();
- console.log("Login successful. UserID = "+app.loggedUser.id);
- app.logoutView = new LogoutView({model: app.loggedUser});
- $('.topBar').html(app.logoutView.render().el);
- app.newTweetView = new TweetView();
- $('#newTweet').html(app.newTweetView.render().el);
- }
- });
- window.LogoutView = Backbone.View.extend({
- events:{
- "click #logoutbut": "logout"
- },
- template: _.template($('#logout-temp').html()),
- render: function(eventName) {
- $(this.el).html(this.template(this.model.toJSON()));
- return this;
- },
- logout: function () {
- this.model = null;
- this.loginView = new LoginView();
- $('.topBar').html(this.loginView.render().el);
- app.newTweetView.remove();
- }
- });
Add Comment
Please, Sign In to add comment