aboutsummaryrefslogtreecommitdiffstats
path: root/core/js
diff options
context:
space:
mode:
Diffstat (limited to 'core/js')
-rw-r--r--core/js/systemtags/systemtagsinputfield.js30
1 files changed, 30 insertions, 0 deletions
diff --git a/core/js/systemtags/systemtagsinputfield.js b/core/js/systemtags/systemtagsinputfield.js
index 2eb8d0a44cb..3ca76f9fa21 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
@@ -241,6 +256,7 @@
}
this._newTag = null;
this.trigger('select', tag);
+ this._lastUsedTags.unshift(tag.id);
},
/**
@@ -400,6 +416,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) {