diff --git a/app/static/js/cookies.js b/app/static/js/cookies.js index 4332eaf57d6664626018cddd4553f3335b5d33b7..0e78e27d95ba20b8aab29541cb3234d3336c156e 100644 --- a/app/static/js/cookies.js +++ b/app/static/js/cookies.js @@ -61,10 +61,32 @@ function save_session() { } function setup_session() { - hierarchy.old_labels_tab = str_to_tab(getCookie('old_labels_tab')); - hierarchy.unselect_tab = str_to_tab(getCookie('unselect_labels_tab')); - hierarchy.labels_language = result.labels_language = getCookie('language'); - hierarchy.init_all_labels(); - result.maj_results(3); - hierarchy.maj_new_labels_tab(); -} + /** + * Return 0 no cookies are found return 0. + * Else return 1 if old_tab cookie are found => the initialization of tutos + * and labels is done from the labels contained in old_tab. + * If language cookie are found, juste th language is modified => labels tab's + * need to be initialise (return 0). + */ + var success = 0; + if (getCookie('language') != null && getCookie('language').length != 0) + hierarchy.labels_language = result.labels_language = getCookie('language'); + if (getCookie('old_labels_tab') != null && getCookie('old_labels_tab').length != 0) + hierarchy.old_labels_tab = str_to_tab(getCookie('old_labels_tab')); + if (getCookie('unselect_labels_tab') != null && getCookie('unselect_labels_tab').length != 0) + hierarchy.unselect_tab = str_to_tab(getCookie('unselect_labels_tab')); + + if (getCookie('old_labels_tab') != null && getCookie('old_labels_tab').length != 0) { + hierarchy.init_all_labels(); + result.maj_results(3); + success = 1; + } else if (getCookie('unselect_labels_tab') != null && getCookie('unselect_labels_tab').length != 0) { + hierarchy.init_all_labels(); + result.init_result_tab(); + del_unselect_language(); + result.del_unselected_results(); + hierarchy.maj_new_labels_tab(); + success = 1; + } + return (success); +} \ No newline at end of file diff --git a/app/templates/browse.html b/app/templates/browse.html index 9734143d40d5368a0495e2c3fb0602ceb8fd995b..ca99c9f0d639e67dc8e5772dca74209a5141272d 100644 --- a/app/templates/browse.html +++ b/app/templates/browse.html @@ -148,9 +148,12 @@ * Initialise the two different par of hierarcy and * the array that contain all tutos. */ - hierarchy.init_all_labels(); - hierarchy.init_new_labels_tab(); - result.init_result_tab(); + setup = setup_session(); + if (setup == 0) { + hierarchy.init_all_labels(); + hierarchy.init_new_labels_tab(); + result.init_result_tab(); + } } function update_loading(value) { @@ -250,6 +253,7 @@ this.new_labels_tab = research(this.new_labels_tab, this.all_labels); this.old_labels_tab = research(this.old_labels_tab, this.all_labels); this.unselect_tab = research(this.unselect_tab, this.all_labels); + save_session(); update_loading(1); }, add_label_to_old_tab: function(index, source) { @@ -268,6 +272,7 @@ this.unselect_tab.splice(index, 1); result.maj_results(3); } + save_session(); update_loading(1); }, rm_label_of_old_tab: function(index) { @@ -320,7 +325,7 @@ hierarchy.maj_new_labels_tab(); } else result.maj_results(3); - save_session(); + save_session(); update_loading(1); }, maj_new_labels_tab: function() {