Quick ListView customization
23 Mar, 2009Posted By: Roger Smith
As the next installment in the Sugar Tips and Tricks series from the Sugar engineering team, I will perform a quick and simple ListView customization which leverages the Carousel widget from the Yahoo UI (YUI) library. This customization completely changes the look and feel of the Contact ListView from a “rows and columns” view of your search results to a Yahoo UI Carousel view. The YUI library is included in SugarCRM and provides a ton of UI features beyond what we use in the core application.

I will only need to customize two files:
- view.list.php in the Contacts module
- ListViewContacts.tpl – a new smarty file which I have added to be used within the view.list.php file
Create a new file view.list.php file in custom/modules/Contacts/views. The beginning of the file including the constructor should look like:
require_once('include/MVC/View/views/view.list.php');
class ContactsViewList extends ViewList {
function ContactsViewList(){
parent::ViewList();
}
You can see that I am extending from the ViewList class as defined in ‘include/MVC/View/views/view.list.php’ so that I can take advantage of the methods which are already implemented and only override what I need. Since I only want to change how the ListView looks, I will do most of that in Smarty so I need to only override the method in ViewList which deals with rendering the template.
listViewProcess()
should do the trick.
Here is the full listing for the ContactsViewList class below:
require_once('include/MVC/View/views/view.list.php');
class ContactsViewList extends ViewList {
function ContactsViewList(){
parent::ViewList();
}
function listViewProcess(){
$this->processSearchForm();
$this->searchColumns = $this->searchColumns;
if(!$this->headers)
return;
if(empty($_REQUEST['search_form_only']) || $_REQUEST['search_form_only'] == false){
$this->lv->setup($this->seed, 'custom/modules/Contacts/tpls/ListViewContacts.tpl', $this->where, $this->params);
$savedSearchName = empty($_REQUEST['saved_search_select_name']) ? '' : (' - ' . $_REQUEST['saved_search_select_name']);
echo get_form_header($GLOBALS['mod_strings']['LBL_LIST_FORM_TITLE'] . $savedSearchName, '', false);
echo $this->lv->display();
}
}
}
Now that we have provided a way to get my own custom smarty template loaded on the Contacts ListView, I will create my Smarty file in custom/modules/Contacts/tpls/ListViewContacts.tpl. My goal here will be to remove most of the table rendering logic defined in ListViewGeneric.tpl and replace it with my own rendering logic to display the carousel.
link rel="stylesheet" type="text/css" href='{sugar_getjspath file='include/javascript/yui/build/fonts/fonts.css'}'>
{literal}
{/literal}
{literal}
{/literal}
You can see from the above I have stripped out the table HTML and now the meat of the display is done here:
{foreach name=rowIteration from=$data key=id item=rowData}
We simply loop through each of our rows and output it into the <li> tags and then once this has rendered the JavaScript:
(function () { var carousel; YAHOO.util.Event.onDOMReady(function (ev) { var carousel = new YAHOO.widget.Carousel("container", { animation: { speed: 0.5 } }); carousel.render(); // get ready for rendering the widget carousel.show(); // display the widget }); })();will render the widget.
Pingback: mainstreet web hosting