添加 javascript 包括使用扩展 [英] Adding javascript include using extension

查看:29
本文介绍了添加 javascript 包括使用扩展的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我开发了一个 javascript 文件,我想将它包含在一个包中,我发现我可以使用自定义的 editviews.php 文件添加它.这很好用.但是,我希望让我的对手轻松安装它.我在 custom/extension/modules/leads/vardefs/文件夹中创建了一个文件,其中包含以下内容(并进行了快速修复):

I've developed a javascript file that I want to include in a package, and I see that I can add it with a custom editviews.php file. That works fine. However, I wish to make it easy for my counterpart to install it. I created a file in the custom/extension/modules/leads/vardefs/ folder with the following contents (and did a quick repair):

$viewdefs['Leads']['EditView']['templateMeta']['includes'][]=array('file'=>'custom/modules/mme_form_js_functions.js');
$viewdefs['Leads']['QuickCreate']['templateMeta']['includes'][]=array('file'=>'custom/modules/mme_form_js_functions.js');

这似乎不起作用,因此如果有人对如何使用扩展框架执行此操作有快速建议,我很想知道答案,而无需解开糖 php 代码.

That does not seem to work, so if anyone has a quick suggestion of how to do this using the extension framework, I would love to know the answer without having to unravel the sugar php code.

推荐答案

这是我最终的做法 (SuiteCRM 7.10):

Here's how I ended up doing it (SuiteCRM 7.10):

首先,注册一个 after_ui_frame application 钩子,即创建包含类似内容的 custom/Extension/application/Ext/LogicHooks/myhooks.php:

First, register an after_ui_frame application hook, i.e. create custom/Extension/application/Ext/LogicHooks/myhooks.php containing something like:

<?php

$hook_version = 1;  
$hook_array = Array();  
$hook_array['after_ui_frame'] = Array();  
$hook_array['after_ui_frame'][] = Array(99, 'Add my custom js',
                      'custom/Extension/application/mycustomizations.php', 'MyHooks', 'add_my_js');

然后创建 custom/Extension/application/mycustomizations.php 并添加您的 javascript 文件(您可以决定仅将其添加到某些模块/操作):

Then create custom/Extension/application/mycustomizations.php and add your javascript file (you can decide to add it only to certain modules/actions):

<?php

if(!defined('sugarEntry') || !sugarEntry) die('Not a valid entry point');

class MyHooks {

    function add_my_js($event, $args){
        if ($_REQUEST['module'] == 'Leads' && $_REQUEST['action'] == 'EditView') {
echo '<script type="text/javascript" src="custom/Extension/application/mycustom.js"></script>';
        }
    }
}

最后,做一个快速修复和重建.

这篇关于添加 javascript 包括使用扩展的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