/*************************************************************************** * 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: mdstatus.js 679 2012-09-04 10:10:11Z namiltd $ // /*global $, jQuery, buildBlock, genlang, createBar, plugin_translate, datetime */ "use strict"; //appendcss("./plugins/MDStatus/css/MDStatus.css"); var mdstatus_show = false; /** * get the details of the raid * @param {jQuery} xml part of the plugin-XML * @param {number} id id of the device */ function mdstatus_buildinfos(xml, id) { var html = "", devstatus = "", devlevel = "", devchunk = 0, devsuper = 0, devalgo = 0, devactive = 0, devregis = 0, button = ""; devstatus = $(xml).attr("Disk_Status"); devlevel = $(xml).attr("Level"); devchunk = parseInt($(xml).attr("Chunk_Size"), 10); devsuper = parseInt($(xml).attr("Persistent_Superblock"), 10); devalgo = parseInt($(xml).attr("Algorithm"), 10); devactive = parseInt($(xml).attr("Disks_Active"), 10); devregis = parseInt($(xml).attr("Disks_Registered"), 10); html += "" + genlang(5, false, "MDStatus") + "" + devstatus + ""; html += "" + genlang(6, false, "MDStatus") + "" + devlevel + ""; if (devchunk !== -1) { html += "" + genlang(7, false, "MDStatus") + "" + devchunk + "K"; } if (devalgo !== -1) { html += "" + genlang(8, false, "MDStatus") + "" + devalgo + ""; } if (devsuper !== -1) { html += "" + genlang(9, false, "MDStatus") + "" + genlang(10, false, "MDStatus") + ""; } else { html += "" + genlang(9, false, "MDStatus") + "" + genlang(11, false, "MDStatus") + ""; } if (devactive !== -1 && devregis !== -1) { html += "" + genlang(12, false, "MDStatus") + "" + devregis + "/" + devactive + ""; } button += "

\"plus\"" + genlang(4, false, "MDStatus") + "

"; button += "

\"minus\"" + genlang(4, false, "MDStatus") + "

"; button += "" + html + "
"; return button; } /** * generate a html string with the current action on the disks * @param {jQuery} xml part of the plugin-XML */ function mdstatus_buildaction(xml) { var html = "", name = "", time = "", tunit = "", percent = 0; $("Action", xml).each(function mdstatus_getaction(id) { name = $(this).attr("Name"); if (parseInt(name, 10) !== -1) { time = $(this).attr("Time_To_Finish"); tunit = $(this).attr("Time_Unit"); percent = parseFloat($(this).attr("Percent")); html += "
"; html += genlang(13, false, "MDStatus") + ": " + name + "
"; html += createBar(percent); html += "
"; html += genlang(14, false, "MDStatus") + " " + time + " " + tunit; html += "
"; } }); return html; } /** * choose the right diskdrive icon * @param {jQuery} xml part of the plugin-XML */ function mdstatus_diskicon(xml) { var html = ""; $("Disks Disk", xml).each(function mdstatus_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; 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 mdstatus_populate(xml) { var htmltypes = ""; $("#Plugin_MDStatusTable").empty(); $("Plugins Plugin_MDStatus Supported_Types Type", xml).each(function mdstatus_getsupportedtypes(id) { // htmltypes += "
  • " + $(this).attr("Name") + "
  • "; htmltypes += "" + $(this).attr("Name") + " "; }); if (htmltypes.length > 0) { htmltypes = ""; $("#Plugin_MDStatusTable").append("" + genlang(2, false, "MDStatus") + "" + htmltypes + ""); mdstatus_show = true; } $("Plugins Plugin_MDStatus Raid", xml).each(function mdstatus_getdevice(id) { var htmldisks = "", htmldisklist = "", topic = "", name = "", buildedaction = ""; name = $(this).attr("Device_Name"); htmldisklist += mdstatus_diskicon(this); htmldisks += ""; htmldisks += ""; buildedaction = mdstatus_buildaction($(this)); if (buildedaction) { htmldisks += ""; } htmldisks += ""; htmldisks += "
    " + htmldisklist + "
    " + buildedaction + "
    " + mdstatus_buildinfos($(this), id) + "
    "; if (id) { topic = ""; } else { topic = genlang(3, false, "MDStatus"); } $("#Plugin_MDStatusTable").append("" + topic + "
    " + name + "
    " + htmldisks + ""); $("#sPlugin_MDStatus_Info" + id).click(function mdstatus_showinfo() { $("#Plugin_MDStatus_InfoTable" + id).slideDown("slow"); $("#sPlugin_MDStatus_Info" + id).hide(); $("#hPlugin_MDStatus_Info" + id).show(); }); $("#hPlugin_MDStatus_Info" + id).click(function mdstatus_hideinfo() { $("#Plugin_MDStatus_InfoTable" + id).slideUp("slow"); $("#hPlugin_MDStatus_Info" + id).hide(); $("#sPlugin_MDStatus_Info" + id).show(); }); mdstatus_show = true; }); if ($("Plugins Plugin_MDStatus Unused_Devices", xml).length > 0) { $("#Plugin_MDStatusTable").append("" + genlang(15, false, "MDStatus") + "" + $(this).attr("Devices") + ""); mdstatus_show = true; } } /** * load the xml via ajax */ function mdstatus_request() { $.ajax({ url: "xml.php?plugin=MDStatus", dataType: "xml", error: function mdstatus_error() { $.jGrowl("Error loading XML document for Plugin MDStatus"); }, success: function mdstatus_buildblock(xml) { populateErrors(xml); mdstatus_populate(xml); if (mdstatus_show) { plugin_translate("MDStatus"); $("#Plugin_MDStatus").show(); } } }); } $(document).ready(function mdstatus_buildpage() { var html = ""; $("#footer").before(buildBlock("MDStatus", 1, true)); html += " \n"; html += "
    \n"; $("#Plugin_MDStatus").append(html); $("#Plugin_MDStatus").css("width", "915px"); mdstatus_request(); $("#Reload_MDStatusTable").click(function mdstatus_reload(id) { mdstatus_request(); $("#Reload_MDStatusTable").attr("title",datetime()); }); });