【问题标题】:How to use JIRA AUI functions in my own custom field - velocity edit.vm如何在我自己的自定义字段中使用 JIRA AUI 函数 - velocity edit.vm
【发布时间】:2014-08-30 08:39:15
【问题描述】:

我正在尝试在我的 JIRA 中使用一些 AUI - 在我自己用 JAVA 编写的自定义字段的编辑模式下。 我找到了这个页面:https://docs.atlassian.com/aui/latest/sandbox/#,以后我想使用设置示例 Auiselect2。

https://docs.atlassian.com/aui/5.5.1/docs/auiselect2.html - 这里写着,这只是实验性的,所以我应该做哪些步骤来使用它?在下面的示例中,您可以看到,我试图添加此功能,但它简单并不起作用。我正在使用文档中提到的示例 -

edit.vm:

$webResourceManager.requireResource("cz.firma.rozy:zakaznik")

<form class="aui">
    <select id="select2-example" multiple>
        <option value="CONF">Confluence</option>
        <option value="JIRA">JIRA</option>
        <option value="BAM">Bamboo</option>
        <option value="JAG">JIRA Agile</option>
        <option value="CAP">JIRA Capture</option>
        <option value="AUI">AUI</option>
    </select>
</form>

和 zakaznik.js

AJS.$(function() {
    AJS.$("#select2-example").auiSelect2();
});

而我的 atlassian-plugin.xml 是:

<web-resource key="zakaznik-resources" name="zakaznik Web Resources">
    <dependency>com.atlassian.auiplugin:ajs</dependency>
    <dependency>com.atlassian.auiplugin:jquery</dependency>
    <dependency>com.atlassian.auiplugin:jquery-ui-other</dependency>
    <dependency>com.atlassian.auiplugin:aui-select2</dependency>
    <context>atl.general</context>
    <context>atl.admin</context>
    <resource type="download" name="zakaznik.css" location="/css/zakaznik.css"/>
    <resource type="download" name="zakaznik.js" location="/js/zakaznik.js"/>
    <resource type="download" name="images/" location="/images"/>
    <context>zakaznik</context>
  </web-resource>

...
  <customfield-type name="Pridani zakaznika" i18n-name-key="customer-add.name" key="customer-add" class="cz.firma.rozy.jira.customfields.CustomerCustomField">
    <description key="customer-add.description">Plugin, ktery prida zakaznika z abry</description>
    <resource name="view" type="velocity" location="templates/viewCustomer.vm"/>
    <resource name="edit" type="velocity" location="templates/edit.vm"/>
  </customfield-type>

但是当我访问编辑模式时,没有 jQuery 完成 - 并且浏览器控制台没有写入任何错误或警告。

【问题讨论】:

    标签: javascript jquery velocity custom-fields jira-plugin


    【解决方案1】:

    只需将此行添加到您的 edit.vm 即可包含 select2 js。

    $webResourceManager.requireResource("com.atlassian.auiplugin:aui-select2")
    

    您不需要将其添加为网络资源中的依赖项。

    在你的 js 文件中调用 select2 只需 -

    AJS.$("#select2-example").select2();
    

    【讨论】:

      【解决方案2】:

      你只需要在你的edit.vm中添加以下内容

      $webResourceManager.requireResourcesForContext("zakaznik")
      

      我不同意提供的其他答案。当我们已经在资源文件中添加了 js 时,为什么还要在 edit.vm 文件中添加它。只需参考我们已经使用它的上下文创建的网络资源。

      【讨论】:

        【解决方案3】:

        您需要通过webResourceManager 加载aui 资源。 atlassian-plugin.xml 不需要更改。 您的自定义字段.vm 文件可能如下所示:

        #controlHeader ($action $customField.id $customField.name $fieldLayoutItem.required $displayParameters.noHeader)
        $webResourceManager.requireResource("com.atlassian.auiplugin:aui-select2")
        
        <script type="text/javascript">
            AJS.toInit(function() {
                AJS.$("#$customField.id").select2();
            });
        </script>
        
        <select name="$customField.id" id="$customField.id" multiple>
        
            #foreach ($option in $options)
                <option value="$option">$option</option>
            #end
        </select>
        
        #controlFooter ($action $fieldLayoutItem.fieldDescription $displayParameters.noHeader)
        

        【讨论】:

          猜你喜欢
          • 2014-08-30
          • 1970-01-01
          • 2015-01-17
          • 2021-08-13
          • 1970-01-01
          • 2017-06-01
          • 1970-01-01
          • 1970-01-01
          • 1970-01-01
          相关资源
          最近更新 更多