-
-
Caricamento...
+
+
Il Lievitario
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+ Il Lievitario
+ ...Caricamento in corso...
+
-
-
+
\ No newline at end of file
diff --git a/js/app.js b/js/app.js
index 73dbf3b..950d9c9 100644
--- a/js/app.js
+++ b/js/app.js
@@ -1,25 +1,28 @@
-define(['jquery', 'underscore', 'backbone', 'router', 'classes/profile', 'classes/cache'], function
- ($, _, Backbone, Router, Profile, Cache) {
+define(['jquery', 'underscore', 'backbone', 'router', 'classes/profile', 'classes/cache', 'libs/fastclick'], function
+ ($, _, Backbone, Router, Profile, Cache, FastClick) {
'use strict';
var init = function () {
//create backbone router
var router = new Router();
+
Backbone.history.start();
Backbone.emulateJSON = true;
+
hello.init({
facebook: '1466942266882168',
google: '319140243944-qk0lfhgmi8shi4go97r83l69f1k0gdf4.apps.googleusercontent.com'
}, {display: 'page', scope: 'email'});
+
//console.log("Backbone history start");
// Trigger 'route' event on router instance.
router.on('route', function (name, args) {
//alert(name);
});
-
+
Cache.checkCacheFromServer();
-
+
if (Profile.isConnected()) {
Profile.loadProfile();
}
@@ -47,22 +50,22 @@ define(['jquery', 'underscore', 'backbone', 'router', 'classes/profile', 'classe
email = json.email;
gender = json.gender;
}
- Profile.internalLoadProfile(id, function(retVal){
- if(retVal === false)
+ Profile._loadProfile(id, function (retVal) {
+ if (retVal === false)
{
Profile.createProfile(
- id,
- auth.network,
- displayName,
- email,
- gender,
- function () {
- window.location.href = "#syncView/tokenFound";
- }
+ id,
+ auth.network,
+ displayName,
+ email,
+ gender,
+ function () {
+ window.location.href = "";
+ }
);
}
else
- window.location.href = "#syncView/tokenFound";
+ window.location.href = "";
});
});
}
diff --git a/js/classes/cachedCollection.js b/js/classes/cachedCollection.js
index 3ab0865..36a7fa8 100644
--- a/js/classes/cachedCollection.js
+++ b/js/classes/cachedCollection.js
@@ -20,12 +20,15 @@ define(['jquery', 'underscore', 'backbone', 'classes/cache'],
{
window.setTimeout(function () {
self[options.reset ? 'reset' : 'set'](false, options);
- deferred.resolve(cachedItem);
+ //deferred.resolve(cachedItem);
+
+ deferred.notify(self);
self.push(cachedItem);
- self.trigger('sync', self, false, options);
if (_.isFunction(options.success)) {
options.success(self, false, options);
- }
+ }
+ deferred.resolve(cachedItem);
+ self.trigger('sync', self, false, options);
return deferred;
}, 0);
}
@@ -48,6 +51,11 @@ define(['jquery', 'underscore', 'backbone', 'classes/cache'],
// return a promise which provides the same methods as a jqXHR object
return deferred;
}
+ },
+ isCached: function () {
+ var cachedItem = Cache.get(this.cacheName);
+
+ return (cachedItem !== null);
}
});
return CachedCollection;
diff --git a/js/classes/profile.js b/js/classes/profile.js
index 0ce5b68..c8b5148 100644
--- a/js/classes/profile.js
+++ b/js/classes/profile.js
@@ -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();
- });
\ No newline at end of file
+ };
+ return Profile._loadme();
+ });
\ No newline at end of file
diff --git a/js/common.min.js b/js/common.min.js
index 7afff58..2036336 100644
--- a/js/common.min.js
+++ b/js/common.min.js
@@ -1,3 +1,3 @@
-var hello=function(e){return hello.use(e)};hello.utils={extend:function(e){for(var t=Array.prototype.slice.call(arguments,1),n=0;n
(new Date).getTime()/1e3){var f=t.diff(c.scope||[],n.qs.state.scope||[]);if(0===f.length)return e.emitAfter("complete success login",{unchanged:!0,network:n.network,authResponse:c}),e}if("page"===i.display&&i.page_uri&&(n.qs.state.page_uri=t.url(i.page_uri).href),"login"in a&&"function"==typeof a.login&&a.login(n),("token"!==u||parseInt(a.oauth.version,10)<2||"none"===i.display&&a.oauth.grant&&c&&c.refresh_token)&&(n.qs.state.oauth=a.oauth,n.qs.state.oauth_proxy=i.oauth_proxy),n.qs.state=JSON.stringify(n.qs.state),1===parseInt(a.oauth.version,10)?o=t.qs(i.oauth_proxy,n.qs):"none"===i.display&&a.oauth.grant&&c&&c.refresh_token?(n.qs.refresh_token=c.refresh_token,o=t.qs(i.oauth_proxy,n.qs)):o=t.qs(a.oauth.auth,n.qs),e.emit("notice","Authorization URL "+o),"none"===i.display)t.iframe(o);else if("popup"===i.display)var p=t.popup(o,l,i.window_width||500,i.window_height||550),m=setInterval(function(){if((!p||p.closed)&&(clearInterval(m),!r)){var t={code:"cancelled",message:"Login has been cancelled"};p||(t={code:"blocked",message:"Popup was blocked"}),e.emit("complete failed error",{error:t,network:n.network})}},100);else window.location=o;return e},logout:function(){var e=this.use(),t=e.utils,n=t.args({name:"s",options:"o",callback:"f"},arguments);if(n.options=n.options||{},e.on("complete",n.callback),n.name=n.name||e.settings.default_service,!n.name||n.name in e.services)if(n.name&&t.store(n.name)){var o=function(t){e.utils.store(n.name,""),e.emitAfter("complete logout success auth.logout auth",hello.utils.merge({network:n.name},t||{}))},i={};if(n.options.force){var a=e.services[n.name].logout;if(a)if("function"==typeof a&&(a=a(o)),"string"==typeof a)t.iframe(a),i.force=null,i.message="Logout success on providers site was indeterminate";else if(void 0===a)return e}o(i)}else if(n.name)e.emitAfter("complete error",{error:{code:"invalid_session",message:"There was no session to remove"}});else{for(var r in e.services)e.services.hasOwnProperty(r)&&e.logout(r);e.service(!1)}else e.emitAfter("complete error",{error:{code:"invalid_network",message:"The network was unrecognized"}});return e},getAuthResponse:function(e){return e=e||this.settings.default_service,e&&e in this.services?this.utils.store(e)||null:(this.emit("complete error",{error:{code:"invalid_network",message:"The network was unrecognized"}}),null)},events:{}}),hello.utils.extend(hello.utils,{qs:function(e,t){if(t){var n;for(var o in t)if(e.indexOf(o)>-1){var i="[\\?\\&]"+o+"=[^\\&]*";n=new RegExp(i),e=e.replace(n,"")}}return e+(this.isEmpty(t)?"":(e.indexOf("?")>-1?"&":"?")+this.param(t))},param:function(e){var t,n,o={};if("string"==typeof e){if(n=e.replace(/^[\#\?]/,"").match(/([^=\/\&]+)=([^\&]+)/g))for(var i=0;i-1&&"string"===i||e[a].indexOf("o")>-1&&"object"===i||e[a].indexOf("i")>-1&&"number"===i||e[a].indexOf("a")>-1&&"object"===i||e[a].indexOf("f")>-1&&"function"===i))n[a]=t[o++];else if("string"==typeof e[a]&&e[a].indexOf("!")>-1)return!1;return n},url:function(e){if(e){if(window.URL&&URL instanceof Function&&0!==URL.length)return new URL(e,window.location);var t=document.createElement("a");return t.href=e,t}return window.location},diff:function(e,t){for(var n=[],o=0;o0)return!1;if(e&&0===e.length)return!0;for(var t in e)if(e.hasOwnProperty(t))return!1;return!0},objectCreate:function(){function e(){}return Object.create?Object.create:function(t){if(1!=arguments.length)throw new Error("Object.create implementation only accepts one parameter.");return e.prototype=t,new e}}(),Event:function(){var e=/[\s\,]+/;return this.parent={events:this.events,findEvents:this.findEvents,parent:this.parent,utils:this.utils},this.events={},this.on=function(t,n){if(n&&"function"==typeof n)for(var o=t.split(e),i=0;i-1)for(var a=0;a0&&u.append(l,o[l].files[0]):o[l]instanceof Blob?u.append(l,o[l],o.name):u.append(l,o[l]));o=u}if(r.open(e,t,!0),s&&("responseType"in r?r.responseType=s:r.overrideMimeType("text/plain; charset=x-user-defined")),n)for(l in n)r.setRequestHeader(l,n[l]);return r.send(o),r},jsonp:function(e,t,n,o){var i,a,r=this,s=0,l=document.getElementsByTagName("head")[0],u={error:{message:"server_error",code:"server_error"}},c=function(){s++||window.setTimeout(function(){t(u),l.removeChild(a)},0)};n=r.globalEvent(function(e){return u=e,!0},n),e=e.replace(new RegExp("=\\?(&|$)"),"="+n+"$1"),a=r.append("script",{id:n,name:n,src:e,async:!0,onload:c,onerror:c,onreadystatechange:function(){/loaded|complete/i.test(this.readyState)&&c()}}),window.navigator.userAgent.toLowerCase().indexOf("opera")>-1&&(i=r.append("script",{text:"document.getElementById('"+cb_name+"').onerror();"}),a.async=!1),o&&window.setTimeout(function(){u={error:{message:"timeout",code:"timeout"}},c()},o),l.appendChild(a),i&&l.appendChild(i)},post:function(e,t,n,o,i,a){var r,s=this,l=document,u=null,c=[],d=0,f=null,p=0,m=function(e){p++||o(e)};s.globalEvent(m,i);var h;try{h=l.createElement('