git-svn-id: https://msi/svn/firstRepo/WebClient/trunk@13 0f545695-f87b-41b6-9a03-7f16563b5454
This commit is contained in:
@@ -0,0 +1,164 @@
|
||||
define(['jquery', 'underscore', 'backbone','text!modules/sync/syncViewTemplate.html', 'modules/base/baseView', 'classes/profile'],
|
||||
function($, _, Backbone, syncViewTemplate, BaseView, Profile){
|
||||
|
||||
var SyncView = BaseView.extend({
|
||||
|
||||
//initialize template
|
||||
template:_.template(syncViewTemplate),
|
||||
|
||||
initialize: function (options) {
|
||||
SyncView.__super__.initialize.call(this);
|
||||
if(options &&
|
||||
options.tokenFound == 1)
|
||||
{
|
||||
if(window.localStorage.getItem("tryLogin")=="fb")
|
||||
{
|
||||
this.fbAfterLogin();
|
||||
}
|
||||
else if(window.localStorage.getItem("tryLogin")=="gplus")
|
||||
{
|
||||
this.gPlusAfterLogin();
|
||||
}
|
||||
}
|
||||
window.localStorage.setItem("tryLogin", null);
|
||||
},
|
||||
|
||||
events: {
|
||||
"click #backBtn": "backBtn",
|
||||
"click #fblogin": "fbLogin",
|
||||
"click #gpluslogin": "gplusLogin",
|
||||
"click #resetBtn": "resetBtn"
|
||||
},
|
||||
|
||||
resetBtn:function(e){
|
||||
e.preventDefault();
|
||||
Profile.setKeySave(null);
|
||||
Backbone.history.loadUrl();
|
||||
},
|
||||
|
||||
backBtn:function(e){
|
||||
e.preventDefault();
|
||||
window.history.back();
|
||||
},
|
||||
|
||||
fbLogin: function(e){
|
||||
var self = this;
|
||||
e.preventDefault();
|
||||
|
||||
if(!Profile.isConnected()) {
|
||||
window.localStorage.setItem("tryLogin", "fb");
|
||||
openFB.login('email');
|
||||
}
|
||||
else if(Profile.isConnected() && Profile.isFbConnected())
|
||||
openFB.revokePermissions(function(){
|
||||
Profile.setKeySave(null);
|
||||
self.updateLoginBtn();
|
||||
});
|
||||
},
|
||||
|
||||
fbAfterLogin: function()
|
||||
{
|
||||
var self = this;
|
||||
openFB.api({
|
||||
path: '/me',
|
||||
success: function (data) {
|
||||
Profile.internalLoadProfile(data.id, function(retVal){
|
||||
if(retVal == false)
|
||||
Profile.createProfile(
|
||||
data.id,
|
||||
"fb",
|
||||
data.name,
|
||||
data.email,
|
||||
data.gender,
|
||||
function(){
|
||||
//Backbone.history.loadUrl();
|
||||
});
|
||||
self.updateLoginBtn();
|
||||
});
|
||||
}});
|
||||
},
|
||||
|
||||
gplusLogin: function(e){
|
||||
var self = this;
|
||||
e.preventDefault();
|
||||
|
||||
if(!Profile.isConnected()) {
|
||||
window.localStorage.setItem("tryLogin", "gplus");
|
||||
openGPlus.login('email');
|
||||
}
|
||||
else if(Profile.isConnected() && Profile.isGPlusConnected())
|
||||
openGPlus.revokePermissions(function(){
|
||||
Profile.setKeySave(null);
|
||||
self.updateLoginBtn();
|
||||
});
|
||||
},
|
||||
|
||||
gPlusAfterLogin: function()
|
||||
{
|
||||
var self = this;
|
||||
openGPlus.api({
|
||||
path: 'people/me',
|
||||
success: function (data) {
|
||||
Profile.internalLoadProfile(data.id, function(retVal){
|
||||
if(retVal == false)
|
||||
Profile.createProfile(
|
||||
data.id,
|
||||
"gplus",
|
||||
data.displayName,
|
||||
data.emails[0].value,
|
||||
data.gender,
|
||||
function(){
|
||||
//Backbone.history.loadUrl();
|
||||
}
|
||||
);
|
||||
self.updateLoginBtn();
|
||||
});
|
||||
}});
|
||||
},
|
||||
|
||||
updateLoginBtn: function()
|
||||
{
|
||||
if(Profile.isConnected()) {
|
||||
if (Profile.isFbConnected()) {
|
||||
this.$el.find("#fblogin").show();
|
||||
this.$el.find("#gpluslogin").hide();
|
||||
this.$el.find("#loginFbImg").removeClass("loginfb");
|
||||
this.$el.find("#loginFbImg").addClass("logoutfb");
|
||||
}
|
||||
|
||||
if (Profile.isGPlusConnected()) {
|
||||
this.$el.find("#gpluslogin").show();
|
||||
this.$el.find("#fblogin").hide();
|
||||
this.$el.find("#loginGPlusImg").removeClass("logingplus");
|
||||
this.$el.find("#loginGPlusImg").addClass("logoutgplus");
|
||||
}
|
||||
}
|
||||
else
|
||||
{
|
||||
this.$el.find("#loginFbImg").removeClass("logoutfb");
|
||||
this.$el.find("#loginFbImg").addClass("loginfb");
|
||||
this.$el.find("#loginGPlusImg").removeClass("logoutgplus");
|
||||
this.$el.find("#loginGPlusImg").addClass("logingplus");
|
||||
}
|
||||
},
|
||||
|
||||
//render the content into div of view
|
||||
render: function(){
|
||||
var self = this;
|
||||
//this.header.title = "pippo";
|
||||
SyncView.__super__.render.call(this);
|
||||
|
||||
this.header.$el.append("<a id=\"backBtn\" href=\"\" data-role=\"button\" class=\"ui-btn-right\" data-icon=\"custom\">Indietro</a>");
|
||||
|
||||
this.$el.append(this.header.$el);
|
||||
this.$el.append(this.template( { app: myManifest }));
|
||||
this.$el.append(this.footer.$el);
|
||||
this.$el.find("#moreBtn").addClass("ui-btn-active");
|
||||
|
||||
this.updateLoginBtn();
|
||||
|
||||
return this;
|
||||
}
|
||||
});
|
||||
return SyncView;
|
||||
});
|
||||
Reference in New Issue
Block a user