Iām trying to hide a panel from Account DetailView depending on the Account Status (custom field).
Iāve been searching arround and Iāve found two ways of doing it, one is using de DevToolKit and the other one by edit the /custom/modules/accounts/views/view.detail.php
The first option didnāt work, and Iām triying with the second, by now I have:
function display(){
if(empty($this->bean->id)){
global $app_strings;
sugar_die($app_strings['ERROR_NO_RECORD']);
}
if($this->bean->estat_c =='POT'){
echo('This is working');
unset($this->dv->defs['panels']['lbl_detailview_panel3']);
}
...
The message āThis is workingā works, but I see the panel. Also tryied in UpperCase and other panel names (lbl_account_information).
I saw in other pots from sugarcrm that this is posible.
Finally Iāve fonud a solution after a long research:
Every time I edit the view-detail file, I make a quick repair and then the page is catched and is showing the panel on the first condition occurs on the client, but for all clients, so if the firts condition was āPOTā then all Accounts panels will be printing the same panels as āPOTā even they arenāt āPOTā.
The only way Iāve found to avoid this is to enable develop mode before the function:
$GLOBALS['sugar_config']['developerMode'] = true;
and then it works.
I think this isnāt the cleanest way to do it. If anyone find a better way to do it it would be great to share it.
Hereās another way using Javascript in your custom ViewDetail
public function display(){
$js= '';
if (your condition to hide panel) {
//JS to hide the panel
$js = <<<EOQ
<script>
// Theme Suite7 & SuiteR
$("#detailpanel_2").addClass('hidden');
// Theme SuiteP
$("a[href=#top-panel-0]").parents('.panel-default').addClass('hidden');
// Hide the tab - common to all themes
$("a#tab1").parent().addClass('hidden');
</script>
EOQ;
}
parent::display();
echo $js; //echo the script.
}
So Iām trying to follow this thread (Iām a noob at this stuff) I gather I need to:
create a custom view.detail.php file in /custom/modules/my_module/view.detail.php
In my case if Line of Business is HVAC I want to hide the 3rd tab, id=ātab2ā
I have to extend ViewDetail and then use the above JS to hide the tab by changing the class to āhiddenā
Am I understanding it correctly or is it more complicated? (I canāt seem to get it to work)
<?php
if (!defined('sugarEntry') || !sugarEntry) {
die('Not A Valid Entry Point');
}
require_once("include/MVC/View/views/view.detail.php");
class bldg_Other_OppsViewDetail extends ViewDetail
{
if($this->bean->line_of_business_c =='HVAC'){
public function display(){
$js= '';
//JS to hide the panel
$js = <<<EOQ
<script type="text/javascript">
// Theme Suite7 & SuiteR
$("#detailpanel_2").addClass('hidden');
// Theme SuiteP
$("a[href=#top-panel-0]").parents('.panel-default').addClass('hidden');
// Hide the tab - common to all themes
$("a#tab2").parent().addClass('hidden');
</script>
EOQ;
parent::display();
echo $js; //echo the script.
}
}
}
Iām using js to hide panel. It is working good with Suie7 until update. When i use SuiteP theme, it doesnāt work. What is wrong? Let me know please.
require_once('include/MVC/View/views/view.detail.php');
class ContactsViewDetail extends ViewDetail {
function display() {
$role_to_check ="CIAD Comitee";
$user_in_group = FALSE;
global $current_user;
global $db;
$getusergroup="select s.securitygroup_id as id from securitygroups_users s where s.deleted=0 and s.user_id='".$current_user->id."'
and s.securitygroup_id in ('ae3d24dc-734d-4c21-149f-4c5035f8b5f8','d357b5ce-1c66-899d-03c9-4c6e20adcd36','8ad4e0e8-8eb4-d10a-a611-4c034f1c5e06')";
$resgetusergroup=$db->query($getusergroup, true);
if($db->getRowCount($resgetusergroup)>0) {
$user_in_group = TRUE;
}
$getuserindss="select s.securitygroup_id as id from securitygroups_users s where s.deleted=0 and s.user_id='".$current_user->id."' and s.securitygroup_id in ('8ad4e0e8-8eb4-d10a-a611-4c034f1c5e06')";
$resgetuserindss=$db->query($getuserindss, true);
if($db->getRowCount($resgetuserindss)>0) {
$user_in_dss = TRUE;
}
if (!$user_in_group){
echo "<script>$(document).ready(function(){ $('#LBL_PANEL100').hide();";
echo "$('#whole_subpanel_contacts_ahis_academichist').hide();";
echo "$('#whole_subpanel_contacts_ahis_advisors').hide();});</script>";
unset($this->dv->defs['templateMeta']['form']['panels']['lbl_panel100']);
$this->th2 = new TemplateHandler();
$this->th2->clearCache($this->module);
}
if (!$user_in_dss){
echo "<script>$(document).ready(function(){ $('#LBL_PANEL101').hide();$('#LBL_PANEL2').hide();});</script>";
unset($this->dv->defs['templateMeta']['form']['panels']['lbl_panel101']);
unset($this->dv->defs['templateMeta']['form']['panels']['lbl_panel2']);
$this->th2 = new TemplateHandler();
$this->th2->clearCache($this->module);
}
$this->dv->process();
echo $this->dv->display();
}
function process() {
echo '<script src="custom/javascript/jquery/external/jquery/jquery.js" type="text/javascript"></script>';
print '<style type="text/css">#create_link, #create_image{ display:none; }</style>';
parent::process();
}
}
I know this post was 5 years ago, but I am working with SuiteCRM v7 and am trying to do what your solution allows, so hopefully you are still available to exchange ideas.
I used your solution and it works fine for my detailview - using both panels and tabs - with the following code
<?php
if(!defined('sugarEntry') || !sugarEntry) die('Not A Valid Entry Point');
require_once('modules/Accounts/views/view.detail.php');
class CustomAccountsViewDetail extends AccountsViewDetail {
public function display() {
// Hide the Venue Information panel if the account_type is not Venue
// Note the use of the editview panel definition 'lbl_editview_panel1'
// which is used since we are synchronizing editview to detailview
if ( $this->bean->account_type != "Venue" ) {
//JavaSscript to hide the panel
$jScriptToHidePanel = '';
// Note that as of phpv7.3 the heredoc contents can be indented
// including the end-of-heredoc line
// Two caveats:
// - the contents of the heredoc must be indented
// at least as much as the end-of-heredoc line
// - the indentation can be either tab or space
// but NOT a combination of both
$jScriptToHidePanel = <<<EndOfScript
<script type="text/javascript">
// Hide the panel
// Theme SuiteP
// Note the difference in the href between editviewdef and detailviewdef
$("a[href=#top-panel-1]").parents('.panel-default').addClass('hidden');
// Hide the tab - common to all themes
$("a#tab2").parent().addClass('hidden');
</script>
EndOfScript;
}
parent::display();
echo $jScriptToHidePanel;
}
}
However, when I try to do the same for the editview, it does work when I use tabs, but not when I use panels. I did change the id to match the panel description for editview instead of detailview, but it does not help
<?php
if(!defined('sugarEntry') || !sugarEntry) die('Not A Valid Entry Point');
require_once('modules/Accounts/views/view.edit.php');
class CustomAccountsViewEdit extends AccountsViewEdit {
public function display() {
// Hide the Venue Information panel if the account_type is not Venue
if ( $this->bean->account_type != "Venue" ) {
//JavaSscript to hide the panel
$jScriptToHidePanel = '';
// Note that as of phpv7.3 the heredoc contents can be indented
// including the end-of-heredoc line
// Two caveats:
// - the contents of the heredoc must be indented
// at least as much as the end-of-heredoc line
// - the indentation can be either tab or space
// but NOT a combination of both
$jScriptToHidePanel = <<<EndOfScript
<script type="text/javascript">
// Hide the panel
// Theme SuiteP
// Note the difference in the href between editviewdef and detailviewdef
$("a[href=#detailpanel_1]").parents('.panel-default').addClass('hidden');
// Hide the tab - common to all themes
$("a#tab2").parent().addClass('hidden');
</script>
EndOfScript;
}
parent::display();
echo $jScriptToHidePanel;
}
}
Do you have any suggestions for how to make this work for the Edit View when using Panels?
So I have it working on edit view perfectly with the code below. My problem is that when I create a new account, it hides the panel because obviously the record is not created yet and ālead_account_type_dom_cā will always not be equal to lender.
Iāve tried AND isset() and !=Null, I just canāt see the right condition for my IF statement to show the tab when itās a new record and the field is blank, or not populated. Anyone point me in the right direction.
<?php
if(!defined('sugarEntry') || !sugarEntry) die('Not A Valid Entry Point');
require_once('modules/Accounts/metadata/editviewdefs.php');
class CustomAccountsViewEdit extends ViewEdit {
public function display() {
// Hide the Venue Information panel if the account_type is not Venue
$value= $this->bean->lead_account_type_dom_c;
if ( $value !="Lender" ) {
//JavaSscript to hide the panel
$jScriptToHidePanel = '';
// Note that as of phpv7.3 the heredoc contents can be indented
// including the end-of-heredoc line
// Two caveats:
// - the contents of the heredoc must be indented
// at least as much as the end-of-heredoc line
// - the indentation can be either tab or space
// but NOT a combination of both
$jScriptToHidePanel = <<<EndOfScript
<script type="text/javascript">
// Hide the panel
// Theme SuiteP
// Note the difference in the href between editviewdef and detailviewdef
$("a[href=#detailpanel_1]").parents('.panel-default').addClass('hidden');
// Hide the tab - common to all themes
$("a#tab1").parent().addClass('hidden');
</script>
EndOfScript;
}
parent::display();
echo $jScriptToHidePanel;
}
}
Thanks @pgr your the best!!! Youāve helped me out tons over the years. Huge thank you. That totally worked!!!
So basically in edit view, a new record shows the tab, since what ātypeā of account isnāt established yet, and if you are editing an existing record, it works properly and hides the tab when it meets the conditions. Working code is below if anyone else needs it:
<?php
if(!defined('sugarEntry') || !sugarEntry) die('Not A Valid Entry Point');
require_once('modules/Accounts/metadata/editviewdefs.php');
class CustomAccountsViewEdit extends ViewEdit {
public function display() {
// Hide the Venue Information panel if the account_type is not Venue
$value= $this->bean->lead_account_type_dom_c;
$id = $this->bean->id;
if ( $value !="Lender" and isset($id)) {
//JavaSscript to hide the panel
$jScriptToHidePanel = '';
// Note that as of phpv7.3 the heredoc contents can be indented
// including the end-of-heredoc line
// Two caveats:
// - the contents of the heredoc must be indented
// at least as much as the end-of-heredoc line
// - the indentation can be either tab or space
// but NOT a combination of both
$jScriptToHidePanel = <<<EndOfScript
<script type="text/javascript">
// Hide the panel
// Theme SuiteP
// Note the difference in the href between editviewdef and detailviewdef
$("a[href=#detailpanel_1]").parents('.panel-default').addClass('hidden');
// Hide the tab - common to all themes
$("a#tab1").parent().addClass('hidden');
</script>
EndOfScript;
}
parent::display();
echo $jScriptToHidePanel;
}
}