diff --git a/app/templates/add_new_tuto.html b/app/templates/add_new_tuto.html index 3f49b2482bfcacf8b804fb29386209cab50c36ad..9ff84653306748d60e83cf9c1bb233014e448189 100644 --- a/app/templates/add_new_tuto.html +++ b/app/templates/add_new_tuto.html @@ -23,7 +23,8 @@ <img v-if='is_active[index] % 2 == 1' src="static/checked.png"> <br> </span> - <span v-bind:src="labels_add[0]"></span> + {{Â labels_add }} + <!-- <span v-bind:src="labels_add[0]"></span> --> <br> </div> </div> @@ -57,6 +58,7 @@ </body> <script src="static/create_arbo.js"></script> + <script src="static/array_opperations.js"></script> <script src="static/ajax.js"></script> <script> @@ -82,9 +84,46 @@ return (childs); } + function get_all_fathers_of_child(tab_labels, child_id) { + /** + * Gets all the fathers (label id) of a child. + */ + var fathers = []; + var posi_child = is_in_tab(child_id, tab_labels, 0, 2); + for (var i = 0; tab_labels[i]; i++) { + if (tab_labels[posi_child][2] == tab_labels[i][0]) { + fathers.push(tab_labels[i][0]); + fathers = fathers.concat(get_all_fathers_of_child(tab_labels, tab_labels[i][0])); + } + } + return (fathers); + } + + function selection_label(id_label) { + var all_fathers = get_all_fathers_of_child(hierarchy.all_labels, id_label); + var all_childs = get_all_childs_of_father(hierarchy.all_labels, id_label); + var posi = -1; + console.log(all_fathers); + console.log(all_childs); + hierarchy.labels_add.push(id_label); + for (var i = 0; all_fathers[i]; i++) { + posi = is_in_tab(all_fathers[i], hierarchy.labels_add, 0, 1); + if (posi == -1) { + hierarchy.labels_add.push(all_fathers[i]); + } + } + for (var i = 0; all_childs[i]; i++) { + posi = is_in_tab(all_childs[i], hierarchy.labels_add, 0, 1); + if (posi == -1) { + hierarchy.labels_add.push(all_childs[i]); + } + } + } + var hierarchy = new Vue({ el: '#hierarchy', data: { + all_labels: this.all_labels = JSON.parse(request_ajax("labels")), table: order_intent_labels_tab(), is_active: create_empty_tab(40), labels_add: [] @@ -93,15 +132,13 @@ activate_lo: function (index) { var id_lab = this.table[index][0]; this.is_active[index] += 1; - if (this.is_active[index] % 2 == 1) - this.labels_add.push(id_lab); - else + if (this.is_active[index] % 2 == 1) { + selection_label(this.table[index][0]); + //this.labels_add.push(index); + } else this.labels_add.splice(this.labels_add.indexOf(id_lab), 1); document.form1.labels.value = this.labels_add; - }, - get_all_labels: function() { - return (JSON.parse(request_ajax("labels"))); - } + } } });