diff --git a/public_html/inc/main.js b/public_html/inc/main.js index 1bfda74..26b3441 100644 --- a/public_html/inc/main.js +++ b/public_html/inc/main.js @@ -33,8 +33,14 @@ on_valid_add_scase_modal=function (e) { alert("Vous devez saisir le nom de la valise !"); return; } - if (scases.byName(name)) { - alert("Cette valise existe déjà !"); + var nameshake=scases.byName(name); + if (nameshake) { + if (nameshake.removed) { + alert("Une valise de ce nom existe dans la corbeille !"); + } + else { + alert("Cette valise existe déjà !"); + } return; } var scase=scases.newSCase(name); @@ -70,8 +76,14 @@ on_valid_rename_scase_modal=function (e) { return; } if ($('#cats').data('scase')!=name) { - if (scases.byName(name)) { - alert("Cette valise existe déjà !"); + var nameshake=scases.byName(name); + if (nameshake) { + if (nameshake.removed) { + alert("Une valise portant ce nom existe dans la corbeille !"); + } + else { + alert("Une valise portant ce nom existe déjà !"); + } return; } @@ -110,8 +122,14 @@ on_valid_copy_scase_modal=function (e) { alert("Vous devez saisir le nom de la nouvelle valise !"); return; } - if (scases.byName(name)) { - alert("Cette valise existe déjà !"); + var nameshake=scases.byName(name); + if (nameshake) { + if (nameshake.removed) { + alert("Une valise portant ce nom existe dans la corbeille !"); + } + else { + alert("Une valise portant ce nom existe déjà !"); + } return; } var scase=scases.copySCase($('#cats').data('scase'),name); @@ -164,6 +182,28 @@ on_delete_scase_btn_click=function(event) { } } +on_restore_scase_btn_click=function(event) { + navbar_collapse_hide(); + var scase=event.data.scase; + if (scase) { + myconfirm('Voulez-vous vraiment restaurer la valise '+scase.name+' ?', + function(data) { + scase.restore(); + scases.save(); + show_scases(); + }); + } +} + +on_scase_trash_btn_click=function(event) { + event.preventDefault(); + navbar_collapse_hide(); + var scase=scases.byName($('#cats').data('scase')); + if (scase) { + show_scase_trash(scase); + } +} + /*********************** * Add cat **********************/ @@ -181,8 +221,14 @@ on_valid_add_cat_modal=function (e) { } var scase=scases.byName($('#cats').data('scase')); if (scase) { - if (scase.cats.byName(name)) { - alert("Cette catégorie existe déjà !"); + var nameshake=scase.cats.byName(name); + if (nameshake) { + if (nameshake.removed) { + alert("Une catégorie portant ce nom existe dans la corbeille !"); + } + else { + alert("Une catégorie portant ce nom existe déjà !"); + } return; } var cat=scase.cats.newCat(name); @@ -222,7 +268,13 @@ on_valid_rename_cat_modal=function (e) { var scase=scases.byName($('#cats').data('scase')); if (scase) { if (scase.cats.byName(name)) { - alert("Cette catégorie existe déjà !"); + var namesake=scase.cats.byName(name); + if (namesake.removed) { + alert("Une catégorie de se nom existe dans la corbeille !"); + } + else { + alert("Cette catégorie existe déjà !"); + } return; } var cat=scase.cats.renameCat($('#rename_cat_modal').data('cat'),name); @@ -259,6 +311,20 @@ on_delete_cat_btn_click=function(event) { } } +on_restore_cat_btn_click=function(event) { + navbar_collapse_hide(); + var scase=scases.byName($('#cats').data('scase')); + if (scase) { + var cat=event.data.cat.name; + myconfirm('Voulez-vous vraiment restaure la catégorie '+cat+' ?', + function(data) { + scase.cats.restoreCat(cat); + scases.save(); + show_scase(scase); + }); + } +} + /************************ * Check/Uncheck thing ***********************/ @@ -385,8 +451,14 @@ on_valid_rename_thing_modal=function (e) { if (scase) { var cat=scase.cats.byName($('#rename_thing_modal').data('cat')); if (cat) { - if (cat.byLabel(label)) { - alert("Un élément de ce nom existe déjà !"); + var namesake=cat.byLabel(label); + if (namesake) { + if (namesake.removed) { + alert("Un élément de ce nom existe dans la corbeille !"); + } + else { + alert("Un élément de ce nom existe déjà !"); + } return; } var thing=cat.renameThing($('#rename_thing_modal').data('thing'),label); @@ -427,6 +499,23 @@ on_delete_thing_btn_click=function(event) { } } +on_restore_thing_btn_click=function(event) { + navbar_collapse_hide(); + var scase=scases.byName($('#cats').data('scase')); + if (scase) { + var cat=scase.cats.byName(event.data.cat.name); + if (cat) { + var thing=event.data.thing.label; + myconfirm("Voulez-vous vraiment restaurer l'élément "+thing+" ?", + function(data) { + cat.restoreThing(thing); + scases.save(); + show_scase(scase,cat.name); + }); + } + } +} + /******************** * Show one scase *******************/ @@ -464,6 +553,9 @@ show_cat=function(cat,displayed) { } var ul=$(''); for (idx in cat.things) { + if (cat.things[idx].removed) { + continue; + } var li=$('
  • '+cat.things[idx].label+'
  • '); if (cat.things[idx].checked) { li.addClass('done'); @@ -495,6 +587,9 @@ show_cat=function(cat,displayed) { show_scase=function(scase,display_cat) { clear_page('

    '+scase.name+'

    '); scase.cats.each(function(idx,cat) { + if (cat.removed) { + return; + } show_cat(cat,(cat.name==display_cat)); }); show_menu('scase'); @@ -506,12 +601,99 @@ on_back_to_scases_btn_click=function(e) { show_scases(); } +/******************** + * Show scase trash + *******************/ +show_scase_trash=function(scase,display_cat) { + clear_page('

    '+scase.name+' : Corbeille

    '); + + $('#content h3 #back_btn').bind('click', {'scase': scase}, function(event) { + show_scase(event.data.scase); + }); + + scase.cats.each(function(idx,cat) { + show_cat_trash(cat,(cat.name==display_cat)); + }); + if ($('#cats .panel').length==0) { + $('#content').append('

    La corbeille est vide.

    '); + } + show_menu('scase'); +} + +show_cat_trash=function(cat,displayed) { + var panel=$('
    '); + var panel_heading=$(''); + var panel_title=$('

    '+cat.name+'

    '); + + var tag=$(''); + + panel_title.append(tag); + + + panel_heading.append(panel_title); + panel.append(panel_heading); + + + if (cat.removed) { + var stats=cat.stats(); + tag.append($(''+stats.things+'')); + + var restore_btn=$(''); + restore_btn.bind('click',{'cat': cat},on_restore_cat_btn_click); + tag.append(restore_btn); + } + else { + var deleted_things=[]; + for (idx in cat.things) { + if (cat.things[idx].removed) { + deleted_things.push(cat.things[idx]); + } + } + if (deleted_things.length==0) { + return true; + } + panel_title.bind('click',on_title_click); + tag.append($(''+deleted_things.length+'')); + + var panel_collapse=$('
    '); + if (displayed) { + panel_collapse.addClass('in'); + } + var ul=$(''); + for (idx in deleted_things) { + var li=$('
  • '+deleted_things[idx].label+'
  • '); + var li_actions=$(''); + + var restore_el_btn=$(''); + restore_el_btn.bind('click',{'cat': cat,'thing': deleted_things[idx]},on_restore_thing_btn_click); + li_actions.append(restore_el_btn); + + li.append(li_actions); + + ul.append(li); + } + panel_collapse.append(ul); + panel.append(panel_collapse); + } + + $('#cats').append(panel); +} + +on_back_to_scase_btn_click=function(e) { + e.preventDefault(); + navbar_collapse_hide(); + show_scase(e.data.scase); +} + /******************** * Show scases *******************/ show_scases=function() { clear_page('

    Vos valises

    '); scases.each(function(idx,scase) { + if (scase.removed) { + return; + } var stats=scase.stats(); var tag=''; if (stats.things==stats.done) { @@ -535,6 +717,37 @@ on_scase_click=function(event) { show_scase(scase); } +/******************** + * Show scases trash + *******************/ +show_scases_trash=function() { + clear_page('

    Corbeille

    '); + $('#content h3 #back_btn').bind('click', function(event) { + show_scases(); + }); + + scases.each(function(idx,scase) { + if (!scase.removed) { + return; + } + var stats=scase.stats(); + var tags=$(''); + tags.append(''+stats.things+''); + + var restore_btn=$(''); + restore_btn.bind('click',{'scase': scase},on_restore_scase_btn_click); + tags.append(restore_btn); + + var li=$('
  • '+scase.name+'
  • '); + li.append(tags); + $('#scases').append(li); + }); + if ($('#scases li').length==0) { + $('#content').append('

    Aucune valise dans la corbeille.

    '); + } + show_menu('scases'); +} + clear_page=function(new_content) { if (new_content) { $('#content').html(new_content); @@ -645,6 +858,8 @@ $( document ).ready( function() { $("#add_scase_modal").on('hidden.bs.modal',on_close_add_scase_modal); $("#add_scase_modal form").bind('submit',on_valid_add_scase_modal); + $('#scases_trash_btn').bind('click',show_scases_trash); + $('#rename_scase_btn').bind('click',on_rename_scase_btn_click); $('#rename_scase_submit').bind('click',on_valid_rename_scase_modal); $("#rename_scase_modal").on('shown.bs.modal',on_show_rename_scase_modal); @@ -659,6 +874,7 @@ $( document ).ready( function() { $('#reset_scase_btn').bind('click',on_reset_scase_btn_click); $('#delete_scase_btn').bind('click',on_delete_scase_btn_click); + $('#scase_trash_btn').bind('click',on_scase_trash_btn_click); $('#add_cat_btn').bind('click',on_add_cat_btn_click); $('#add_cat_submit').bind('click',on_valid_add_cat_modal); diff --git a/public_html/inc/mysc_objects.js b/public_html/inc/mysc_objects.js index 86d446c..6b995cf 100644 --- a/public_html/inc/mysc_objects.js +++ b/public_html/inc/mysc_objects.js @@ -127,7 +127,7 @@ function SCaseList() { this.removeSCase=function(name) { for (el in this) { if (this.isSCase(this[el]) && this[el].name==name) { - delete this[el]; + this[el].remove(); return true; } } @@ -135,7 +135,15 @@ function SCaseList() { } this.newSCase=function(name) { - if (!this.byName(this[name])) { + if (this.byName(this[name])) { + var scase=this.byName(name); + if (scase.removed) { + scase.restore(); + return true; + } + + } + else { var uuid=uuid||generate_uuid(); this[uuid]=new SCase(uuid,name); return this[uuid]; @@ -181,6 +189,7 @@ function SCase(uuid,name,data) { this.name=name; this.cats=new CatList(); this.lastChange=new Date().getTime(); + this.removed=false; this.isSCase=function() { return true; @@ -190,6 +199,7 @@ function SCase(uuid,name,data) { this.uuid=data.uuid || generate_uuid(); this.lastChange=data.lastChange || new Date().getTime(); this.name=decodeURIComponent(data.name); + this.removed=data.removed||false; if (jQuery.type(data.cats) == 'object') { this.cats=new CatList(data.cats); } @@ -201,6 +211,7 @@ function SCase(uuid,name,data) { 'uuid': this.uuid, 'lastChange': this.lastChange, 'name': encodeURIComponent(this.name), + 'removed': this.removed, 'cats': this.cats.export() }; } @@ -246,6 +257,16 @@ function SCase(uuid,name,data) { return true; } + this.remove=function() { + this.removed=true; + this.lastChange=new Date().getTime(); + } + + this.restore=function() { + this.removed=false; + this.lastChange=new Date().getTime(); + } + /* * Contructor */ @@ -316,7 +337,14 @@ function CatList(data) { } this.newCat=function(name) { - if (!this.isCat(this[name])) { + if (this.byName(name)) { + var cat=this.byName(name); + if (cat.removed) { + cat.restore(); + return true; + } + } + else { var uuid=uuid||generate_uuid(); this[uuid]=new Cat(uuid,name); return this[uuid]; @@ -337,13 +365,22 @@ function CatList(data) { this.removeCat=function(name) { for (el in this) { if (this.isCat(this[el]) && this[el].name==name) { - delete this[el]; + this[el].remove(); return true; } } return false; } + 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; + } /* @@ -367,6 +404,7 @@ function Cat(uuid,name,color,data) { this.name=name; this.color=color || '#'+(0x1000000+(Math.random())*0xffffff).toString(16).substr(1,6); this.things={}; + this.removed=false; this.isCat=function() { return true; @@ -377,6 +415,7 @@ function Cat(uuid,name,color,data) { this.lastChange=data.lastChange||new Date().getTime(); this.name=decodeURIComponent(data.name); this.color=data.color; + this.removed=data.removed||false; if (jQuery.type(data.things) == 'object') { for (tuuid in data.things) { this.things[tuuid]=new Thing(tuuid); @@ -396,6 +435,7 @@ function Cat(uuid,name,color,data) { 'lastChange': this.lastChange, 'name': encodeURIComponent(this.name), 'color': this.color, + 'removed': this.removed, 'things': things }; } @@ -429,7 +469,15 @@ function Cat(uuid,name,color,data) { } this.newThing=function(label) { - if (!this.byLabel(label)) { + if (this.byLabel(label)) { + var thing=this.byLabel(label); + if (thing.removed) { + thing.restore(); + thing.setChecked(false); + return true; + } + } + else { var uuid=generate_uuid(); this.things[uuid]=new Thing(uuid,label); return true; @@ -450,13 +498,34 @@ function Cat(uuid,name,color,data) { this.removeThing=function(label) { for (idx in this.things) { if (this.things[idx].label==label) { - delete this.things[idx]; + 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(); + return true; + } + } + return false; + } + + this.remove=function() { + this.removed=true; + this.lastChange=new Date().getTime(); + } + + this.restore=function() { + this.removed=false; + this.lastChange=new Date().getTime(); + } + + /* * Contructor */ @@ -477,12 +546,14 @@ function Thing(uuid,label,checked) { this.lastChange=new Date().getTime(); this.label=label; this.checked=checked; + this.removed=false; this.import=function(data) { this.uuid=data.uuid||generate_uuid(); this.lastChange=data.lastChange||new Date().getTime(); this.label=decodeURIComponent(data.label), this.checked=data.checked; + this.removed=data.removed||false; } this.export=function() { @@ -490,7 +561,8 @@ function Thing(uuid,label,checked) { 'uuid': this.uuid, 'lastChange': this.lastChange, 'label': encodeURIComponent(this.label), - 'checked': this.checked + 'checked': this.checked, + 'removed': this.removed, }; } @@ -498,4 +570,14 @@ function Thing(uuid,label,checked) { this.checked=value; this.lastChange=new Date().getTime(); } + + this.remove=function() { + this.removed=true; + this.lastChange=new Date().getTime(); + } + + this.restore=function() { + this.removed=false; + this.lastChange=new Date().getTime(); + } } diff --git a/public_html/index.html b/public_html/index.html index ceea5a0..606e35b 100644 --- a/public_html/index.html +++ b/public_html/index.html @@ -68,6 +68,7 @@ div.panel-heading, li.list-group-item, a {