From d0d55ee8e56b5725082d6d0c36253969b24721ed Mon Sep 17 00:00:00 2001 From: hexstudy Date: Sun, 25 Jan 2015 13:57:37 +0000 Subject: [PATCH] git-svn-id: https://msi/svn/firstRepo/WebClient/branches/Manut_2.2.3@25 0f545695-f87b-41b6-9a03-7f16563b5454 --- build.cmd | 2 +- css/_star.png | Bin 0 -> 2856 bytes index.php | 16 +- js/app.js | 85 ++++-- js/classes/cache.js | 66 ++++ js/classes/cachedCollection.js | 54 ++++ js/classes/profile.js | 4 +- js/common.min.js | 3 + js/libs/hello.min.js | 2 + js/manifest.js | 6 +- js/model/category/categoryCollection.js | 25 +- .../categoryItem/categoryItemCollection.js | 7 +- js/modules/category/category.js | 122 ++++---- js/modules/sync/sync.js | 287 ++++++++---------- js/router.js | 6 +- nbproject/private/private.xml | 16 +- sitemap.php | 63 ++++ sitemap.xml | 15 + test.php | 30 ++ 19 files changed, 517 insertions(+), 292 deletions(-) create mode 100644 css/_star.png create mode 100644 js/classes/cache.js create mode 100644 js/classes/cachedCollection.js create mode 100644 js/common.min.js create mode 100644 js/libs/hello.min.js create mode 100644 sitemap.php create mode 100644 sitemap.xml create mode 100644 test.php diff --git a/build.cmd b/build.cmd index 444874f..afe61f5 100644 --- a/build.cmd +++ b/build.cmd @@ -1,4 +1,4 @@ -call uglifyjs .\js\openfb.js .\js\opengplus.js .\js\libs\ua-parser.min.js -o .\js\common.min.js +call uglifyjs .\js\libs\hello.min.js .\js\libs\ua-parser.min.js -o .\js\common.min.js REM node r.js -o app.build_dev.js node r.js -o app.build_prod.js REM call cleancss -o .\css\loadingStyle.min.css .\css\loadingStyle.css diff --git a/css/_star.png b/css/_star.png new file mode 100644 index 0000000000000000000000000000000000000000..b0c5942f781814d081bfadd01f989e7b8c7343c6 GIT binary patch literal 2856 zcmX9=2|U!>7a!Rt`!>Qzvd54uTgvil#t^3HJPbRf!G4%2d-hy zo?!eLfw^NdY@@I~c*aV7{rIJ&-eop-9Y0J?tSML_8-H-OCMG7jC=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jquery','underscore', 'backbone', 'router', 'classes/profile'],function -($, _, Backbone,Router, Profile) { - 'use strict'; - var init=function(){ +define(['jquery', 'underscore', 'backbone', 'router', 'classes/profile', 'classes/cache'], function + ($, _, Backbone, Router, Profile, Cache) { + 'use strict'; + var init = function () { //create backbone router - var router=new Router(); + var router = new Router(); Backbone.history.start(); Backbone.emulateJSON = true; - var origin = location.protocol + '//' + location.hostname + (location.port ? ':' + location.port : '') + (location.pathname?location.pathname:''); - openFB.init('1466942266882168', origin, window.localStorage); - openGPlus.init('319140243944-qk0lfhgmi8shi4go97r83l69f1k0gdf4.apps.googleusercontent.com', origin, window.localStorage); - //console.log("Backbone history start"); - // Trigger 'route' event on router instance. - router.on('route', function(name, args) { - //alert(name); - }); - if( Profile.isConnected()) { + 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(); } + hello.on('auth.login', function (auth) { + if (!Profile.isConnected()) + { + hello(auth.network).api("me").then(function (json) { + var id = ""; + var displayName = ""; + var email = ""; + var gender = ""; + + if (auth.network === "google") + { + id = json.id; + displayName = json.displayName; + email = json.email; + gender = json.gender; + } + else if (auth.network === "facebook") + { + id = json.id; + displayName = json.name; + email = json.email; + gender = json.gender; + } + Profile.internalLoadProfile(id, function(retVal){ + if(retVal === false) + { + Profile.createProfile( + id, + auth.network, + displayName, + email, + gender, + function () { + window.location.href = "#syncView/tokenFound"; + } + ); + } + else + window.location.href = "#syncView/tokenFound"; + }); + }); + } + }); + $('body').css('background-color', ''); $('#loadingFrm').remove(); - }; - - return { - initialize:init + }; + + return { + initialize: init }; }); \ No newline at end of file diff --git a/js/classes/cache.js b/js/classes/cache.js new file mode 100644 index 0000000..c703ecc --- /dev/null +++ b/js/classes/cache.js @@ -0,0 +1,66 @@ +/* + * To change this license header, choose License Headers in Project Properties. + * To change this template file, choose Tools | Templates + * and open the template in the editor. + */ + +define(['jquery', 'backbone'], + function ($, Backbone) { + + var Cache = { + convertToDate: function (mysql_string) + { + if (typeof mysql_string === 'string') + { + var t = mysql_string.split(/[- :]/); + + //when t[3], t[4] and t[5] are missing they defaults to zero + return new Date(t[0], t[1] - 1, t[2], t[3] || 0, t[4] || 0, t[5] || 0); + } + + return null; + }, + prefix: "cacheItem", + get: function (name) { + var item = window.localStorage.getItem(this.prefix + name); + if(item === null) + return null; + item = JSON.parse(item); + return item.storeValue; + }, + set: function (name, value) { + window.localStorage.setItem(this.prefix + name, JSON.stringify({setTime: new Date(), storeValue: value})); + }, + isExpired: function (name, timeDiff) { + var item = window.localStorage.getItem(this.prefix + name); + if(item === null) + return true; + + item = JSON.parse(item); + var time = item.setTime; + if(timeDiff.getTime() > Date.parse(time)) + return true; + return false; + }, + checkCacheFromServer: function () + { + var self = this; + $.ajax({ + url: myManifest.Settings.DefaultURL + "/api/profile/statusCache", + //dataType: "json", + type: 'GET', + success: function (msg) { + $(msg).each(function (index, element) { + var elemName = "Category" + element.ID_CATEGORIA; + if (self.isExpired(elemName, self.convertToDate(element.LastDateModified))) + { + self.set(elemName, null); + } + }); + } + }); + } + }; + + return Cache; + }); \ No newline at end of file diff --git a/js/classes/cachedCollection.js b/js/classes/cachedCollection.js new file mode 100644 index 0000000..3ab0865 --- /dev/null +++ b/js/classes/cachedCollection.js @@ -0,0 +1,54 @@ +/* + * To change this license header, choose License Headers in Project Properties. + * To change this template file, choose Tools | Templates + * and open the template in the editor. + */ + +define(['jquery', 'underscore', 'backbone', 'classes/cache'], + function ($, _, Backbone, Cache) { + + var CachedCollection = Backbone.Collection.extend({ + cacheName: null, + fetch: function (options) { + options = _.defaults(options || {}, {parse: true}); + var deferred = new $.Deferred(), + self = this; + + var cachedItem = Cache.get(this.cacheName); + + if (cachedItem !== null) + { + window.setTimeout(function () { + self[options.reset ? 'reset' : 'set'](false, options); + deferred.resolve(cachedItem); + self.push(cachedItem); + self.trigger('sync', self, false, options); + if (_.isFunction(options.success)) { + options.success(self, false, options); + } + return deferred; + }, 0); + } + else + { + // Delegate to the actual fetch method and store the attributes in the cache + var jqXHR = Backbone.Collection.prototype.fetch.apply(this, arguments); + // resolve the returned promise when the AJAX call completes + jqXHR.done(_.bind(deferred.resolve, this, this)) + // Set the new data in the cache + .done(_.bind( + function (a, b, c) { + Cache.set(self.cacheName, a); + } + , null, this, options)) + // Reject the promise on fail + .fail(_.bind(deferred.reject, this, this)); + + deferred.abort = jqXHR.abort; + // return a promise which provides the same methods as a jqXHR object + return deferred; + } + } + }); + return CachedCollection; + }); diff --git a/js/classes/profile.js b/js/classes/profile.js index 5ecb682..0ce5b68 100644 --- a/js/classes/profile.js +++ b/js/classes/profile.js @@ -73,12 +73,12 @@ define(['jquery', 'backbone'], }, isGPlusConnected: function(){ - if(this.data.type == "gplus") + if(this.data.type === "google") return true; return false; }, isFbConnected: function(){ - if(this.data.type == "fb") + if(this.data.type === "facebook") return true; return false; }, diff --git a/js/common.min.js b/js/common.min.js new file mode 100644 index 0000000..7afff58 --- /dev/null +++ b/js/common.min.js @@ -0,0 +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('