64 lines
2.0 KiB
JavaScript
64 lines
2.0 KiB
JavaScript
// Copyright 1999-2023. Plesk International GmbH. All rights reserved.
|
|
|
|
Jsw.namespace('PleskExt.Git');
|
|
|
|
const repositoryAction = function (action, url, id) {
|
|
const button = $$('.active-list-item a[href=javascript\\:PleskExt\\.Git\\.' + action + '\\(' + id + '\\)\\;]').first();
|
|
if (!button) {
|
|
return;
|
|
}
|
|
|
|
const setSpinner = function () {
|
|
button.addClassName('disabled');
|
|
const spinner = button.down('.icon-indicator');
|
|
if (!spinner) {
|
|
button.insert({ top: '<i class="icon-indicator"></i>' });
|
|
}
|
|
};
|
|
|
|
const removeSpinner = function () {
|
|
const spinner = button.down('.icon-indicator');
|
|
if (spinner) {
|
|
spinner.remove();
|
|
}
|
|
button.removeClassName('disabled');
|
|
};
|
|
|
|
setSpinner();
|
|
new Ajax.Request(url, {
|
|
method: 'post',
|
|
contentType: 'application/json',
|
|
postBody: JSON.stringify({
|
|
id: id,
|
|
}),
|
|
onSuccess: function (response) {
|
|
const data = response.responseText.evalJSON();
|
|
if (data.componentType === 'Jsw.Task.ProgressBar.Item') {
|
|
window.Jsw.getComponent('asyncProgressBarWrapper').progressDialog(data, {
|
|
onComplete: removeSpinner(),
|
|
});
|
|
}
|
|
}.bind(this),
|
|
onFailure: function (response) {
|
|
removeSpinner();
|
|
const data = response.responseText.evalJSON();
|
|
const detailsStr = data.details
|
|
? ('<br/><ul><li>' + data.details.join('</li><li>') + '</li></ul>')
|
|
: '';
|
|
new Jsw.Popup({
|
|
title: data.title,
|
|
content: data.message + detailsStr,
|
|
closeButtonEnabled: true,
|
|
});
|
|
}.bind(this),
|
|
});
|
|
};
|
|
|
|
PleskExt.Git.deploy = function (id) {
|
|
repositoryAction('deploy', PleskExt.Git.Config.deployUrl, id);
|
|
};
|
|
|
|
PleskExt.Git.pull = function (id) {
|
|
repositoryAction('pull', PleskExt.Git.Config.pullUrl, id);
|
|
};
|