Klipfolio Dashboard 5 API

Object ListControl

Object
   |
   +--ListControl

The ListControl object provides an API to a list component in the Customize Klip window. A ListControl is a single or multi-select, checked or unchecked lists of items.

Note: The term 'item' here refers to an entry in the ListControl, not an item in the Klip.

Use myTab.addListControl() to add a ListControl to a tab, where myTab is a Tab object.

Example

The following function creates a new tab called 'New Tab', then adds a multi-select ListControl with checkboxes.
 function onLoad() {
 
     // Create a new tab
     var tab = Setup.addTab( "New Tab" );
 
     // Add a listcontrol using the following parameters
     //
     //    true -- give each item in the list a checkbox
     //    true -- allow the user to select multiple items
     //
     listControl = tab.addListControl( true, true );
   
     // Add three entries
     listControl.addItem( "First Item" );
     listControl.addItem( "Second Item" );
     listControl.addItem( "Third Item" );
 }
 
The above function call to Setup.addTab( "New Tab" ) adds a new Tab object to the Klip's Setup array.

Each Tab object in the Setup array corresponds to a tab in a Klip's Customize window. This window is visible when a user right-clicks on a Klip and chooses the command 'Customize Klip...'

Each Tab object can have multiple UI components, and each Klip can have multiple tabs. Use the Button, Checkbox, ComboBox, ListControl, Spacer, Text, TextArea, and TextField objects in a tab to enable users to configure the Klip to their preferences.

Example

