HOWTO: Add more info hover links to any record link in a subpanel

sugarcrmdevelopers —  May 8, 2012 — 6 Comments

In a follow-up to an earlier blog post, Sugar Professional customer and avid community member Blake Robertson asked this question:

I think most people would prefer to have it so when you hover over the link field it displayed more info.  Thoughts on extending SubPanelDetailViewLink widget to handle on hover events?

This actually pretty easy; you just need to add a new widget that extends from the existing one in the custom/include/generic/SugarWidgets/ directory. So for this example, let’s add a new widget named  SubPanelDetailViewLinkHover, which will build from the SubPanelDetailViewLink widget and be defined in the SugarWidgetSubPanelDetailViewLinkHover.php file as shown below:

require_once("include/generic/SugarWidgets/SugarWidgetSubPanelDetailViewLink.php");

class SugarWidgetSubPanelDetailViewLinkHover extends SugarWidgetSubPanelDetailViewLink
{
	function displayList(&$layout_def)
	{
		global $focus;

		$module = '';
		$record = '';

		if(isset($layout_def['varname']))
		{
			$key = strtoupper($layout_def['varname']);
		}
		else
		{
			$key = $this->_get_column_alias($layout_def);
			$key = strtoupper($key);
		}
		if (empty($layout_def['fields'][$key])) {
			return "";
		} else {
			$value = $layout_def['fields'][$key];
		}


		if(empty($layout_def['target_record_key']))
		{
			$record = $layout_def['fields']['ID'];
		}
		else
		{
			$record_key = strtoupper($layout_def['target_record_key']);
			$record = $layout_def['fields'][$record_key];
		}

		if(!empty($layout_def['target_module_key'])) {
			if (!empty($layout_def['fields'][strtoupper($layout_def['target_module_key'])])) {
				$module=$layout_def['fields'][strtoupper($layout_def['target_module_key'])];
			}
		}

        if (empty($module)) {
			if(empty($layout_def['target_module']))
			{
				$module = $layout_def['module'];
			}
		else
			{
				$module = $layout_def['target_module'];
			}
		}

        //links to email module now need additional information.
        //this is to resolve the information about the target of the emails. necessitated by feature that allow
        //only on email record for the whole campaign.
        $parent='';
        if (!empty($layout_def['parent_info'])) {
			if (!empty($focus)){
	            $parent="&parent_id=".$focus->id;
	            $parent.="&parent_module=".$focus->module_dir;
			}
        } else {
            if(!empty($layout_def['parent_id'])) {
                if (isset($layout_def['fields'][strtoupper($layout_def['parent_id'])])) {
                    $parent.="&parent_id=".$layout_def['fields'][strtoupper($layout_def['parent_id'])];
                }
            }
            if(!empty($layout_def['parent_module'])) {
                if (isset($layout_def['fields'][strtoupper($layout_def['parent_module'])])) {
                    $parent.="&parent_module=".$layout_def['fields'][strtoupper($layout_def['parent_module'])];
                }
            }
        }

		$action = 'DetailView';
		$value = $layout_def['fields'][$key];
		global $current_user;
		if(  !empty($record) &&
			($layout_def['DetailView'] && !$layout_def['owner_module']
			||  $layout_def['DetailView'] && !ACLController::moduleSupportsACL($layout_def['owner_module'])
			|| ACLController::checkAccess($layout_def['owner_module'], 'view', $layout_def['owner_id'] == $current_user->id)))
        {
            $linkIdTag = 'aip_' . $record;
            $mouseEvents = ' id="' . $linkIdTag . '" onmouseover="javascript:SUGAR.util.getAdditionalDetails('' . $module . '','' . $record . '','' . $linkIdTag . '');" onmouseout="javascript:cClick(); SUGAR.util.clearAdditionalDetailsCall();"';
            $link = ajaxLink("index.php?module=$module&action=$action&record={$record}{$parent}");
            return '<a href="' . $link .'"' . $mouseEvents .' >'."$value</a>";
		}else{
			return $value;
		}
	}
}

