From af96509fbb84f2c05426ba2e5208dcd34edd4f90 Mon Sep 17 00:00:00 2001 From: Egil Moeller Date: Sat, 17 Mar 2012 18:17:10 +0100 Subject: [PATCH] Plugin install/uninstall --- src/node/hooks/express/adminplugins.js | 22 +++++++++++---- src/templates/admin/plugins.html | 38 +++++++++++++++++--------- 2 files changed, 41 insertions(+), 19 deletions(-) diff --git a/src/node/hooks/express/adminplugins.js b/src/node/hooks/express/adminplugins.js index d3884acb2..4dbd788fe 100644 --- a/src/node/hooks/express/adminplugins.js +++ b/src/node/hooks/express/adminplugins.js @@ -32,14 +32,24 @@ exports.socketio = function (hook_name, args, cb) { }); }); - socket.on("install", function (query) { + socket.on("install", function (plugin_name) { + socket.emit("progress", {progress:0, message:'Downloading and installing ' + plugin_name + "..."}); + installer.install(plugin_name, function (er) { + if (er) + socket.emit("progress", {progress:1, error:er}); + else + socket.emit("progress", {progress:1, message:'Done.'}); + }); }); - socket.on("uninstall", function (query) { + socket.on("uninstall", function (plugin_name) { + socket.emit("progress", {progress:0, message:'Uninstalling ' + plugin_name + "..."}); + installer.uninstall(plugin_name, function (er) { + if (er) + socket.emit("progress", {progress:1, error:er}); + else + socket.emit("progress", {progress:1, message:'Done.'}); + }); }); - - - - }); } diff --git a/src/templates/admin/plugins.html b/src/templates/admin/plugins.html index f83168574..61e277d2f 100644 --- a/src/templates/admin/plugins.html +++ b/src/templates/admin/plugins.html @@ -54,14 +54,28 @@ $(document).ready(function () { var socket = io.connect().of("/pluginfw/installer"); - $("#progress.dialog .close").click(function () { - $("#progress.dialog").hide(); - }); + function updateHandlers() { + $("#progress.dialog .close").click(function () { + $("#progress.dialog").hide(); + }); - $("#do-search").click(function () { - if ($("#search-query")[0].value != "") - socket.emit("search", $("#search-query")[0].value); - }); + $("#do-search").click(function () { + if ($("#search-query")[0].value != "") + socket.emit("search", $("#search-query")[0].value); + }); + + $("#do-install").click(function (e) { + var row = $(e.target).closest("tr"); + socket.emit("install", row.find(".name").html()); + }); + + $("#do-uninstall").click(function (e) { + var row = $(e.target).closest("tr"); + socket.emit("install", row.find(".name").html()); + }); + } + + updateHandlers(); socket.on('progress', function (data) { $("#progress.dialog .close").hide(); @@ -93,6 +107,7 @@ } $("#search-results").append(row); } + updateHandlers(); }); }); @@ -120,13 +135,10 @@ <% for (var plugin_name in plugins) { %> <% var plugin = plugins[plugin_name]; %> - <%= plugin.package.name %> + <%= plugin.package.name %> <%= plugin.package.description %> -
- - -
+ <% } %> @@ -153,7 +165,7 @@ - +