Merge pull request #13663 from owncloud/issue/13624-notification-when-favorting-fails

Only update favorite icon if the operation was successful
This commit is contained in:
Morris Jobke 2015-02-10 00:05:39 +01:00
commit 4a99849c6c
2 changed files with 17 additions and 5 deletions

View file

@ -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;
}

View file

@ -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.<String>} 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);
@ -171,6 +175,14 @@
}),
dataType: 'json',
type: 'POST'
}).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);
toggleStar($actionEl, isFavorite);
});
}
};