Subversion Repositories ALCASAR

Rev

Details | Last modification | View Log

Rev Author Line No. Line
2782 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: raid.js 679 2012-09-04 10:10:11Z namiltd $
22
//
23
 
24
/*global $, jQuery, buildBlock, genlang, createBar, plugin_translate, datetime */
25
 
26
"use strict";
27
 
28
var raid_show = false;
29
 
30
/**
31
 * get the details of the raid
32
 * @param {jQuery} xml part of the plugin-XML
33
 * @param {number} id id of the device
34
 */
35
function raid_buildinfos(xml, id) {
36
    var html = "", prog = "", devname = "", devstatus = "", devlevel = "", devcontroller = "", devbattery = "", devsupported = "", devsize = 0, devstride = 0, devsubsets = 0, devdevs = 0, devspares = 0, devchunk = 0, devalgor = "", devpersist = 0, devreg = 0, devact = 0, devcache = 0, devbad = 0, devread = "", devwrite = "", button = "";
37
 
38
    prog = $(xml).attr("Program");
39
    devname = $(xml).attr("Name");
40
    devstatus = $(xml).attr("Status");
41
    devlevel = $(xml).attr("Level");
42
    devcontroller = $(xml).attr("Controller");
43
    devbattery = $(xml).attr("Battery");
44
    devsupported = $(xml).attr("Supported");
45
    devsize = parseInt($(xml).attr("Size"), 10);
46
    devstride = parseInt($(xml).attr("Stride"), 10);
47
    devsubsets = parseInt($(xml).attr("Subsets"), 10);
48
    devdevs = parseInt($(xml).attr("Devs"), 10);
49
    devspares = parseInt($(xml).attr("Spares"), 10);
50
    devchunk = parseInt($(xml).attr("Chunk_Size"), 10);
51
    devalgor = $(xml).attr("Algorithm");
52
    devpersist = parseInt($(xml).attr("Persistend_Superblock"), 10);
53
    devreg = parseInt($(xml).attr("Disks_Registered"), 10);
54
    devact = parseInt($(xml).attr("Disks_Active"), 10);
55
    devcache = parseInt($(xml).attr("Cache_Size"), 10);
56
    devbad = parseInt($(xml).attr("Bad_Blocks"), 10);
57
    devread = $(xml).attr("ReadPolicy");
58
    devwrite = $(xml).attr("WritePolicy");
59
    html += "<tr><td>" + genlang(22, "Raid") + "</td><td>" + prog + "</td></tr>";
60
    if (devname !== undefined) html += "<tr><td>" + genlang(3, "Raid") + "</td><td>" + devname + "</td></tr>";
61
    html += "<tr><td>" + genlang(4, "Raid") + "</td><td>" + devstatus + "</td></tr>";
62
    if (devlevel !== undefined) html += "<tr><td>" + genlang(5, "Raid") + "</td><td>" + devlevel + "</td></tr>";
63
    if (!isNaN(devsize)) html += "<tr><td>" + genlang(6, "Raid") + "</td><td>" + formatBytes(devsize, xml) + "</td></tr>";
64
    if (!isNaN(devstride)) html += "<tr><td>" + genlang(7, "Raid") + "</td><td>" + devstride + "</td></tr>";
65
    if (!isNaN(devsubsets)) html += "<tr><td>" + genlang(8, "Raid") + "</td><td>" + devsubsets + "</td></tr>";
66
    if (!isNaN(devdevs)) html += "<tr><td>" + genlang(9, "Raid") + "</td><td>" + devdevs + "</td></tr>";
67
    if (!isNaN(devspares)) html += "<tr><td>" + genlang(10, "Raid") + "</td><td>" + devspares + "</td></tr>";
68
 
69
    if (!isNaN(devchunk)) html += "<tr><td>" + genlang(13, "Raid") + "</td><td>" + devchunk + "K</td></tr>";
70
    if (devalgor !== undefined) html += "<tr><td>" + genlang(14, "Raid") + "</td><td>" + devalgor + "</td></tr>";
71
    if (!isNaN(devpersist)) {
72
        if (devpersist == 1) {
73
            html += "<tr><td>" + genlang(15, "Raid") + "</td><td>" + genlang(16, "Raid") + "</td></tr>";
74
        } else {
75
            html += "<tr><td>" + genlang(15, "Raid") + "</td><td>" + genlang(17, "Raid") + "</td></tr>";
76
        }
77
    }
78
    if (!isNaN(devreg) && !isNaN(devact)) html += "<tr><td>" + genlang(18, "Raid") + "</td><td>" + devreg + "/" + devact + "</td></tr>";
79
    if (devcontroller !== undefined) html += "<tr><td>" + genlang(19, "Raid") + "</td><td>" + devcontroller + "</td></tr>";
80
    if (devbattery !== undefined) html += "<tr><td>" + genlang(20, "Raid") + "</td><td>" + devbattery + "</td></tr>";
81
    if (devsupported !== undefined) html += "<tr><td>" + genlang(21, "Raid") + "</td><td>" + devsupported + "</td></tr>";
82
    if (devread !== undefined) html += "<tr><td>" + genlang(23, "Raid") + "</td><td>" + devread + "</td></tr>";
83
    if (devwrite !== undefined) html += "<tr><td>" + genlang(24, "Raid") + "</td><td>" + devwrite + "</td></tr>";
84
    if (!isNaN(devcache)) html += "<tr><td>" + genlang(25, "Raid") + "</td><td>" + formatBytes(devcache, xml) + "</td></tr>";
85
    if (!isNaN(devbad)) html += "<tr><td>" + genlang(26, "Raid") + "</td><td>" + devbad + "</td></tr>";
86
 
87
    button += "<h3 style=\"cursor:pointer\" id=\"sPlugin_Raid_Info" + id + "\"><img src=\"./gfx/bullet_toggle_plus.gif\" alt=\"plus\" title=\"\" style=\"vertical-align:middle;width:16px;\" />" + genlang(2, "Raid") + "</h3>";
88
    button += "<h3 style=\"cursor:pointer; display:none;\" id=\"hPlugin_Raid_Info" + id + "\"><img src=\"./gfx/bullet_toggle_minus.gif\" alt=\"minus\" title=\"\" style=\"vertical-align:middle;width:16px;\" />" + genlang(2, "Raid") + "</h3>";
89
    button += "<table id=\"Plugin_Raid_InfoTable" + id + "\" style=\"border:none; border-collapse:collapse; display:none;\"><tbody>" + html + "</tbody></table>";
90
    return button;
91
}
92
 
