create separate apply function

add apply to sweet alert
This commit is contained in:
dmacias72 2017-06-17 02:35:34 -06:00
parent e38f5f2944
commit 9e854565a0

View File

@ -1,15 +1,11 @@
$(function(){ $(function(){
// add switches to title bar
$('#title')
.append("<span class='status'><input id='uninstallpkg' type='checkbox'></span>")
.append("<span class='status'><input id='deletepkg' type='checkbox'></span>");
// tablesorter options // tablesorter options
$('#tblPackages').tablesorter({ $('#tblPackages').tablesorter({
sortList: [[0,0]], sortList: [[0,0]],
widgets: ['saveSort', 'filter', 'stickyHeaders'], widgets: ['saveSort', 'filter', 'stickyHeaders', 'zebra'],
widgetOptions: { widgetOptions: {
stickyHeaders_filteredToTop: true, stickyHeaders_filteredToTop: false,
//stickyHeaders_yScroll: $('.page_nerdpack'),
filter_hideEmpty: true, filter_hideEmpty: true,
filter_liveSearch: true, filter_liveSearch: true,
filter_saveFilters: true, filter_saveFilters: true,
@ -25,7 +21,7 @@ $(function(){
// "uninstall package" switch and cookie // "uninstall package" switch and cookie
$('#uninstallpkg') $('#uninstallpkg')
.switchButton({ .switchButton({
labels_placement: 'left', labels_placement: 'right',
on_label: 'unInstall On', on_label: 'unInstall On',
off_label: 'unInstall Off', off_label: 'unInstall Off',
checked: $.cookie('nerdpack_packages_uninstall') == '--uninstall' checked: $.cookie('nerdpack_packages_uninstall') == '--uninstall'
@ -34,18 +30,6 @@ $(function(){
$.cookie('nerdpack_packages_uninstall', $('#uninstallpkg')[0].checked ? '--uninstall' : '', { expires: 3650 }); $.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 });
});
// select all packages switch // select all packages switch
$('#checkall') $('#checkall')
.switchButton({ .switchButton({
@ -60,17 +44,7 @@ $(function(){
$('#tblPackages tbody td:visible .pkgcheckbox').switchButton({checked: myval}); $('#tblPackages tbody td:visible .pkgcheckbox').switchButton({checked: myval});
}); });
// set cookie on apply button press $('#btnApply').click(Apply);
$('#btnApply').click(function() {
checkDepends();
var Arg2 = (typeof $.cookie('nerdpack_packages_uninstall') === 'undefined') ? '' : '&arg2='+$.cookie('nerdpack_packages_uninstall');
var Arg3 = (typeof $.cookie('nerdpack_packages_delete') === 'undefined') ? '' : '&arg3='+$.cookie('nerdpack_packages_delete');
$.post('/update.php', $('#package_form').serializeArray(), function() {
openBox('/plugins/NerdPack/scripts/packagemanager&arg1=--download'+ Arg2 + Arg3,
'Package Manager', 600, 900, true);
}
);
});
packageQuery(); packageQuery();
}); });
@ -88,7 +62,7 @@ function packageQuery(force) {
if (data.packages[i].downloadeq == data.packages[i].downloaded && data.packages[i].installeq == data.packages[i].installed){ if (data.packages[i].downloadeq == data.packages[i].downloaded && data.packages[i].installeq == data.packages[i].installed){
Update = "<span><i class='uptodate fa fa-check'></i> up-to-date </span>"; Update = "<span><i class='uptodate fa fa-check'></i> up-to-date </span>";
}else{ }else{
Update = "<span ><a><i class='updateready fa fa-cloud-download'></i> update ready </a></span>"; Update = "<span ><a class='update'><i class='updateready fa fa-cloud-download'></i> update ready </a></span>";
Ready = true; Ready = true;
} }
@ -97,8 +71,6 @@ function packageQuery(force) {
Downloaded = 'old'; Downloaded = 'old';
var Installed = data.packages[i].installed; var Installed = data.packages[i].installed;
if (data.packages[i].installeq != data.packages[i].installed)
Installed = 'old';
var Checked = ""; var Checked = "";
if (data.packages[i].config=="yes"){ if (data.packages[i].config=="yes"){
@ -134,22 +106,47 @@ function packageQuery(force) {
$('#btnApply').prop("disabled", false); $('#btnApply').prop("disabled", false);
}); });
// attach submit to update ready
$('.update').click(Apply);
// restore filters // restore filters
var lastSearch = $('#tblPackages')[0].config.lastSearch; var lastSearch = $('#tblPackages')[0].config.lastSearch;
$('#tblPackages').trigger('update') $('#tblPackages').trigger('update')
.trigger('search', [lastSearch]); .trigger('search', [lastSearch]);
if (data.empty == true && Count > 0) { 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() { swal({
$('#btnApply').prop('disabled', false); title:'Downloaded Packages Missing!',
$('html, body').animate({ text:'You either changed unRAID versions or deleted your downloaded packages. Click Download or the Apply button below to download and install your selected packages.',
scrollTop: $("#btnApply").offset().top type:'warning',
}, 2000); showCancelButton: true,
}); confirmButtonColor: "#00AA00",
confirmButtonText: 'Download',
closeOnConfirm: true,},
function(isConfirm) {
$('#btnApply').prop('disabled', false);
if(isConfirm)
Apply();
else
$('html, body').animate({
scrollTop: $("#btnApply").offset().top
}, 2000);
}
);
} }
}); });
} }
function Apply() {
checkDepends();
var Arg2 = (typeof $.cookie('nerdpack_packages_uninstall') === 'undefined') ? '' : '&arg2='+$.cookie('nerdpack_packages_uninstall');
$.post('/update.php', $('#package_form').serializeArray(), function() {
openBox('/plugins/NerdPack/scripts/packagemanager&arg1=--download'+ Arg2,
'Package Manager', 600, 900, true);
}
);
}
function checkDepends() { function checkDepends() {
if ($('#screen')[0].checked) { if ($('#screen')[0].checked) {
$('#utempter').switchButton({checked: true}); $('#utempter').switchButton({checked: true});