From df75a6e5f37d4dbd1fe6abc0cdfb27037ffd1c99 Mon Sep 17 00:00:00 2001 From: Joas Schilling Date: Mon, 26 Jan 2015 10:45:49 +0100 Subject: [PATCH 1/3] Only update favorite icon if the operation was successful Also shows a notification in case an error occured on updating the tags --- apps/files/js/tagsplugin.js | 4 +++- 1 file changed, 3 insertions(+), 1 deletion(-) diff --git a/apps/files/js/tagsplugin.js b/apps/files/js/tagsplugin.js index 27ab3eced0..b00aacfba5 100644 --- a/apps/files/js/tagsplugin.js +++ b/apps/files/js/tagsplugin.js @@ -105,12 +105,12 @@ } else { tags.push(OC.TAG_FAVORITE); } - toggleStar($actionEl, !isFavorite); self.applyFileTags( dir + '/' + fileName, tags ).then(function(result) { + toggleStar($actionEl, !isFavorite); // response from server should contain updated tags var newTags = result.tags; if (_.isUndefined(newTags)) { @@ -171,6 +171,8 @@ }), dataType: 'json', type: 'POST' + }).fail(function() { + OC.Notification.showTemporary(t('files', 'An error occurred while trying to update the tags')); }); } }; From 8e2b99c3a964d5eef174c068919ce7a941266cf1 Mon Sep 17 00:00:00 2001 From: Morris Jobke Date: Mon, 26 Jan 2015 11:27:51 +0100 Subject: [PATCH 2/3] fix response for tags and show error message --- apps/files/controller/apicontroller.php | 6 +++--- apps/files/js/tagsplugin.js | 11 ++++++++--- 2 files changed, 11 insertions(+), 6 deletions(-) diff --git a/apps/files/controller/apicontroller.php b/apps/files/controller/apicontroller.php index a8bea27e4b..1bb07010a2 100644 --- a/apps/files/controller/apicontroller.php +++ b/apps/files/controller/apicontroller.php @@ -76,11 +76,11 @@ class ApiController extends Controller { try { $this->tagService->updateFileTags($path, $tags); } catch (\OCP\Files\NotFoundException $e) { - return new DataResponse($e->getMessage(), Http::STATUS_NOT_FOUND); + return new DataResponse(['message' => $e->getMessage()], Http::STATUS_NOT_FOUND); } catch (\OCP\Files\StorageNotAvailableException $e) { - return new DataResponse($e->getMessage(), Http::STATUS_SERVICE_UNAVAILABLE); + return new DataResponse(['message' => $e->getMessage()], Http::STATUS_SERVICE_UNAVAILABLE); } catch (\Exception $e) { - return new DataResponse($e->getMessage(), Http::STATUS_NOT_FOUND); + return new DataResponse(['message' => $e->getMessage()], Http::STATUS_NOT_FOUND); } $result['tags'] = $tags; } diff --git a/apps/files/js/tagsplugin.js b/apps/files/js/tagsplugin.js index b00aacfba5..b81f1ec575 100644 --- a/apps/files/js/tagsplugin.js +++ b/apps/files/js/tagsplugin.js @@ -105,12 +105,12 @@ } else { tags.push(OC.TAG_FAVORITE); } + toggleStar($actionEl, !isFavorite); self.applyFileTags( dir + '/' + fileName, tags ).then(function(result) { - toggleStar($actionEl, !isFavorite); // response from server should contain updated tags var newTags = result.tags; if (_.isUndefined(newTags)) { @@ -171,8 +171,13 @@ }), dataType: 'json', type: 'POST' - }).fail(function() { - OC.Notification.showTemporary(t('files', 'An error occurred while trying to update the tags')); + }).fail(function(response) { + var message = ''; + // show message if it is available + if(response.responseJSON && response.responseJSON.message) { + message = ': ' + response.responseJSON.message; + } + OC.Notification.showTemporary(t('files', 'An error occurred while trying to update the tags') + message); }); } }; From 12f835b1981ecfbfb99687b9f61294653a9863bc Mon Sep 17 00:00:00 2001 From: Joas Schilling Date: Mon, 26 Jan 2015 12:01:07 +0100 Subject: [PATCH 3/3] toggle back when the action was not performed --- apps/files/js/tagsplugin.js | 9 +++++++-- 1 file changed, 7 insertions(+), 2 deletions(-) diff --git a/apps/files/js/tagsplugin.js b/apps/files/js/tagsplugin.js index b81f1ec575..293e25176f 100644 --- a/apps/files/js/tagsplugin.js +++ b/apps/files/js/tagsplugin.js @@ -109,7 +109,9 @@ self.applyFileTags( dir + '/' + fileName, - tags + tags, + $actionEl, + isFavorite ).then(function(result) { // response from server should contain updated tags var newTags = result.tags; @@ -157,8 +159,10 @@ * * @param {String} fileName path to the file or folder to tag * @param {Array.} tagNames array of tag names + * @param {Object} $actionEl element + * @param {boolean} isFavorite Was the item favorited before */ - applyFileTags: function(fileName, tagNames) { + applyFileTags: function(fileName, tagNames, $actionEl, isFavorite) { var encodedPath = OC.encodePath(fileName); while (encodedPath[0] === '/') { encodedPath = encodedPath.substr(1); @@ -178,6 +182,7 @@ message = ': ' + response.responseJSON.message; } OC.Notification.showTemporary(t('files', 'An error occurred while trying to update the tags') + message); + toggleStar($actionEl, isFavorite); }); } };