Welcome to mirror list, hosted at ThFree Co, Russian Federation.

github.com/nextcloud/server.git - Unnamed repository; edit this file 'description' to name the repository.
summaryrefslogtreecommitdiff
diff options
context:
space:
mode:
authorDaniel Calviño Sánchez <danxuliu@gmail.com>2017-09-27 09:07:20 +0300
committerDaniel Calviño Sánchez <danxuliu@gmail.com>2017-10-19 02:46:13 +0300
commit420d1b91ab0d3c9e521bf6def682fd3c58fde997 (patch)
treee871cb10a061ebffade06c37e8b79511be802a96 /apps/files/js/tagsplugin.js
parenta8f1902b02d02cc2b7d624b3d7b288f8aea84fdc (diff)
Add "Favorite" action to the file actions menu
The new FileAction for the menu is essentially the same as the old inline FileAction, except for the rendering; in this case the FileAction is shown in the menu in a standard way, so there is no need to provide a custom renderer (although the menu entry text and icon change depending on whether the file is currently a favorite or not, but that can be done just with displayName and iconClass functions). Signed-off-by: Daniel Calviño Sánchez <danxuliu@gmail.com>
Diffstat (limited to 'apps/files/js/tagsplugin.js')
-rw-r--r--apps/files/js/tagsplugin.js75
1 files changed, 74 insertions, 1 deletions
diff --git a/apps/files/js/tagsplugin.js b/apps/files/js/tagsplugin.js
index 9bd20be4bf8..22d04e9f19f 100644
--- a/apps/files/js/tagsplugin.js
+++ b/apps/files/js/tagsplugin.js
@@ -86,7 +86,7 @@
var self = this;
// register "star" action
fileActions.registerAction({
- name: 'Favorite',
+ name: 'FavoriteInline',
displayName: t('files', 'Favorite'),
mime: 'all',
permissions: OC.PERMISSION_READ,
@@ -141,6 +141,79 @@
});
}
});
+
+ fileActions.registerAction({
+ name: 'Favorite',
+ displayName: function(context) {
+ var $file = context.$file;
+ var isFavorite = $file.data('favorite') === true;
+
+ if (isFavorite) {
+ return t('files', 'Remove from favorites');
+ }
+
+ // As it is currently not possible to provide a context for
+ // the i18n strings "Add to favorites" was used instead of
+ // "Favorite" to remove the ambiguity between verb and noun
+ // when it is translated.
+ return t('files', 'Add to favorites');
+ },
+ mime: 'all',
+ order: -23,
+ permissions: OC.PERMISSION_READ,
+ iconClass: function(fileName, context) {
+ var $file = context.$file;
+ var isFavorite = $file.data('favorite') === true;
+
+ if (isFavorite) {
+ return 'icon-starred';
+ }
+
+ return 'icon-star';
+ },
+ actionHandler: function(fileName, context) {
+ var $actionEl = context.$file.find('.action-favorite');
+ var $file = context.$file;
+ var fileInfo = context.fileList.files[$file.index()];
+ var dir = context.dir || context.fileList.getCurrentDirectory();
+ var tags = $file.attr('data-tags');
+ if (_.isUndefined(tags)) {
+ tags = '';
+ }
+ tags = tags.split('|');
+ tags = _.without(tags, '');
+ var isFavorite = tags.indexOf(OC.TAG_FAVORITE) >= 0;
+ if (isFavorite) {
+ // remove tag from list
+ tags = _.without(tags, OC.TAG_FAVORITE);
+ } else {
+ tags.push(OC.TAG_FAVORITE);
+ }
+
+ // pre-toggle the star
+ toggleStar($actionEl, !isFavorite);
+
+ context.fileInfoModel.trigger('busy', context.fileInfoModel, true);
+
+ self.applyFileTags(
+ dir + '/' + fileName,
+ tags,
+ $actionEl,
+ isFavorite
+ ).then(function(result) {
+ context.fileInfoModel.trigger('busy', context.fileInfoModel, false);
+ // response from server should contain updated tags
+ var newTags = result.tags;
+ if (_.isUndefined(newTags)) {
+ newTags = tags;
+ }
+ context.fileInfoModel.set({
+ 'tags': newTags,
+ 'favorite': !isFavorite
+ });
+ });
+ }
+ });
},
_extendFileList: function(fileList) {