+ if ($scope.editFile) {
+ $scope.editFile = angular.copy(data);
+ data.link = '';
+ }
+ });
+ events.emit('success', trans('entities.attachments_file_updated'));
+ };
+
+ /**
+ * Delete a file from the server and, on success, the local listing.
+ * @param file
+ */
+ $scope.deleteFile = function(file) {
+ if (!file.deleting) {
+ file.deleting = true;
+ return;
+ }
+ $http.delete(window.baseUrl(`/attachments/${file.id}`)).then(resp => {
+ events.emit('success', resp.data.message);
+ $scope.files.splice($scope.files.indexOf(file), 1);
+ }, checkError('delete'));
+ };
+
+ /**
+ * Attach a link to a page.
+ * @param file
+ */
+ $scope.attachLinkSubmit = function(file) {
+ file.uploaded_to = pageId;
+ $http.post(window.baseUrl('/attachments/link'), file).then(resp => {
+ $scope.files.push(resp.data);
+ events.emit('success', trans('entities.attachments_link_attached'));
+ $scope.file = getCleanFile();
+ }, checkError('link'));
+ };
+
+ /**
+ * Start the edit mode for a file.
+ * @param file
+ */
+ $scope.startEdit = function(file) {
+ $scope.editFile = angular.copy(file);
+ $scope.editFile.link = (file.external) ? file.path : '';
+ };