The following Klip shows how to filter items in a Klip using a ListControl:
<?xml version='1.0' ?>
  <klip>
     <identity>
        <title>
           API: ListControl
        </title>
     </identity>
     <locations>
        <contentsource>
           http://support.klipfolio.com/files/demo/demo.xml
        </contentsource>
      <icon>
         http://www.klipfolio.com/static/klips/klipfolio/sample_icon.png
      </icon>
      <banner>
         http://www.klipfolio.com/static/klips/klipfolio/sample_banner.png   
      </banner>
     </locations>
     <setup>
        <refresh>
          1
        </refresh>
     </setup>
     <style>
        alert { 
           type: item;
        } 
        sender {
           itemcol: 2;
           noterow: 1;
           label: 'Sender';
           emphasis: strong;
        } 
        summary {
           itemcol: 3;
           noterow: 4;
           wrap: false;
           notelabel: false;
        } 
        date {
           itemcol: 4;
           noterow: 2;
           label: 'Date';
        } 
        category {
           noterow: 3;
           label: 'Category';
        } 
        level {
           itemcol: 1;
           noterow: 5;
           notelabel: false;
           type: image;
        } 
        url {
           type: link;
        } 
        id {
           key: override;
        } 
  </style>
  <klipscript>
  <![CDATA[

// Globals
var LC_category;            // List Control Object
var LC_category_choices = [];    // Array to hold choices for List Control
var B_category_clear;        // Button event handler for clear
var B_category_all;            // Button event handler for show all

var hidden_count;

function onLoad()
{
    var tab,p;    

    // Create Filters Tab
    tab = Setup.addTab ("Filters");    

    tab.addText ("Filter category:");
    LC_category = tab.addListControl (true, false);
    LC_category.onStateChange = LC_category_onStateChange;        
    B_category_clear = tab.addButton( "Clear All" );
    B_category_clear.onClick = B_category_clear_onClick;
    B_category_all = tab.addButton( "Select All" );
    B_category_all.onClick = B_category_all_onClick;
    
    tab.addSpacer (false);
    button = tab.addButton ("Show State");
    button.onClick = show_state;


    // Load preferences
    // Retrieve Preferences for category
    var re_cat_category = new RegExp ("cat_category_(.*)", "i");
    var match;
   
    for (var i = 0; i < Prefs.length; i++) 
    { 
        match = re_cat_category.exec (Prefs[i].name);
        if (match) 
        {
            insert (LC_category, match[1], Prefs[i].value != "false");
        }
    }


    Setup.onOpen = Setup_onOpen;
    Setup.onClose = Setup_onClose;
}


function onRefresh()
{
    _t( "onRefresh () -- " + Prefs.contentsource );
    var result = Engines.Data.process ( Prefs.contentsource );
        
    // Apply Filters
    filter_items();

    return result;
}


//
// Support functions -----------------------------------------------
//

// Called when the user clicks a check box in the List Control for category
//
function LC_category_onStateChange (index)
{
    _t( "  LC_category_onStateChange(" + index + ") -- \"" + LC_category[index] + "\" set to " + this.getState(index) );
    
    var s = "cat_category_" + this[index];
    Prefs.setPref (s, this.getState(index));
    
    filter_items ();
}

// Called when the clicks the "Clear" button
//
function B_category_clear_onClick () 
{
    _t( "  B_category_clear_onClick" );
    
    for( var i = 0; i<LC_category.length; i++ ) 
    {
        var s = "cat_category_" + LC_category[i];
        LC_category.setState ( i, false);
        Prefs.setPref (s, "false");
    }
    
    filter_items ();
}

// Called when the user clicks the "Select All" button
//
function B_category_all_onClick () 
{
    _t( "  B_category_all_onClick" );
    
    for( var i = 0; i<LC_category.length; i++ ) 
    {
        var s = "cat_category_" + LC_category[i];
        LC_category.setState (i, true);
        Prefs.setPref (s, "true");
    }
    
    filter_items ();
}

// Inserts items a list control in alphabetical order
//
function insert (obj, entry, state) 
{
    var index = obj.length;
    obj.addItem( entry );
    obj.setState( index, state );
    if( index > 0 ) 
    {
        while( --index >= 0 ) 
        {
            if( obj[index + 1] < obj[index] ) 
            {
                var s = obj[index + 1];
                var state = obj.getState( index + 1 );
                var selected = obj.getSelected( index + 1 );

                obj[index + 1] = obj[index];
                obj.setState( index + 1, obj.getState( index ) ); 
                obj.setSelected( index + 1, obj.getSelected( index ) ); 

                obj[index] = s;
                obj.setState( index, state );
                obj.setSelected( index, selected );
            }
        }
    }
}


function Setup_onClose()
{
    _t( "Setup_onClose()" );
    set_status ();
}

function Setup_onOpen()
{
    _t( "Setup_onOpen()" );
    set_status ();
}

function filter_items()
{
    hidden_count = 0;
    var hidden;


    for (var i=0; i < Items.length; i++ ) 
    {
        hidden = false;

        // Dynamically build prefs for category if no prefs exist
        var category = Items[i].getData ("category");

        if (Prefs.getPref( "cat_category_" + category ) == "") 
        {
            Prefs.setPref ("cat_category_" + category, "true");
            insert( LC_category, category, true );
        }

        if ( Prefs.getPref ("cat_category_" + category) == "false" ) {
            hidden = true;
        }                        ;        


        Items[i].hidden = hidden;
        if ( Items[i].hidden == true ) {
            hidden_count++;
        }
        
    }
    set_status ();
}

function set_status() 
{
    var s = "";

    if (hidden_count > 0) 
    {
        Klip.progressmessage = "[ Hidden = " + hidden_count + "]";
    } 
}


//
// Useful Debug Code -----------------------------------------------
//
var button;
function show_state() 
{
       show_items ();
      show_itemsDeleted ();
    show_all_prefs ();
        
    // Dump state of ListControl
    for (i = 0; i < LC_category.length; i++) 
    {
        _t( "LC_category[" + i + "]=\""
            + LC_category[i] + "\" ("
            + LC_category.getState(i) + ")");
    }
}

function show_items() 
{
    if (Items.length == 0) 
    {
        trace ("There are no items in the Items[] array\r\n");
        return;
    }

    for( i = 0; i < Items.length; i++ ) 
    {
        trace ("Items[" + i + "]: \r\n");        
        queryItem (Items[i]);
    }
}

function show_itemsDeleted() 
{
    if (Items.Deleted.length == 0) 
    {
        trace ("There are no items in the Items.Deleted[] array\r\n");
        return;
    }
    
    for (i = 0; i < Items.Deleted.length; i++) 
    {
        trace ("Items.Deleted[" + i + "]: \r\n");        
        queryItem ( Items.Deleted[i]);
    }
}

function queryItem( item ) 
{
    trace( "-----------------\r\n" );
    trace( "    .hidden       = " + item.hidden + " (boolean)\r\n" );
    trace( "    .visited      = " + item.visited + " (boolean)\r\n" );
    trace( "    .canpurge     = " + item.canpurge + "  (boolean)\r\n" );
    trace( "    .alerting     = " + item.alerting + " (boolean)\r\n" );
    trace( "    .creation     = " + item.creation + " (double)\r\n" );
    trace( "    .pubdate      = " + item.pubdate + "  (double)\r\n" );
    trace( "    .lastmodified = " + item.lastmodified + "  (double)\r\n" );

    // Output the current value of each defined element in an item

        trace( "      .getData (\"level\") = \"" + item.getData( "level" ) + "\" (string)\r\n" );
        trace( "      .getData (\"sender\") = \"" + item.getData( "sender" ) + "\" (string)\r\n" );
        trace( "      .getData (\"summary\") = \"" + item.getData( "summary" ) + "\" (string)\r\n" );
        trace( "      .getData (\"date\") = \"" + item.getData( "date" ) + "\" (string)\r\n" );
        trace( "      .getData (\"category\") = \"" + item.getData( "category" ) + "\" (string)\r\n" );
        trace( "      .getData (\"url\") = \"" + item.getData( "url" ) + "\" (string)\r\n" );
        trace( "      .getData (\"id\") = \"" + item.getData( "id" ) + "\" (string)\r\n" );
    
    trace( "\r\n" );
}

function show_all_prefs() 
{
   if (Prefs.length == 0) 
   {
      trace ("There are no Prefs defined\r\n");
      return;
   }
   
   trace( "------------------------\r\n" );

   for (var i = 0; i < Prefs.length; i++) 
   { 
      trace("Prefs.getPref( \""+Prefs[i].name+"\" ) == \""+Prefs[i].value+"\"\r\n"); 
   }
   
   trace( "------------------------\r\n" );
}

function _t( s ) 
{
   trace( s + "\r\n" );
}
    ]]>
    </klipscript>
