From 39853fc171f95614cda14c26c396a256fa39ade0 Mon Sep 17 00:00:00 2001 From: dmacias72 Date: Fri, 9 Sep 2016 23:16:39 -0600 Subject: [PATCH] formatting, add checks for unRAID version change or empty download folder --- .../plugins/NerdPack/js/jquery.NerdPack.js | 268 ++++++++++-------- 1 file changed, 142 insertions(+), 126 deletions(-) diff --git a/source/NerdPack/usr/local/emhttp/plugins/NerdPack/js/jquery.NerdPack.js b/source/NerdPack/usr/local/emhttp/plugins/NerdPack/js/jquery.NerdPack.js index a3c0a74c..c64ae731 100644 --- a/source/NerdPack/usr/local/emhttp/plugins/NerdPack/js/jquery.NerdPack.js +++ b/source/NerdPack/usr/local/emhttp/plugins/NerdPack/js/jquery.NerdPack.js @@ -1,147 +1,163 @@ $(function(){ - // add switches to title bar - $('#title') - .append("") - .append(""); + // add switches to title bar + $('#title') + .append("") + .append(""); - // tablesorter options - $('#tblPackages').tablesorter({ - sortList: [[0,0]], - widgets: ['saveSort', 'filter', 'stickyHeaders'], - widgetOptions: { - stickyHeaders_filteredToTop: true, - filter_hideEmpty: true, - filter_liveSearch: true, - filter_saveFilters: true, - filter_reset: '.reset', - filter_functions: { - '.filter-version': true, - '.filter-downloaded': true, - '.filter-installed': true - } - } - }); + // tablesorter options + $('#tblPackages').tablesorter({ + sortList: [[0,0]], + widgets: ['saveSort', 'filter', 'stickyHeaders'], + widgetOptions: { + stickyHeaders_filteredToTop: true, + filter_hideEmpty: true, + filter_liveSearch: true, + filter_saveFilters: true, + filter_reset: '.reset', + filter_functions: { + '.filter-version': true, + '.filter-downloaded': true, + '.filter-installed': true + } + } + }); - // "uninstall package" switch and cookie - $('#uninstallpkg') - .switchButton({ - labels_placement: 'left', - on_label: 'unInstall On', - off_label: 'unInstall Off', - checked: $.cookie('nerdpack_packages_uninstall') == '--uninstall' - }) - .change(function () { - $.cookie('nerdpack_packages_uninstall', $('#uninstallpkg')[0].checked ? '--uninstall' : '', { expires: 3650 }); - }); + // "uninstall package" switch and cookie + $('#uninstallpkg') + .switchButton({ + labels_placement: 'left', + on_label: 'unInstall On', + off_label: 'unInstall Off', + checked: $.cookie('nerdpack_packages_uninstall') == '--uninstall' + }) + .change(function () { + $.cookie('nerdpack_packages_uninstall', $('#uninstallpkg')[0].checked ? '--uninstall' : '', { expires: 3650 }); + }); - // "delete package" switch and cookie - $('#deletepkg') - .switchButton({ - labels_placement: 'left', - on_label: 'delete On', - off_label: 'delete Off', - checked: $.cookie('nerdpack_packages_delete') == '--delete' - }) - .change(function () { - $.cookie('nerdpack_packages_delete', $('#deletepkg')[0].checked ? '--delete' : '', { expires: 3650 }); - }); + // "delete package" switch and cookie + $('#deletepkg') + .switchButton({ + labels_placement: 'left', + on_label: 'delete On', + off_label: 'delete Off', + checked: $.cookie('nerdpack_packages_delete') == '--delete' + }) + .change(function () { + $.cookie('nerdpack_packages_delete', $('#deletepkg')[0].checked ? '--delete' : '', { expires: 3650 }); + }); - // select all packages switch - $('#checkall') - .switchButton({ - labels_placement: 'right', - on_label: 'Select All', - off_label: 'Select All', - checked: $.cookie('nerdpack_checkall') == 'yes' - }) - .change(function () { - var myval = $(this)[0].checked; - $.cookie('nerdpack_checkall', myval ? 'yes' : 'no', { expires: 3650 }); - $('#tblPackages tbody td:visible .pkgcheckbox').switchButton({checked: myval}); - }); + // select all packages switch + $('#checkall') + .switchButton({ + labels_placement: 'right', + on_label: 'Select All', + off_label: 'Select All', + checked: $.cookie('nerdpack_checkall') == 'yes' + }) + .change(function () { + var myval = $(this)[0].checked; + $.cookie('nerdpack_checkall', myval ? 'yes' : 'no', { expires: 3650 }); + $('#tblPackages tbody td:visible .pkgcheckbox').switchButton({checked: myval}); + }); - // set cookie on apply button press - $('#btnApply').click(function() { - checkDepends(); + // set cookie on apply button press + $('#btnApply').click(function() { + checkDepends(); - $.post('/update.php', $('#package_form').serializeArray(), function() { - openBox('/plugins/NerdPack/scripts/packagemanager&arg1=--download'+ - '&arg2='+$.cookie('nerdpack_packages_uninstall')+ - '&arg3='+$.cookie('nerdpack_packages_delete'), - 'Package Manager', 600, 900, true); - } - ); - }); + $.post('/update.php', $('#package_form').serializeArray(), function() { + openBox('/plugins/NerdPack/scripts/packagemanager&arg1=--download'+ + '&arg2='+$.cookie('nerdpack_packages_uninstall')+ + '&arg3='+$.cookie('nerdpack_packages_delete'), + 'Package Manager', 600, 900, true); + } + ); + }); - packageQuery(); + packageQuery(); }); //list all available packages in a table function packageQuery(force) { - $('#tblPackages tbody').html("
Please wait, retrieving plugin information ..."); - $.getJSON('/plugins/NerdPack/include/PackageQuery.php', {force: force}, function(packages) { - $('#tblPackages tbody').empty(); - var Ready; - var len = packages.length, i = 0; - for (i; i < len; i++) { - var Update; - if (packages[i].downloadeq == packages[i].downloaded && packages[i].installeq == packages[i].installed){ - Update = " up-to-date "; - }else{ - Update = " update ready "; - Ready = true; - } + $('#tblPackages tbody').html("
Please wait, retrieving plugin information ..."); + $.getJSON('/plugins/NerdPack/include/PackageQuery.php', {force: force}, function(data) { + $('#tblPackages tbody').empty(); + var Ready; + var Count = 0; + var len = data.packages.length, i = 0; + for (i; i < len; i++) { + var Update; + if (data.packages[i].downloadeq == data.packages[i].downloaded && data.packages[i].installeq == data.packages[i].installed){ + Update = " up-to-date "; + }else{ + Update = " update ready "; + Ready = true; + } - var Downloaded = packages[i].downloaded; - if (packages[i].downloadeq != packages[i].downloaded) - Downloaded = 'old'; + var Downloaded = data.packages[i].downloaded; + if (data.packages[i].downloadeq != data.packages[i].downloaded) + Downloaded = 'old'; - var Installed = packages[i].installed; - if (packages[i].installeq != packages[i].installed) - Installed = 'old'; + var Installed = data.packages[i].installed; + if (data.packages[i].installeq != data.packages[i].installed) + Installed = 'old'; - $('#tblPackages tbody').append(""+ - ""+packages[i].name+""+ // package name - ""+Update+""+ // package status - ""+packages[i].size+""+ // package size - ""+Downloaded+""+ // package downloaded - ""+Installed+""+ // package installed - ""+packages[i].plugins+""+ // package dependents - ""+ - ""+ - ""); - } - if (Ready) - $('#btnApply').prop('disabled', false); + var Checked = ""; + if (data.packages[i].config=="yes"){ + Checked = "checked"; + Count++; + } - // attach switch buttons to every package checkbox all at once - $('.pkgcheckbox') - .switchButton({ - labels_placement: 'right', - on_label: 'On', - off_label: 'Off' - }) - .change(function() { - $(this).parent().parent().find('.pkgvalue').val(this.checked ? "yes": "no"); - if (this.checked) - checkDepends(); - $('#btnApply').prop("disabled", false); - }); + $('#tblPackages tbody').append(""+ + ""+data.packages[i].name+""+ // package name + ""+Update+""+ // package status + ""+data.packages[i].size+""+ // package size + ""+Downloaded+""+ // package downloaded + ""+Installed+""+ // package installed + ""+data.packages[i].plugins+""+ // package dependents + ""+ + ""+ + ""); + } + if (Ready) + $('#btnApply').prop('disabled', false); - // restore filters - var lastSearch = $('#tblPackages')[0].config.lastSearch; - $('#tblPackages').trigger('update') - .trigger('search', [lastSearch]); - }); + // attach switch buttons to every package checkbox all at once + $('.pkgcheckbox') + .switchButton({ + labels_placement: 'right', + on_label: 'On', + off_label: 'Off' + }) + .change(function() { + $(this).parent().parent().find('.pkgvalue').val(this.checked ? "yes": "no"); + if (this.checked) + checkDepends(); + $('#btnApply').prop("disabled", false); + }); + + // restore filters + var lastSearch = $('#tblPackages')[0].config.lastSearch; + $('#tblPackages').trigger('update') + .trigger('search', [lastSearch]); + + if (data.empty == true && Count > 0) { + swal({title:'Downloaded Packages Missing!',text:'You either changed unRAID versions or deleted your downloaded packages. Click the Apply button below to download and install your selected packages.',type:'warning',closeOnConfirm: true,},function() { + $('#btnApply').prop('disabled', false); + $('html, body').animate({ + scrollTop: $("#btnApply").offset().top + }, 2000); + }); + } + }); } function checkDepends() { - if ($('#screen')[0].checked) { - $('#utempter').switchButton({checked: true}); - $('#utempter', '.pkgvalue').val('yes'); - } - if ($('#iotop')[0].checked) { - $('#python').switchButton({checked: true}); - $('#python', '.pkgvalue').val('yes'); - } + if ($('#screen')[0].checked) { + $('#utempter').switchButton({checked: true}); + $('#utempter', '.pkgvalue').val('yes'); + } + if ($('#iotop')[0].checked) { + $('#python').switchButton({checked: true}); + $('#python', '.pkgvalue').val('yes'); + } }