Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Allow external javascript in the detailed view #8430

Open
wants to merge 2 commits into
base: hotfix-7.10.x
Choose a base branch
from

Conversation

dominicchinkh
Copy link
Contributor

Allow external javascript in the detailed view

Description

Allow including external javascript in the detailed view by adding viewdefs[]['DetailView']['templateMeta']['javascript'] configuration, such as
"""
'javascript' => '{sugar_getscript file="custom/modules/Opportunities/views/test.js"}',
"""

Motivation and Context

This allows customizing the detailed view using a javascript. This is consistent with how we currently customizing the edit view with a javascript.

How To Test This

Add a configuration as described in the Description session. Add a javascript such as
"""
$( document ).ready(function() {
console.log("Hello Dominic!");
});
"""
as custom/modules/Opportunities/views/test.js. Go to Opportunities detailed view

Types of changes

  • Bug fix (non-breaking change which fixes an issue)
  • New feature (non-breaking change which adds functionality)
  • Breaking change (fix or feature that would cause existing functionality to change)

Final checklist

  • My code follows the code style of this project found here.
  • My change requires a change to the documentation.
  • I have read the How to Contribute guidelines.

@codecov-commenter
Copy link

Codecov Report

Merging #8430 into hotfix-7.10.x will not change coverage.
The diff coverage is n/a.

@@              Coverage Diff               @@
##           hotfix-7.10.x    #8430   +/-   ##
==============================================
  Coverage          10.69%   10.69%           
==============================================
  Files               3230     3230           
  Lines             241063   241063           
==============================================
  Hits               25792    25792           
  Misses            215271   215271           

@pgorod
Copy link
Contributor

pgorod commented Jul 15, 2020

Doesn't it work to add an templateMeta\includes section to the viewdefs? I know that works for ListView. but maybe not for DetailView.

Even so, it might be better to emulate that same mechanism, instead of creating a new one...

Example:

custom/modules/Accounts/metadata/listviewdefs.php

<?php
// include all the $listViewDefs[$module] field and search definitions from parent:
require_once 'modules/Accounts/metadata/listviewdefs.php';

$viewdefs[$module]['ListView'] = [
    'templateMeta' => [
        'form' => [
            'actions' => [
                [
                    'customCode' => '<a onclick="bulkActionRunWorkflows()" title="Do it!">Do it!</a>'
                ],
            ],
        ],
        'includes' => [
            [
                'file' => 'custom/pgr/js/DoThingsFromViews.js',
            ],
        ],
    ]
];

See https://github.com/salesagility/SuiteCRM/blob/master/include/ListView/ListViewSmarty.php#L167
and https://github.com/salesagility/SuiteCRM/blob/master/themes/SuiteP/include/ListView/ListViewGeneric.tpl#L41

@dominicchinkh
Copy link
Contributor Author

Hi @pgorod, this change applies to all DetailView. It is in consistent with how EditView allow external JS file

See https://github.com/salesagility/SuiteCRM/blob/master/include/EditView/footer.tpl#L88

@SuiteBot
Copy link

SuiteBot commented Aug 27, 2020

CLA assistant check
Thank you for your submission! We really appreciate it. Like many open source projects, we ask that you all sign our Contributor License Agreement before we can accept your contribution.
1 out of 2 committers have signed the CLA.

✅ dominicchinkh
❌ Dominic Chin


Dominic Chin seems not to be a GitHub user. You need a GitHub account to be able to sign the CLA. If you have already a GitHub account, please add the email address used for this commit to your account.
You have signed the CLA already but the status is still pending? Let us recheck it.

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

Successfully merging this pull request may close these issues.

None yet

4 participants