@@ -57,7 +77,7 @@
diff --git a/src/views/app.js b/src/views/app.js index 2becef493..80444b64f 100644 --- a/src/views/app.js +++ b/src/views/app.js @@ -411,6 +411,33 @@ angular.module('Application').controller('AppController', ['$scope', '$location' } }; + $scope.uninstall = { + busy: false, + error: {}, + + show: function () { + $('#uninstallModal').modal('show'); + }, + + submit: function () { + $scope.uninstall.busy = true; + + Client.uninstallApp($scope.app.id, 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'); + Client.refreshAppCache($scope.app.id); // reflect the new app state immediately + $location.path('/apps'); + } + + $scope.uninstall.busy = false; + }); + } + }; + function fetchUsers(callback) { Client.getUsers(function (error, users) { if (error) return callback(error); diff --git a/src/views/apps.html b/src/views/apps.html index dfa501c76..d13d3c5c6 100644 --- a/src/views/apps.html +++ b/src/views/apps.html @@ -497,24 +497,6 @@
diff --git a/src/views/app.js b/src/views/app.js index 2becef493..80444b64f 100644 --- a/src/views/app.js +++ b/src/views/app.js @@ -411,6 +411,33 @@ angular.module('Application').controller('AppController', ['$scope', '$location' } }; + $scope.uninstall = { + busy: false, + error: {}, + + show: function () { + $('#uninstallModal').modal('show'); + }, + + submit: function () { + $scope.uninstall.busy = true; + + Client.uninstallApp($scope.app.id, 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'); + Client.refreshAppCache($scope.app.id); // reflect the new app state immediately + $location.path('/apps'); + } + + $scope.uninstall.busy = false; + }); + } + }; + function fetchUsers(callback) { Client.getUsers(function (error, users) { if (error) return callback(error); diff --git a/src/views/apps.html b/src/views/apps.html index dfa501c76..d13d3c5c6 100644 --- a/src/views/apps.html +++ b/src/views/apps.html @@ -497,24 +497,6 @@