How to hide “Checkbox” for contracts ListView in Sugarcrm for the records having status = 'Signed'?

Hello everyone ,

How to hide or remove “Checkbox” for Contracts ListView in “SugarCRM Community Edition 6.5.16” for the records having status = ‘Signed’.

Regards, IDRISSI Soukaina

Hi There,

Do you mean the Checkbox that selects a record for Mass Actions i.e. Delete, Mass Update and Export?

1 Like

yes exactly

if possible, Can u help me to solve this issue ??

Hi there,

To adjust the ListView template without using javascript you will need to create a custom ListView template specific for AOS_Contracts.

  1. Create a new file called ‘view.list.php’ within ‘custom/modules/AOS_Contracts/views’ (create this folder structure if you haven’t got it already)

  2. Insert the following code into your new view.list.php


<?php
require_once('include/MVC/View/views/view.list.php');

class AOS_ContractsViewList extends ViewList
{
    function AOS_ContractsViewList(){

        parent::ViewList();
    }

    function listViewProcess(){
       $this->processSearchForm();
        $this->lv->searchColumns = $this->searchForm->searchColumns;

        if(!$this->headers)
            return;
        if(empty($_REQUEST['search_form_only']) || $_REQUEST['search_form_only'] == false){
            $this->lv->ss->assign("SEARCH",true);
            $this->lv->setup($this->seed, 'custom/modules/AOS_Contracts/tpls/ListViewContracts.tpl', $this->where, $this->params);
            $savedSearchName = empty($_REQUEST['saved_search_select_name']) ? '' : (' - ' . $_REQUEST['saved_search_select_name']);
            echo $this->lv->display();
        }

    }

}

The line we are interested in is the call to the template:


$this->lv->setup($this->seed, 'custom/modules/AOS_Contracts/tpls/ListViewContracts.tpl', $this->where, $this->params);

I have linked in a (soon to be) custom ListView template to overwrite the existing Generic one.

  1. Copy the generic template from below

include/ListView/ListViewGeneric.tpl

and rename the copy to:


custom/modules/AOS_Contracts/tpls/ListViewContracts.tpl
  1. Now edit the new custom template to disable the checkbox if the Contract’s status is ‘Signed’. Navigate to around the below code (around line 184):

{if $prerow}
					<td width='1%' class='nowrap'>
						{if !$is_admin && is_admin_for_user && $rowData.IS_ADMIN==1}
							<input type='checkbox' disabled="disabled" class='checkbox' value='{$rowData.ID}'>
						{else}
							<input title="{sugar_translate label='LBL_SELECT_THIS_ROW_TITLE'}" onclick='sListView.check_item(this, document.MassUpdate)' type='checkbox' class='checkbox' name='mass[]' value='{$rowData.ID}'>
						{/if}
					</td>
				{/if}

and replace it with the following:


{if $prerow}
					<td width='1%' class='nowrap'>
						{if !$is_admin && is_admin_for_user && $rowData.IS_ADMIN==1}
							<input type='checkbox' disabled="disabled" class='checkbox' value='{$rowData.ID}'>
						{else}
							{if $pageData.bean.moduleDir == 'AOS_Contracts' && $rowData.STATUS == 'Signed'}
								<input type='checkbox' disabled="disabled" class='checkbox' value='{$rowData.ID}'>
							{else}
								<input title="{sugar_translate label='LBL_SELECT_THIS_ROW_TITLE'}" onclick='sListView.check_item(this, document.MassUpdate)' type='checkbox' class='checkbox' name='mass[]' value='{$rowData.ID}'>
							{/if}
						{/if}
					</td>
				{/if}
  1. After saving, do a Quick Repair & Rebuild via Admin > Repair. This will refresh all the template caches.

  2. Then visit the ListView of Contracts and now it should show disabled checkboxes if the Contracts’ status equals ‘Signed’.

Let me know if that helps.

1 Like

Thank u for ur replay Mr AshleyNic

I followed the steps, step by step, but I have no result
STEP1: Create view.list.php file in <PRJ_NAME>\custom\modules<MODULE_NAME>\views
In this file i added this code

AFTER that i created a tpls folder in : <PRJ_NAME>\custom\modules<MODULE_NAME>tpls\ListViewContrat.tpl based on generic tpl file in the include directory and in this file i modified the preRow part like that :

and FINALLY i clicked quick repair

But the checkboxes r not disabled

Hi dpccrt87

In the view.list.php change all the <MODULE_NAME> to the names of your module (which I believe is P_Aws_Contrat)

Also in the ListViewContrat.tpl change the field name to uppercase characters: STATUT_CTR_C

Double check that ‘Signed’ is the correct value of that dropdown.

Try that and let me know how you get on.

1 Like

