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:
commit
4a99849c6c
|
@ -76,11 +76,11 @@ class ApiController extends Controller {
|
||||||
try {
|
try {
|
||||||
$this->tagService->updateFileTags($path, $tags);
|
$this->tagService->updateFileTags($path, $tags);
|
||||||
} catch (\OCP\Files\NotFoundException $e) {
|
} 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) {
|
} 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) {
|
} 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;
|
$result['tags'] = $tags;
|
||||||
}
|
}
|
||||||
|
|
|
@ -109,7 +109,9 @@
|
||||||
|
|
||||||
self.applyFileTags(
|
self.applyFileTags(
|
||||||
dir + '/' + fileName,
|
dir + '/' + fileName,
|
||||||
tags
|
tags,
|
||||||
|
$actionEl,
|
||||||
|
isFavorite
|
||||||
).then(function(result) {
|
).then(function(result) {
|
||||||
// response from server should contain updated tags
|
// response from server should contain updated tags
|
||||||
var newTags = result.tags;
|
var newTags = result.tags;
|
||||||
|
@ -157,8 +159,10 @@
|
||||||
*
|
*
|
||||||
* @param {String} fileName path to the file or folder to tag
|
* @param {String} fileName path to the file or folder to tag
|
||||||
* @param {Array.<String>} tagNames array of tag names
|
* @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);
|
var encodedPath = OC.encodePath(fileName);
|
||||||
while (encodedPath[0] === '/') {
|
while (encodedPath[0] === '/') {
|
||||||
encodedPath = encodedPath.substr(1);
|
encodedPath = encodedPath.substr(1);
|
||||||
|
@ -171,6 +175,14 @@
|
||||||
}),
|
}),
|
||||||
dataType: 'json',
|
dataType: 'json',
|
||||||
type: 'POST'
|
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);
|
||||||
});
|
});
|
||||||
}
|
}
|
||||||
};
|
};
|
||||||
|
|
Loading…
Reference in New Issue