summaryrefslogtreecommitdiffstats
path: root/core
diff options
context:
space:
mode:
authorMorris Jobke <hey@morrisjobke.de>2016-12-05 16:10:33 +0100
committerGitHub <noreply@github.com>2016-12-05 16:10:33 +0100
commit8fdfb41b932cb50fdafe251f75d342c06e924d36 (patch)
treed06ca98ceddeb19ff81d24a4dacae74829fdbc5d /core
parent7ce53033747542d565716cdb3080f642a6092339 (diff)
parent8e5651cd9eb9e9b9df5648a1f7bbb8d4f9302964 (diff)
downloadnextcloud-server-8fdfb41b932cb50fdafe251f75d342c06e924d36.tar.gz
nextcloud-server-8fdfb41b932cb50fdafe251f75d342c06e924d36.zip
Merge pull request #1934 from nextcloud/move-latly-used-tags-to-the-top
Move lately used tags to the top
Diffstat (limited to 'core')
-rw-r--r--core/js/systemtags/systemtagsinputfield.js31
1 files changed, 31 insertions, 0 deletions
diff --git a/core/js/systemtags/systemtagsinputfield.js b/core/js/systemtags/systemtagsinputfield.js
index 5d986d17290..690525c0ebb 100644
--- a/core/js/systemtags/systemtagsinputfield.js
+++ b/core/js/systemtags/systemtagsinputfield.js
@@ -57,6 +57,8 @@
_newTag: null,
+ _lastUsedTags: [],
+
className: 'systemTagsInputFieldContainer',
template: function(data) {
@@ -97,6 +99,8 @@
_.defer(self._refreshSelection);
});
+ _.defer(_.bind(this._getLastUsedTags, this));
+
_.bindAll(
this,
'_refreshSelection',
@@ -108,6 +112,17 @@
);
},
+ _getLastUsedTags: function() {
+ var self = this;
+ $.ajax({
+ type: 'GET',
+ url: OC.generateUrl('/apps/systemtags/lastused'),
+ success: function (response) {
+ self._lastUsedTags = response;
+ }
+ });
+ },
+
/**
* Refreshes the selection, triggering a call to
* select2's initSelection
@@ -211,6 +226,7 @@
}, {
success: function(model) {
self._addToSelect2Selection(model.toJSON());
+ self._lastUsedTags.unshift(model.id);
self.trigger('select', model);
},
error: function(model, xhr) {
@@ -238,6 +254,7 @@
return false;
} else {
tag = this.collection.get(e.object.id);
+ this._lastUsedTags.unshift(tag.id);
}
this._newTag = null;
this.trigger('select', tag);
@@ -400,6 +417,20 @@
var aSelected = selectedItems.indexOf(a.id) >= 0;
var bSelected = selectedItems.indexOf(b.id) >= 0;
if (aSelected === bSelected) {
+ var aLastUsed = self._lastUsedTags.indexOf(a.id);
+ var bLastUsed = self._lastUsedTags.indexOf(b.id);
+
+ if (aLastUsed !== bLastUsed) {
+ if (bLastUsed === -1) {
+ return -1;
+ }
+ if (aLastUsed === -1) {
+ return 1;
+ }
+ return aLastUsed < bLastUsed ? -1 : 1;
+ }
+
+ // Both not found
return OC.Util.naturalSortCompare(a.name, b.name);
}
if (aSelected && !bSelected) {