Skip to content

Instantly share code, notes, and snippets.

@jechlin
Created May 20, 2016 12:27
Show Gist options
  • Star 0 You must be signed in to star a gist
  • Fork 0 You must be signed in to fork a gist
  • Save jechlin/16da177ed43aff75d28588a0e6d3df68 to your computer and use it in GitHub Desktop.
Save jechlin/16da177ed43aff75d28588a0e6d3df68 to your computer and use it in GitHub Desktop.
(function ($) {
$(function () {
function replaceDeleteButton(repoId) {
var $deleteLink = $("#repository-settings-delete-button");
$deleteLink.attr("href", "#")
.html("Archive Repository");
$deleteLink.removeClass("delete-repository-link").on("click", function (e) {
e.preventDefault();
e.stopImmediatePropagation();
$.ajax({
url: AJS.contextPath() + "/rest/scriptrunner/latest/custom/moveRepo",
dataType: "json",
contentType: "application/json; charset=utf-8",
data: JSON.stringify({
id: repoId
}),
type: "POST",
beforeSend: function (request) {
request.setRequestHeader("X-Atlassian-token", "no-check");
}
}).fail(function (XMLHttpRequest, textStatus, errorThrown) {
console.log("failed... look at server logs for why");
}).done(function (data) {
alert("Repository has been archived... you will now be redirected to the home page");
var baseUrl = location.protocol + '//' + location.hostname + (location.port ? ':' + location.port : '');
location.href = baseUrl + "/" + AJS.contextPath()
});
});
}
require(["bitbucket/util/state"], function (state) {
if (state.getProject().key != "ARCHIVE") {
replaceDeleteButton(state.getRepository().id);
}
});
});
})(AJS.$);
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment