Click here to Skip to main content
15,881,709 members
Articles / Programming Languages / C#

Events Manager: A Vista Gadget

Rate me:
Please Sign up or sign in to vote.
4.35/5 (28 votes)
2 Feb 20076 min read 91.8K   2.6K   55  
An events manager gadget for Windows Vista
// JScript File
// Slider struct (see Slider.js for more details)
var A_INIT = {'s_name': 'SliderInput','n_minValue' : 0,'n_maxValue' : 100,'n_value' : 100,'n_step' : 1,'b_vertical' : true,'b_watch': true,'n_controlWidth': 10,'n_controlHeight': 100,'n_sliderWidth': 10,'n_sliderHeight': 35,'n_pathLeft' : 0,'n_pathTop' : 0,'n_pathLength' : 66,'s_imgControl' : '../images/SliderBgImage.gif', 's_imgSlider': '','n_zIndex': 1}
// Init the gadget's important settings
function Init()
{
//debugger;
    // Load saved and/or default settings
    SetSettings();
    // Init slider
    SetSlider();
    // Set size for Dock/Undock
    System.Gadget.onUndock = DockUndock;
    System.Gadget.onDock = DockUndock;
    DockUndock();
    UpdateSizeAndLocation();
    // Set the settings html page
    System.Gadget.settingsUI = "Settings.htm";
    // Set the flyout html page
    System.Gadget.Flyout.file = "AddEvent.htm";
    System.Gadget.onSettingsClosed = SettingsClosed;
    // Start a timer to check for upcoming events
    NotificationTimer();
}
// Show event's details
function DisplayEventInfo(eventId)
{
    var radical = "Event" + eventId;
    EditEventId = eventId;
    // read data from settings
    // and then fill fields in the EventInfo div
    document.getElementById("EventInfoName").innerHTML = System.Gadget.Settings.read(radical+"Name");
    document.getElementById("EventInfoName").title = System.Gadget.Settings.read(radical+"Name");
    document.getElementById("EventInfoDate").innerHTML = System.Gadget.Settings.read(radical+"EventDate");
    document.getElementById("EventInfoDescription").innerHTML = System.Gadget.Settings.read(radical+"Description");
    document.getElementById("EventInfoDescription").title = System.Gadget.Settings.read(radical+"Description");
    document.getElementById("DeleteEvent").href = "javascript:RemoveEvent(" + eventId + ");";
    // Show the EventInfo div
    document.getElementById("EventInfo").style.visibility = "visible";
    // Hide events list when gadget is docked
    if (System.Gadget.docked) document.getElementById("LeftPage").style.visibility = "hidden";
}
// Hide event's details
function HideEventInfo()
{
    // Hide EventInfo div
    document.getElementById("EventInfo").style.visibility = "hidden";
    // Show events list when gadget is docked
    if (System.Gadget.docked) document.getElementById("LeftPage").style.visibility = "visible";
}
// Show flyout in add event mode
function ShowAddEventFlyout()
{
    if(System.Gadget.Flyout.show==false)
    {
        System.Gadget.Flyout.show = true;
        // MainScript is used to call functions of this window from flyout
        System.Gadget.Flyout.document.MainScript = this;
        System.Gadget.Flyout.document.EventId = CurrentEventId;
        System.Gadget.Flyout.document.EditEvent = false;
    }
    else
    {
        System.Gadget.Flyout.show = false;
    }
}
// Show flyout in edit event mode
function ShowEditEventFlyout()
{
    if(System.Gadget.Flyout.show==false)
    {
        System.Gadget.Flyout.show = true;
        // MainScript is used to call functions of this window from flyout
        System.Gadget.Flyout.document.MainScript = this;
        System.Gadget.Flyout.document.EventId = EditEventId;
        System.Gadget.Flyout.document.EditEvent = true;
    }
    else
    {
        System.Gadget.Flyout.show = false;
    }
}
// Hide flyout
function HideAddEventFlyout()
{
    System.Gadget.Flyout.show = false;
}
// Called when settings window is closed
function SettingsClosed()
{
    // Save new settings
    SetSettings();
    // Update gadget's layout
    UpdateSizeAndLocation();
    UpdateSliderInput();
}
// Activate the search box
function EnableSearchTextBox()
{
    document.getElementById("SearchTextBox").className = "";
    document.getElementById("SearchIcon").className = "searchCloseButton";
}
// Disable the search box
function DisableSearchTextBox()
{
    var searchTextBox = document.getElementById("SearchTextBox");
    searchTextBox.value = ""
    searchTextBox.className = "disabled";    
    document.getElementById("SearchIcon").className = "searchIcon";
    //Reload the event's list
    LoadEvents();
}
function CloseSearch()
{
    DisableSearchTextBox();
}
// Set slider visibility
// depending of the events number
function SetSlider()
{
    var slider = document.getElementById("Slider");
    if(EventsNumber > EventsPerPage)
    {
        slider.style.visibility = "visible";
    }
    else
    {
        slider.style.visibility = "hidden";
    }
}
// Scroll the event's list
function UpdateSliderInput()
{
    var eventsList = document.getElementById("EventsList");
    if(EventsNumber > EventsPerPage)
    {
        var percentage = (100 - parseInt(document.getElementById("SliderInput").value)) / 100;
        eventsList.style.top = parseInt(-(EventsNumber - EventsPerPage) * 20 * percentage) + "px";
    }
    else
    {
        eventsList.style.top = "0px";
    }
}
// Update the gadget size
function DockUndock()
{
    if (System.Gadget.docked)
    {
        HideEventInfo();
        document.getElementById("Body").style.width = "134px";
    }
    else
    {
        document.getElementById("Body").style.width = "268px";        
        document.getElementById("LeftPage").style.visibility = "visible";        
    }
}
// Update layers (div) size and location
// for visual coherence
function UpdateSizeAndLocation()
{
    var listHeight = (EventsPerPage * 20);
    document.getElementById("Events").style.height = listHeight + "px";
    document.getElementById("RightPage").style.height = listHeight + "px";
    document.getElementById("Footer").style.top =  (listHeight + 50) + "px";
    document.getElementById("Body").style.height = (listHeight + 60) + "px";
    document.getElementById("Binder").style.height = (listHeight + 30) + "px";
    document.getElementById("EventInfoDescription").style.height = (listHeight - 35) + "px";
}

By viewing downloads associated with this article you agree to the Terms of Service and the article's licence.

If a file you wish to view isn't highlighted, and is a text file (not binary), please let us know and we'll add colourisation support for it.

License

This article has no explicit license attached to it but may contain usage terms in the article text or the download files themselves. If in doubt please contact the author via the discussion board below.

A list of licenses authors might use can be found here


Written By
Canada Canada
This member has not yet provided a Biography. Assume it's interesting and varied, and probably something to do with programming.

Comments and Discussions