$(document).ready(function () { 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('/'), // Strip admin/plugins baseURL = pathComponents.slice(0,pathComponents.length-2).join('/') + '/', resource = baseURL.substring(1) + "socket.io"; //connect socket = io.connect(url, {resource : resource}).of("/pluginfw/installer"); $('.search-results').data('query', { pattern: '', offset: 0, limit: 12, }); var doUpdate = false; var search = function () { socket.emit("search", $('.search-results').data('query')); } function updateHandlers() { $("form").submit(function(){ var query = $('.search-results').data('query'); query.pattern = $("#search-query").val(); query.offset = 0; search(); return false; }); $("#search-query").unbind('keyup').keyup(function () { var query = $('.search-results').data('query'); query.pattern = $("#search-query").val(); 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()); }); $(".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(); }); $('#progress .showhistory').unbind('click').click(function() { $("#progress .history").toggle() }); } updateHandlers(); socket.on('progress', function (data) { if (data.progress > 0 && $('#progress').data('progress') > data.progress) return; $("#progress .history").hide(); $("#progress").show(); $('#progress').data('progress', data.progress); var message = "Unknown status"; if (data.message) { message = "" + data.message.toString() + ""; } if (data.error) { data.progress = 1; } $("#progress .message").html(message); $("#progress .history").append("