1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 20 21 22 23 24 25 26 27 28 29 30 31 32 33 34 35 36 37 38 39 40 41 42 43 44 45 46 47 48 49 50 51 52 53 54 55 56 57 58 59 60 61 62 63 64 65 66 67 68 69 70 71 72 73 74 75 76 77 78 79 80 81 82 83 84 85 86 87 88 89 90 91 92 93 94 95 96 97 98 99 100 101 102 103 104 105 106 107 108 109 110 111 112 113 114 115 116 117 118 119 120 121 122 123 124 125 126 127 128 129 130 131 132 133 134 135 136 137 138 139 140 141 142 143 144 145 146 147 148
|
/*
** Zabbix
** Copyright (C) 2001-2019 Zabbix SIA
**
** This program is free software; you can redistribute it and/or modify
** it under the terms of the GNU General Public License as published by
** the Free Software Foundation; either version 2 of the License, or
** (at your option) any later version.
**
** This program is distributed in the hope that it will be useful,
** but WITHOUT ANY WARRANTY; without even the implied warranty of
** MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
** GNU General Public License for more details.
**
** You should have received a copy of the GNU General Public License
** along with this program; if not, write to the Free Software
** Foundation, Inc., 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301, USA.
**/
var CTree = Class.create();
CTree.prototype = {
name: null,
nodes: [],
/*
* Encoding values separated by a comma (%2C), makes the cookie very large in size. A dot, however, remains a dot.
* Must be synced with class.cookie.js for consistency.
*/
cookie_delimiter: '.',
initialize: function(name, nodes) {
this.name = name;
this.nodes = nodes;
if ((tree_init = cookie.read(name)) != null) {
var nodes = tree_init.split(this.cookie_delimiter);
for (var i = 0, size = nodes.length; i < size; i++) {
this.onStartSetStatus(nodes[i]);
}
this.onStartOpen(nodes);
}
},
getNodeStatus: function(id) {
return (empty(this.nodes[id]) || this.nodes[id].status == 'close') ? 'close' : 'open';
},
changeNodeStatus: function(id) {
if (!empty(this.nodes[id])) {
this.nodes[id].status = (this.nodes[id].status == 'close') ? 'open' : 'close';
var cookieData = '';
for (var id in this.nodes) {
var node = this.nodes[id];
if (!empty(node.status) && node.status == 'open') {
cookieData += id + this.cookie_delimiter;
}
}
cookie.create(this.name, cookieData.slice(0, -1));
}
},
closeSNodeX: function(id, arrow) {
if (!empty(this.nodes[id]) && !empty(arrow)) {
var nodelist = this.nodes[id].nodelist.split(',');
if (this.getNodeStatus(id) == 'close') {
this.openNode(nodelist);
arrow.className = 'arrow-down';
}
else {
this.closeNode(nodelist);
arrow.className = 'arrow-right';
}
this.changeNodeStatus(id);
}
},
openNode: function(nodes) {
for (var i = 0, size = nodes.length; i < size; i++) {
var nodeId = nodes[i].replace('.', '\\.');
jQuery('#id_' + nodeId).show();
if (this.getNodeStatus(nodes[i]) == 'open') {
this.openNode(this.nodes[nodes[i]].nodelist.split(','));
}
}
},
closeNode: function(nodes) {
for (var i = 0, size = nodes.length; i < size; i++) {
var nodeId = nodes[i].replace('.', '\\.');
jQuery('#id_' + nodeId).hide();
if (this.checkParent(nodes[i])) {
if (this.getNodeStatus(nodes[i]) == 'open') {
this.closeNode(this.nodes[nodes[i]].nodelist.split(','));
}
}
}
},
onStartOpen: function(nodes) {
for (var i = 0, size = nodes.length; i < size; i++) {
if (!empty(nodes[i])) {
if (this.checkParent(nodes[i])) {
this.openNode(this.nodes[nodes[i]].nodelist.split(','));
}
}
}
},
onStartSetStatus: function(id) {
if (!empty(this.nodes[id])) {
var arrow = document.getElementById('idi_' + id).getElementsByTagName('span')[0];
if (!empty(arrow)) {
arrow.className = 'arrow-down';
}
this.nodes[id].status = 'open';
}
},
checkParent: function(id) {
if (id == '0') {
return true;
}
else if (empty(this.nodes[id])) {
return false;
}
else if (this.nodes[id].status != 'open') {
return false;
}
else {
return this.checkParent(this.nodes[id].parentid);
}
}
};
|