Subversion Repositories ALCASAR

Rev

Details | Last modification | View Log

























































































































































































































Rev Author Line No. Line
2781 rexy 1
/***************************************************************************
2
 *   Copyright (C) 2008 by phpSysInfo - A PHP System Information Script    *
3
 *   http://phpsysinfo.sourceforge.net/                                    *
4
 *                                                                         *
5
 *   This program is free software; you can redistribute it and/or modify  *
6
 *   it under the terms of the GNU General Public License as published by  *
7
 *   the Free Software Foundation; either version 2 of the License, or     *
8
 *   (at your option) any later version.                                   *
9
 *                                                                         *
10
 *   This program is distributed in the hope that it will be useful,       *
11
 *   but WITHOUT ANY WARRANTY; without even the implied warranty of        *
12
 *   MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the         *
13
 *   GNU General Public License for more details.                          *
14
 *                                                                         *
15
 *   You should have received a copy of the GNU General Public License     *
16
 *   along with this program; if not, write to the                         *
17
 *   Free Software Foundation, Inc.,                                       *
18
 *   59 Temple Place - Suite 330, Boston, MA  02111-1307, USA.             *
19
 ***************************************************************************/
20
//
21
// $Id: snmppinfo.js 661 2012-08-27 11:26:39Z namiltd $
22
//
23
 
24
/*global $, jQuery, buildBlock, datetime, plugin_translate, createBar, genlang */
25
 
26
"use strict";
27
 
28
var snmppinfo_show = false;
29
 
30
/**
31
 * build the table where content is inserted
32
 * @param {jQuery} xml plugin-XML
33
 */
34
function snmppinfo_buildTable(xml) {
35
    var html = "", tree = [], closed = [];
36
 
37
    $("#Plugin_SNMPPInfo #Plugin_SNMPPInfoTable").remove();
38
 
39
    html += "  <div style=\"overflow-x:auto;\">\n";
40
    html += "    <table id=\"Plugin_SNMPPInfoTable\" class=\"tablemain\">\n";
41
    html += "     <thead>\n";
42
    html += "      <tr>\n";
43
    html += "       <th>" + genlang(2, "SNMPPInfo") + "</th>\n";
44
    html += "       <th style=\"width:120px;\">" + genlang(3, "SNMPPInfo") + "</th>\n";
45
    html += "       <th class=\"right\" style=\"width:100px;\">" + genlang(4, "SNMPPInfo") + "</th>\n";
46
    html += "      </tr>\n";
47
    html += "     </thead>\n";
48
    html += "     <tbody class=\"tree\">\n";
49
 
50
    var lastdev="", index = 0 ;
51
    $("Plugins Plugin_SNMPPInfo Printer MarkerSupplies", xml).each(function snmppinfo_getprinters(id) {
52
        var close = 0, name = "", device = "", desc = "", unit = 0, max = 0, level = 0, percent = 0, units = "", supply = 0, sunits = "";
53
        name = $(this).parent().attr("Name");
54
        device = $(this).parent().attr("Device");
55
        desc = $(this).attr("Description");
56
 
57
        unit = parseInt($(this).attr("SupplyUnit"), 10);
58
        max = parseInt($(this).attr("MaxCapacity"), 10);
59
        level = parseInt($(this).attr("Level"), 10);
60
        supply = parseInt($(this).attr("SupplyUnit"), 10);
61
 
62
        if (max>0 && (level>=0) && (level<=max) ) {
63
            percent = Math.round(100*level/max);
64
            units = level+" / "+max;
65
        } else if (max==-2 && (level>=0) && (level<=100) ) {
66
            percent = level;
67
            units = level+" / 100";
68
        } else if (level==-3) {
69
            percent = 100;
70
            units = genlang(5, "SNMPPInfo");
71
        } else {
72
            percent = 0;
73
            units = genlang(6, "SNMPPInfo");
74
        }
75
 
76
        if (device!=lastdev) {
77
            html += "      
" + device + " (" + name + ") div></span>td></tr>\n";
78
index = tree.push(0);
79
lastdev = device;
80
}
81
 
82
if (!isNaN(supply)) {
83
switch (supply) {
84
case 7:
85
sunits = "
" + genlang(9, "SNMPPInfo");
86

break;
87

case 13:
88

sunits = "
" + genlang(8, "SNMPPInfo");

89


break;

90


case 15:

91


sunits = "
" + genlang(7, "SNMPPInfo");


92



break;


93



case 19:


94



sunits = "
" + genlang(3, "SNMPPInfo");



95




break;



96




}



97




}



98




html += "
" + desc + "div></span>td><td>" + createBar(percent) +"</td>
" + units + sunits + "td></tr>\n";
99
 
100




tree.push(index);
101




snmppinfo_show = true;
102




});
103
 
104




html += " tbody>\n";
105




html += " </table>\n";
106




html += " div>\n";
107
 
108




$("#Plugin_SNMPPInfo").append(html);
109
 
110




$("#Plugin_SNMPPInfoTable").jqTreeTable(tree, {
111




openImg: "./gfx/treeTable/tv-collapsable.gif",
112




shutImg: "./gfx/treeTable/tv-expandable.gif",
113




leafImg: "./gfx/treeTable/tv-item.gif",
114




lastOpenImg: "./gfx/treeTable/tv-collapsable-last.gif",
115




lastShutImg: "./gfx/treeTable/tv-expandable-last.gif",
116




lastLeafImg: "./gfx/treeTable/tv-item-last.gif",
117




vertLineImg: "./gfx/treeTable/vertline.gif",
118




blankImg: "./gfx/treeTable/blank.gif",
119




collapse: closed,
120




column: 0,
121




striped: true,
122




highlight: false,
123




state: false
124




});
125
 
126




}
127
 
128




/**
129




* load the xml via ajax
130




*/
131




function snmppinfo_request() {
132




$("#Reload_SNMPPInfoTable").attr("title", "reload");
133




$.ajax({
134




url: "xml.php?plugin=SNMPPInfo",
135




dataType: "xml",
136




error: function snmppinfo_error() {
137




$.jGrowl("Error loading XML document for Plugin SNMPPInfo!");
138




},
139




success: function snmppinfo_buildblock(xml) {
140




populateErrors(xml);
141




snmppinfo_buildTable(xml);
142




if (snmppinfo_show) {
143




plugin_translate("SNMPPInfo");
144




$("#Plugin_SNMPPInfo").show();
145




}
146




}
147




});
148




}
149
 
150




$(document).ready(function snmppinfo_buildpage() {
151




$("#footer").before(buildBlock("SNMPPInfo", 1, true));
152




$("#Plugin_SNMPPInfo").css("width", "451px");
153
 
154




snmppinfo_request();
155
 
156




$("#Reload_SNMPPInfoTable").click(function snmppinfo_reload(id) {
157




snmppinfo_request();
158




$(this).attr("title", datetime());
159




});
160




});