SugarCRM Developer Blog

Quick ListView customization

23 Mar, 2009
Posted 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.

Carousel Widget on Contacts Listview

I will only need to customize two files:

  1. view.list.php in the Contacts module
  2. 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:

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.

  • http://www.robertsjeremy.com/ Jeremy R

    Thanks! This information was exactly what I was after in order to custom a list only slightly. Though, I can see potential for a cool customisation to optionally select an option to make the contacts listview appear as contact cards, like in outlook!

  • http://www.robertsjeremy.com Jeremy R

    Thanks! This information was exactly what I was after in order to custom a list only slightly. Though, I can see potential for a cool customisation to optionally select an option to make the contacts listview appear as contact cards, like in outlook!

  • http://radicalpython.blogspot.com/ RadicalEd

    Hi, I have a question, I followed your instructions but when I want to seed the view in the explorer it shows me the default view, What could happend?

    Thanks

  • http://radicalpython.blogspot.com RadicalEd

    Hi, I have a question, I followed your instructions but when I want to seed the view in the explorer it shows me the default view, What could happend?

    Thanks

  • http://www.thecampaigncompany.co.uk/ christian

    Hello, I am new in Sugar, I am interesting to get a proper display in my contact list. I followed the instruction, but get this error message.
    Any ideas?

    thank you.
    Christian.

    Warning: Smarty error: unable to read resource: “custom/modules/Contacts/tpls/ListViewContacts.tpl” in /home/tccwebsi/public_html/sugar/include/Smarty/Smarty.class.php on line 1095

  • http://www.thecampaigncompany.co.uk christian

    Hello, I am new in Sugar, I am interesting to get a proper display in my contact list. I followed the instruction, but get this error message.
    Any ideas?

    thank you.
    Christian.

    Warning: Smarty error: unable to read resource: “custom/modules/Contacts/tpls/ListViewContacts.tpl” in /home/tccwebsi/public_html/sugar/include/Smarty/Smarty.class.php on line 1095

  • David

    You said SugarCRM will introduce a fresh look and feel to CRM this summer. We are looking to see more updates for this. I'm impressed by the clean friendly design as well. David part of hemorrhoids treatment team.

  • http://www.panicblock.com controlling panic attacks

    thanks for the explanation.

  • http://www.mysassydate.com completely free dating sites

    are we able to easily add column and rows into it?

  • http://www.keeperglove.com reusch goalkeeper gloves

    Hi,
    I'm new in sugar too……hope everything is easy smooth and sweet as, programming is not really my specialty but was force to for my project.

  • Pingback: mainstreet web hosting

Have feedback for us? Drop us a line.
Terms & Conditions | Privacy | Trademark Info | Contact Info | FAQs | SugarCRM Inc.© 2004 - 2009 All rights reserved.