</klip>
     	
This Klip uses Klip.trace() to show many of the events as you interact with the UI.
 onRefresh () -- http://support.klipfolio.com/files/demo/demo.xml
 Setup_onOpen()
   LC_category_onStateChange(0) -- "Category 1" set to false
   LC_category_onStateChange(1) -- "Category 2" set to false
   LC_category_onStateChange(1) -- "Category 2" set to true
 Setup_onClose()
 

Accessing ListControl as an Array

You can read/write items in the ListControl through the array ListControl[]. Each item in ListControl[] is a string. For example, If there is no item at the given index, Klipfolio Dashboard will append the item to the list. If your intent is to add a new item, use addItem().


Properties Summary
 boolean disabled
          The enabled (true) or disabled (false) state of this component.
 boolean editable
          The editable (true) or static (false) state of this listcontrol.
 integer length
          The number of items in the list (read-only).
 String value
          The text of the currently selected item.
   
Function Summary
 function addItem( <String> name, [<boolean> checked, [<boolean> selected]] )
           Appends a new item to the list of items in this component.
 function clear()
           Clears all items from the listcontrol.
 function clearSelection()
           Deselects all selected in the ListControl.
 boolan getSelected( <integer> index )
           Returns the selected (true) or unselected (false) state of a specific item.
 boolan getState( <integer> index )
           Returns the checked (true) or unchecked (false) state of an item at a specific index.
 function onClick( [<integer> index] )
           Specifies a Handler Function for Klipfolio Dashboard to call when the user clicks an item in the list.
 function onDblClick( [<integer> index] )
           Specifies a Handler Function for Klipfolio Dashboard to call when the user double-clicks an item in the ListControl.
 function onEndEdit( [<integer> index [, <String> text]] )
           Specifies a Handler Function for Klipfolio Dashboard to call when the user finishes editing the text of an item in the ListControl object.
 function onStateChange( [<integer> index] )
           Specifies a Handler Function for Klipfolio Dashboard to call when the user clicks the checkbox of an item in the ListControl.
 boolean remove( <String> name | <integer> index )
           Removes the specified item.
 boolan setSelected( <integer> index, <boolean> state )
           Sets the selected (true) or unselected (false) state of a specific item.
 function setState( <integer> index, <boolean> state )
           Sets the checked (true) or unchecked (false) state of an item at a specific index.

Properties Detail

disabled

boolean disabled

editable

boolean editable

length

integer length

value

String value

Function Detail

addItem

function addItem( <String> name, [<boolean> checked, [<boolean> selected]] )

clear

function clear()

clearSelection

function clearSelection()

getSelected

boolan getSelected( <integer> index )

getState

boolan getState( <integer> index )

onClick

function onClick( [<integer> index] )

onDblClick

function onDblClick( [<integer> index] )

onEndEdit

function onEndEdit( [<integer> index [, <String> text]] )

onStateChange

function onStateChange( [<integer> index] )

remove

boolean remove( <String> name | <integer> index )

setSelected

boolan setSelected( <integer> index, <boolean> state )

setState

function setState( <integer> index, <boolean> state )

Klipfolio Dashboard 5 API

© 2009 Klipfolio Inc. All Rights Reserved.