diff --git a/source/NerdPack/usr/local/emhttp/plugins/NerdPack/javascript/jquery.NerdPack.js b/source/NerdPack/usr/local/emhttp/plugins/NerdPack/javascript/jquery.NerdPack.js index dec92e5f..bc588fb2 100644 --- a/source/NerdPack/usr/local/emhttp/plugins/NerdPack/javascript/jquery.NerdPack.js +++ b/source/NerdPack/usr/local/emhttp/plugins/NerdPack/javascript/jquery.NerdPack.js @@ -1,14 +1,13 @@ $(function(){ - //Shadowbox.init({onClose:packageQuery}); //tablesorter options $('#tblPackages').tablesorter({headers:{5:{sorter:false}}}); // "uninstall package" switch and cookie $('#removepkg') .switchButton({ - labels_placement: "right", - on_label: 'uninstall packages On', - off_label: 'uninstall packages Off', + labels_placement: "left", + on_label: 'unInstall Packages', + off_label: 'unInstall Packages', checked: $.cookie('nerdpack_packages') == 'remove' }) .change(function () { @@ -19,8 +18,8 @@ $(function(){ $('#checkall') .switchButton({ labels_placement: "right", - on_label: 'select all', - off_label: ' select all', + on_label: 'Select All', + off_label: 'Select All', checked: $.cookie('nerdpack_checkall') == 'yes' }) .change(function() { //on change @@ -55,8 +54,9 @@ function packageManager() { type : "POST", url : "/update.php", data : $('#package_form').serializeArray(), - complete: function() { - openBox('/plugins/NerdPack/scripts/packagemanager&arg1=webgui&arg2='+$.cookie('nerdpack_packages'),'Manage Packages',600,900,true); + success: function() { + openBox('/plugins/NerdPack/scripts/packagemanager&arg1=download&arg2='+ + $.cookie('nerdpack_packages'),'Manage Packages',600,900,true); } }); }; @@ -69,127 +69,53 @@ function packageQuery() { dataType: "json", url: "/plugins/NerdPack/include/PackageQuery.php", success: function(data) { - if (data.length > 1){ - for( i in data ) { - $("#tblPackages tbody").append( - ""+ - ""+data[i].name+""+ //package name - ""+ //package status - ""+(data[i].size / 1000).toFixed(0)+""+ //package size - ""+data[i].downloaded+""+ //package installed - ""+data[i].installed+""+ //package installed - ""+ - ""+ - ""); - $('#'+data[i].pkgname) - .switchButton({ - labels_placement: 'right', - on_label: 'On', - off_label: 'Off', - checked: data[i].config == "yes" - }) - .change(function() { - var par = $(this).parent().parent(); - if(this.checked) - par.find('.pkgvalue').val("yes"); - else - par.find('.pkgvalue').val("no"); - $("#btnApply").prop("disabled", false); - checkDepends(); - }); - } - }else { + for( i in data ) { + var Update; + if (data[i].downloadeq == data[i].downloaded && data[i].installeq == data[i].installed ) + Update = " up-to-date"; + else + Update = " update ready"; + $("#tblPackages tbody").append( ""+ - ""+ + ""+data[i].name+""+ //package name + ""+Update+""+ //package status + ""+(data[i].size / 1000).toFixed(0)+""+ //package size + ""+data[i].downloaded+""+ //package installed + ""+data[i].installed+""+ //package installed + ""+ + ""+ + ""+ ""); - + $(".btnRemove").unbind("click", Remove).bind("click", Remove); + $('#'+data[i].pkgname) + .switchButton({ + labels_placement: 'right', + on_label: 'On', + off_label: 'Off', + checked: data[i].config == "yes" + }) + .change(function() { + var par = $(this).parent().parent(); + if(this.checked) + par.find('.pkgvalue').val("yes"); + else + par.find('.pkgvalue').val("no"); + $("#btnApply").prop("disabled", false); + checkDepends(); + }); } }, complete : function () { $("#tblPackages").trigger("update"); - packageCheck() }, error: function () { } }); }; -// check github for newer package and report status -function packageCheck() { - $.ajax({ - type: "GET", - url: "/boot/config/plugins/NerdPack/packages.json", - dataType: "json", - success: function(data) { - $('#tblPackages tbody tr').each(function(row, tr) { - var tblPackage = $(tr).children("td:nth-child(1)").html(); - var tblName = $(tr).children("td:nth-child(6)").find('.pkgcheckbox').attr("id"); - for( i in data ) { - var Package = data[i].name; - var pkgNameArray = Package.split('-'); - var pkgName = pkgNameArray[0]; - if (pkgNameArray.length > 4){ - for( var ii = 1; ii < pkgNameArray.length-3; ii++ ) { - pkgName = pkgName+"-"+pkgNameArray[ii]; - } - } - if ( tblName == pkgName){ - if (tblPackage == Package) - var Update = " up-to-date"; - else - var Update = " update ready"; - } - } - $(tr).children("td:nth-child(2)").html(Update); - }); - - }, - complete : function () { - $("#tblPackages").trigger("update"); - }, - error: function () { - } - }); -}; - -// update packages -function packageUpdate(pkgName, pkgOld, pkgNew, pkgSha) { - $.ajax({ - type: "POST", - dataType: "json", - url: "/plugins/NerdPack/include/PackageUpdate.php", - data: {pkgname: pkgName, pkgold: pkgOld, pkgnew: pkgNew, pkgsha: pkgSha}, - success: function(data) { - alert(data); - }, - complete : function () { - //location.reload(); - }, - error: function () { - } - }); -}; - -function downloadPackages() { - $.ajax({ - type: "POST", - url: "/plugins/NerdPack/include/PackageDownload.php", - dataType: "json", - success: function(data) { - for( i in data ) { - packageUpdate(null,null,data[i].name,data[i].sha); - } - }, - complete : function () { - $("#tblPackages").trigger("update"); - }, - error: function () { - } - }); -}; - - function checkDepends() { if ($('#screen').prop('checked') == true){ $('#utempter').switchButton({checked: true}); @@ -200,3 +126,22 @@ function checkDepends() { $('#python','.pkgvalue').val('yes'); } }; + +function Remove(){ + var par = $(this).parent().parent(); + if (par.children("td:nth-child(4)").html() == "yes"){ + var Package = par.children("td:nth-child(1)").html(); + var Downloaded = par.children("td:nth-child(4)").html(); + var Confirm = confirm("Remove package "+Package+" from flash drive?") + if (Confirm) { + par.children("td:nth-child(4)").html("no"); + $.ajax({ + type : "POST", + url: '/plugins/NerdPack/include/PackageRemove.php', + data : {pkg:Package}, + success: function() { + } + }); + } + } +};