From c171cd51e4b2e3f553cebcbd6526832350b8a53e Mon Sep 17 00:00:00 2001 From: Jamie Cameron Date: Mon, 9 Jun 2014 20:41:40 -0700 Subject: [PATCH] Add buttons to move cron jobs to the top and bottom --- cron/CHANGELOG | 2 ++ cron/images/bottom.gif | Bin 0 -> 82 bytes cron/images/top.gif | Bin 0 -> 84 bytes cron/index.cgi | 26 +++++++++++++++++++------- cron/move.cgi | 20 ++++++++++++++++++-- ui-lib.pl | 16 +++++++++++----- 6 files changed, 50 insertions(+), 14 deletions(-) create mode 100644 cron/images/bottom.gif create mode 100644 cron/images/top.gif diff --git a/cron/CHANGELOG b/cron/CHANGELOG index 74ead3162..840b1c70a 100644 --- a/cron/CHANGELOG +++ b/cron/CHANGELOG @@ -39,3 +39,5 @@ Converted commands in the module's API file to POD format, and added more detail Added a Module Config option to add new cron jobs to a specific file, like /etc/cron.d/webmin, instead of users' personal crontab files. ---- Changes since 1.670 ---- Fixed a security hole what could be exploited by passing in an invalid username. +---- Changes since 1.690 ---- +Added buttons to move cron jobs to the top and bottom of the list. diff --git a/cron/images/bottom.gif b/cron/images/bottom.gif new file mode 100644 index 0000000000000000000000000000000000000000..f4c0eb151f48aa6d9faba736ff1b7e9d01ff80c8 GIT binary patch literal 82 zcmZ?wbhEHb6krfwSjfQe|NnolmH)x?f5o3Hj9d&13_3szloeoLU{Y@BUwK+gQK~A? hDkFcZN%OqMv(8D%JLj(4;`g-M>X6U%E$t!<)&PWn9o+x` literal 0 HcmV?d00001 diff --git a/cron/images/top.gif b/cron/images/top.gif new file mode 100644 index 0000000000000000000000000000000000000000..5c1010e84a67c7fb4f5e858773851727d2564dd7 GIT binary patch literal 84 zcmZ?wbhEHb6krfwSjfQe|NnolmH&Y>0|SHNPZmZX#h?QsK=KSssxAGQ2jA*Wo3SNm it3jUB&Ks;u#ib0Hav4=!Io!)uzuA=Z=UFTxgEasb4;z>O literal 0 HcmV?d00001 diff --git a/cron/index.cgi b/cron/index.cgi index fe5c5e4b4..d4feeb6e5 100755 --- a/cron/index.cgi +++ b/cron/index.cgi @@ -180,13 +180,25 @@ foreach $u (@ulist) { local $prv = $i > 0 ? $plist[$i-1]->[0] : undef; local $nxt = $i != $#plist ? $plist[$i+1]->[0] : undef; if ($access{'move'}) { + local $canup = $prv && + $prv->{'file'} eq $job->{'file'} && + ($job->{'type'} == 0 || $job->{'type'} == 3); + local $candown = $nxt && + $nxt->{'file'} eq $job->{'file'} && + ($job->{'type'} == 0 || $job->{'type'} == 3); + local $mover = "move.cgi?search=". + &urlize($in{'search'})."&idx=$idx"; push(@cols, &ui_up_down_arrows( - "move.cgi?idx=$idx&up=1", - "move.cgi?idx=$idx&down=1", - $prv && $prv->{'file'} eq $job->{'file'} && - ($job->{'type'} == 0 || $job->{'type'} == 3), - $nxt && $nxt->{'file'} eq $job->{'file'} && - ($job->{'type'} == 0 || $job->{'type'} == 3) + "$mover&up=1", + "$mover&down=1", + $canup, $candown, + )); + push(@cols, &ui_up_down_arrows( + "$mover&top=1", + "$mover&bottom=1", + $canup, $candown, + "images/top.gif", + "images/bottom.gif", )); } @@ -235,7 +247,7 @@ elsif (@rows) { $config{'show_comment'} || $userconfig{'show_comment'} ? ( $text{'index_comment'} ) : ( ), $config{'show_run'} ? ( $text{'index_run'} ) : ( ), - $access{'move'} ? ( $text{'index_move'} ) : ( ), + $access{'move'} ? ( $text{'index_move'}, "" ) : ( ), ], 100, 0, \@tds); foreach my $r (@rows) { print &ui_checked_columns_row([ @$r[1..(@$r-2)] ], diff --git a/cron/move.cgi b/cron/move.cgi index 2f8ce652d..a4305dc76 100755 --- a/cron/move.cgi +++ b/cron/move.cgi @@ -11,9 +11,25 @@ $job = $jobs[$in{'idx'}]; if ($in{'up'}) { $swap = $jobs[$in{'idx'}-1]; } -else { +elsif ($in{'down'}) { $swap = $jobs[$in{'idx'}+1]; } +elsif ($in{'top'}) { + for(my $i=$in{'idx'}; + $i && $jobs[$i]->{'file'} eq $job->{'file'}; $i--) { + $swap = $jobs[$i]; + } + } +elsif ($in{'bottom'}) { + for(my $i=$in{'idx'}; + $i < @jobs && $jobs[$i]->{'file'} eq $job->{'file'}; $i++) { + $swap = $jobs[$i]; + } + } +else { + &error("Unknown mode!"); + } +$swap || &error("No job to swap with found"); $access{'move'} && &can_edit_user(\%access, $job->{'user'}) || &error(&text('save_ecannot', $job->{'user'})); &can_edit_user(\%access, $swap->{'user'}) || @@ -25,5 +41,5 @@ $job->{'file'} eq $swap->{'file'} && &swap_cron_jobs($job, $swap); &unlock_file($job->{'file'}); &webmin_log("move", "cron", $job->{'user'}); -&redirect(""); +&redirect("index.cgi?search=".&urlize($in{'search'})); diff --git a/ui-lib.pl b/ui-lib.pl index 94bc6b7b4..46ae21a3a 100755 --- a/ui-lib.pl +++ b/ui-lib.pl @@ -2224,23 +2224,29 @@ Returns HTML for moving some objects in a table up or down. The parameters are : =item down-show - Set to 1 if the down-arrow should be shown, 0 if not. +=item up-icon - Optional path to icon for up link + +=item down-icon - Optional path to icon for down link + =cut sub ui_up_down_arrows { return &theme_ui_up_down_arrows(@_) if (defined(&theme_ui_up_down_arrows)); -my ($uplink, $downlink, $upshow, $downshow) = @_; +my ($uplink, $downlink, $upshow, $downshow, $upicon, $downicon) = @_; my $mover; my $imgdir = "$gconfig{'webprefix'}/images"; +$upicon ||= "$imgdir/moveup.gif"; +$downicon ||= "$imgdir/movedown.gif"; if ($downshow) { - $mover .= "". - ""; + $mover .= "". + ""; } else { $mover .= ""; } if ($upshow) { - $mover .= "". - ""; + $mover .= "". + ""; } else { $mover .= "";