I cannot use jquery in my js when page is rendered from soy Edited

I am writing a plugin that needs to call a rest api

I started with a soy template example. The script executes, but fails when I switch the toggle with $ undefined.

Can someone help?

my atlassian-plugin.xml

 <?xml version="1.0" encoding="UTF-8"?>

<atlassian-plugin key="${atlassian.plugin.key}" name="${project.name}" plugins-version="2">
<plugin-info>
<description>${project.description}</description>
<version>${project.version}</version>
<vendor name="${project.organization.name}" url="${project.organization.url}"/>
<param name="plugin-icon">images/pluginIcon.png</param>
<param name="plugin-logo">images/pluginLogo.png</param>
</plugin-info>
<!-- Servlets -->
<servlet name="Repository Servlet" key="repository-servlet" class="com.kns.corp.bitbucket.servlet.RepositoryServlet">
<description key="repository-servlet.description">The Repository Servlet Plugin</description>
<url-pattern>/sprint/*</url-pattern>
</servlet>

<web-resource key="resources" name="Web Resources">
<resource type="download" name="images" location="/images/" />;
</web-resource>

<web-resource key="sss-resources" name="Web Resources">
<resource type="download" name="enablesss.js" location="/js/enablesss.js" />
<resource type="download" name="voorbeeld.css" location="/css/voorbeeld.css" />;
<resource type="download" name="images" location="/images/" />;
<dependency>com.atlassian.bitbucket.server.bitbucket-web-api:aui</dependency>
<dependency>com.atlassian.bitbucket.server.bitbucket-web-api:amd</dependency>
<dependency>com.atlassian.bitbucket.server.bitbucket-web-api:jquery</dependency>
<context>sss</context>
</web-resource>

<!-- Client web resources -->
<client-resource key="example-soy" name="Example Soy Templates">
<directory location="/templates/"/>
<dependency>com.atlassian.auiplugin:ajs</dependency>
<dependency>com.atlassian.bitbucket.server.bitbucket-web-api:aui</dependency>
<dependency>com.atlassian.bitbucket.server.bitbucket-web-api:amd</dependency>
<dependency>com.atlassian.bitbucket.server.bitbucket-web-api:client-soy</dependency>
</client-resource>
<!-- Web items -->
<web-item key="repository-plugin-tab" name="Repository navigation tab" section="bitbucket.web.repository.header.buttons" weight="500">
<label>Stop/Start sprint</label>
<link>/plugins/servlet/sprint/${repository.project.key}/${repository.slug}</link>
<!-- optional style for the icon: see https://design.atlassian.com/2.0/product/foundations/iconography for a list of available images -->
<param name="iconClass" value="aui-icon-small aui-iconfont-devtools-repository-locked"/>
<conditions type="AND">
<condition class="com.kns.corp.bitbucket.components.sprintmgmtEnabled">
<param name="sprintmgmt" value="true"/>
</condition>
</conditions>
</web-item>
<web-item key="repository-settings-plugin-tab" name="Repository settings navigation tab" section="bitbucket.repository.settings.panel/repository-settings-section" weight="500">
<label>Stop/Start sprint</label>
<link>/plugins/servlet/sprint/${repository.project.key}/${repository.slug}/settings</link>
</web-item>
<resource type="i18n" name="i18n" location="${atlassian.plugin.key}"/>
<rest name="Enable Sprint Mgr" i18n-name-key="enable-sprint-mgr.name" key="enable-sprint-mgr" path="/enablesprintmgr" version="1.0">
<description key="enable-sprint-mgr.description">The Enable Sprint Mgr Plugin</description>
</rest>
</atlassian-plugin>

 

my soy template

{namespace plugin.example}

/**
* @param repository Repository object
*/
{template .repository}
<html>
<head>
<meta name="decorator" content="bitbucket.repository.general">
<meta name="projectKey" content="{$repository.project.key}">
<meta name="repositorySlug" content="{$repository.slug}">
<meta name="activeTab" content="repository-plugin-tab">
<title>{$repository.slug} / Example Tab</title>
</head>
<body>
<h3>Repository: {$repository.slug}</h3>
<p>Welcome to my plugin tab in the repository page.</p>
</body>
</html>
{/template}

/**
* @param repository Repository object
*/
{template .repositorySettings}
<html>
<head>
<meta name="decorator" content="bitbucket.repository.settings">
<meta name="projectKey" content="{$repository.project.key}">
<meta name="repositorySlug" content="{$repository.slug}">
<meta name="activeTab" content="repository-settings-plugin-tab">
{webResourceManager_requireResource('com.kns.corp.bitbucket.SprintStarter:sss-resources')}
<title>{$repository.slug} / Example Tab</title>
</head>
<body>
<h3>Repository: {$repository.slug}</h3>
<p>
<table cellpadding="10">
<tr>
<td><aui-label for="start-stop-sprint">Enable Start/Stop Sprint functionality for repository</aui-label></td>
<td><aui-toggle id="start-stop-sprint" label="Enable Start/Stop Sprint functionality"></aui-toggle></td>
</tr>
</table>
</p>
<div class="image-class">
</div>
</body>
</html>
{/template}

 

and my javascript

AJS.toInit(function (){
var toggle = document.querySelector('#start-stop-sprint');
toggle.addEventListener('change', function(e) {
var isChecked = toggle.checked;
toggle.busy = true;
$.post('set/my/variable', { value: isChecked })
.done(function () {
console.log('success');
})
.fail(function () {
toggle.checked = !isChecked;
console.error('display an error message');
})
.always(function () {
toggle.busy = false;
});
});
});

 

 does anyone know how to do this? 

0 answers

Suggest an answer

Log in or Sign up to answer
How to earn badges on the Atlassian Community

How to earn badges on the Atlassian Community

Badges are a great way to show off community activity, whether you’re a newbie or a Champion.

Learn more
Community showcase
Published yesterday in Jira Service Desk

Wy are we still using email for Service Desk workflows?

...attest to the experience of an urgent approval that gets lost in the boss’s inbox and requires that special “Please Approve” email or text message. In an age where we have distributed teams...

104 views 0 2
Read article

Atlassian User Groups

Connect with like-minded Atlassian users at free events near you!

Find a group

Connect with like-minded Atlassian users at free events near you!

Find my local user group

Unfortunately there are no AUG chapters near you at the moment.

Start an AUG

You're one step closer to meeting fellow Atlassian users at your local meet up. Learn more about AUGs

Groups near you