diff options
Diffstat (limited to 'pyload/web/app/scripts/models/AddonHandler.js')
-rw-r--r-- | pyload/web/app/scripts/models/AddonHandler.js | 55 |
1 files changed, 55 insertions, 0 deletions
diff --git a/pyload/web/app/scripts/models/AddonHandler.js b/pyload/web/app/scripts/models/AddonHandler.js new file mode 100644 index 000000000..8a138b45d --- /dev/null +++ b/pyload/web/app/scripts/models/AddonHandler.js @@ -0,0 +1,55 @@ +define(['jquery', 'backbone', 'underscore', 'app', 'utils/apitypes'], + function($, Backbone, _, App, Api) { + 'use strict'; + + return Backbone.Model.extend({ + + // cache results for 1 min + CACHE: 60 * 1000, + + defaults: { + timestamp: 0, + // dict with all addon handlers + data: null + }, + + fetch: function(options) { + return Backbone.Model.prototype.fetch.call(this, + App.apiRequest('getAddonHandler', null, options)); + }, + + parse: function(resp) { + this.set('timestamp', new Date().getTime()); + return {data: resp}; + }, + + // available addon handler for package or media types + // async when callback is set + getForType: function(pack, media, callback) { + var self = this; + + if (callback && (!this.has('data') || this.get('timestamp') + this.CACHE < new Date().getTime())) { + this.fetch({success: function() { + callback(self.getForType(pack, media)); + }}); + return; + } + + var addons = this.get('data'); + + // TODO: filter accordingly + + if (_.isFunction(callback)) { + callback(addons); + } + else { + return addons; + } + }, + + // dispatches call to the plugin + invoke: function(plugin, func, args, success) { + console.log(plugin, func, args); + } + }); + });
\ No newline at end of file |