Created
August 25, 2011 00:41
-
-
Save SET001/1169674 to your computer and use it in GitHub Desktop.
login shit
This file contains hidden or 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
User = Backbone.Model.extend({ | |
login_attempts: 3, | |
login: function(){ | |
var that = this; | |
var res = null; | |
$.ajaxSetup({async:false}); | |
$.post(SITE_PATH + 'user/login', $('form#loginform').serialize(), function(data){ | |
try{ | |
res = $.parseJSON(data); | |
} | |
catch(e){ | |
--that.login_attempts; | |
res = false; | |
} | |
}); | |
return res; | |
} | |
}); | |
ApplicationView = Backbone.View.extend({ | |
_name: 'common', | |
_content: null, | |
_loginBarState: -1, | |
el: "body", | |
events:{ | |
"click a.login" : "popup_login", | |
"submit form#loginform": "login" | |
}, | |
initialize: function(){ | |
this.model.bind('reset', this.render); | |
}, | |
login: function(){ | |
var res = this.model.login(); | |
if(res){ | |
this.model = res; | |
} | |
else{ | |
if (this.model.login_attempts){ | |
$('#loginform span.error').html('Email or password incorrect!' + ' ' + this.model.login_attempts); | |
} | |
else this.trigger('remindpass'); | |
}; | |
return false; | |
}, | |
popup_login: function(){ | |
this._loginBarState = this._loginBarState*-1; | |
var height = $('header').height() + this._loginBarState*document.getElementById('login').offsetHeight + this._loginBarState*10; | |
$('header').animate( | |
{height: height}, | |
1000); | |
return false; | |
}, | |
render: function(){ | |
$(this.el).html($('#tmpl_' + this._name).tmpl({a: this.model})); | |
} | |
}); | |
Application = Backbone.Router.extend({ | |
_user: null, | |
_view: null, | |
_realty: null, | |
routes: { | |
"": "index", | |
"register": "register", | |
"remindpass": "remindpass" | |
}, | |
initialize: function(){ | |
try{ | |
this._user = new User(eval('('+$("#data_user").html()+')')); | |
} | |
catch(e){ | |
this._user = new User(); | |
} | |
this._view = new ApplicationView({model: this._user, router: this}); | |
this._view.bind('remindpass', this.remindpass); | |
this._view.render(); | |
this._realty = new Realty(); | |
this._realty.fetch({ | |
error: function(){console.log('fetching failed')} | |
}); | |
}, | |
index: function(){ | |
this._view._content = new StartPage({collection: this._realty}); | |
this._view._content.render(); | |
}, | |
register: function(){ | |
this._view._content = new RegisterPage(); | |
this._view._content.render(); | |
}, | |
remindpass: function(){ | |
console.log(this); | |
this._view._content = new RemindpassPage(); | |
this._view._content.render(); | |
} | |
}); | |
StartPage = PageView.extend({ | |
el: "#content", | |
_name: 'startpage', | |
initialize: function(){ | |
PageView.prototype.initialize(this); | |
_.bindAll(this, "render"); | |
this.collection.bind('reset', this.render); | |
}, | |
render: function(){ | |
$(this.el).html($('#tmpl_' + this._name).tmpl([{hotpisc: this.collection.models.slice(0, 3)}])); | |
this.renderMap(); | |
}, | |
renderMap: function(){ | |
// map | |
var myLatlng = new google.maps.LatLng(48.166085,14.017868); // TODO: how to find what possion should be here? | |
var myOptions = { | |
zoom: 8, | |
center: myLatlng, | |
mapTypeId: google.maps.MapTypeId.ROADMAP | |
} | |
var map = new google.maps.Map(document.getElementById("google_map"), myOptions); | |
// markers | |
this.collection.each(function(immo){ | |
var marker = new google.maps.Marker({ | |
position: new google.maps.LatLng(immo.get('latitude'), immo.get('longitude')), | |
map: map, | |
title: immo.get('name') | |
}); | |
}); | |
} | |
}); |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment