summaryrefslogtreecommitdiffstats
path: root/pyload
diff options
context:
space:
mode:
Diffstat (limited to 'pyload')
-rw-r--r--pyload/api/AddonApi.py2
-rw-r--r--pyload/web/ServerThread.py2
-rw-r--r--pyload/web/app/scripts/default.js7
-rw-r--r--pyload/web/app/scripts/models/AddonHandler.js55
-rw-r--r--pyload/web/app/scripts/views/dashboard/packageView.js27
-rw-r--r--pyload/web/app/templates/default/dashboard/package.html4
-rw-r--r--pyload/web/app/templates/default/dashboard/submenu.html8
7 files changed, 95 insertions, 10 deletions
diff --git a/pyload/api/AddonApi.py b/pyload/api/AddonApi.py
index ea1e3ce6e..7a1a651fc 100644
--- a/pyload/api/AddonApi.py
+++ b/pyload/api/AddonApi.py
@@ -35,7 +35,7 @@ class AddonApi(ApiComponent):
handler = {}
for name, data in self.core.addonManager.iterAddons():
if data.handler:
- handler[name] = data.handler
+ handler[name] = data.handler.values()
return handler
@RequirePerm(Permission.Interaction)
diff --git a/pyload/web/ServerThread.py b/pyload/web/ServerThread.py
index c55ddef0f..809c6c800 100644
--- a/pyload/web/ServerThread.py
+++ b/pyload/web/ServerThread.py
@@ -107,7 +107,7 @@ class WebServer(threading.Thread):
log.error(_("Failed importing webserver: " + e.message))
if unavailable: # Just log whats not available to have some debug information
- log.debug("Unavailable webserver: " + ",".join(unavailable))
+ log.debug("Unavailable webserver: " + ", ".join(unavailable))
if not server and self.force_server:
server = self.force_server # just return the name
diff --git a/pyload/web/app/scripts/default.js b/pyload/web/app/scripts/default.js
index 91b46715e..d66c0e1f8 100644
--- a/pyload/web/app/scripts/default.js
+++ b/pyload/web/app/scripts/default.js
@@ -1,5 +1,6 @@
-define('default', ['require', 'backbone', 'jquery', 'app', 'router', 'models/UserSession'],
- function(require, Backbone, $, App, Router, UserSession) {
+define('default', ['require', 'backbone', 'jquery', 'app', 'router',
+ 'models/UserSession', 'models/AddonHandler'],
+ function(require, Backbone, $, App, Router, UserSession, AddonHandler) {
'use strict';
// Global ajax options
@@ -20,6 +21,8 @@ define('default', ['require', 'backbone', 'jquery', 'app', 'router', 'models/Use
return Backbone.$.ajax.apply(Backbone.$, arguments);
};
+ App.addons = new AddonHandler();
+
$(function() {
// load setup async
if (window.setup === 'true') {
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
diff --git a/pyload/web/app/scripts/views/dashboard/packageView.js b/pyload/web/app/scripts/views/dashboard/packageView.js
index 2738fcbea..30121c344 100644
--- a/pyload/web/app/scripts/views/dashboard/packageView.js
+++ b/pyload/web/app/scripts/views/dashboard/packageView.js
@@ -1,5 +1,5 @@
-define(['jquery', 'app', 'views/abstract/itemView', 'underscore', 'hbs!tpl/dashboard/package'],
- function($, App, itemView, _, template) {
+define(['jquery', 'app', 'views/abstract/itemView', 'underscore', 'hbs!tpl/dashboard/package', 'hbs!tpl/dashboard/submenu'],
+ function($, App, itemView, _, template, templateSubmenu) {
'use strict';
// Renders a single package item
@@ -12,7 +12,9 @@ define(['jquery', 'app', 'views/abstract/itemView', 'underscore', 'hbs!tpl/dashb
'click .package-name, .btn-open': 'open',
'click .icon-refresh': 'restart',
'click .select': 'select',
- 'click .btn-delete': 'deleteItem'
+ 'click .icon-chevron-down': 'loadMenu',
+ 'click .btn-delete': 'deleteItem',
+ 'click .dropdown-submenu a': 'invokeAddon'
},
// Ul for child packages (unused)
@@ -44,6 +46,10 @@ define(['jquery', 'app', 'views/abstract/itemView', 'underscore', 'hbs!tpl/dashb
return this;
},
+ renderSubmenu: function(addons) {
+ this.$('.dropdown-submenu ul').html(templateSubmenu(addons));
+ },
+
unrender: function() {
itemView.prototype.unrender.apply(this);
@@ -51,7 +57,6 @@ define(['jquery', 'app', 'views/abstract/itemView', 'underscore', 'hbs!tpl/dashb
App.vent.trigger('dashboard:loading', null);
},
-
// TODO
// Toggle expanding of packages
expand: function(e) {
@@ -70,6 +75,20 @@ define(['jquery', 'app', 'views/abstract/itemView', 'underscore', 'hbs!tpl/dashb
this.model.set('selected', !checked, {silent: true});
this.$('.select').toggleClass('icon-check').toggleClass('icon-check-empty');
App.vent.trigger('package:selection');
+ },
+
+ loadMenu: function() {
+ App.addons.getForType(true, null, _.bind(this.renderSubmenu, this));
+ },
+
+ invokeAddon: function(e) {
+ var el = $(e.target);
+ // clicked on icon
+ if (el.context.tagName === 'IMG')
+ el = el.parent();
+
+ App.addons.invoke(el.data('plugin'), el.data('func'), this.model.get('pid'));
}
+
});
}); \ No newline at end of file
diff --git a/pyload/web/app/templates/default/dashboard/package.html b/pyload/web/app/templates/default/dashboard/package.html
index 83f4fa39e..cde0dda6e 100644
--- a/pyload/web/app/templates/default/dashboard/package.html
+++ b/pyload/web/app/templates/default/dashboard/package.html
@@ -31,9 +31,9 @@
<li><a href="#" class="btn-recheck"><i class="icon-refresh"></i> Recheck</a></li>
<li class="divider"></li>
<li class="dropdown-submenu">
- <a>Addons</a>
+ <a>{{ _ "Addons" }}</a>
<ul class="dropdown-menu">
- <li><a>Test</a></li>
+ <li><a><i class="icon-spinner icon-spin"></i> {{ _ "Loading..." }}</a></li>
</ul>
</li>
</ul>
diff --git a/pyload/web/app/templates/default/dashboard/submenu.html b/pyload/web/app/templates/default/dashboard/submenu.html
new file mode 100644
index 000000000..70e067b84
--- /dev/null
+++ b/pyload/web/app/templates/default/dashboard/submenu.html
@@ -0,0 +1,8 @@
+{{#each this}}
+ {{#each this}}
+ <li><a href="#" data-plugin="{{@key}}" data-func="{{func_name}}">
+ <img src="{{pluginIcon @key}}" style="width: 20px; height: 20px">&nbsp;
+ {{label}}</a>
+ </li>
+ {{/each}}
+{{/each}} \ No newline at end of file