如何使用JIRA AUI功能在我自己的自定义领域-速度编辑

How to use JIRA AUI functions in my own custom field - velocity edit.vm

本文关键字:自定义 编辑 速度 自己的 我自己 JIRA 何使用 AUI 功能      更新时间:2023-09-26

我正在尝试在JIRA中使用一些AUI -在编辑模式下使用JAVA编写我自己的自定义字段。我发现这个页面:https://docs.atlassian.com/aui/latest/sandbox/#和在未来我想使用设置一个例子Auiselect2。

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

中提到的一个例子

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完成-浏览器控制台没有写任何错误或警告。

只需将这一行添加到编辑中。Vm将包含select2 js.

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

你不需要把它作为依赖项添加到web-resource中。

在js文件中通过-

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

您需要通过webResourceManager加载aui资源。不需要更改atlassian-plugin.xml。您的customfields .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)

您只需要在edit.vm

中添加以下内容
$webResourceManager.requireResourcesForContext("zakaznik")

我不同意提供的其他答案。当我们已经在资源文件中添加了js,为什么要在编辑中再做一次呢?虚拟机文件。参考我们已经创建的web资源和它的上下文