From eaf2c8d0f45914e5468a41da65204a3bb63674b8 Mon Sep 17 00:00:00 2001 From: Benjamin Renard Date: Sun, 12 Jan 2014 03:05:14 +0100 Subject: [PATCH] Manage local data loading error --- inc/myco_objects.js | 25 ++++++++++++++++++++----- 1 file changed, 20 insertions(+), 5 deletions(-) diff --git a/inc/myco_objects.js b/inc/myco_objects.js index 626f5a1..e97910c 100644 --- a/inc/myco_objects.js +++ b/inc/myco_objects.js @@ -3,11 +3,26 @@ function GroupList() { lastChange=0; this.loadFromLocalStorage=function() { - if (localStorage.groups!==undefined) { - var data=JSON.parse(localStorage.groups); - this.lastChange=data.lastChange; - for (el in data.groups) { - this[el]=new Group(el,data.groups[el]); + if (jQuery.type(localStorage.groups)!='undefined') { + try { + var data=JSON.parse(localStorage.groups); + this.lastChange=data.lastChange; + for (el in data.groups) { + this[el]=new Group(el,data.groups[el]); + } + } + catch(e) { + for (el in this) { + if (this.isGroup(this[el])) { + delete this[el]; + } + } + myconfirm('Erreur en chargeant les données locales. On les purges ?', + function(data) { + delete localStorage.groups; + location.reload(); + } + ); } } }