2019-09-25 19:19:42 +03:00
|
|
|
/* eslint-disable */
|
2015-11-30 17:40:17 +03:00
|
|
|
/*
|
|
|
|
* Copyright (c) 2015
|
|
|
|
*
|
|
|
|
* This file is licensed under the Affero General Public License version 3
|
|
|
|
* or later.
|
|
|
|
*
|
|
|
|
* See the COPYING-README file.
|
|
|
|
*
|
|
|
|
*/
|
|
|
|
|
|
|
|
(function(OC) {
|
|
|
|
|
|
|
|
function filterFunction(model, term) {
|
2019-09-25 19:19:42 +03:00
|
|
|
return model.get('name').substr(0, term.length).toLowerCase() === term.toLowerCase()
|
2015-11-30 17:40:17 +03:00
|
|
|
}
|
|
|
|
|
|
|
|
/**
|
|
|
|
* @class OCA.SystemTags.SystemTagsCollection
|
|
|
|
* @classdesc
|
|
|
|
*
|
|
|
|
* Collection of tags assigned to a file
|
|
|
|
*
|
|
|
|
*/
|
|
|
|
var SystemTagsCollection = OC.Backbone.Collection.extend(
|
|
|
|
/** @lends OC.SystemTags.SystemTagsCollection.prototype */ {
|
|
|
|
|
2019-09-25 19:19:42 +03:00
|
|
|
sync: OC.Backbone.davSync,
|
2015-11-30 17:40:17 +03:00
|
|
|
|
2019-09-25 19:19:42 +03:00
|
|
|
model: OC.SystemTags.SystemTagModel,
|
2015-11-30 17:40:17 +03:00
|
|
|
|
2019-09-25 19:19:42 +03:00
|
|
|
url: function() {
|
|
|
|
return OC.linkToRemote('dav') + '/systemtags/'
|
|
|
|
},
|
2015-11-30 17:40:17 +03:00
|
|
|
|
2019-09-25 19:19:42 +03:00
|
|
|
filterByName: function(name) {
|
|
|
|
return this.filter(function(model) {
|
|
|
|
return filterFunction(model, name)
|
|
|
|
})
|
|
|
|
},
|
2015-11-30 17:40:17 +03:00
|
|
|
|
2019-09-25 19:19:42 +03:00
|
|
|
reset: function() {
|
|
|
|
this.fetched = false
|
|
|
|
return OC.Backbone.Collection.prototype.reset.apply(this, arguments)
|
|
|
|
},
|
2015-11-30 17:40:17 +03:00
|
|
|
|
2019-09-25 19:19:42 +03:00
|
|
|
/**
|
2015-11-30 17:40:17 +03:00
|
|
|
* Lazy fetch.
|
|
|
|
* Only fetches once, subsequent calls will directly call the success handler.
|
|
|
|
*
|
|
|
|
* @param options
|
|
|
|
* @param [options.force] true to force fetch even if cached entries exist
|
|
|
|
*
|
|
|
|
* @see Backbone.Collection#fetch
|
|
|
|
*/
|
2019-09-25 19:19:42 +03:00
|
|
|
fetch: function(options) {
|
|
|
|
var self = this
|
|
|
|
options = options || {}
|
|
|
|
if (this.fetched || options.force) {
|
2015-11-30 17:40:17 +03:00
|
|
|
// directly call handler
|
2019-09-25 19:19:42 +03:00
|
|
|
if (options.success) {
|
|
|
|
options.success(this, null, options)
|
|
|
|
}
|
|
|
|
// trigger sync event
|
|
|
|
this.trigger('sync', this, null, options)
|
|
|
|
return Promise.resolve()
|
2015-11-30 17:40:17 +03:00
|
|
|
}
|
|
|
|
|
2019-09-25 19:19:42 +03:00
|
|
|
var success = options.success
|
|
|
|
options = _.extend({}, options)
|
|
|
|
options.success = function() {
|
|
|
|
self.fetched = true
|
|
|
|
if (success) {
|
|
|
|
return success.apply(this, arguments)
|
|
|
|
}
|
2015-11-30 17:40:17 +03:00
|
|
|
}
|
|
|
|
|
2019-09-25 19:19:42 +03:00
|
|
|
return OC.Backbone.Collection.prototype.fetch.call(this, options)
|
|
|
|
}
|
|
|
|
})
|
2015-11-30 17:40:17 +03:00
|
|
|
|
2019-09-25 19:19:42 +03:00
|
|
|
OC.SystemTags = OC.SystemTags || {}
|
|
|
|
OC.SystemTags.SystemTagsCollection = SystemTagsCollection
|
2015-11-30 17:40:17 +03:00
|
|
|
|
|
|
|
/**
|
|
|
|
* @type OC.SystemTags.SystemTagsCollection
|
|
|
|
*/
|
2019-09-25 19:19:42 +03:00
|
|
|
OC.SystemTags.collection = new OC.SystemTags.SystemTagsCollection()
|
|
|
|
})(OC)
|