Ok Miss AshleyNic ,
yes the <MODULE_NAME> is already replaced by P_Asw_Contrat in view.list.php
ok,I will write in upper case, and I’ll let you know the result, now
Signed is the value stored in DB

The view.list.php is

The ListViewContrat.tpl is

And i did quick repair , but nothing happen

Ok, lets try abit of troubleshooting.

If you put into ListViewContrat.tpl a HELLO somewhere:


{if $prerow}
					<td width='1%' class='nowrap'>
HELLO<br />
$rowData.STATUT_CTR_C<br />

						{if !$is_admin && is_admin_for_user && $rowData.IS_ADMIN==1}
							<input type='checkbox' disabled="disabled" class='checkbox' value='{$rowData.ID}'>
						{else}
							{if $pageData.bean.moduleDir == 'P_Aws_Contrat' && $rowData.STATUT_CTR_C == 'Signed'}
								<input type='checkbox' disabled="disabled" class='checkbox' value='{$rowData.ID}'>
							{else}
								<input title="{sugar_translate label='LBL_SELECT_THIS_ROW_TITLE'}" onclick='sListView.check_item(this, document.MassUpdate)' type='checkbox' class='checkbox' name='mass[]' value='{$rowData.ID}'>
							{/if}
						{/if}
					</td>
				{/if}

Do a Repair & Rebuild and hopefully this will at least show that this is indeed using the custom list view template.

1 Like

Thank u miss Miss AshleyNic now it works( but in 50%), I had to change the value Signed,
But I still have a concern is that when I go to the advanced search, and when I change the structure of the list view by masking the status of the contract, the list view returns to its initial state (ie the checkbox and edit_pencil appear bright)

Bcz of that i wanted to remove the layout option in ADVANCED SEARCH

When I do advanced search the ListView appears as expected - the checkbox is disabled. I didn’t include the pencil to be disabled - will need to adjust that.

Could you show me screenshot of the normal ListView (when you have no searches) and a Advanced Search ListView screenshot.

Thanks!

1 Like

ok ;
Concerning the edit pencil i did it using logic hook
like that

NB: But if I could hide the EDIT_BTN using only the TPL file that will be the ideal

LISTVIEW without searching is like that

LISTVIEW using advanced search is like that

Ahhhh!

That possibly an issue - we’ll have a think about this and get back to you.

1 Like

ok, Thank u so so much Miss AshleyNic;
But if I want to hide, the part of columns in layout option , just a temporary way,
How I can proceed ??

Ok dpccrt87,

I have a response.

What you will need to do in steps are:

  1. Create a Custom template (which you have) that will disable and remove the edit button if Status EQUALS Signed
  2. Always ensure that the Status field is included in the ListView columns regardless if it is in the ‘Hide Columns’ selection - this is a must as that will be the only way to determine if it is Signed or not.

You will need to edit two files (which you should have already created).

custom/modules/<MODULE_NAME>/tpls/ListView<MODULE_NAME>.tpl
custom/modules/<MODULE_NAME>/views/view.list.php

Within view.list.php you will need to copy another function from the generic view.list.php (include/MVC/View/views/view.list.php) called listViewPrepare. Paste that function in above the already copied and edited function listViewProcess.

Essentially we are going to trick the system into thinking you are going to display the field STATUS to ensure its data is pushed to the smarty template.

Look for a line that declares the $displayColumns within that copied function listViewPrepare

$displayColumns = array();

Replace the above with the following code - obviously replacing the FIELD_NAME with your field (mine was STATUS). Tip - ensure it is in Capitals and you keep the | character.



$pos = strpos($_REQUEST['displayColumns'], '<FIELD_NAME>');
        if($pos === false){
            // Add the field manually doesn't matter where
            $_REQUEST['displayColumns'] .= '|<FIELD_NAME>';
            $_GET['displayColumns'] .= '|<FIELD_NAME>';
        }

$displayColumns = array();

Now there will be a slight adjustment to the copied listViewProcess function you adjusted in your custom view.list.php

Look for the following piece of code:

$this->processSearchForm();

And Replace it will the following:


$dpos = strpos($_REQUEST['displayColumns'], '<FIELD_NAME>');
$hpos = strpos($_REQUEST['hideTabs'], '<FIELD_NAME>');
if($dpos !== false && $hpos !== false){  // the assumption that the field being in the hide columns was a user decision! So it will take priority
	$dCol = explode('|', $_REQUEST['displayColumns']);
	if(($key = array_search('<FIELD_NAME>', $dCol)) !== false) {
		unset($dCol[$key]);
	}
	$_REQUEST['displayColumns'] = implode('|', $dCol);
}
$this->processSearchForm();

