2012-04-11 18:07:19 +02:00
|
|
|
$(document).ready(function () {
|
|
|
|
var socket = io.connect().of("/pluginfw/installer");
|
|
|
|
|
2012-04-18 13:43:34 +02:00
|
|
|
$('.search-results').data('query', {
|
|
|
|
pattern: '',
|
|
|
|
offset: 0,
|
|
|
|
limit: 4,
|
|
|
|
});
|
|
|
|
|
2012-04-11 18:07:19 +02:00
|
|
|
var doUpdate = false;
|
|
|
|
|
2012-04-18 13:43:34 +02:00
|
|
|
var search = function () {
|
|
|
|
socket.emit("search", $('.search-results').data('query'));
|
|
|
|
}
|
|
|
|
|
2012-04-11 18:07:19 +02:00
|
|
|
function updateHandlers() {
|
|
|
|
$("#progress.dialog .close").unbind('click').click(function () {
|
|
|
|
$("#progress.dialog").hide();
|
|
|
|
});
|
|
|
|
|
|
|
|
$("#do-search").unbind('click').click(function () {
|
2012-04-18 13:43:34 +02:00
|
|
|
var query = $('.search-results').data('query');
|
|
|
|
query.pattern = $("#search-query")[0].value;
|
|
|
|
query.offset = 0;
|
|
|
|
search();
|
2012-04-11 18:07:19 +02:00
|
|
|
});
|
|
|
|
|
|
|
|
$(".do-install").unbind('click').click(function (e) {
|
|
|
|
var row = $(e.target).closest("tr");
|
|
|
|
doUpdate = true;
|
|
|
|
socket.emit("install", row.find(".name").html());
|
|
|
|
});
|
|
|
|
|
|
|
|
$(".do-uninstall").unbind('click').click(function (e) {
|
|
|
|
var row = $(e.target).closest("tr");
|
|
|
|
doUpdate = true;
|
|
|
|
socket.emit("uninstall", row.find(".name").html());
|
|
|
|
});
|
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();
|
|
|
|
});
|
2012-04-11 18:07:19 +02:00
|
|
|
}
|
|
|
|
|
|
|
|
updateHandlers();
|
|
|
|
|
|
|
|
socket.on('progress', function (data) {
|
2012-04-18 13:43:34 +02:00
|
|
|
if (data.progress > 0 && $('#progress.dialog').data('progress') > data.progress) return;
|
2012-04-17 22:18:43 +02:00
|
|
|
|
2012-04-11 18:07:19 +02:00
|
|
|
$("#progress.dialog .close").hide();
|
|
|
|
$("#progress.dialog").show();
|
2012-04-17 22:18:43 +02:00
|
|
|
|
|
|
|
$('#progress.dialog').data('progress', data.progress);
|
|
|
|
|
2012-04-11 18:07:19 +02:00
|
|
|
var message = "Unknown status";
|
|
|
|
if (data.message) {
|
|
|
|
message = "<span class='status'>" + data.message.toString() + "</span>";
|
|
|
|
}
|
|
|
|
if (data.error) {
|
|
|
|
message = "<span class='error'>" + data.error.toString() + "<span>";
|
|
|
|
}
|
|
|
|
$("#progress.dialog .message").html(message);
|
|
|
|
$("#progress.dialog .history").append("<div>" + message + "</div>");
|
|
|
|
|
|
|
|
if (data.progress >= 1) {
|
|
|
|
if (data.error) {
|
|
|
|
$("#progress.dialog .close").show();
|
|
|
|
} else {
|
|
|
|
if (doUpdate) {
|
|
|
|
doUpdate = false;
|
|
|
|
socket.emit("load");
|
|
|
|
}
|
|
|
|
$("#progress.dialog").hide();
|
|
|
|
}
|
|
|
|
}
|
|
|
|
});
|
|
|
|
|
|
|
|
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);
|
|
|
|
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();
|
2012-04-11 18:07:19 +02:00
|
|
|
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-04-11 18:07:19 +02:00
|
|
|
|
|
|
|
for (attr in plugin) {
|
|
|
|
row.find("." + attr).html(plugin[attr]);
|
|
|
|
}
|
2012-04-17 22:18:43 +02:00
|
|
|
widget.find(".results").append(row);
|
2012-04-11 18:07:19 +02:00
|
|
|
}
|
2012-04-17 22:18:43 +02:00
|
|
|
|
2012-04-11 18:07:19 +02:00
|
|
|
updateHandlers();
|
|
|
|
});
|
|
|
|
|
|
|
|
socket.on('installed-results', function (data) {
|
|
|
|
$("#installed-plugins *").remove();
|
|
|
|
for (plugin_name in data.results) {
|
|
|
|
var plugin = data.results[plugin_name];
|
|
|
|
var row = $("#installed-plugin-template").clone();
|
|
|
|
|
|
|
|
for (attr in plugin.package) {
|
|
|
|
row.find("." + attr).html(plugin.package[attr]);
|
|
|
|
}
|
|
|
|
$("#installed-plugins").append(row);
|
|
|
|
}
|
|
|
|
updateHandlers();
|
|
|
|
});
|
|
|
|
|
|
|
|
socket.emit("load");
|
2012-04-18 13:43:34 +02:00
|
|
|
search();
|
2012-04-11 18:07:19 +02:00
|
|
|
|
|
|
|
});
|