93
/**
94
 * generate a html string with the current action on the disks
95
 * @param {jQuery} xml part of the plugin-XML
96
 */
97
function raid_buildaction(xml) {
98
    var html = "", name = "", time = "", tunit = "", percent = 0;
99
    $("Action", xml).each(function mdstatus_getaction(id) {
100
        name = $(this).attr("Name");
101
        if (parseInt(name, 10) !== -1) {
102
            time = $(this).attr("Time_To_Finish");
103
            tunit = $(this).attr("Time_Unit");
104
            percent = parseFloat($(this).attr("Percent"));
105
            html += "<div style=\"padding-left:10px;\">";
106
            html += genlang(11, "Raid") + ":&nbsp;" + name + "<br>";
107
            html += createBar(percent);
108
            if ((time !== undefined) && (tunit !== undefined)) {
109
                html += "<br>";
110
                html += genlang(12, "Raid") + ":&nbsp;" + time + "&nbsp;" + tunit;
111
            }
112
            html += "</div>";
113
        }
114
    });
115
    return html;
116
}
117
 
118
/**
119
 * choose the right diskdrive icon
120
 * @param {jQuery} xml part of the plugin-XML
121
 */
122
function raid_diskicon(xml, id) {
123
    $("RaidItems Item", xml).each(function raid_getitems(itemid) {
124
        var status = "", name = "", type = "", info = "", parentid = 0;
125
 
126
        status = $(this).attr("Status");
127
        name = $(this).attr("Name");
128
        type = $(this).attr("Type");
129
        info = $(this).attr("Info");
130
        if (info === undefined) info = "";
131
        parentid = parseInt($(this).attr("ParentID"), 10);
132
 
133
        var img = "", alt = "", bcolor = "";
134
        switch (status) {
135
        case "ok":
136
            img = "harddriveok.png";
137
            alt = "ok";
138
            bcolor = "green";
139
            break;
140
        case "F":
141
            img = "harddrivefail.png";
142
            alt = "fail";
143
            bcolor = "red";
144
            break;
145
        case "U":
146
            img = "harddriveunc.png";
147
            alt = "unconfigured";
148
            bcolor = "purple";
149
            break;
150
        case "S":
151
            img = "harddrivespare.png";
152
            alt = "spare";
153
            bcolor = "gray";
154
            break;
155
        case "W":
156
            img = "harddrivewarn.png";
157
            alt = "warning";
158
            bcolor = "orange";
159
            break;
160
        default:
161
//            alert("--" + diskstatus + "--");
162
            img = "error.png";
163
            alt = "error";
164
 
165
            break;
166
        }
167
 
168
        if (!isNaN(parentid)) {
169
            if (type === "disk") {
170
                $("#Plugin_Raid_Item" + id + "-" + parentid).append("<div class=\"plugin_raid_biun\" title=\"" + info + "\"><img src=\"./plugins/raid/gfx/" + img + "\" alt=\"" + alt + "\" style=\"width:60px;height:60px;\" onload=\"PNGload($(this));\" /><br><small>" + name + "</small></div>"); //onload IE6 PNG fix
171
            } else {
172
                if (parentid === 0) {
173
                    $("#Plugin_Raid_List-" + id).append("<div class=\"plugin_raid_item\" id=\"Plugin_Raid_Item" + id + "-" + (itemid+1) + "\" style=\"border-color:" + bcolor + "\">" + name + "<br></div>");
174
                } else {
175
                    $("#Plugin_Raid_Item" + id + "-" + parentid).append("<div class=\"plugin_raid_item\" id=\"Plugin_Raid_Item" + id + "-" + (itemid+1) + "\" style=\"border-color:" + bcolor + "\">" + name + "<br></div>");
176
                } 
177
            }
178
        }
179
    });
180
}
181
 
