/
jira_key_query.js
36 lines (36 loc) · 1.12 KB
/
jira_key_query.js
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
<form class="aui">
<script>
AJS.toInit(function() {
AJS.$("#check-key").click(function() {
var JIRA_HOST = 'YOUR JIRA HOST'; // https://jira.mydomain.com
var validate = /^[A-Z]+$/;
var projectkey = AJS.$("#project-key").val();
if (projectkey.match(validate)) {
AJS.$.ajax({
url: JIRA_HOST + '/rest/api/2/project/' + projectkey,
type: "GET",
xhrFields: {
withCredentials: true
},
success: function(msg){
alert('No, ' + projectkey + ' has already been used :(');
},
error: function(xhr, err) {
alert('Yes! ' + projectkey + ' is available :)' + xhr.status);
}
});
}
else {
alert('Invalid Project Key! It can only contain upper case letters (A-Z)');
AJS.$("#project-key").focus();
}
return false;
});
});
</script>
<div class="field-group">
<label for="project-key">Check Project Key</label>
<input id="project-key" class="text" type="text">
<button class="aui-button aui-button-primary" id="check-key">Go!</button>
</div>
</form>