sfdeveloper
sfdeveloper

Reputation: 196

Add action menu on detail view of sugarcrm

enter image description here

I need to add action menu as shown in image on detail view. I have already referred following topic to achieve this, but it's not working for detail view.

Adding new option in the action button of sugarCRM

require_once('include/MVC/View/views/view.detail.php');

class CustomAccountsViewDetail extends ViewDetail
{
    function preDisplay()
    {
        parent::preDisplay();
        $this->dv->actionsMenuExtraItems[] = $this->buildMyMenuItem();
    }

    function buildMyMenuItem()
    {
        global $app_strings;
        return <<<EOHTML
<a class="menuItem" style="width: 150px;" href="#" onmouseover='hiliteItem(this,"yes");' 
onmouseout='unhiliteItem(this);' 
onclick="sugarListView.get_checks();
if(sugarListView.get_checks_count() &lt; 1) {
alert('{$app_strings['LBL_LISTVIEW_NO_SELECTED']}');
return false;
    }
    document.MassUpdate.action.value='displaypassedids';
    document.MassUpdate.submit();">Send records to a new view!</a>
EOHTML;
    }    
}

I have added following code in \custom\Modules\Account\views\view.detail.php Thanks

Upvotes: 0

Views: 3612

Answers (2)

sfdeveloper
sfdeveloper

Reputation: 196

Though it is tough to customize SugarCRM in it's own way, i got the answer on following link

http://www.technologyworkshops.net/php/add-custom-action-menu-in-sugarcrm-with-post-method-t133.html

This is what they say

            0 => 'EDIT',
        1 => 'DUPLICATE',
        2 => 'DELETE',
        3 => 'FIND_DUPLICATES',
        4 =>  array (
        'customCode' => '<input 
                         class="button" 
                         title = "My Duplicate",
                         value="My Duplicate,
                         type="button" 
                         name="duplicate_with_dets"  
                         onclick="var _form = document.getElementById(\'formDetailView\');
                                var element = document.createElement(\'input\');
                                //Assign different attributes to the element.
                                element.setAttribute(\'type\', \'hidden\');
                                element.setAttribute(\'value\', \'{$fields.id.value}\');
                                element.setAttribute(\'name\', \'add_dets\');
                                _form.appendChild(element);

                         _form.return_module.value=\'Accounts\'; _form.return_action.value=\'DetailView\';
                         _form.isDuplicate.value=true; _form.action.value=\'EditView\'; _form.return_id.value=\'{$fields.id.value}\';
                         SUGAR.ajaxUI.submitForm(_form);"" />',
      ),

This also adds an custom hidden field that will be posted on next page..

cheers :)

Upvotes: 1

Hakulukiam
Hakulukiam

Reputation: 379

There's a more elegant solution to that. Copy the detailviewdefs.php from modules/Accounts/metadata to custom/modules/Accounts/metadata

At the beginning of the file you have an array called 'buttons' here you can add a customCode row with any html content as shown below:

$viewdefs = array (
'Accounts' => array (
'DetailView' => array (
  'templateMeta' => array (
    'form' => array (
      'buttons' => 
      array (
        0 => 'EDIT',
        1 => 'DUPLICATE',
        2 => 'DELETE',
        3 => 
        array (
          'customCode' => '<input title="{$APP.LBL_DUP_MERGE}" accesskey="M" class="button" onclick="this.form.return_module.value=\'Opportunities\';this.form.return_action.value=\'DetailView\';this.form.return_id.value=\'{$fields.id.value}\'; this.form.action.value=\'Step1\'; this.form.module.value=\'MergeRecords\';" name="button" value="{$APP.LBL_DUP_MERGE}" type="submit">',
        ),
      ),
    ),
.
.
.
.

Upvotes: 0

Related Questions