/***************************************************************************
* Copyright (C) 2008 by phpSysInfo - A PHP System Information Script *
* http://phpsysinfo.sourceforge.net/ *
* *
* 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., *
* 59 Temple Place - Suite 330, Boston, MA 02111-1307, USA. *
***************************************************************************/
//
// $Id: dmraid.js 679 2012-09-04 10:10:11Z namiltd $
//
/*global $, jQuery, buildBlock, genlang, createBar, plugin_translate, datetime */
"use strict";
var dmraid_show = false;
/**
* get the details of the raid
* @param {jQuery} xml part of the plugin-XML
* @param {number} id id of the device
*/
function dmraid_buildinfos(xml, id) {
var html = "", devname = "", devstatus = "", devtype = "",devsize = 0, devstride = 0, devsubsets = 0, devdevs = 0, devspares = 0, button = "";
devname = $(xml).attr("Name");
devstatus = $(xml).attr("Disk_Status");
devtype = $(xml).attr("Type");
devsize = parseInt($(xml).attr("Size"), 10);
devstride = parseInt($(xml).attr("Stride"), 10);
devsubsets = parseInt($(xml).attr("Subsets"), 10);
devdevs = parseInt($(xml).attr("Devs"), 10);
devspares = parseInt($(xml).attr("Spares"), 10);
html += "
" + genlang(4, false, "DMRaid") + " | " + devname + " |
";
html += "" + genlang(5, false, "DMRaid") + " | " + devstatus + " |
";
html += "" + genlang(6, false, "DMRaid") + " | " + devtype + " |
";
html += "" + genlang(7, false, "DMRaid") + " | " + devsize + " |
";
html += "" + genlang(8, false, "DMRaid") + " | " + devstride + " |
";
html += "" + genlang(9, false, "DMRaid") + " | " + devsubsets + " |
";
html += "" + genlang(10, false, "DMRaid") + " | " + devdevs + " |
";
html += "" + genlang(11, false, "DMRaid") + " | " + devspares + " |
";
button += "" + genlang(3, false, "DMRaid") + "
";
button += "" + genlang(3, false, "DMRaid") + "
";
button += "";
return button;
}
/**
* choose the right diskdrive icon
* @param {jQuery} xml part of the plugin-XML
*/
function dmraid_diskicon(xml) {
var html = "";
$("Disks Disk", xml).each(function dmraid_getdisk(id) {
var diskstatus = "", diskname = "", img = "", alt = "";
html += "";
diskstatus = $(this).attr("Status");
diskname = $(this).attr("Name");
switch (diskstatus) {
case " ":
case "":
img = "harddriveok.png";
alt = "ok";
break;
case "F":
img = "harddrivefail.png";
alt = "fail";
break;
case "S":
img = "harddrivespare.png";
alt = "spare";
break;
case "W":
img = "harddrivewarn.png";
alt = "fail";
break;
default:
alert("--" + diskstatus + "--");
img = "error.png";
alt = "error";
break;
}
html += "
";
html += "
" + diskname + "";
html += "
";
});
return html;
}
/**
* fill the plugin block
* @param {jQuery} xml plugin-XML
*/
function dmraid_populate(xml) {
var htmltypes = "";
$("#Plugin_DMRaidTable").empty();
$("Plugins Plugin_DMRaid Raid", xml).each(function dmraid_getdevice(id) {
var htmldisks = "", htmldisklist = "", topic = "", name = "", buildedaction = "";
name = $(this).attr("Device_Name");
htmldisklist += dmraid_diskicon(this);
htmldisks += "";
htmldisks += "" + htmldisklist + " |
";
htmldisks += "" + dmraid_buildinfos($(this), id) + " | |
";
htmldisks += "
";
if (id) {
topic = "";
}
else {
topic = genlang(2, false, "DMRaid");
}
$("#Plugin_DMRaidTable").append("" + topic + " | " + name + " " + htmldisks + " |
");
$("#sPlugin_DMRaid_Info" + id).click(function dmraid_showinfo() {
$("#Plugin_DMRaid_InfoTable" + id).slideDown("slow");
$("#sPlugin_DMRaid_Info" + id).hide();
$("#hPlugin_DMRaid_Info" + id).show();
});
$("#hPlugin_DMRaid_Info" + id).click(function dmraid_hideinfo() {
$("#Plugin_DMRaid_InfoTable" + id).slideUp("slow");
$("#hPlugin_DMRaid_Info" + id).hide();
$("#sPlugin_DMRaid_Info" + id).show();
});
dmraid_show = true;
});
}
/**
* load the xml via ajax
*/
function dmraid_request() {
$.ajax({
url: "xml.php?plugin=DMRaid",
dataType: "xml",
error: function dmraid_error() {
$.jGrowl("Error loading XML document for Plugin DMRaid");
},
success: function dmraid_buildblock(xml) {
populateErrors(xml);
dmraid_populate(xml);
if (dmraid_show) {
plugin_translate("DMRaid");
$("#Plugin_DMRaid").show();
}
}
});
}
$(document).ready(function dmraid_buildpage() {
var html = "";
$("#footer").before(buildBlock("DMRaid", 1, true));
html += " \n";
$("#Plugin_DMRaid").append(html);
$("#Plugin_DMRaid").css("width", "915px");
dmraid_request();
$("#Reload_DMRaidTable").click(function dmraid_reload(id) {
dmraid_request();
$("#Reload_DMRaidTable").attr("title",datetime());
});
});