Subversion Repositories ALCASAR

Rev

Go to most recent revision | 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: smart.js 707 2012-11-28 10:20:49Z namiltd $
22
 
23
 
24
/*global $, jQuery, genlang, formatTemp, plugin_translate, buildBlock, datetime */
25
 
26
"use strict";
27
 
28
var smart_show = false, smart_table;
29
 
30
//appendcss("./plugins/SMART/css/SMART.css");
31
 
32
/**
33
 * fill the plugin block with table structure
34
 */
35
function smart_buildTable(xml) {
36
    var html = "";
37
 
38
    html += "<div style=\"overflow-x:auto;\">\n";
39
    html += "  <table id=\"Plugin_SMARTTable\" style=\"border-collapse:collapse;\">\n";
40
    html += "    <thead>\n";
41
    html += "      <tr>\n";
42
    html += "        <th class=\"right\">" + genlang(2, "SMART") + "</th>\n";
43
    $("Plugins Plugin_SMART columns column", xml).each(function smart_table_header() {
44
        html += "        <th class=\"right\">" + genlang(100 + parseInt($(this).attr("id"), 10), "SMART") + "</th>\n";
45
    });
46
    html += "      </tr>\n";
47
    html += "    </thead>\n";
48
    html += "    <tbody>\n";
49
    html += "    </tbody>\n";
50
    html += "  </table>\n";
51
    html += "</div>\n";
52
 
53
    $("#Plugin_SMART").append(html);
54
 
55
    smart_table = $("#Plugin_SMARTTable").dataTable({
56
        "bPaginate": false,
57
        "bLengthChange": false,
58
        "bFilter": false,
59
        "bSort": true,
60
        "bInfo": false,
61
        "bProcessing": true,
62
        "bAutoWidth": false,
63
        "bStateSave": true
64
    });
65
}
66
 
67
/**
68
 * insert content into table
69
 * @param {jQuery} xml plugin-XML
70
 */
71
function smart_populate(xml) {
72
    var name = "", columns = [];
73
    smart_table.fnClearTable();
74
 
75
    // Get datas that the user want to be displayed
76
    $("Plugins Plugin_SMART columns column", xml).each(function smart_find_columns() {
77
        columns[parseInt($(this).attr("id"), 10)] = $(this).attr("name");
78
        smart_show = true;
79
    });
80
 
81
    // Now we add selected datas in the table
82
    $("Plugins Plugin_SMART disks disk", xml).each(function smart_fill_table() {
83
        var values = [], display = [], i;
84
        name = $(this).attr("name").replace(/\)/g, ")<wbr>");
85
        $(this).find("attribute").each(function smart_fill_data() {
86
            if (columns[parseInt($(this).attr("id"), 10)] && columns[parseInt($(this).attr("id"), 10)] !== "") {
87
                values[parseInt($(this).attr("id"), 10)] = $(this).attr(columns[parseInt($(this).attr("id"), 10)]);
88
            }
89
        });
90
 
91
        display.push("<span style=\"display:none;\">" + name + "</span>" + name);
92
 
93
        // On "columns" so we get the right order
94
        // fixed for Firefox (fix wrong order)
95
        $("Plugins Plugin_SMART columns column", xml).each(function smart_find_columns() {
96
            i  = parseInt($(this).attr("id"), 10);
97
            if (typeof(values[i])==='undefined') {
98
                display.push("<span style=\"display:none;\"></span>");
99
            }
100
            else if (i === 194) {
101
                display.push("<span style=\"display:none;\">" + values[i] + "</span>" + formatTemp(values[i], xml));
102
            }
103
            else {
104
                display.push("<span style=\"display:none;\">" + values[i] + "</span>" + values[i]);
105
            }
106
        });
107
        smart_table.fnAddData(display);
108
    });
109
}
110
 
111
/**
112
 * load the xml via ajax
113
 */
114
function smart_request() {
115
    $("#Reload_SMARTTable").attr("title", "reload");
116
    $.ajax({
117
        url: "xml.php?plugin=SMART",
118
        dataType: "xml",
119
        error: function smart_error() {
120
            $.jGrowl("Error loading XML document for Plugin SMART");
121
        },
122
        success: function smart_buildBlock(xml) {
123
            populateErrors(xml);
124
            if ((smart_table === undefined) || (typeof(smart_table) !== "object")) {
125
                smart_buildTable(xml);
126
            }
127
            smart_populate(xml);
128
            if (smart_show) {
129
                plugin_translate("SMART");
130
                $("#Plugin_SMART").show();
131
            }
132
        }
133
    });
134
}
135
 
136
$(document).ready(function smart_buildpage() {
137
    var html = "";
138
 
139
    $("#footer").before(buildBlock("SMART", 1, true));
140
    $("#Plugin_SMART").css("width", "915px");
141
 
142
    smart_request();
143
 
144
    $("#Reload_SMARTTable").click(function smart_reload(id) {
145
        smart_request();
146
        $(this).attr("title", datetime());
147
    });
148
});