Guest User

Untitled

a guest
Oct 3rd, 2018
132
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
text 1.38 KB | None | 0 0
  1. window.User = Backbone.Model.extend({
  2. urlRoot: "../api/login",
  3. idAttribute: "userID",
  4. defaults: {
  5. username: "",
  6. password: "",
  7. },
  8. validate: function(attrs) {
  9. if (attrs.username == "" || attrs.password == "") {
  10. return {responseText: "empty values are not allowed"};
  11. }
  12. },
  13. initialize: function() {
  14. this.on("error", function(model, error) {
  15. alert(error.responseText);
  16. });
  17. }
  18. });
  19.  
  20. window.LoginView = Backbone.View.extend({
  21. events:{
  22. "click #logbut": "login"
  23. },
  24. template: _.template($('#login-temp').html()),
  25. render: function(eventName) {
  26. $(this.el).html(this.template());
  27. return this;
  28. },
  29. login: function () {
  30. //Només heu d'implementar això!
  31. },
  32. change: function() {
  33. app.loginView.remove();
  34. console.log("Login successful. UserID = "+app.loggedUser.id);
  35. app.logoutView = new LogoutView({model: app.loggedUser});
  36. $('.topBar').html(app.logoutView.render().el);
  37. app.newTweetView = new TweetView();
  38. $('#newTweet').html(app.newTweetView.render().el);
  39. }
  40. });
  41.  
  42. window.LogoutView = Backbone.View.extend({
  43. events:{
  44. "click #logoutbut": "logout"
  45. },
  46. template: _.template($('#logout-temp').html()),
  47. render: function(eventName) {
  48. $(this.el).html(this.template(this.model.toJSON()));
  49. return this;
  50. },
  51. logout: function () {
  52. this.model = null;
  53. this.loginView = new LoginView();
  54. $('.topBar').html(this.loginView.render().el);
  55. app.newTweetView.remove();
  56. }
  57. });
Add Comment
Please, Sign In to add comment