+ $scope.file = getCleanFile();
+ }, checkError('link'));
+ };
+
+ /**
+ * Start the edit mode for a file.
+ * @param fileId
+ */
+ $scope.startEdit = function(file) {
+ console.log(file);
+ $scope.editFile = angular.copy(file);
+ $scope.editFile.link = (file.external) ? file.path : '';
+ };
+
+ /**
+ * Cancel edit mode
+ */
+ $scope.cancelEdit = function() {
+ $scope.editFile = false;
+ };
+
+ /**
+ * Update the name and link of a file.
+ * @param file
+ */
+ $scope.updateFile = function(file) {
+ $http.put(`/files/${file.id}`, file).then(resp => {
+ let search = filesIndexOf(resp.data);
+ if (search !== -1) $scope.files[search] = resp.data;
+
+ if ($scope.editFile && !file.external) {
+ $scope.editFile.link = '';
+ }
+ $scope.editFile = false;
+ events.emit('success', 'Attachment details updated');
+ }, checkError('edit'));