archive: add confirm dialog

This commit is contained in:
Girish Ramakrishnan
2024-12-09 20:53:53 +01:00
parent 24df6edbf1
commit fe68887cdd
4 changed files with 48 additions and 29 deletions
+17 -22
View File
@@ -1735,7 +1735,6 @@ angular.module('Application').controller('AppController', ['$scope', '$location'
error: {},
busyRunState: false,
startButton: false,
busyArchive: false,
latestBackup: null,
toggleRunState: function (confirmStop) {
@@ -1770,40 +1769,36 @@ angular.module('Application').controller('AppController', ['$scope', '$location'
});
},
ask: function () {
$('#uninstallModal').modal('show');
ask: function (what) {
if (what === 'uninstall') {
$('#uninstallModal').modal('show');
} else {
$('#archiveModal').modal('show');
}
},
archive: function () {
$scope.uninstall.busyArchive = true;
Client.archiveApp($scope.app.id, $scope.uninstall.latestBackup.id, function (error) {
if (error && error.statusCode === 402) { // unpurchase failed
Client.error('Relogin to Cloudron App Store');
} else if (error) {
Client.error(error);
} else {
$location.path('/apps');
}
$scope.uninstall.busyArchive = false;
});
},
submit: function () {
submit: function (what) {
$scope.uninstall.busy = true;
var NOOP = function (next) { return next(); };
var stopAppTask = $scope.app.taskId ? Client.stopTask.bind(null, $scope.app.taskId) : NOOP;
stopAppTask(function () { // ignore error
Client.uninstallApp($scope.app.id, function (error) {
const func = what === 'uninstall' ?
Client.uninstallApp.bind(null, $scope.app.id) :
Client.archiveApp.bind(Client, $scope.app.id, $scope.uninstall.latestBackup.id);
func(function (error) {
if (error && error.statusCode === 402) { // unpurchase failed
Client.error('Relogin to Cloudron App Store');
} else if (error) {
Client.error(error);
} else {
$('#uninstallModal').modal('hide');
if (what === 'uninstall') {
$('#uninstallModal').modal('hide');
} else {
$('#archiveModal').modal('hide');
}
$location.path('/apps');
}