aboutsummaryrefslogtreecommitdiffstats
path: root/lib/Fripost/Panel
diff options
context:
space:
mode:
authorGuilhem Moulin <guilhem.moulin@fripost.org>2012-09-09 23:34:54 +0200
committerGuilhem Moulin <guilhem.moulin@fripost.org>2012-09-09 23:34:54 +0200
commit62f0ac114989808ebb84e7728b4b7e9f65d53c0e (patch)
tree52d70e2bbff7c37eaabe625186444e26dd0feadc /lib/Fripost/Panel
parentec17f0ce71a233025768a54b4a1beae34e2b8a45 (diff)
Added delete links.
Diffstat (limited to 'lib/Fripost/Panel')
-rw-r--r--lib/Fripost/Panel/Interface.pm57
1 files changed, 34 insertions, 23 deletions
diff --git a/lib/Fripost/Panel/Interface.pm b/lib/Fripost/Panel/Interface.pm
index b636861..6859e57 100644
--- a/lib/Fripost/Panel/Interface.pm
+++ b/lib/Fripost/Panel/Interface.pm
@@ -171,7 +171,7 @@ sub EditDomain : Runmode {
my $template = $self->load_tmpl( 'edit-domain.html', cache => 1, utf8 => 1
, loop_context_vars => 1
, global_vars => 1 );
- $template->param( url => $self->query->url
+ $template->param( url => $q->url
, user_localpart => $ul
, user_domainpart => $ud
, domain => $d
@@ -190,7 +190,7 @@ sub EditDomain : Runmode {
, catchalls => join ("\x{0D}\x{0A}",
@{$domain{catchalls}}) );
}
- $template->param( newChanges => defined $self->query->param('submit') );
+ $template->param( newChanges => defined $q->param('submit') );
return $template->output;
}
@@ -209,10 +209,25 @@ sub EditLocal : Runmode {
my $fp = Fripost::Schema::->SASLauth( $self->authen->username, %CFG );
+ # Search for *the* matching mailbox, alias or list.
+ my %local = $fp->local->get ($l, $d, -die => 404,
+ -concat => "\x{0D}\x{0A}");
+ die "Unknown type" unless grep { $local{type} eq $_ }
+ qw/mailbox alias list/;
+
my $error; # Tells whether the change submission has failed.
- if (defined $q->param('submit')) {
+ my $t = $local{type};
+
+ if (defined $q->param('a') and $q->param('a') eq 'delete') {
+ # Delete the entry
+ $error = $fp->$t->delete($l, $d, -die => 0);
+ unless ($error) {
+ $fp->done;
+ return $self->redirect($q->url .'/'. $d .'/');
+ }
+ }
+ elsif (defined $q->param('submit')) {
# Changes have been submitted: process them
- my $t = $q->param('t') // die "Undefined type";
my %entry;
if ($t eq 'mailbox') {
$entry{user} = $l.'@'.$d;
@@ -269,19 +284,16 @@ sub EditLocal : Runmode {
unless $error;
}
- # Search for *the* matching mailbox, alias or list.
- my %local = $fp->local->get ($l, $d, -die => 404,
- -concat => "\x{0D}\x{0A}");
$fp->done;
- my $template = $self->load_tmpl( "edit-$local{type}.html",
+ my $template = $self->load_tmpl( "edit-$t.html",
cache => 1, utf8 => 1 );
- $template->param( url => $self->query->url
+ $template->param( url => $q->url
, user_localpart => $ul
, user_domainpart => $ud
, domain => $d
);
- if ($error) {
+ if ($error and defined $q->param('submit')) {
# Preserve the (incorrect) form, except the passwords
if ($local{type} eq 'mailbox') {
$template->param( user => $l
@@ -295,33 +307,32 @@ sub EditLocal : Runmode {
$template->param( list => $l );
}
else {
- # Unknown type
- return $self->redirect($q->url.'/'.$d.'/');
+ die "Unknown type";
}
$template->param( isactive => $q->param('isactive')
- , description => $q->param('description')
- , error => encode_entities ($error, "‘‘") );
+ , description => $q->param('description') );
}
else {
- if ($local{type} eq 'mailbox') {
+ if ($t eq 'mailbox') {
$template->param( user => $local{user}
, forwards => $local{forwards} );
}
- elsif ($local{type} eq 'alias') {
+ elsif ($t eq 'alias') {
$template->param( alias => $local{alias}
, maildrop => $local{maildrop} );
}
- elsif ($local{type} eq 'list') {
+ elsif ($t eq 'list') {
$template->param( list => $local{list} );
}
- else {
- # Unknown type
- return $self->redirect($q->url.'/'.$d.'/');
- }
$template->param( isactive => $local{isactive}
, description => $local{description} );
}
- $template->param( newChanges => defined $self->query->param('submit') );
+ my $news = (defined $q->param('submit') or
+ (defined $q->param('a') and $q->param('a') eq 'delete'));
+ $template->param( newChanges => $news );
+ $template->param( error => encode_entities ($error, "‘‘") ) if $error;
+ $template->param( canDelete => 1 ); # TODO
+ $q->delete('a');
return $template->output;
}
@@ -383,7 +394,7 @@ sub AddLocal : Runmode {
}
my $template = $self->load_tmpl( "add-$t.html", cache => 1, utf8 => 1 );
- $template->param( url => $self->query->url
+ $template->param( url => $q->url
, user_localpart => $ul
, user_domainpart => $ud
, domain => $d