Guest User

Untitled

a guest
Jan 23rd, 2018
114
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
text 3.20 KB | None | 0 0
  1. User = Backbone.Model.extend({
  2. login_attempts: 3,
  3.  
  4. login: function(){
  5. var that = this;
  6. var res = null;
  7. $.ajaxSetup({async:false});
  8. $.post(SITE_PATH + 'user/login', $('form#loginform').serialize(), function(data){
  9. try{
  10. res = $.parseJSON(data);
  11. }
  12. catch(e){
  13. --that.login_attempts;
  14. res = false;
  15. }
  16. });
  17. return res;
  18. }
  19. });
  20.  
  21.  
  22. ApplicationView = Backbone.View.extend({
  23. _name: 'common',
  24. _content: null,
  25. _loginBarState: -1,
  26. el: "body",
  27.  
  28. events:{
  29. "click a.login" : "popup_login",
  30. "submit form#loginform": "login"
  31. },
  32.  
  33. initialize: function(){
  34. this.model.bind('reset', this.render);
  35. },
  36.  
  37. login: function(){
  38. var res = this.model.login();
  39. if(res){
  40. this.model = res;
  41. }
  42. else{
  43. if (this.model.login_attempts){
  44. $('#loginform span.error').html('Email or password incorrect!' + ' ' + this.model.login_attempts);
  45. }
  46. else this.trigger('remindpass');
  47. };
  48.  
  49. return false;
  50. },
  51.  
  52. popup_login: function(){
  53. this._loginBarState = this._loginBarState*-1;
  54. var height = $('header').height() + this._loginBarState*document.getElementById('login').offsetHeight + this._loginBarState*10;
  55. $('header').animate(
  56. {height: height},
  57. 1000);
  58. return false;
  59. },
  60.  
  61. render: function(){
  62. $(this.el).html($('#tmpl_' + this._name).tmpl({a: this.model}));
  63. }
  64. });
  65.  
  66.  
  67. Application = Backbone.Router.extend({
  68. _user: null,
  69. _view: null,
  70. _realty: null,
  71.  
  72. routes: {
  73. "": "index",
  74. "register": "register",
  75. "remindpass": "remindpass"
  76. },
  77.  
  78. initialize: function(){
  79. try{
  80. this._user = new User(eval('('+$("#data_user").html()+')'));
  81. }
  82. catch(e){
  83. this._user = new User();
  84. }
  85. this._view = new ApplicationView({model: this._user, router: this});
  86. this._view.bind('remindpass', this.remindpass);
  87. this._view.render();
  88.  
  89. this._realty = new Realty();
  90. this._realty.fetch({
  91. error: function(){console.log('fetching failed')}
  92. });
  93. },
  94.  
  95. index: function(){
  96. this._view._content = new StartPage({collection: this._realty});
  97. this._view._content.render();
  98. },
  99.  
  100. register: function(){
  101. this._view._content = new RegisterPage();
  102. this._view._content.render();
  103. },
  104.  
  105. remindpass: function(){
  106. console.log(this);
  107. this._view._content = new RemindpassPage();
  108. this._view._content.render();
  109. }
  110.  
  111. });
  112.  
  113. StartPage = PageView.extend({
  114. el: "#content",
  115. _name: 'startpage',
  116.  
  117. initialize: function(){
  118.  
  119. PageView.prototype.initialize(this);
  120.  
  121.  
  122. _.bindAll(this, "render");
  123. this.collection.bind('reset', this.render);
  124. },
  125.  
  126. render: function(){
  127. $(this.el).html($('#tmpl_' + this._name).tmpl([{hotpisc: this.collection.models.slice(0, 3)}]));
  128. this.renderMap();
  129. },
  130.  
  131. renderMap: function(){
  132. // map
  133. var myLatlng = new google.maps.LatLng(48.166085,14.017868); // TODO: how to find what possion should be here?
  134. var myOptions = {
  135. zoom: 8,
  136. center: myLatlng,
  137. mapTypeId: google.maps.MapTypeId.ROADMAP
  138. }
  139. var map = new google.maps.Map(document.getElementById("google_map"), myOptions);
  140. // markers
  141. this.collection.each(function(immo){
  142. var marker = new google.maps.Marker({
  143. position: new google.maps.LatLng(immo.get('latitude'), immo.get('longitude')),
  144. map: map,
  145. title: immo.get('name')
  146. });
  147. });
  148. }
  149. });
Add Comment
Please, Sign In to add comment