Subversion Repositories ALCASAR

Rev

Go to most recent revision | Details | Last modification | View Log

Rev Author Line No. Line
2784 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: ps.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 ps_show = false;
29
 
30
/**
31
 * build the table where content is inserted
32
 * @param {jQuery} xml plugin-XML
33
 */
34
function ps_buildTable(xml) {
35
    var html = "", tree = [], closed = [], memwas = false, cpuwas = false;
36
 
37
    $("#Plugin_PS #Plugin_PSTable").remove();
38
 
39
    html += "  <div style=\"overflow-x:auto;\">\n";
40
    html += "    <table id=\"Plugin_PSTable\" class=\"tablemain\">\n";
41
    html += "      <thead>\n";
42
    html += "        <tr>\n";
43
    html += "          <th>" + genlang(2, "PS") + "</th>\n";
44
    html += "          <th style=\"width:40px;\">" + genlang(3, "PS") + "</th>\n";
45
    html += "          <th style=\"width:40px;\">" + genlang(4, "PS") + "</th>\n";
46
    html += "          <th style=\"width:120px;\">" + genlang(5, "PS") + "</th>\n";
47
    html += "          <th style=\"width:120px;\">" + genlang(6, "PS") + "</th>\n";
48
    html += "        </tr>\n";
49
    html += "      </thead>\n";
50
    html += "      <tbody class=\"tree\">\n";
51
 
52
    $("Plugins Plugin_PS Process", xml).each(function ps_getprocess(id) {
53
        var close = 0, pid = 0, ppid = 0, name = "", percent = 0, parentId = 0, expanded = 0, cpu = 0;
54
        name = $(this).attr("Name").replace(/,/g, ",<wbr>").replace(/\s/g, " <wbr>").replace(/\./g, ".<wbr>").replace(/-/g, "<wbr>-").replace(/\//g, "<wbr>/"); /* split long name */
55
        parentId = parseInt($(this).attr("ParentID"), 10);
56
        pid = parseInt($(this).attr("PID"), 10);
57
        ppid = parseInt($(this).attr("PPID"), 10);
58
        percent = parseInt($(this).attr("MemoryUsage"), 10);
59
        cpu = parseInt($(this).attr("CPUUsage"), 10);
60
        expanded = parseInt($(this).attr("Expanded"), 10);
61
 
62
        html += "        <tr><td><div class=\"treediv\"><span class=\"treespan\">" + name + "</div></span></td><td>" + pid + "</td><td>" + ppid + "</td><td>" + createBar(percent) + "</td><td>" + createBar(cpu) + "</td></tr>\n";
63
        close = tree.push(parentId);
64
        if (!isNaN(expanded) && (expanded === 0)) {
65
            closed.push(close);
66
        }
67
        if (!memwas && !isNaN(percent)) {
68
            memwas = true;
69
        }
70
        if (!cpuwas && !isNaN(cpu)) {
71
            cpuwas = true;
72
        }
73
        ps_show = true;
74
    });
75
 
76
    html += "      </tbody>\n";
77
    html += "    </table>\n";
78
    html += "  </div>\n";
79
 
80
    $("#Plugin_PS").append(html);
81
 
82
    if (memwas) {
83
        $('#Plugin_PSTable td:nth-child(4),#Plugin_PSTable th:nth-child(4)').show();
84
    } else {
85
        $('#Plugin_PSTable td:nth-child(4),#Plugin_PSTable th:nth-child(4)').hide();
86
    }
87
    if (cpuwas) {
88
        $('#Plugin_PSTable td:nth-child(5),#Plugin_PSTable th:nth-child(5)').show();
89
    } else {
90
        $('#Plugin_PSTable td:nth-child(5),#Plugin_PSTable th:nth-child(5)').hide();
91
    }
92
 
93
    $("#Plugin_PSTable").jqTreeTable(tree, {
94
        openImg: "./gfx/treeTable/tv-collapsable.gif",
95
        shutImg: "./gfx/treeTable/tv-expandable.gif",
96
        leafImg: "./gfx/treeTable/tv-item.gif",
97
        lastOpenImg: "./gfx/treeTable/tv-collapsable-last.gif",
98
        lastShutImg: "./gfx/treeTable/tv-expandable-last.gif",
99
        lastLeafImg: "./gfx/treeTable/tv-item-last.gif",
100
        vertLineImg: "./gfx/treeTable/vertline.gif",
101
        blankImg: "./gfx/treeTable/blank.gif",
102
        collapse: closed,
103
        column: 0,
104
        striped: true,
105
        highlight: false,
106
        state: false
107
    });
108
}
109
 
110
/**
111
 * load the xml via ajax
112
 */
113
function ps_request() {
114
    $("#Reload_PSTable").attr("title", "reload");
115
    $.ajax({
116
        url: "xml.php?plugin=PS",
117
        dataType: "xml",
118
        error: function ps_error() {
119
            $.jGrowl("Error loading XML document for Plugin PS!");
120
        },
121
        success: function ps_buildblock(xml) {
122
            populateErrors(xml);
123
            ps_buildTable(xml);
124
            if (ps_show) {
125
                plugin_translate("PS");
126
                $("#Plugin_PS").show();
127
            }
128
        }
129
    });
130
}
131
 
132
$(document).ready(function ps_buildpage() {
133
    $("#footer").before(buildBlock("PS", 1, true));
134
    $("#Plugin_PS").css("width", "915px");
135
 
136
    ps_request();
137
 
138
    $("#Reload_PSTable").click(function ps_reload(id) {
139
        ps_request();
140
        $(this).attr("title", datetime());
141
    });
142
});