From 78b1d6b898528a550df42edd48a1e8d47219cf93 Mon Sep 17 00:00:00 2001
From: CyrilM <mammar@lal.in2p3.fr>
Date: Tue, 6 Nov 2018 14:36:21 +0100
Subject: [PATCH] =?UTF-8?q?Correction=20des=20labels=20non=20s=C3=A9lectio?=
 =?UTF-8?q?nn=C3=A9s=20qui=20n'=C3=A9taient=20pas=20mis=20=C3=A0=20jour=20?=
 =?UTF-8?q?lors=20du=20setup=5Fsession()?=
MIME-Version: 1.0
Content-Type: text/plain; charset=UTF-8
Content-Transfer-Encoding: 8bit

---
 app/static/js/cookies.js  | 36 +++++++++++++++++++++++++++++-------
 app/templates/browse.html | 13 +++++++++----
 2 files changed, 38 insertions(+), 11 deletions(-)

diff --git a/app/static/js/cookies.js b/app/static/js/cookies.js
index 4332eaf..0e78e27 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 9734143..ca99c9f 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() {
-- 
GitLab