This portion of code just jumps back what we had tricked the system into thinking (that our field was a DisplayColumn). If we do not have this portion in the code the field will be visible in the multi-select Display Columns search field when it should actually be in the Hide Columns field.

Now onto the TEMPLATE (custom/modules/<MODULE_NAME>/tpls/ListView<MODULE_NAME>.tpl)

First place we wish to do adjustments is where you want to miss out the field’s header row/column if the field is meant to be hidden (remember we’ve tricked the system into always thinking it should show the field)

Look for a line of code that says:


{assign var='datahide' value="phone"}

Underneath it should be a foreach loop on the displayColumns {foreach from=$displayColumns key=colHeader item=params}


{assign var='datahide' value="phone"}  <------ Reference to line
{foreach from=$displayColumns key=colHeader item=params} <----- Insert code after this
	{if $colHeader == '<FIELD_NAME>' and $pageData.queries.baseURL.hideTabs|strstr:'<FIELD_NAME>'}
		{php}continue;{/php}
	{/if}
	{if $colCounter == '3'}{assign var='datahide' value="phone,phonelandscape"}{/if} <----- Insert code before this

This piece of code below will skip the row that is your field name only if the field name is set to HideTabs - remember to have the FIELD_NAME in caps like STATUS. The point here is that IF a user selects the column as a Hidden Column then it will correctly hide that column!


{if $colHeader == '<FIELD_NAME>' and $pageData.queries.baseURL.hideTabs|strstr:'<FIELD_NAME>'}
	{php}continue;{/php}
{/if}

Next place you wish to edit is find the following code:

{$displayColumns[type]}

We will want to replace it with the following code:


{if $col == '<FIELD_NAME>' && $pageData.queries.baseURL.hideTabs|strstr:'<FIELD_NAME>'}
	{php}continue;{/php}
{/if}
{$displayColumns[type]}

To remove the single (chunky) edit pencil within the template find:



{capture assign=linkModule}{if $params.dynamic_module}{$rowData[$params.dynamic_module]}{else}{$pageData.bean.moduleDir}{/if}{/capture}
{capture assign=action}{if $act}{$act}{else}EditView{/if}{/capture}
<td width='2%' nowrap>
	{if $pageData.rowAccess[$id].edit}
			<a title='{$editLinkString}' id="edit-{$rowData.ID}" href="index.php?module={$linkModule}&offset={$offset}&stamp={$pageData.stamp}&return_module={$linkModule}&action={$action}&record={$rowData.ID}">
			{capture name='tmp1' assign='alt_edit'}{sugar_translate label="LNK_EDIT"}{/capture}
			{sugar_getimage name="edit_inline.gif" attr='border="0" ' alt="$alt_edit"}</a>
	{/if}
</td>

Then replace it with:



{capture assign=linkModule}{if $params.dynamic_module}{$rowData[$params.dynamic_module]}{else}{$pageData.bean.moduleDir}{/if}{/capture}
{capture assign=action}{if $act}{$act}{else}EditView{/if}{/capture}
<td width='2%' nowrap>
	{if $pageData.rowAccess[$id].edit}
		{if $pageData.bean.moduleDir == '<MODULE_NAME>' && $rowData.<FIELD_NAME> != 'Signed'}
			<a title='{$editLinkString}' id="edit-{$rowData.ID}" href="index.php?module={$linkModule}&offset={$offset}&stamp={$pageData.stamp}&return_module={$linkModule}&action={$action}&record={$rowData.ID}">
			{capture name='tmp1' assign='alt_edit'}{sugar_translate label="LNK_EDIT"}{/capture}
			{sugar_getimage name="edit_inline.gif" attr='border="0" ' alt="$alt_edit"}</a>
		{/if}
	{/if}
</td>

That should be it (after a Repair & Rebuild).

What you should see is that whether the user has added the particular field in the Hidden Columns or not, the field should correctly filter what should be disabled or not.

Pointers though:

I haven’t tested this with other modules linking in, but the Account Name seems ok. Also I have not looked into the inline editing disable per condition, so you may need to look at that through javascript.

1 Like

Thank u so so much Miss AshleyNic for ur response ,and for the time you’ve taken for me.
I will test it in my system , and I will make you a return above

Hi Miss AshleyNic
I tested ur code and i get some errors , i think bcz u using the last version of suiteCRM with SUITE R Theme
( Im using the SuiteCRM 7.1.5 with Suite7 theme )

Those errors actually looks like you have warnings set up on your server.

Try the following:

if(isset($_REQUEST['displayColumns'])  && isset($_REQUEST['hideTabs'])){

	// insert your custom cude in here.
}
1 Like

I wrote ur if statment in the top of the file view.list.php like

and i did quick repair, and i get this result

All checkboxes r enabled