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) { this.updateLoginBtn(); } 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); window.localStorage.setItem("hello", null); Backbone.history.loadUrl(); }, backBtn: function (e) { e.preventDefault(); window.history.back(); }, fbLogin: function (e) { var self = this; e.preventDefault(); hello('facebook').login(); }, 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(); hello('google').login(); }, 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("#fblogin").removeClass("loginfb"); this.$el.find("#fblogin").addClass("logoutfb"); } if (Profile.isGPlusConnected()) { this.$el.find("#gpluslogin").show(); this.$el.find("#fblogin").hide(); this.$el.find("#gpluslogin").removeClass("logingplus"); this.$el.find("#gpluslogin").addClass("logoutgplus"); } } else { this.$el.find("#fblogin").removeClass("logoutfb"); this.$el.find("#fblogin").addClass("loginfb"); this.$el.find("#gpluslogin").removeClass("logoutgplus"); this.$el.find("#gpluslogin").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("Indietro"); 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; });