pad.libre-service.eu-etherpad/src/static/js/admin/plugins.js

165 lines
4.7 KiB
JavaScript
Raw Normal View History

$(document).ready(function () {
2012-04-29 19:54:38 +02:00
var socket,
loc = document.location,
port = loc.port == "" ? (loc.protocol == "https:" ? 443 : 80) : loc.port,
url = loc.protocol + "//" + loc.hostname + ":" + port + "/",
pathComponents = location.pathname.split('/'),
2012-04-29 20:12:15 +02:00
// Strip admin/plugins
baseURL = pathComponents.slice(0,pathComponents.length-2).join('/') + '/',
2012-04-29 19:54:38 +02:00
resource = baseURL.substring(1) + "socket.io";
//connect
socket = io.connect(url, {resource : resource}).of("/pluginfw/installer");
2012-04-18 13:43:34 +02:00
$('.search-results').data('query', {
pattern: '',
offset: 0,
limit: 12,
2012-04-18 13:43:34 +02:00
});
var doUpdate = false;
2012-04-18 13:43:34 +02:00
var search = function () {
socket.emit("search", $('.search-results').data('query'));
}
function updateHandlers() {
$("form").submit(function(){
var query = $('.search-results').data('query');
2013-01-07 12:27:40 +01:00
query.pattern = $("#search-query").val();
query.offset = 0;
search();
return false;
});
$("#search-query").unbind('keyup').keyup(function () {
2012-04-18 13:43:34 +02:00
var query = $('.search-results').data('query');
2013-01-07 12:27:40 +01:00
query.pattern = $("#search-query").val();
2012-04-18 13:43:34 +02:00
query.offset = 0;
search();
});
$(".do-install").unbind('click').click(function (e) {
var row = $(e.target).closest("tr");
doUpdate = true;
socket.emit("install", row.find(".name").text());
});
$(".do-uninstall").unbind('click').click(function (e) {
var row = $(e.target).closest("tr");
doUpdate = true;
socket.emit("uninstall", row.find(".name").text());
});
2012-04-18 13:43:34 +02:00
$(".do-prev-page").unbind('click').click(function (e) {
var query = $('.search-results').data('query');
query.offset -= query.limit;
if (query.offset < 0) {
query.offset = 0;
}
search();
});
$(".do-next-page").unbind('click').click(function (e) {
var query = $('.search-results').data('query');
var total = $('.search-results').data('total');
if (query.offset + query.limit < total) {
query.offset += query.limit;
}
search();
});
}
updateHandlers();
socket.on('progress', function (data) {
if (data.progress > 0 && $('#progress').data('progress') > data.progress) return;
2012-04-17 22:18:43 +02:00
$("#progress").show();
2012-04-17 22:18:43 +02:00
$('#progress').data('progress', data.progress);
2012-04-17 22:18:43 +02:00
var message = "Unknown status";
if (data.message) {
message = data.message.toString();
}
if (data.error) {
data.progress = 1;
}
$("#progress .message").html(message);
if (data.progress >= 1) {
$("#progress").hide();
if (data.error) {
alert('An error occurred: '+data.error+' -- the server log might know more...');
}else {
if (doUpdate) {
doUpdate = false;
socket.emit("load");
}
}
}
});
socket.on('search-result', function (data) {
2012-04-17 22:18:43 +02:00
var widget=$(".search-results");
widget.data('query', data.query);
widget.data('total', data.total);
2012-04-18 10:16:41 +02:00
widget.find('.offset').html(data.query.offset);
2013-01-21 00:11:59 +01:00
if (data.query.offset + data.query.limit > data.total){
widget.find('.limit').html(data.total);
}else{
widget.find('.limit').html(data.query.offset + data.query.limit);
}
2012-04-17 22:18:43 +02:00
widget.find('.total').html(data.total);
widget.find(".results *").remove();
for (plugin_name in data.results) {
var plugin = data.results[plugin_name];
2012-04-17 22:18:43 +02:00
var row = widget.find(".template tr").clone();
2012-12-04 14:30:30 +01:00
var version = '0.0.0';
// hack to access "versions" property of the npm package object
2012-12-04 14:30:30 +01:00
for (version in data.results[plugin_name].versions) break;
for (attr in plugin) {
if(attr == "name"){ // Hack to rewrite URLS into name
row.find(".name").html("<a target='_blank' href='https://npmjs.org/package/"+plugin['name']+"'>"+plugin[attr]+"</a>");
2013-01-20 23:34:27 +01:00
}else{
row.find("." + attr).html(plugin[attr]);
2013-01-20 23:34:27 +01:00
}
}
2012-12-04 14:30:30 +01:00
row.find(".version").html(version);
2012-04-17 22:18:43 +02:00
widget.find(".results").append(row);
}
2012-04-17 22:18:43 +02:00
updateHandlers();
});
socket.on('installed-results', function (data) {
$("#installed-plugins *").remove();
for (plugin_name in data.results) {
if (plugin_name == "ep_etherpad-lite") continue; // Hack...
var plugin = data.results[plugin_name];
var row = $("#installed-plugin-template").clone();
for (attr in plugin.package) {
2013-01-24 13:43:42 +01:00
if(attr == "name"){ // Hack to rewrite URLS into name
row.find(".name").html("<a target='_blank' href='https://npmjs.org/package/"+plugin.package['name']+"'>"+plugin.package[attr]+"</a>");
}else{
row.find("." + attr).html(plugin.package[attr]);
}
}
$("#installed-plugins").append(row);
}
updateHandlers();
});
socket.emit("load");
2012-04-18 13:43:34 +02:00
search();
});