【问题标题】:Where to Include Sugarcrm在哪里包括 Sugarcrm
【发布时间】:2016-12-13 17:11:56
【问题描述】:

我一直在为糖模块编写一些自定义代码,但不清楚将我的 javascript 代码放在模块中调用的位置。

目前我已将自定义 JS 放入 include/javascript/popup_parent_helper.js

这在开发者模式下工作正常,但在关闭时不起作用,不幸的是开发者模式运行超级慢

我做了很多研究,但得到了一些相互矛盾的结果。

有人告诉我应该把它包含在:

  • /modules/[模块名称]/

别人说应该在:

  • /custom/modules/[模块名称/
    • 还有一些将 js 添加为目录的方法

请帮助我澄清正确的结构以及我需要在哪里进行正确的包含语句

说明:

我们正在使用 SugarCrm 6.5x

在这种情况下,JS 仅用于一个模块。

它被用于快速创建视图和编辑视图

【问题讨论】:

  • 你使用的是sugar 7.x吗?
  • 这个javascript做了什么样的事情?它是否与特定视图(记录、列表等)隔离?
  • 添加了关于JS使用的版本和细节的说明

标签: javascript php include sugarcrm include-path


【解决方案1】:

如果任何模块都可以访问 javascript,您可以创建一个新的 JSGrouping 并使用以下技术拉入您的自定义 js 文件: http://support.sugarcrm.com/Documentation/Sugar_Developer/Sugar_Developer_Guide_7.6/Extension_Framework/JSGroupings/#Creating_New_JSGroupings

听起来您希望它与您的自定义模块隔离,因此您可能应该扩展所需的视图。如果要扩展记录视图,请在 custom/modules/-your_module-/clients/base/views/record/ 处创建一个名为 record.js 的新文件

({
extendsFrom: 'RecordView',

initialize: function(options) {
    this._super('initialize', [options]);
    this.doSomething();
},

doSomething: function(){
    console.log("Help you I will");
},

...

})

https://developer.sugarcrm.com/2014/02/10/extending-sugar-7-record-view/

【讨论】:

  • 这个方法只适用于Sugar 7.x,所以对你的OP没有帮助。它可能对其他人有帮助,所以我将把它留在这里。另一个答案涉及Sugar 6。
【解决方案2】:

我也遇到过类似的问题(JS 应该适用于编辑和快速创建表单)但是在做了一些 RnD 之后,我按照以下方式实现了它:

\custom\modules\<modulename>\views\view.edit.php

<?php
if(!defined('sugarEntry') || !sugarEntry) die('Not A Valid Entry Point');

require_once('include/MVC/View/views/view.edit.php');

class {moduleName}ViewEdit extends ViewEdit {

      public function __construct() {
        parent::ViewEdit();
        $this->useForSubpanel = true; // this variable specifies that these changes should work for subpanel
       // / $this->useModuleQuickCreateTemplate = true; // quick create template too
    }

    function display(){ ?>
        <?php

                 $jsscript = <<<EOQ
                            <script>
                                    Your JS code
                            </script>
EOQ;

        parent::display();
           echo $jsscript;     //echo the script

    }   

}
?>

【讨论】:

    猜你喜欢
    • 2015-12-07
    • 1970-01-01
    • 1970-01-01
    • 2015-01-24
    • 1970-01-01
    • 1970-01-01
    • 1970-01-01
    • 2016-09-26
    • 2012-05-04
    相关资源
    最近更新 更多