2016-09-08 01:23:15 +02:00
|
|
|
|
|
|
|
|
|
|
|
function SCaseList() {
|
|
|
|
lastChange=0;
|
|
|
|
|
|
|
|
this.importExampleData=function() {
|
|
|
|
var exampleData={
|
|
|
|
'Vacances': {
|
|
|
|
'Papier': {
|
|
|
|
'color': '#f00',
|
2017-09-17 19:43:57 +02:00
|
|
|
'things': [
|
|
|
|
{'label': 'Papier blanc', 'nb': 1 },
|
|
|
|
{'label': 'Stylo', 'nb': 3 },
|
|
|
|
{'label': "Carte d'identité", 'nb': 1 },
|
|
|
|
]
|
2016-09-08 01:23:15 +02:00
|
|
|
},
|
|
|
|
'Multimédia' : {
|
|
|
|
'color': '#0f0',
|
2017-09-17 19:43:57 +02:00
|
|
|
'things': [
|
|
|
|
{'label': 'Montre', 'nb': 1 },
|
|
|
|
{'label': 'Chargeur montre', 'nb': 1 },
|
|
|
|
{'label': 'PC portable', 'nb': 1 },
|
|
|
|
]
|
2016-09-08 01:23:15 +02:00
|
|
|
}
|
|
|
|
}
|
|
|
|
};
|
|
|
|
for (scaseName in exampleData) {
|
|
|
|
var scase=this.newSCase(scaseName);
|
|
|
|
for (catName in exampleData[scaseName]) {
|
|
|
|
var cat=scase.cats.newCat(catName);
|
|
|
|
for (idx in exampleData[scaseName][catName].things) {
|
2017-09-17 19:43:57 +02:00
|
|
|
cat.newThing(exampleData[scaseName][catName].things[idx]['label'],exampleData[scaseName][catName].things[idx]['nb']);
|
2016-09-06 01:12:46 +02:00
|
|
|
}
|
|
|
|
}
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
2024-09-21 17:07:52 +02:00
|
|
|
this.loadFromLocalStorage=function(data) {
|
2016-09-06 01:12:46 +02:00
|
|
|
if (jQuery.type(localStorage.scases)!='undefined') {
|
|
|
|
try {
|
2024-09-21 17:07:52 +02:00
|
|
|
return this.loadFromJsonData(JSON.parse(localStorage.scases));
|
2016-09-06 01:12:46 +02:00
|
|
|
}
|
|
|
|
catch(e) {
|
2024-09-21 17:07:52 +02:00
|
|
|
return false;
|
2016-09-06 01:12:46 +02:00
|
|
|
}
|
|
|
|
}
|
2024-09-21 17:07:52 +02:00
|
|
|
return null;
|
|
|
|
}
|
|
|
|
|
|
|
|
this.loadFromJsonData=function(data) {
|
|
|
|
try {
|
|
|
|
this.lastChange=data.lastChange;
|
|
|
|
for (el in data.scases) {
|
|
|
|
this[el]=new SCase(false,false,data.scases[el]);
|
|
|
|
}
|
|
|
|
return true;
|
|
|
|
}
|
|
|
|
catch(e) {
|
|
|
|
for (el in this) {
|
|
|
|
if (this.isSCase(this[el])) {
|
|
|
|
delete this[el];
|
|
|
|
}
|
|
|
|
}
|
2016-09-06 01:12:46 +02:00
|
|
|
}
|
2024-09-21 17:07:52 +02:00
|
|
|
return false;
|
2016-09-06 01:12:46 +02:00
|
|
|
}
|
|
|
|
|
|
|
|
this.export=function() {
|
|
|
|
return {
|
|
|
|
'lastChange': this.lastChange,
|
|
|
|
'scases': this.each(function(idx,scase) {
|
|
|
|
return scase.export();
|
|
|
|
})
|
|
|
|
};
|
|
|
|
}
|
|
|
|
|
|
|
|
this.import=function(data) {
|
|
|
|
ret={};
|
|
|
|
for (el in this) {
|
|
|
|
if (this.isSCase(this[el])) {
|
|
|
|
delete ret[el];
|
|
|
|
}
|
|
|
|
}
|
|
|
|
this.lastChange=data.lastChange;
|
|
|
|
for (el in data.scases) {
|
2016-09-08 01:23:15 +02:00
|
|
|
this[el]=new SCase(false,false,data.scases[el]);
|
2016-09-06 01:12:46 +02:00
|
|
|
}
|
|
|
|
return true;
|
|
|
|
}
|
|
|
|
|
|
|
|
this.save=function() {
|
|
|
|
localStorage.scases=JSON.stringify(this.export());
|
|
|
|
}
|
|
|
|
|
|
|
|
this.each=function(fct) {
|
|
|
|
var idx=0;
|
|
|
|
var ret={};
|
|
|
|
for (el in this) {
|
|
|
|
if(this.isSCase(this[el])) {
|
|
|
|
ret[el]=fct(idx++,this[el]);
|
|
|
|
}
|
|
|
|
}
|
|
|
|
return ret;
|
|
|
|
}
|
|
|
|
|
|
|
|
this.count=function() {
|
|
|
|
len=0;
|
|
|
|
this.each(function(idx,scase) {
|
|
|
|
len=len+1;
|
|
|
|
});
|
|
|
|
return len;
|
|
|
|
}
|
|
|
|
|
|
|
|
this.isSCase=function(el) {
|
|
|
|
return (jQuery.type(el)=='object' && jQuery.type(el.isSCase)=='function' && el.isSCase());
|
|
|
|
}
|
|
|
|
|
|
|
|
this.byName=function(name) {
|
|
|
|
for (el in this) {
|
|
|
|
if(this.isSCase(this[el])) {
|
|
|
|
if (this[el].name==name) {
|
|
|
|
return this[el];
|
|
|
|
}
|
|
|
|
}
|
|
|
|
}
|
|
|
|
return false;
|
|
|
|
}
|
|
|
|
|
2024-09-21 17:07:52 +02:00
|
|
|
this.byUUID=function(uuid) {
|
|
|
|
return this.isCase(this[uuid]) ? this[uuid] : null;
|
|
|
|
}
|
|
|
|
|
2016-09-06 01:12:46 +02:00
|
|
|
this.removeSCase=function(name) {
|
|
|
|
for (el in this) {
|
|
|
|
if (this.isSCase(this[el]) && this[el].name==name) {
|
2017-09-17 18:55:25 +02:00
|
|
|
this[el].remove();
|
2016-09-06 01:12:46 +02:00
|
|
|
return true;
|
|
|
|
}
|
|
|
|
}
|
|
|
|
return false;
|
|
|
|
}
|
|
|
|
|
|
|
|
this.newSCase=function(name) {
|
2017-09-17 18:55:25 +02:00
|
|
|
if (this.byName(this[name])) {
|
|
|
|
var scase=this.byName(name);
|
|
|
|
if (scase.removed) {
|
|
|
|
scase.restore();
|
|
|
|
return true;
|
|
|
|
}
|
|
|
|
|
|
|
|
}
|
|
|
|
else {
|
2016-09-08 01:23:15 +02:00
|
|
|
var uuid=uuid||generate_uuid();
|
|
|
|
this[uuid]=new SCase(uuid,name);
|
|
|
|
return this[uuid];
|
2016-09-06 01:12:46 +02:00
|
|
|
}
|
|
|
|
return false;
|
|
|
|
}
|
|
|
|
|
|
|
|
this.renameSCase=function(name,newname) {
|
|
|
|
var scase=this.byName(name);
|
|
|
|
if (scase && !this.byName(newname)) {
|
|
|
|
scase.name=newname;
|
2016-09-08 01:23:15 +02:00
|
|
|
scase.lastChange=new Date().getTime();
|
2016-09-06 01:12:46 +02:00
|
|
|
return scase;
|
|
|
|
}
|
|
|
|
return false;
|
|
|
|
}
|
|
|
|
|
|
|
|
this.copySCase=function(name,newname) {
|
|
|
|
var orig_scase=this.byName(name);
|
|
|
|
if (this.isSCase(orig_scase) && !this.byName(newname)) {
|
2016-09-08 01:23:15 +02:00
|
|
|
var uuid=uuid||generate_uuid();
|
|
|
|
this[uuid]=new SCase(false,false,orig_scase.export());
|
|
|
|
this[uuid].uuid=uuid;
|
|
|
|
this[uuid].lastChange=new Date().getTime();
|
|
|
|
this[uuid].name=newname;
|
|
|
|
return this[uuid];
|
2016-09-06 01:12:46 +02:00
|
|
|
}
|
|
|
|
return false;
|
|
|
|
}
|
|
|
|
|
2016-09-07 00:30:25 +02:00
|
|
|
this.resetSCase=function(name) {
|
|
|
|
for (el in this) {
|
|
|
|
if (this.isSCase(this[el]) && this[el].name==name) {
|
|
|
|
return this[el].reset();
|
|
|
|
}
|
|
|
|
}
|
|
|
|
return false;
|
|
|
|
}
|
2016-09-06 01:12:46 +02:00
|
|
|
}
|
|
|
|
|
2016-09-08 01:23:15 +02:00
|
|
|
function SCase(uuid,name,data) {
|
|
|
|
this.uuid=uuid||generate_uuid();
|
2016-09-06 01:12:46 +02:00
|
|
|
this.name=name;
|
|
|
|
this.cats=new CatList();
|
2016-09-08 01:23:15 +02:00
|
|
|
this.lastChange=new Date().getTime();
|
2017-09-17 18:55:25 +02:00
|
|
|
this.removed=false;
|
2016-09-06 01:12:46 +02:00
|
|
|
|
|
|
|
this.isSCase=function() {
|
|
|
|
return true;
|
|
|
|
}
|
|
|
|
|
2016-09-08 01:23:15 +02:00
|
|
|
this.import=function(data) {
|
|
|
|
this.uuid=data.uuid || generate_uuid();
|
|
|
|
this.lastChange=data.lastChange || new Date().getTime();
|
|
|
|
this.name=decodeURIComponent(data.name);
|
2017-09-17 18:55:25 +02:00
|
|
|
this.removed=data.removed||false;
|
2016-09-08 01:23:15 +02:00
|
|
|
if (jQuery.type(data.cats) == 'object') {
|
|
|
|
this.cats=new CatList(data.cats);
|
|
|
|
}
|
|
|
|
return true;
|
|
|
|
}
|
|
|
|
|
2016-09-06 01:12:46 +02:00
|
|
|
this.export=function() {
|
|
|
|
return {
|
2016-09-08 01:23:15 +02:00
|
|
|
'uuid': this.uuid,
|
|
|
|
'lastChange': this.lastChange,
|
2016-09-06 01:12:46 +02:00
|
|
|
'name': encodeURIComponent(this.name),
|
2017-09-17 18:55:25 +02:00
|
|
|
'removed': this.removed,
|
2016-09-06 01:12:46 +02:00
|
|
|
'cats': this.cats.export()
|
|
|
|
};
|
|
|
|
}
|
|
|
|
|
|
|
|
this.byName=function(name) {
|
|
|
|
for (idx in this.cats) {
|
|
|
|
if (name==this.cats[idx].name) {
|
|
|
|
return this.cats[idx];
|
|
|
|
}
|
|
|
|
}
|
|
|
|
return false;
|
|
|
|
}
|
|
|
|
|
2016-09-07 19:06:11 +02:00
|
|
|
this.stats=function() {
|
|
|
|
var cats=0;
|
|
|
|
var things=0;
|
|
|
|
var things_done=0;
|
|
|
|
this.cats.each(function(cidx,cat) {
|
2018-06-18 13:49:42 +02:00
|
|
|
if (cat.removed) {
|
|
|
|
return true;
|
|
|
|
}
|
2016-09-07 19:06:11 +02:00
|
|
|
cats++;
|
|
|
|
for (idx in cat.things) {
|
2018-06-18 13:49:42 +02:00
|
|
|
if (cat.things[idx].removed) {
|
|
|
|
continue;
|
|
|
|
}
|
2016-09-07 19:06:11 +02:00
|
|
|
things++;
|
|
|
|
if (cat.things[idx].checked) {
|
|
|
|
things_done++;
|
|
|
|
}
|
|
|
|
}
|
|
|
|
});
|
|
|
|
return {
|
|
|
|
'cats': cats,
|
|
|
|
'things': things,
|
|
|
|
'done': things_done
|
|
|
|
}
|
2016-09-06 01:12:46 +02:00
|
|
|
}
|
|
|
|
|
2016-09-07 00:30:25 +02:00
|
|
|
this.reset=function() {
|
|
|
|
this.cats.each(function(idx,cat) {
|
|
|
|
for (idx in cat.things) {
|
|
|
|
if (cat.things[idx].checked) {
|
|
|
|
cat.things[idx].checked=false;
|
|
|
|
}
|
|
|
|
}
|
|
|
|
});
|
2016-09-08 01:23:15 +02:00
|
|
|
this.lastChange=new Date().getTime();
|
2016-09-07 00:30:25 +02:00
|
|
|
return true;
|
|
|
|
}
|
|
|
|
|
2017-09-17 18:55:25 +02:00
|
|
|
this.remove=function() {
|
|
|
|
this.removed=true;
|
|
|
|
this.lastChange=new Date().getTime();
|
|
|
|
}
|
|
|
|
|
|
|
|
this.restore=function() {
|
|
|
|
this.removed=false;
|
|
|
|
this.lastChange=new Date().getTime();
|
|
|
|
}
|
|
|
|
|
2016-09-06 01:12:46 +02:00
|
|
|
/*
|
|
|
|
* Contructor
|
|
|
|
*/
|
|
|
|
if (jQuery.type(data)=='object') {
|
|
|
|
try {
|
2016-09-08 01:23:15 +02:00
|
|
|
this.import(data);
|
2016-09-06 01:12:46 +02:00
|
|
|
}
|
|
|
|
catch (e) {
|
|
|
|
console.log(e);
|
|
|
|
alert('Une erreur est survenue en chargeant la valise '+this.name+' depuis le cache');
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
|
|
function CatList(data) {
|
|
|
|
this.export=function() {
|
2016-09-08 01:23:15 +02:00
|
|
|
return this.each(function(idx,cat) {
|
|
|
|
return cat.export();
|
|
|
|
});
|
2016-09-06 01:12:46 +02:00
|
|
|
}
|
|
|
|
|
|
|
|
this.import=function(data) {
|
|
|
|
for (el in this) {
|
|
|
|
if (this.isCat(this[el])) {
|
|
|
|
delete this[el];
|
|
|
|
}
|
|
|
|
}
|
2016-09-08 01:23:15 +02:00
|
|
|
for (el in data) {
|
|
|
|
this[el]=new Cat(el,false,false,data[el]);
|
2016-09-06 01:12:46 +02:00
|
|
|
}
|
|
|
|
return true;
|
|
|
|
}
|
|
|
|
|
|
|
|
this.each=function(fct) {
|
|
|
|
var idx=0;
|
|
|
|
var ret={};
|
|
|
|
for (el in this) {
|
|
|
|
if(this.isCat(this[el])) {
|
|
|
|
ret[el]=fct(idx++,this[el]);
|
|
|
|
}
|
|
|
|
}
|
|
|
|
return ret;
|
|
|
|
}
|
|
|
|
|
|
|
|
this.count=function() {
|
|
|
|
len=0;
|
|
|
|
this.each(function(idx,cat) {
|
|
|
|
len=len+1;
|
|
|
|
});
|
|
|
|
return len;
|
|
|
|
}
|
|
|
|
|
|
|
|
this.isCat=function(el) {
|
|
|
|
return (jQuery.type(el)=='object' && jQuery.type(el.isCat)=='function' && el.isCat());
|
|
|
|
}
|
|
|
|
|
|
|
|
this.byName=function(name) {
|
|
|
|
for (el in this) {
|
|
|
|
if(this.isCat(this[el])) {
|
|
|
|
if (this[el].name==name) {
|
|
|
|
return this[el];
|
|
|
|
}
|
|
|
|
}
|
|
|
|
}
|
|
|
|
return false;
|
|
|
|
}
|
|
|
|
|
2024-09-21 17:07:52 +02:00
|
|
|
this.byUUID=function(uuid) {
|
|
|
|
return this.isCas(this[uuid]) ? this[uuid] : null;
|
|
|
|
}
|
|
|
|
|
2016-09-06 01:12:46 +02:00
|
|
|
this.newCat=function(name) {
|
2017-09-17 18:55:25 +02:00
|
|
|
if (this.byName(name)) {
|
|
|
|
var cat=this.byName(name);
|
|
|
|
if (cat.removed) {
|
|
|
|
cat.restore();
|
|
|
|
return true;
|
|
|
|
}
|
|
|
|
}
|
|
|
|
else {
|
2016-09-08 01:23:15 +02:00
|
|
|
var uuid=uuid||generate_uuid();
|
|
|
|
this[uuid]=new Cat(uuid,name);
|
|
|
|
return this[uuid];
|
2016-09-06 01:12:46 +02:00
|
|
|
}
|
|
|
|
return false;
|
|
|
|
}
|
|
|
|
|
|
|
|
this.renameCat=function(name,newname) {
|
|
|
|
var cat=this.byName(name);
|
|
|
|
if (cat && !this.byName(newname)) {
|
|
|
|
cat.name=newname;
|
2016-09-08 01:23:15 +02:00
|
|
|
cat.lastChange=new Date().getTime();
|
2016-09-06 01:12:46 +02:00
|
|
|
return cat;
|
|
|
|
}
|
|
|
|
return false;
|
|
|
|
}
|
|
|
|
|
|
|
|
this.removeCat=function(name) {
|
|
|
|
for (el in this) {
|
|
|
|
if (this.isCat(this[el]) && this[el].name==name) {
|
2017-09-17 18:55:25 +02:00
|
|
|
this[el].remove();
|
2016-09-06 01:12:46 +02:00
|
|
|
return true;
|
|
|
|
}
|
|
|
|
}
|
|
|
|
return false;
|
|
|
|
}
|
|
|
|
|
2017-09-17 18:55:25 +02:00
|
|
|
this.restoreCat=function(name) {
|
|
|
|
for (el in this) {
|
|
|
|
if (this.isCat(this[el]) && this[el].name==name && this[el].removed) {
|
|
|
|
this[el].restore();
|
|
|
|
return true;
|
|
|
|
}
|
|
|
|
}
|
|
|
|
return false;
|
|
|
|
}
|
2016-09-06 01:12:46 +02:00
|
|
|
|
|
|
|
|
|
|
|
/*
|
|
|
|
* Contructor
|
|
|
|
*/
|
|
|
|
if (jQuery.type(data)=='object') {
|
|
|
|
try {
|
|
|
|
this.import(data);
|
|
|
|
}
|
|
|
|
catch (e) {
|
|
|
|
console.log(e);
|
|
|
|
alert('Une erreur est survenue en chargeant la liste de catégorie depuis le cache');
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
|
|
|
}
|
|
|
|
|
2016-09-08 01:23:15 +02:00
|
|
|
function Cat(uuid,name,color,data) {
|
|
|
|
this.uuid=generate_uuid();
|
|
|
|
this.lastChange=new Date().getTime();
|
2016-09-06 01:12:46 +02:00
|
|
|
this.name=name;
|
|
|
|
this.color=color || '#'+(0x1000000+(Math.random())*0xffffff).toString(16).substr(1,6);
|
2016-09-08 01:23:15 +02:00
|
|
|
this.things={};
|
2017-09-17 18:55:25 +02:00
|
|
|
this.removed=false;
|
2016-09-06 01:12:46 +02:00
|
|
|
|
|
|
|
this.isCat=function() {
|
|
|
|
return true;
|
|
|
|
}
|
|
|
|
|
2016-09-08 01:23:15 +02:00
|
|
|
this.import=function(data) {
|
|
|
|
this.uuid=data.uuid || generate_uuid();
|
|
|
|
this.lastChange=data.lastChange||new Date().getTime();
|
|
|
|
this.name=decodeURIComponent(data.name);
|
|
|
|
this.color=data.color;
|
2017-09-17 18:55:25 +02:00
|
|
|
this.removed=data.removed||false;
|
2016-09-08 01:23:15 +02:00
|
|
|
if (jQuery.type(data.things) == 'object') {
|
|
|
|
for (tuuid in data.things) {
|
|
|
|
this.things[tuuid]=new Thing(tuuid);
|
|
|
|
this.things[tuuid].import(data.things[tuuid]);
|
|
|
|
}
|
|
|
|
}
|
|
|
|
return true;
|
|
|
|
}
|
|
|
|
|
2016-09-06 01:12:46 +02:00
|
|
|
this.export=function() {
|
2016-09-08 01:23:15 +02:00
|
|
|
var things={};
|
|
|
|
for (tuuid in this.things) {
|
|
|
|
things[tuuid]=this.things[tuuid].export();
|
2016-09-06 01:12:46 +02:00
|
|
|
}
|
|
|
|
return {
|
2016-09-08 01:23:15 +02:00
|
|
|
'uuid': this.uuid,
|
|
|
|
'lastChange': this.lastChange,
|
2016-09-06 01:12:46 +02:00
|
|
|
'name': encodeURIComponent(this.name),
|
|
|
|
'color': this.color,
|
2017-09-17 18:55:25 +02:00
|
|
|
'removed': this.removed,
|
2016-09-06 01:12:46 +02:00
|
|
|
'things': things
|
|
|
|
};
|
|
|
|
}
|
|
|
|
|
|
|
|
this.byLabel=function(label) {
|
|
|
|
for (idx in this.things) {
|
|
|
|
if (label==this.things[idx].label) {
|
|
|
|
return this.things[idx];
|
|
|
|
}
|
|
|
|
}
|
|
|
|
return false;
|
|
|
|
}
|
|
|
|
|
|
|
|
this.count=function() {
|
2016-09-08 01:23:15 +02:00
|
|
|
return keys(this.things).length;
|
2016-09-06 01:12:46 +02:00
|
|
|
}
|
|
|
|
|
2016-09-08 01:23:15 +02:00
|
|
|
this.stats=function() {
|
2016-09-06 01:12:46 +02:00
|
|
|
var count=0;
|
2016-09-08 01:23:15 +02:00
|
|
|
var done=0;
|
2016-09-06 01:12:46 +02:00
|
|
|
for (idx in this.things) {
|
2018-06-18 13:49:42 +02:00
|
|
|
if (this.things[idx].removed) {
|
|
|
|
continue;
|
|
|
|
}
|
2016-09-06 01:12:46 +02:00
|
|
|
if (this.things[idx].checked) {
|
2016-09-08 01:23:15 +02:00
|
|
|
done+=1;
|
2016-09-06 01:12:46 +02:00
|
|
|
}
|
2016-09-08 01:23:15 +02:00
|
|
|
count+=1;
|
2016-09-06 01:12:46 +02:00
|
|
|
}
|
2016-09-08 01:23:15 +02:00
|
|
|
return {
|
|
|
|
'things': count,
|
|
|
|
'done': done
|
|
|
|
};
|
|
|
|
}
|
|
|
|
|
2017-09-17 19:43:57 +02:00
|
|
|
this.newThing=function(label,nb) {
|
2017-09-17 18:55:25 +02:00
|
|
|
if (this.byLabel(label)) {
|
|
|
|
var thing=this.byLabel(label);
|
|
|
|
if (thing.removed) {
|
|
|
|
thing.restore();
|
|
|
|
thing.setChecked(false);
|
2017-09-17 19:43:57 +02:00
|
|
|
thing.setNb(nb);
|
2017-09-17 18:55:25 +02:00
|
|
|
return true;
|
|
|
|
}
|
|
|
|
}
|
|
|
|
else {
|
2016-09-08 01:23:15 +02:00
|
|
|
var uuid=generate_uuid();
|
2017-09-17 19:43:57 +02:00
|
|
|
this.things[uuid]=new Thing(uuid,label,nb);
|
2016-09-08 01:23:15 +02:00
|
|
|
return true;
|
|
|
|
}
|
|
|
|
return false;
|
2016-09-06 01:12:46 +02:00
|
|
|
}
|
|
|
|
|
|
|
|
this.renameThing=function(label,newlabel) {
|
|
|
|
var thing=this.byLabel(label);
|
|
|
|
if (thing && !this.byLabel(newlabel)) {
|
|
|
|
thing.label=newlabel;
|
2016-09-08 01:23:15 +02:00
|
|
|
thing.lastChange=new Date().getTime();
|
2016-09-06 01:12:46 +02:00
|
|
|
return thing;
|
|
|
|
}
|
|
|
|
return false;
|
|
|
|
}
|
|
|
|
|
|
|
|
this.removeThing=function(label) {
|
|
|
|
for (idx in this.things) {
|
|
|
|
if (this.things[idx].label==label) {
|
2017-09-17 18:55:25 +02:00
|
|
|
this.things[idx].remove();
|
|
|
|
return true;
|
|
|
|
}
|
|
|
|
}
|
|
|
|
return false;
|
|
|
|
}
|
|
|
|
|
|
|
|
this.restoreThing=function(label) {
|
|
|
|
for (idx in this.things) {
|
|
|
|
if (this.things[idx].label==label && this.things[idx].removed) {
|
|
|
|
this.things[idx].restore();
|
2016-09-06 01:12:46 +02:00
|
|
|
return true;
|
|
|
|
}
|
|
|
|
}
|
|
|
|
return false;
|
|
|
|
}
|
|
|
|
|
2017-09-17 18:55:25 +02:00
|
|
|
this.remove=function() {
|
|
|
|
this.removed=true;
|
|
|
|
this.lastChange=new Date().getTime();
|
|
|
|
}
|
|
|
|
|
|
|
|
this.restore=function() {
|
|
|
|
this.removed=false;
|
|
|
|
this.lastChange=new Date().getTime();
|
|
|
|
}
|
|
|
|
|
|
|
|
|
2016-09-06 01:12:46 +02:00
|
|
|
/*
|
|
|
|
* Contructor
|
|
|
|
*/
|
|
|
|
if (jQuery.type(data)=='object') {
|
|
|
|
try {
|
2016-09-08 01:23:15 +02:00
|
|
|
this.import(data);
|
2016-09-06 01:12:46 +02:00
|
|
|
}
|
|
|
|
catch (e) {
|
|
|
|
console.log(e);
|
|
|
|
alert('Une erreur est survenue en chargeant la catégorie catégorie '+this.name+' depuis le cache');
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
|
|
|
}
|
|
|
|
|
2017-09-17 19:43:57 +02:00
|
|
|
function Thing(uuid,label,nb,checked) {
|
2016-09-08 01:23:15 +02:00
|
|
|
this.uuid=uuid||generate_uuid();
|
|
|
|
this.lastChange=new Date().getTime();
|
2016-09-06 01:12:46 +02:00
|
|
|
this.label=label;
|
2017-09-17 19:43:57 +02:00
|
|
|
this.nb=nb || 1;
|
2016-09-06 01:12:46 +02:00
|
|
|
this.checked=checked;
|
2017-09-17 18:55:25 +02:00
|
|
|
this.removed=false;
|
2016-09-08 01:23:15 +02:00
|
|
|
|
|
|
|
this.import=function(data) {
|
|
|
|
this.uuid=data.uuid||generate_uuid();
|
|
|
|
this.lastChange=data.lastChange||new Date().getTime();
|
|
|
|
this.label=decodeURIComponent(data.label),
|
2017-09-17 19:43:57 +02:00
|
|
|
this.nb=data.nb||1;
|
2016-09-08 01:23:15 +02:00
|
|
|
this.checked=data.checked;
|
2017-09-17 18:55:25 +02:00
|
|
|
this.removed=data.removed||false;
|
2016-09-08 01:23:15 +02:00
|
|
|
}
|
|
|
|
|
2016-09-06 01:12:46 +02:00
|
|
|
this.export=function() {
|
|
|
|
return {
|
2016-09-08 01:23:15 +02:00
|
|
|
'uuid': this.uuid,
|
|
|
|
'lastChange': this.lastChange,
|
2016-09-06 01:12:46 +02:00
|
|
|
'label': encodeURIComponent(this.label),
|
2017-09-17 19:43:57 +02:00
|
|
|
'nb': this.nb,
|
2017-09-17 18:55:25 +02:00
|
|
|
'checked': this.checked,
|
|
|
|
'removed': this.removed,
|
2016-09-06 01:12:46 +02:00
|
|
|
};
|
|
|
|
}
|
2016-09-08 01:23:15 +02:00
|
|
|
|
2017-09-17 19:43:57 +02:00
|
|
|
this.setNb=function(nb) {
|
|
|
|
this.nb=nb;
|
|
|
|
this.lastChange=new Date().getTime();
|
|
|
|
}
|
|
|
|
|
2016-09-08 01:23:15 +02:00
|
|
|
this.setChecked=function(value) {
|
|
|
|
this.checked=value;
|
|
|
|
this.lastChange=new Date().getTime();
|
2024-09-21 17:07:52 +02:00
|
|
|
console.log(`Thing<${this.uuid}>.setChecked(${this.checked}): ${this.lastChange}`);
|
2016-09-08 01:23:15 +02:00
|
|
|
}
|
2017-09-17 18:55:25 +02:00
|
|
|
|
|
|
|
this.remove=function() {
|
|
|
|
this.removed=true;
|
|
|
|
this.lastChange=new Date().getTime();
|
|
|
|
}
|
|
|
|
|
|
|
|
this.restore=function() {
|
|
|
|
this.removed=false;
|
|
|
|
this.lastChange=new Date().getTime();
|
|
|
|
}
|
2016-09-06 01:12:46 +02:00
|
|
|
}
|
2024-09-21 17:07:52 +02:00
|
|
|
|
|
|
|
function User() {
|
|
|
|
this.username = null;
|
|
|
|
this.name = null;
|
|
|
|
this.token = null;
|
|
|
|
this.loadFromLocalStorage=function() {
|
|
|
|
if (jQuery.type(localStorage.user) == 'undefined')
|
|
|
|
return;
|
|
|
|
try {
|
|
|
|
var data=JSON.parse(localStorage.user);
|
|
|
|
this.username = data.username;
|
|
|
|
this.name = data.name;
|
|
|
|
this.token = data.token;
|
|
|
|
}
|
|
|
|
catch(e) {
|
|
|
|
alert('Erreur en chargeant vos informations de connexion. Merci de vous reconnecter.');
|
|
|
|
}
|
|
|
|
};
|
|
|
|
|
|
|
|
this.connected=function() {
|
|
|
|
return this.username && this.token;
|
|
|
|
}
|
|
|
|
|
|
|
|
this.reset=function() {
|
|
|
|
this.username = null;
|
|
|
|
this.name = null;
|
|
|
|
this.token = null;
|
|
|
|
}
|
|
|
|
|
|
|
|
this.save=function() {
|
|
|
|
localStorage.user = JSON.stringify({
|
|
|
|
username: this.username,
|
|
|
|
name: this.name,
|
|
|
|
token: this.token,
|
|
|
|
});
|
|
|
|
}
|
|
|
|
}
|