With the field defined, you can enable this for any listview field by changing the ‘widget_class’ attribute from ‘SubPanelDetailViewLink’ to ‘SubPanelDetailViewLinkHover’ and the link will now show the more info popup when you hover over the link.

6 responses to HOWTO: Add more info hover links to any record link in a subpanel

  1. 

    Where is the best-practices location that this widget should be placed? custom/include/generic/SugarWidgets/

  2. 
    Isleshocky77 May 8, 2012 at 1:47 pm

    I’m receiving the errors, “overlib is not defined” and “cClick is not defined”. I have tracked this down to Sugar not including the overlib library obviously. However, I’m not sure where I should be enabling it for my module. The hover is in a Subpanel for a custom module which is displayed with a Contact.  Should the overlib be turned on in the Contact module or somewhere in the custom modules definition of the subpanel?

  3. 

    Isleshockey77, Do you get errors on a page without your custom module?  You shouldn’t have to load overlib manually.  Location you suggested is correct.

    Call me crazy… but for a modification like this that isn’t truly upgrade safe… (in this case the 95% of displayList was copied from a core file and pasted into the custom file)…  I feel like this approach is worse then just modifying the core file.  If the displayList method changes for a good reason… we’ll be overriding it and that could lead to some really difficult to track down consequences.  Where as the worst that could happen with modifying the core file is forgetting to update it after an upgrade.  It’s also slighly annoying that with the custom widget approach you have to modify the metadata to use the new widget instead… 

  4. 

    I have a created a custom  SugarWidgets. In this I’m calling a custom Javascript function. For this javascript function, I have created a javascript file and placed it in custom/include/generic/hrishi.min.js.

    The most important thing I’m using this custom sugarwidget in subpanel as a custom button in each row.

    My custom sugarWidget loads successfully but unable to locate the custom js function which I have defined in custom/include/generic/hrishi.min.js. I am unable to include this file in proper place. Please suggest.

    Code:

    require_once(‘include/generic/SugarWidgets/SugarWidgetField.php’);

    class SugarWidgetSubPanelFabOrderItemStatusChangeButton extends SugarWidgetField {

        function displayHeaderCell(&$layout_def) {
            return ‘ ‘;
        }

        function displayList(&$layout_def) {

            global $app_strings;
            global $subpanel_item_count;
           
           
            $orderButtonAction= $layout_def[‘fab_orderbt_actionType’];
            $orderButtonActionText= $layout_def[‘fab_orderbt_actionType_text’];
           
            $unique_id = $layout_def[‘subpanel_id’] . “_remove_” . $subpanel_item_count; //bug 51512

            $parent_record_id = $_REQUEST[‘record’];
            $parent_module = $_REQUEST[‘module’];

            $action = ‘ConfirmOrderItem’;
            $record = $layout_def[‘fields’][‘ID’];
            $current_module = $layout_def[‘module’];
           
           
            $return_module = $_REQUEST[‘module’];
            $return_action = ‘SubPanelViewer’;
            $subpanel = $layout_def[‘subpanel_id’];
            $return_id = $_REQUEST[‘record’];
           
           
            $refresh_page = 1;
           
            $return_url = “index.php?module=$return_module&action=$return_action&subpanel=$subpanel&record=$return_id&sugar_body_only=1&inline=1”;

            $icon_remove_text = strtolower($app_strings[‘LBL_ID_FF_REMOVE’]);

           
         
                $retStr = ““.$orderButtonActionText.”“;
               
                return $retStr;
           
        }

    }

    The javascript function testAlan() is defined in custom/include/generic/hrishi.min.js. But I have no idea where should i include this js file. But I am calling this in custom subpane.

  5. 

    How can i add more info pop-up in detail view beside in Leads module first name.?

Leave a Reply

Fill in your details below or click an icon to log in:

WordPress.com Logo

You are commenting using your WordPress.com account. Log Out / Change )

Twitter picture

You are commenting using your Twitter account. Log Out / Change )

Facebook photo

You are commenting using your Facebook account. Log Out / Change )

Google+ photo

You are commenting using your Google+ account. Log Out / Change )

Connecting to %s