1. Welcome to the new MacRumors forums. See our announcement and read our FAQ

Help w/Dashcode Widget: Ping & Refresh to Indicate Status

Discussion in 'Mac Programming' started by fitinferno, Jan 19, 2007.

  1. macrumors 6502

    #1
    Hello all. Wondering if anyone can help me out w/this as I've been googling and learning all the js I can, but still can't seem to figure things out :(

    Basically, I am trying to make a widget that will show the status of 9 computers on my network I am required to monitor. I have a feeling that by pinging the computers every 5 minutes or so and seeing if it gives a response that will let me know whether it's funcitioning properly or not (my job is just to make sure they stay connected to the network).

    So, I've gone into the custom widget on Dashcode. I've gotten far enough to make a widget that has the 9 indicator buttons and then let them know that at a certain range in value 0 I want it to go green or red. However, I have no idea what to tell it so that I can have the ping status reflected as that green or red indication.

    Here's my js code for the widget. At the bottom is the silly attempt I've made at adding in a refresh, but I don't think it's what I'm looking for (to be honest, I just cut it from another widget :eek: ). I really feel thick as this sounds so simple!

    // This file was generated by Dashcode from Apple Computer, Inc.
    // You may edit this file to customize your Dashboard widget.

    function load()
    {
    setupParts();
    }

    function remove()
    {
    // your widget has just been removed from the layer
    // remove any preferences as needed
    // widget.setPreferenceForKey(null, createInstancePreferenceKey("your-key"));
    }

    function hide()
    {
    // your widget has just been hidden stop any timers to
    // prevent cpu usage
    }

    function show()
    {
    // your widget has just been shown. restart any timers
    // and adjust your interface as needed
    }

    function showBack(event)
    {
    // your widget needs to show the back

    var front = document.getElementById("front");
    var back = document.getElementById("back");

    if (window.widget)
    widget.prepareForTransition("ToBack");

    front.style.display="none";
    back.style.display="block";

    if (window.widget)
    setTimeout('widget.performTransition();', 0);
    }

    function showFront(event)
    {
    // your widget needs to show the front

    var front = document.getElementById("front");
    var back = document.getElementById("back");

    if (window.widget)
    widget.prepareForTransition("ToFront");

    front.style.display="block";
    back.style.display="none";

    if (window.widget)
    setTimeout('widget.performTransition();', 0);
    }

    if (window.widget)
    {
    widget.onremove = remove;
    widget.onhide = hide;
    widget.onshow = show;
    }
    function show ()
    {
    document.getElementById("indicator").object.setValue(1);document.getElementById("indicator1").object.setValue(1);document.getElementById("indicator2").object.setValue(1);document.getElementById("indicator3").object.setValue(1);document.getElementById("indicator4").object.setValue(1);document.getElementById("indicator5").object.setValue(1);document.getElementById("indicator6").object.setValue(1);document.getElementById("indicator7").object.setValue(1);document.getElementById("indicator8").object.setValue(1);
    }


    function refreshState() {
    if(refreshBlocked) {
    countdownCalledWhileBlocked = true;
    setTimer('blocked...');
    seconds_left = 0;
    return;
    }
    countdownCalledWhileBlocked = false;

    currentlyRefreshingState = true;
    setTimer("in progress...");
    window.clearTimeout(the_timeout);
    the_timeout = null;

    // get Location
    setupLocations();

    // setup internal and external IPs (calls checkWAN() on itself)
    addInterfaces();
    }

    // call if refresh ended
    function refreshEnded(seconds_already_set) {
    lastRefresh = new Date();
    getObj("lastRefresh").innerHTML = formatDate(lastRefresh, true);

    currentlyRefreshingState = false;
    if(!seconds_already_set) {
    seconds_left = original_timer;
    }

    setTimeout("adjustTotalSize(-1)", ANIM_DEF_TIME);
    setTimeout("countdown()", 10);
    }
     

Share This Page