New module or new query?

Hi,
765/5000

I would like to know the best way to proceed. I explain the problem:
I created a module (B), this module is related to another module (A), so in module A I have a subpanel that goes into module B.
Now, I would like to click on an element of the subpanel (row 1 - column 1; row 1 - column 3; row 1 - column 4), to open the detail of that element. My question, is it necessary to create a form for each item I click (the data is the same, but grouped differently - for example, if I click on the date, I will have the detail of that particular day; if I click on the name I will have the detail of that particular name).
Or do I have to create a new query, modifying the code in some way?
Hope to get an answer, thanks in advance

@fab
You should make some forms for each view. Additionally you should do custom button to change object: “SugarWidgetSubPanelDetailViewLink”
Example code for modules/< module name >/metadata/subpanels/< subpanel name >.php

$subpanel_layout = array (
...
    'list_fields' => array (
...
        <field name> => array (
...
            'widget_class' => 'SubPanelDetailViewLink',
            'target_record_key' => '<id record>',
            'target_module' => '<module name>',
            '<target variable of object SugarWidgetSubPanelDetailViewLink>' => '<value of variable>'
...
        ),
...
    ),
...
)

It’s only direction. May be you should do something other.

Ok, so the way to proceed is to create a module for each element I click, I thought that being the same data anyway, but grouped differently, I could use other, I saw it a waste to create a module

@fab
Yes. There are 1 module and several views. See Module “Users” and files:

  • modules/Users/metadata/detailgroupviewdefs.php
  • modules/Users/metadata/detailviewdefs.php

hi p.konetskiy,
I’ve been hitting my head for a while and I’m only now answering. Two questions:
ok target_record
ok target_module
but I do not understand

'<target variable of object SugarWidgetSubPanelDetailViewLink>' => '<value of variable>'

what should be put in place of
target variable of object SugarWidgetSubPanelDetailViewLink?

another thing:
through the targets I activated the link to my module, the problem is that that link in the subpanel does not correspond to a unique record in the target panel (for example the record that contains the date 25/08, in the target module there are more records with that date and therefore, apparently, cannot identify it).
How can I solve?

@fab

  1. For different links to look at:
    file include/generic/SugarWidgets/SugarWidgetSubPanelDetailViewLink.php
  • You should write your custom function “displayList” in file:
    custom/include/generic/SugarWidgets/SugarWidgetSubPanelDetailViewLink.php
  • This function will be call for all links. You analyse your combination filed and value ( ‘< target variable of object SugarWidgetSubPanelDetailViewLink >’ => ‘< value of variable >’ ) and make custom link or call parent function.
  1. For different view to look at:
    function “getMetaDataFile” in file modules/Users/views/view.detail.php
  • You should write custom function “getMetaDataFile” for your module and copy it to file: custom/modules/<your_module_name>/views/view.detail.php

I entered in SugarWidgetSubPanelDetailViewLink a query to the table referenced by the subpanel click, this way I get the ID that record points to and replaced $ record = $ id, now, when I click on that element, the connection string becomes … record = $ id and that’s fine, but if, going to the subpanel, I go to the next pages of the subpanel, I lose the links to the elements, reloading the whole page, the links reappear

@fab
I tested my decision. You can see my an example next:

  1. custom/modules/Contacts/metadata/subpanels/ForAccounts.php
...
        'primary_address_city'=>array(
            'name'=>'primary_address_city',
            'vname' => 'LBL_LIST_CITY',
            'width' => '20%',
/* add  */
            'target_field' => 'city',
            'target_record_key' => 'id',
            'target_module' => 'Contacts',
            'widget_class' => 'SubPanelDetailViewLink',
/*  */
        ),
...
  1. custom/include/generic/SugarWidgets/SugarWidgetSubPanelDetailViewLink.php
...
class SugarWidgetSubPanelDetailViewLink extends SugarWidgetField
{
    public function displayList(&$layout_def)
    {
        global $focus;
/* add */
$add_params='';
if (!empty($layout_def['target_field'])) {
    $add_params='&detailviewform='.$layout_def['target_field'];
}
/* */
        $module = '';
        $record = '';

...
/* change */
            $link = ajaxLink("index.php?module=$module&action=$action&record={$record}{$parent}$add_params");
//            $link = ajaxLink("index.php?module=$module&action=$action&record={$record}{$parent}");
/*  */
...
  1. custom/modules/Contacts/views/view.detail.php
class ContactsViewDetail extends ViewDetail
{
/* add */
    public function getMetaDataFile()
    {
        if ($_REQUEST['detailviewform'] == 'city') {
            $oldType = $this->type;
            $this->type = $oldType . 'city';
        }
        $metadataFile = parent::getMetaDataFile();
        if ($_REQUEST['detailviewform'] == 'city') {
            $this->type = $oldType;
        }
        
        return $metadataFile;
    }
/* */
  1. Make the file “custom/modules/Contacts/metadata/detailcityviewdefs.php” which base on “modules/Contacts/metadata/detailviewdefs.php”
2 Likes

I made some small changes to your code because it didn’t work for me.
Once I got the record id through my query, I changed
$add_params = '&detailviewform ='. $Layout_def['target_field'];
in
$ add_params = '&record ='. $id;
and I haven’t used the function
getMetaDataFile()
now it seems to be fine, at least at first sensation, I have to finish testing it.
Thank you very much p.konetskiy, you have been of great help.

@fab

  1. Be careful because the parameter ‘record’ already present in http link. Look at ajaxlink in the file: custom/include/generic/SugarWidgets/SugarWidgetSubPanelDetailViewLink.php
  2. The code in file (custom/modules/Contacts/views/view.detail.php) make to open different forms. The ajaxlink was modified for it.

Yes, I saw that record is already present, but apparently if I insert &record=…&record=… in the connection string, it doesn’t create any problems and is very useful if you want to insert a search with a double parameter.
Honestly, I don’t understand either getMetaDataFile() (why use it?), Nor where does it get the ‘city’ value you set in
custom/modules/Contacts/metadata/subpanels/ForAccounts.php:
'target_field' => 'city'
because in
SugarWidgetSubPanelDetailViewLink I don’t see anything

@fab

  1. This is your choice “record = … record = …”. I paid attention to this only.
  2. The function “getMetaDataFile” select file for detailview. There are the custom “detailcityviewdefs.php” or the standard “detailviewdefs.php” in my example.
  3. The parametr ‘target_field’ => ‘city’ is example only.
  4. I pay attention that I made the file custom/include/generic/SugarWidgets/SugarWidgetSubPanelDetailViewLink.php in custom directory. I copied to the file standard class and changed it as I wrote before.