Subversion Repository Public Repository

Nextrek

Diff Revisions 1047 vs 1048 for /legal-map/js/tree.js

Diff revisions: vs.
  @@ -1,4 +1,4 @@
1 - function openNode(clicked, level) {
1 + function openNode(clicked, level, nodesObj) {
2 2 var node = clicked.parent().parent();
3 3 function ajaxResOpenNode(data) {
4 4 var nodes = data.nodes;
  @@ -36,21 +36,25 @@
36 36 //node.parent().append(htmlToAppend);
37 37 $("#list-id-"+node.attr("node-id")).append(htmlToAppend);
38 38
39 + if (nodes[i].NODES) {
40 + var children = {};
41 + children.nodes = nodes[i].NODES;
42 + openNode($('#treeContainer #node-id-' + nodes[i].id + ' .node-container .node-text'), nodes[i].level+1, children);
43 + }
39 44 }
40 45
41 46 $("#list-id-"+node.attr("node-id")).show();
42 - node.find(".close-button").show();
43 - $("#list-id-"+node.attr("node-id")+" .close-button").hide();
47 + node.find(".close-button").eq(0).show();
48 + // $("#list-id-"+node.attr("node-id")+" .close-button").hide();
44 49
45 50 /*node.parent().find(".level-node-"+level+"[leaf='0'] > .node-container .node-text").click(function() {
46 51 openNode($(this), level+1);
47 52 });*/
48 -
49 53 node.parent().find("#list-id-"+node.attr("node-id")+" .level-node-"+level+"[leaf='0'] > .node-container .node-text").click(function() {
50 54 openNode($(this), level+1);
51 55 });
52 56
53 - node.parent().find()
57 + // node.parent().find()
54 58
55 59 $("#list-id-"+node.attr("node-id")+" .close-button").click(function() {
56 60 $(this).parent().parent().find("ul").hide();
  @@ -60,65 +64,82 @@
60 64 });*/
61 65 })
62 66 }
63 -
64 - if ($("#list-id-"+node.attr("node-id")+" > li").length>0) { //nodi già presenti
65 - $("#list-id-"+node.attr("node-id")).show();
66 - node.find(".close-button").show();
67 - $("#list-id-"+node.attr("node-id")+" .close-button").hide();
67 + if (nodesObj) {
68 + ajaxResOpenNode(nodesObj);
68 69 } else {
69 - $.ajax({
70 - url: "./ajax/treeLoader.php",
71 - data: {
72 - filename: "jobsact",
73 - idpadre: node.attr("node-id")
74 - },
75 - dataType: "JSON",
76 - type: "GET",
77 - success: function(data) {
78 - ajaxResOpenNode(data);
79 - },
80 - error: function() {
81 - alert("Errore nel caricamento dei nodi figli");
82 - }
83 - });
70 + if ($("#list-id-"+node.attr("node-id")+" > li").length>0) { //nodi già presenti
71 + $("#list-id-"+node.attr("node-id")).show();
72 + node.find(".close-button").eq(0).show();
73 + //$("#list-id-"+node.attr("node-id")+" .close-button").hide();
74 + } else {
75 + $.ajax({
76 + url: "./ajax/treeLoader.php",
77 + data: {
78 + filename: "jobsact",
79 + idpadre: node.attr("node-id")
80 + },
81 + dataType: "JSON",
82 + type: "GET",
83 + success: function(data) {
84 + ajaxResOpenNode(data);
85 + },
86 + error: function() {
87 + alert("Errore nel caricamento dei nodi figli");
88 + }
89 + });
90 + }
84 91 }
85 92
86 93 //clicked.unbind("click");
87 94
88 95 }
89 96
90 - function loadTree(data) {
97 + function loadTree(data, mode) {
91 98 var nodes = data.nodes;
99 + if (nodes.length > 0) {
92 100
93 - for (var i = 0; i<nodes.length; i++) {
94 - /*var htmlToAppend = '<div id="container-id-'+nodes[i].id+'">';
95 - htmlToAppend += '<div id="node-id-'+nodes[i].id+'" ';
96 - htmlToAppend += 'node-id="'+nodes[i].id+'" ';
97 - htmlToAppend += 'level="'+nodes[i].level+'" ';
98 - htmlToAppend += 'cat="'+(i+1)+'" ';
99 - htmlToAppend += 'leaf="'+((nodes[i].is_leaf) ? 1 : 0)+'" ';
100 - htmlToAppend += 'class="level-node-1 cat-node-'+(i+1)+'">';
101 - htmlToAppend += nodes[i].ramodescrizione+"</div></div>";*/
102 -
103 - var htmlToAppend = '<li id="node-id-'+nodes[i].id+'" ';
104 - htmlToAppend += 'node-id="'+nodes[i].id+'" ';
105 - htmlToAppend += 'level="'+nodes[i].level+'" ';
106 - htmlToAppend += 'cat="'+(i+1)+'" ';
107 - htmlToAppend += 'leaf="'+((nodes[i].is_leaf) ? 1 : 0)+'" ';
108 - htmlToAppend += 'class="level-node-1 cat-node-'+(i+1)+'">';
109 - htmlToAppend += "<div class='cat-icon'></div>";
110 - htmlToAppend += "<div class='node-container'><div class='node-text'>"+nodes[i].ramodescrizione+"</div></div>"+"</li>";
111 - htmlToAppend += (!nodes[i].is_leaf) ? "<ul id='list-id-"+nodes[i].id+"' class='level-list-2' style='display:none;'></ul>" : "";
101 + for (var i = 0; i<nodes.length; i++) {
102 + /*var htmlToAppend = '<div id="container-id-'+nodes[i].id+'">';
103 + htmlToAppend += '<div id="node-id-'+nodes[i].id+'" ';
104 + htmlToAppend += 'node-id="'+nodes[i].id+'" ';
105 + htmlToAppend += 'level="'+nodes[i].level+'" ';
106 + htmlToAppend += 'cat="'+(i+1)+'" ';
107 + htmlToAppend += 'leaf="'+((nodes[i].is_leaf) ? 1 : 0)+'" ';
108 + htmlToAppend += 'class="level-node-1 cat-node-'+(i+1)+'">';
109 + htmlToAppend += nodes[i].ramodescrizione+"</div></div>";*/
112 110
113 - $("#treeContainer").append(htmlToAppend);
114 - }
111 + var htmlToAppend = '<li id="node-id-'+nodes[i].id+'" ';
112 + var catNode = nodes[i].catNode ? nodes[i].catNode : i+1;
113 + htmlToAppend += 'node-id="'+nodes[i].id+'" ';
114 + htmlToAppend += 'level="'+nodes[i].level+'" ';
115 + htmlToAppend += 'cat="'+catNode+'" ';
116 + htmlToAppend += 'leaf="'+((nodes[i].is_leaf) ? 1 : 0)+'" ';
117 + htmlToAppend += 'class="level-node-1 cat-node-'+catNode+'">';
118 + htmlToAppend += "<div class='cat-icon'></div>";
119 + htmlToAppend += "<div class='node-container'><div class='node-text'>"+nodes[i].ramodescrizione+"</div></div>"+"</li>";
120 + htmlToAppend += (!nodes[i].is_leaf) ? "<ul id='list-id-"+nodes[i].id+"' class='level-list-2' style='display:none;'></ul>" : "";
121 +
122 + $("#treeContainer").append(htmlToAppend);
123 +
124 + if (nodes[i].NODES) {
125 + var children = {};
126 + children.nodes = nodes[i].NODES;
127 + openNode($('#treeContainer #node-id-' + nodes[i].id + ' .node-container .node-text'), nodes[i].level+1, children);
128 + }
129 + }
115 130
116 - $("#treeContainer .level-node-1 .node-container .node-text").click(function() {
117 - openNode($(this), 2);
118 - });
131 + $("#treeContainer .level-node-1 .node-container .node-text").click(function() {
132 + openNode($(this), 2);
133 + });
134 +
135 + if (!mode)
136 + $("#treeContainer .level-node-1 .node-container .node-text").trigger("click"); //apertura nodi primo livello
137 +
138 + } else {
139 + $("#treeContainer").next('p').remove();
140 + $("#treeContainer").after('<p style="text-align: center;">Nessun articolo trovato.</p>');
141 + }
119 142
120 - $("#treeContainer .level-node-1 .node-container .node-text").trigger("click"); //apertura nodi primo livello
121 -
122 143 $("p.gen-comandi a.gen-espandi").click(function(){
123 144 if (!window.blockExpandCollapse){
124 145 window.blockExpandCollapse = true;
  @@ -135,7 +156,7 @@
135 156 $("#treeContainer .level-node-2 .node-container .node-text").trigger("click");
136 157 }
137 158 });
138 -
159 +
139 160 $("p.gen-comandi a.gen-collassa").click(function(){
140 161 if (!window.blockExpandCollapse){
141 162 if ($("#treeContainer .level-node-2 > div.node-container .light-close-button") && $("#treeContainer .level-node-2 > div.node-container .light-close-button").length>0){
  @@ -145,9 +166,9 @@
145 166 }
146 167 }
147 168 });
148 -
169 +
149 170 $(".itinerario-button").click(function(e){
150 171 window.open("./itinerary.php?title=Jobs Act");
151 172 })
152 -
153 - }
173 +
174 + }