git-svn-id: https://msi/svn/firstRepo/WebClient/branches/NewRelease@33 0f545695-f87b-41b6-9a03-7f16563b5454
This commit is contained in:
+199
-161
@@ -2,165 +2,183 @@
|
||||
* Created by Denis on 19/06/2014.
|
||||
*/
|
||||
define(['jquery', 'backbone'],
|
||||
function($, Backbone){
|
||||
function ($, Backbone) {
|
||||
|
||||
var Profile = {
|
||||
|
||||
_loadme:function(){
|
||||
if(this.isConnected()) {
|
||||
if (this.data.type == null)
|
||||
this.loadProfile();
|
||||
}
|
||||
return this;
|
||||
},
|
||||
|
||||
dataloaded: false,
|
||||
|
||||
data: {
|
||||
"name": null,
|
||||
"email": null,
|
||||
"gender":null,
|
||||
"tema": 'b',
|
||||
"risRic": '10',
|
||||
"type": null
|
||||
},
|
||||
|
||||
isConnected: function(){
|
||||
return this.getKeySave() != "null" &&
|
||||
this.getKeySave() != null &&
|
||||
this.getKeySave() != "undefined" &&
|
||||
this.getKeySave() != undefined;
|
||||
},
|
||||
|
||||
loadProfile:function(successFn) {
|
||||
this.internalLoadProfile(this.getKeySave(), successFn);
|
||||
},
|
||||
|
||||
internalLoadProfile:function(keyStore, successFn){
|
||||
if(this.dataloaded)
|
||||
return;
|
||||
//var keyStore = this.getKeySave();
|
||||
var self = this;
|
||||
var retBool = false;
|
||||
var resp = $.ajax({
|
||||
url: myManifest.Settings.DefaultURL + "/api/profile/" + keyStore,
|
||||
//dataType: "json",
|
||||
async: false,
|
||||
type: 'GET'
|
||||
}).responseText;
|
||||
|
||||
var response = JSON.parse(resp);
|
||||
if(response.length > 0)
|
||||
{
|
||||
self.dataloaded = true;
|
||||
self.setKeySave(keyStore);
|
||||
self.data.name = response[0].Name;
|
||||
self.data.gender = response[0].Gender;
|
||||
self.data.tema = response[0].TemaUI;
|
||||
self.data.risRic = response[0].RisultatiRicerca;
|
||||
self.data.type = response[0].TipoAccesso;
|
||||
retBool = true;
|
||||
}
|
||||
if(successFn)
|
||||
successFn(retBool);
|
||||
},
|
||||
|
||||
getKeySave: function(){
|
||||
return window.localStorage.getItem("KeySave");
|
||||
},
|
||||
setKeySave: function(val){
|
||||
window.localStorage.setItem("KeySave", val);
|
||||
},
|
||||
|
||||
isGPlusConnected: function(){
|
||||
if(this.data.type === "google")
|
||||
return true;
|
||||
return false;
|
||||
},
|
||||
isFbConnected: function(){
|
||||
if(this.data.type === "facebook")
|
||||
return true;
|
||||
return false;
|
||||
},
|
||||
|
||||
addRicettaBloccoNote: function(ricetta_id, successFn) {
|
||||
var sendobj = {
|
||||
"ricetta_id": ricetta_id,
|
||||
"keyStore": this.getKeySave()
|
||||
};
|
||||
|
||||
$.ajax({
|
||||
url: myManifest.Settings.DefaultURL + "/api/profile/ricetta",
|
||||
//dataType: "json",
|
||||
type: 'POST',
|
||||
data: { dataPair: JSON.stringify(sendobj) },
|
||||
success: function(msg){
|
||||
if(successFn)
|
||||
successFn(msg);
|
||||
var Profile = {
|
||||
_loadme: function () {
|
||||
this.data.name = this.getName();
|
||||
this.data.gender = this.getGender();
|
||||
if (this.isConnected()) {
|
||||
if (this.data.type == null)
|
||||
this.loadProfile();
|
||||
}
|
||||
});
|
||||
},
|
||||
|
||||
removeRicettaBloccoNote: function(ricetta_id, successFn) {
|
||||
$.ajax({
|
||||
url: myManifest.Settings.DefaultURL + "/api/profile/" + this.getKeySave() + "/ricetta/" + ricetta_id,
|
||||
//dataType: "json",
|
||||
type: 'DELETE',
|
||||
success: function(msg){
|
||||
if(successFn)
|
||||
successFn(msg);
|
||||
return this;
|
||||
},
|
||||
dataloaded: false,
|
||||
data: {
|
||||
"name": null,
|
||||
"email": null,
|
||||
"gender": null,
|
||||
"tema": 'd',
|
||||
"risRic": '10',
|
||||
"type": null,
|
||||
"picture": null
|
||||
},
|
||||
isConnected: function () {
|
||||
return this.getKeySave() != "null" &&
|
||||
this.getKeySave() != null &&
|
||||
this.getKeySave() != "undefined" &&
|
||||
this.getKeySave() != undefined;
|
||||
},
|
||||
setPictureEvent: null,
|
||||
setPicture: function (val) {
|
||||
this.data.picture = val;
|
||||
if (this.setPictureEvent)
|
||||
this.setPictureEvent(val);
|
||||
},
|
||||
loadProfile: function (successFn) {
|
||||
this._loadProfile(this.getKeySave(), successFn);
|
||||
},
|
||||
_loadProfile: function (keyStore, successFn) {
|
||||
if (this.dataloaded) {
|
||||
if (successFn)
|
||||
successFn(retBool);
|
||||
return;
|
||||
}
|
||||
});
|
||||
},
|
||||
//var keyStore = this.getKeySave();
|
||||
var self = this;
|
||||
var retBool = false;
|
||||
var resp = $.ajax({
|
||||
url: myManifest.Settings.DefaultURL + "/api/profile/" + keyStore,
|
||||
//dataType: "json",
|
||||
//async: false,
|
||||
type: 'GET',
|
||||
success: function (response) {
|
||||
if (response.length > 0)
|
||||
{
|
||||
self.dataloaded = true;
|
||||
self.data.name = response[0].Name;
|
||||
self.data.gender = response[0].Gender;
|
||||
self.data.tema = response[0].TemaUI;
|
||||
self.data.risRic = response[0].RisultatiRicerca;
|
||||
self.data.type = response[0].TipoAccesso;
|
||||
self.setKeySave(keyStore);
|
||||
self.setName(self.data.name);
|
||||
self.setGender(self.data.gender);
|
||||
retBool = true;
|
||||
|
||||
existRicettaBloccoNote: function(ricettaID, successFn){
|
||||
$.ajax({
|
||||
url: myManifest.Settings.DefaultURL + "/api/profile/" + this.getKeySave() + "/ricetta/" + ricettaID,
|
||||
//dataType: "json",
|
||||
type: 'GET',
|
||||
success: function(msg){
|
||||
if(successFn)
|
||||
successFn(msg);
|
||||
}
|
||||
});
|
||||
},
|
||||
switch (self.data.type)
|
||||
{
|
||||
case "facebook":
|
||||
img = "https://graph.facebook.com/" + keyStore + "/picture?type=normal";
|
||||
self.setPicture(img);
|
||||
break;
|
||||
case "google":
|
||||
var resp = $.ajax({
|
||||
url: "https://www.googleapis.com/plus/v1/people/" + keyStore + "?fields=image&key=" + myManifest.getGPublicApiKey(),
|
||||
//dataType: "json",
|
||||
//async: false,
|
||||
type: 'GET',
|
||||
success: function (resp) {
|
||||
self.setPicture(resp.image.url.replace("?sz=50", "?sz=150"));
|
||||
}
|
||||
});
|
||||
break;
|
||||
}
|
||||
}
|
||||
if (successFn)
|
||||
successFn(retBool);
|
||||
}
|
||||
});
|
||||
},
|
||||
_getVal: function (key) {
|
||||
return window.localStorage.getItem(key);
|
||||
},
|
||||
_setVal: function (key, val) {
|
||||
window.localStorage.setItem(key, val);
|
||||
},
|
||||
getKeySave: function () {
|
||||
return this._getVal("KeySave");
|
||||
},
|
||||
setKeySave: function (val) {
|
||||
this._setVal("KeySave", val);
|
||||
},
|
||||
getName: function () {
|
||||
return this._getVal("userName");
|
||||
},
|
||||
setName: function (val) {
|
||||
this._setVal("userName", val);
|
||||
},
|
||||
getGender: function () {
|
||||
return this._getVal("userGender");
|
||||
},
|
||||
setGender: function (val) {
|
||||
this._setVal("userGender", val);
|
||||
},
|
||||
isGPlusConnected: function () {
|
||||
if (this.data.type === "google")
|
||||
return true;
|
||||
return false;
|
||||
},
|
||||
isFbConnected: function () {
|
||||
if (this.data.type === "facebook")
|
||||
return true;
|
||||
return false;
|
||||
},
|
||||
addRicettaBloccoNote: function (ricetta_id, successFn) {
|
||||
var sendobj = {
|
||||
"ricetta_id": ricetta_id,
|
||||
"keyStore": this.getKeySave()
|
||||
};
|
||||
|
||||
createProfile: function(keyStore, typeProfile, name, email,gender, successFn) {
|
||||
this.data.type = typeProfile;
|
||||
this.data.name = name;
|
||||
this.data.email = email;
|
||||
this.data.gender = gender;
|
||||
this.setKeySave(keyStore);
|
||||
$.ajax({
|
||||
url: myManifest.Settings.DefaultURL + "/api/profile/ricetta",
|
||||
//dataType: "json",
|
||||
type: 'POST',
|
||||
data: {dataPair: JSON.stringify(sendobj)},
|
||||
success: function (msg) {
|
||||
if (successFn)
|
||||
successFn(msg);
|
||||
}
|
||||
});
|
||||
},
|
||||
removeRicettaBloccoNote: function (ricetta_id, successFn) {
|
||||
$.ajax({
|
||||
url: myManifest.Settings.DefaultURL + "/api/profile/" + this.getKeySave() + "/ricetta/" + ricetta_id,
|
||||
//dataType: "json",
|
||||
type: 'DELETE',
|
||||
success: function (msg) {
|
||||
if (successFn)
|
||||
successFn(msg);
|
||||
}
|
||||
});
|
||||
},
|
||||
existRicettaBloccoNote: function (ricettaID, successFn) {
|
||||
$.ajax({
|
||||
url: myManifest.Settings.DefaultURL + "/api/profile/" + this.getKeySave() + "/ricetta/" + ricettaID,
|
||||
//dataType: "json",
|
||||
type: 'GET',
|
||||
success: function (msg) {
|
||||
if (successFn)
|
||||
successFn(msg);
|
||||
}
|
||||
});
|
||||
},
|
||||
createProfile: function (keyStore, typeProfile, name, email, gender, successFn) {
|
||||
this.data.type = typeProfile;
|
||||
this.data.name = name;
|
||||
this.data.email = email;
|
||||
this.data.gender = gender;
|
||||
this.setKeySave(keyStore);
|
||||
|
||||
window.localStorage.removeItem("risRic");
|
||||
window.localStorage.removeItem("tema");
|
||||
window.localStorage.removeItem("risRic");
|
||||
window.localStorage.removeItem("tema");
|
||||
|
||||
var sendobj = {
|
||||
"keyStore": this.getKeySave(),
|
||||
"name": this.data.name,
|
||||
"email": this.data.email,
|
||||
"gender": this.data.gender,
|
||||
"tema": this.data.tema,
|
||||
"risRic": this.data.risRic,
|
||||
"type": this.data.type
|
||||
};
|
||||
|
||||
$.ajax({
|
||||
url: myManifest.Settings.DefaultURL + "/api/profile",
|
||||
//dataType: "json",
|
||||
type: 'POST',
|
||||
data: { dataPair: JSON.stringify(sendobj) },
|
||||
success: function(msg){
|
||||
if(successFn)
|
||||
successFn(msg);
|
||||
}
|
||||
});
|
||||
},
|
||||
|
||||
updateProfile: function(successFn) {
|
||||
if(this.isConnected()) {
|
||||
var sendobj = {
|
||||
"keyStore": this.getKeySave(),
|
||||
"name": this.data.name,
|
||||
"email": this.data.email,
|
||||
"gender": this.data.gender,
|
||||
"tema": this.data.tema,
|
||||
"risRic": this.data.risRic,
|
||||
"type": this.data.type
|
||||
@@ -169,20 +187,40 @@ define(['jquery', 'backbone'],
|
||||
$.ajax({
|
||||
url: myManifest.Settings.DefaultURL + "/api/profile",
|
||||
//dataType: "json",
|
||||
type: 'PUT',
|
||||
data: { dataPair: JSON.stringify(sendobj) },
|
||||
type: 'POST',
|
||||
data: {dataPair: JSON.stringify(sendobj)},
|
||||
success: function (msg) {
|
||||
if (successFn)
|
||||
successFn(msg);
|
||||
}
|
||||
});
|
||||
},
|
||||
updateProfile: function (successFn) {
|
||||
if (this.isConnected()) {
|
||||
var sendobj = {
|
||||
"keyStore": this.getKeySave(),
|
||||
"tema": this.data.tema,
|
||||
"risRic": this.data.risRic,
|
||||
"type": this.data.type
|
||||
};
|
||||
|
||||
$.ajax({
|
||||
url: myManifest.Settings.DefaultURL + "/api/profile",
|
||||
//dataType: "json",
|
||||
type: 'PUT',
|
||||
data: {dataPair: JSON.stringify(sendobj)},
|
||||
success: function (msg) {
|
||||
if (successFn)
|
||||
successFn(msg);
|
||||
}
|
||||
});
|
||||
}
|
||||
else
|
||||
{
|
||||
window.localStorage.setItem("risRic", this.data.risRic);
|
||||
window.localStorage.setItem("tema", this.data.tema);
|
||||
}
|
||||
}
|
||||
else
|
||||
{
|
||||
window.localStorage.setItem("risRic", this.data.risRic);
|
||||
window.localStorage.setItem("tema", this.data.tema);
|
||||
}
|
||||
}
|
||||
};
|
||||
return Profile._loadme();
|
||||
});
|
||||
};
|
||||
return Profile._loadme();
|
||||
});
|
||||
Reference in New Issue
Block a user