flash a notice on article deletion
authorTony Cook <tony@develop-help.com>
Tue, 16 Apr 2013 23:47:41 +0000 (09:47 +1000)
committerTony Cook <tony@develop-help.com>
Tue, 16 Apr 2013 23:47:41 +0000 (09:47 +1000)
(instead of posting it as a "message" parameter)

The message is *always* flashed, even with a caller supplied URL

site/cgi-bin/modules/BSE/Edit/Article.pm
site/cgi-bin/modules/BSE/Message.pm
site/data/db/bse_msg_base.data
site/data/db/bse_msg_defaults.data
site/templates/admin/edit_0.tmpl
t/070-user/010-edit.t
t/070-user/020-images.t
t/BSE/Test.pm

index a64d2b185d3a2fc6aa74840dbd5396c8ba41e38b..7538e5d8805ca0bd7a2d89d1ed750b243e98bc29 100644 (file)
@@ -16,7 +16,7 @@ use List::Util qw(first);
 use constant MAX_FILE_DISPLAYNAME_LENGTH => 255;
 use constant ARTICLE_CUSTOM_FIELDS_CFG => "article custom fields";
 
-our $VERSION = "1.034";
+our $VERSION = "1.035";
 
 =head1 NAME
 
@@ -1231,8 +1231,8 @@ sub low_edit_tags {
   my $cgi = $request->cgi;
   my $show_full = $cgi->param('f_showfull');
   my $if_error = $msg || ($errors && keys %$errors) || $request->cgi->param("_e");
-  $msg ||= join "\n", map escape_html($_), $cgi->param('message'), $cgi->param('m');
-  $msg ||= $request->message($errors);
+  #$msg ||= join "\n", map escape_html($_), $cgi->param('message'), $cgi->param('m');
+  $msg .= $request->message($errors);
   my $parent;
   if ($article->{id}) {
     if ($article->{parentid} > 0) {
@@ -4903,7 +4903,7 @@ sub remove {
     return $self->_service_error($req, $article, $articles, $why_not, {}, $code);
   }
 
-  my $id = $article->id;
+  my $data = $article->data_only;
 
   my $parentid = $article->{parentid};
   $article->remove($req->cfg);
@@ -4912,16 +4912,17 @@ sub remove {
     return $req->json_content
       (
        success => 1,
-       article_id => $id,
+       article_id => $data->{id},
       );
   }
 
   my $url = $req->cgi->param('r');
   unless ($url) {
-    my $urlbase = admin_base_url($req->cfg);
-    $url = "$urlbase$ENV{SCRIPT_NAME}?id=$parentid";
-    $url .= "&message=Article+deleted";
+    $url = $req->cfg->admin_url("add", { id => $parentid });
   }
+
+  $req->flash_notice("msg:bse/admin/edit/remove", [ $data ]);
+
   return BSE::Template->get_refresh($url, $self->{cfg});
 }
 
index 4022b354080395795504b0a326f10dce51bf3e2a..c960a41976e3e6abc765208f2787ee8fec519d17 100644 (file)
@@ -5,11 +5,12 @@ use BSE::DB;
 use BSE::Cfg;
 use BSE::Cache;
 use DevHelp::HTML;
+use Scalar::Util qw(reftype blessed);
 use overload 
   "&{}" => sub { my $self = $_[0]; return sub { $self->_old_msg(@_) } },
   "bool" => sub { 1 };
 
-our $VERSION = "1.005";
+our $VERSION = "1.006";
 
 my $single;
 
@@ -158,9 +159,19 @@ sub _value {
   my $value = $parms->[$index-1];
   if (ref $value) {
     local $@;
-    my $good = eval { $value = $value->$method; 1; };
-    unless ($good) {
-      return "(Bad parameter $index - ref but no $method)";
+    if (blessed $value) {
+      my $good = eval { $value = $value->$method; 1; };
+      unless ($good) {
+       return "(Bad parameter $index - blessed but no $method)";
+      }
+    }
+    elsif (reftype $value eq "HASH") {
+      defined $value->{$method}
+       or return "(Unknown key $method for $index)";
+      $value = $value->{$method};
+    }
+    else {
+      return "(Can't handle ".reftype($value)." values)";
     }
   }
 
index e620dea34621ff2a25bf7ec79871720a84ddc5d2..d5d807b63383f954ac482ba366cc465be993b153 100644 (file)
@@ -1,5 +1,5 @@
 --
-# VERSION=1.005
+# VERSION=1.006
 id: bse/
 description: BSE messages
 
@@ -128,6 +128,9 @@ description: If the image couldn't be deleted from an external store ($1 - the b
 id: bse/admin/edit/uplabelsect
 description: label in parent list to make article a section
 
+id: bse/admin/edit/remove
+description: Flashed when an article is removed (%1 - the original article data)
+
 id: bse/admin/edit/tags/
 description: System tags management
 
index e0ca7853b4036ecf1d2f2788610efb76111d480f..e0e51a70d6210d333d79cfc1d02dd4c2bda15ae2 100644 (file)
@@ -1,5 +1,5 @@
 ---
-# VERSION=1.005
+# VERSION=1.006
 # defaults for the following
 language_code: en
 priority: 0
@@ -82,6 +82,9 @@ message: Could not delete file from external store: %1:s
 id: bse/admin/edit/uplabelsect
 message: -- move up a level -- become a section
 
+id: bse/admin/edit/remove
+message: Article '%1:{title}s' (%1:{id}d) deleted.
+
 id: bse/admin/edit/tags/saved
 message: Tag renamed from '%1:s' to '%2:s'
 
index 64c6d5bb0de0ed002db0dc55e9ad00a64863c4e5..7425f79ce445a6e222c7aef5f5b1227df21fba6f 100644 (file)
@@ -1,8 +1,6 @@
 <:wrap admin/base.tmpl title=>"Manage Sections":>
 <h1>Manage Sections</h1>
-<:ifMessage:> 
-<p><b><:message:></b></p>
-<:or:><:eif:>
+<:.call "messages" -:>
 <:include admin/include/site_menu.tmpl:>
 <:if Or [iadminuser_count] [iadmingroup_count]:>
       <form action="/cgi-bin/admin/adminusers.pl">
index 0853b2d567135c79efa7bdcfad2b3ed7413f2aca..dd5fed9cc0038215bec0b87d0f177e771f809155 100644 (file)
@@ -1,12 +1,12 @@
 #!perl -w
 use strict;
 use Test::More tests => 22;
-use BSE::Test qw(base_url make_ua check_form post_ok
+use BSE::Test qw(base_securl make_ua check_form post_ok
                  check_content follow_ok);
 use URI::QueryParam;
 #use WWW::Mechanize;
 ++$|;
-my $baseurl = base_url;
+my $baseurl = base_securl;
 my $ua = make_ua;
 
 ok($ua->get("$baseurl/cgi-bin/admin/add.pl?parentid=-1"), "edit page");
@@ -43,4 +43,4 @@ follow_ok($ua, "clean up",
          {
           text => "Delete",
           url_regex => qr/id=$id/
-         }, qr/Article deleted/);
+         }, qr/Article 'Test Article' \($id\) deleted/);
index 9c11be1017ac4489fc6b1282218450b3b0228319..f907f1f16a9ce302d6161c906dc3eac039f1e83c 100644 (file)
@@ -1,9 +1,9 @@
 #!perl -w
 use strict;
-use BSE::Test qw(make_ua base_url fetch_ok follow_ok click_ok follow_refresh_ok);
+use BSE::Test qw(make_ua base_securl fetch_ok follow_ok click_ok follow_refresh_ok);
 use Test::More tests => 114;
 
-my $base_url = base_url;
+my $base_url = base_securl;
 my $ua = make_ua;
 
 my $title = "t40images.t ".time;
@@ -225,7 +225,7 @@ follow_ok($ua, "delete article",
           text => "Delete",
           url_regex => qr/id=$article_id/
          },
-         qr/Article deleted/);
+         qr/Article '\Q$title\E' \([0-9]+\) deleted/);
 
 sub image1 {
   # based on testout/t105pal.gif from Imager
index ecaefe0f9d550c8d3d8b4da7f3a5bbdc5cedaa68..f05270ae0670d43c26e13a62712cb5f2f73b7665 100644 (file)
@@ -3,7 +3,7 @@ use strict;
 use vars qw(@ISA @EXPORT @EXPORT_OK);
 use Exporter 'import';
 @EXPORT = qw(base_url fetch_ok make_url skip make_ua);
-@EXPORT_OK = qw(base_url make_ua fetch_url fetch_ok make_url skip 
+@EXPORT_OK = qw(base_url base_securl make_ua fetch_url fetch_ok make_url skip 
                 make_post check_form post_ok check_content follow_ok
                 follow_refresh_ok click_ok config test_actions);
 use lib 'site/cgi-bin/modules';