diff --git a/src/js/client.js b/src/js/client.js index 50b1eb344..0df0e607c 100644 --- a/src/js/client.js +++ b/src/js/client.js @@ -1880,6 +1880,15 @@ angular.module('Application').service('Client', ['$http', '$interval', '$timeout }); }; + Client.prototype.updateApplink = function (id, data, callback) { + post('/api/v1/applinks/' + id, data, null, function (error, data, status) { + if (error) return callback(error); + if (status !== 202) return callback(new ClientError(status, data)); + + callback(null); + }); + }; + Client.prototype.removeApplink = function (id, callback) { del('/api/v1/applinks/' + id, null, function (error, data, status) { if (error) return callback(error); diff --git a/src/views/apps.html b/src/views/apps.html index c77b275d9..ea5aca1e1 100644 --- a/src/views/apps.html +++ b/src/views/apps.html @@ -50,7 +50,7 @@ @@ -70,13 +70,13 @@ - + diff --git a/src/views/apps.js b/src/views/apps.js index 1105d6f3a..53abe9e18 100644 --- a/src/views/apps.js +++ b/src/views/apps.js @@ -99,6 +99,9 @@ angular.module('Application').controller('AppsController', ['$scope', '$translat $scope.applinksAdd.busy = false; $scope.applinksAdd.upstreamUri = ''; + $scope.applinksAddForm.$setUntouched(); + $scope.applinksAddForm.$setPristine(); + $('#applinksAddModal').modal('show'); return false; // prevent propagation and default @@ -117,27 +120,48 @@ angular.module('Application').controller('AppsController', ['$scope', '$translat $scope.applinksEdit = { error: {}, - busy: false, + busyEdit: false, + busyRemove: false, id: '', upstreamUri: '', show: function (applink) { $scope.applinksEdit.error = {}; - $scope.applinksEdit.busy = false; + $scope.applinksEdit.busyEdit = false; + $scope.applinksEdit.busyRemove = false; $scope.applinksEdit.id = applink.id; $scope.applinksEdit.upstreamUri = applink.upstreamUri; + $scope.applinksEditForm.$setUntouched(); + $scope.applinksEditForm.$setPristine(); + $('#applinksEditModal').modal('show'); return false; // prevent propagation and default }, submit: function () { - $('#applinksEditModal').modal('hide'); + $scope.applinksEdit.busyEdit = true; + + var data = { + upstreamUri: $scope.applinksEdit.upstreamUri + }; + + Client.updateApplink($scope.applinksEdit.id, data, function (error) { + $scope.applinksEdit.busyEdit = false; + + if (error) return console.error('Failed to update applink', error); + + $('#applinksEditModal').modal('hide'); + }); }, remove: function () { + $scope.applinksEdit.busyRemove = true; + Client.removeApplink($scope.applinksEdit.id, function (error) { + $scope.applinksEdit.busyRemove = false; + if (error) return console.error('Failed to remove applink', error); Client.refreshInstalledApps();