Table of Contents Previous Next

Sugar Developer Guide

Version 5.1


Chapter 2 Application Framework : Sugar Dashlets : Sugar Dashlet Base Class

Sugar Dashlet Base Class
The main Sugar Dashlet base class is include/Dashlets/Dashlet.php. All Sugar Dashlets should extend this class.
class Dashlet {
// guid of the Dashlet, assigned on creation of the Dashlet
var $id;
// Title of the Dashlet
var $title = 'Generic Dashlet';
// true if the Dashlet has configuration options.
var $isConfigurable = false;
// true if the Dashlet contains JavaScript
var $hasScript = false;
// Language strings, must be loaded at the
// Dashlet level w/ loadLanguage
var $DashletStrings;
 
function Dashlet($id) {
$this->id = $id;
}
Each Sugar Dashlet upon creation must be assigned a unique id. This id is used in the HTML id when the Sugar Dashlet is displayed. This way multiple Sugar Dashlets of the same type can be included on the page.
// Title portion of the Dashlet, $text is any text to be put
// in between the title and the Close icon
function getTitle($text) { ...}
 
// Displays the actual Dashlets
// *Inheriting Dashlet should override this
function display($text = '') { ... }
// Displays the Dashlets options
// *Inheriting Dashlet should override this if isConfigurable
function displayOptions() { … }
// override if you need to do pre-processing before
// display is called
function process() {
}
 
// Override this if your Dashlet is configurable
// (this is called when the configureDashlet form is shown)
function saveOptions($req) {
}
saveOptions() is called when the configuration form is submitted. This function need to filter out the $_REQUEST array and only return an array of the options that needs to be saved
// loads language strings from files and stores them
// $DashletStrings. This will try to load the current language
// file first, then default of en_us
function loadLanguage($DashletClassname, $DashletDirectory) { ... }
// Generic way to store Dashlet options into user preferences
function storeOptions($optionsArray) { ... }
// Generic way to load Dashlet options from user preferences
function loadOptions() { ... }
 
Sugar Dashlets are stored in the table user_preferences under the name ‘Dashlets’ and the category ‘home’. Here is a sample array element of ‘Dashlets’ from the MyOpportunitiesDashlets
[425f8ca8-663c-dabe-b483-448f6e4fb9a8] => Array
(
[className] => MyOpportunitiesDashlet
[fileLocation] => /Dashlets./modules/Opportunities/Dashlets/MyOpportunitiesDashlet/MyOpportunitiesDashlet.php
[options] => Array
(
[filters] => Array
(
)
 
[title] => My Top Open Opportunities
[myItemsOnly] => true
[displayRows] => 5
[displayColumns] => Array
(
[0] => name
[1] => amount
[2] => team_name
)
 
)
 
)
The ‘options’ element stores the options for the Sugar Dashlet and this is the element that is loaded/stored by storeOptions / loadOptions functions in the base Dashlet class.

Table of Contents Previous Next

Copyright 2004-2008 SugarCRM Inc.
Product License