182
/**
183
 * fill the plugin block
184
 * @param {jQuery} xml plugin-XML
185
 */
186
function raid_populate(xml) {
187
    $("#Plugin_RaidTable").empty();
188
    $("#Plugin_RaidTable").append("<tbody>");
189
    var arr = $("Plugins Plugin_Raid Raid", xml);
190
    arr.each(function raid_getdevice(id) {
191
        var htmldisks = "", buildedaction = "";
192
        htmldisks += "<table style=\"border:none; width:100%;\"><tbody>";
193
        htmldisks += "<tr><td id=\"Plugin_Raid_List-" + id + "\"></td></tr>";
194
        buildedaction = raid_buildaction($(this));
195
        if (buildedaction) {
196
            htmldisks += "<tr><td>" + buildedaction + "</td></tr>";
197
        }
198
        htmldisks += "<tr><td>" + raid_buildinfos($(this), id);
199
        /*if (id != (arr.length - 1)) { // not last element
200
            htmldisks += "<br>";
201
        }*/
202
        htmldisks += "</td></tr>";        
203
        htmldisks += "</tbody></table>";
204
 
205
        $("#Plugin_RaidTable").append("<tr><td><br>" + $(this).attr("Device_Name") + "</td><td>" + htmldisks + "</td></tr>");
206
        raid_diskicon(this, id);
207
 
208
        $("#sPlugin_Raid_Info" + id).click(function raid_showinfo() {
209
            $("#Plugin_Raid_InfoTable" + id).slideDown("fast");
210
            $("#sPlugin_Raid_Info" + id).hide();
211
            $("#hPlugin_Raid_Info" + id).show();
212
        });
213
        $("#hPlugin_Raid_Info" + id).click(function raid_hideinfo() {
214
            $("#Plugin_Raid_InfoTable" + id).slideUp("fast");
215
            $("#hPlugin_Raid_Info" + id).hide();
216
            $("#sPlugin_Raid_Info" + id).show();
217
        });
218
        raid_show = true;
219
    });
220
 
221
    $("#Plugin_RaidTable").append("</tbody>");
222
}
223
 
224
/**
225
 * load the xml via ajax
226
 */
227
function raid_request() {
228
    $("#Reload_RaidTable").attr("title", "reload");
229
    $.ajax({
230
        url: "xml.php?plugin=Raid",
231
        dataType: "xml",
232
        error: function raid_error() {
233
            $.jGrowl("Error loading XML document for Plugin Raid");
234
        },
235
        success: function raid_buildblock(xml) {
236
            populateErrors(xml);
237
            raid_populate(xml);
238
            if (raid_show) {
239
                plugin_translate("Raid");
240
                $("#Plugin_Raid").show();
241
            }
242
        }
243
    });
244
}
245
 
246
$(document).ready(function raid_buildpage() {
247
    var html = "";
248
 
249
    $("#footer").before(buildBlock("Raid", 1, true));
250
    html += "        <div style=\"overflow-x:auto;\">\n";
251
    html += "          <table id=\"Plugin_RaidTable\" style=\"border-collapse:collapse;\">\n";
252
    html += "          </table>\n";
253
    html += "        </div>\n";
254
    $("#Plugin_Raid").append(html);
255
 
256
    $("#Plugin_Raid").css("width", "915px");
257
 
258
    raid_request();
259
 
260
    $("#Reload_RaidTable").click(function raid_reload(id) {
261
        raid_request();
262
        $(this).attr("title", datetime());
263
    });
264
});