From c1048e0862defc4a2d351eb1ad7dbaf857543adc Mon Sep 17 00:00:00 2001 From: Josef Moravec Date: Thu, 18 May 2017 09:09:33 +0000 Subject: [PATCH] Bug 18606: Unify handling of success/error messages --- .../en/modules/rotating_collections/addItems.tt | 52 +++++------- .../rotating_collections/editCollections.tt | 93 ++++++++-------------- rotating_collections/editCollections.pl | 28 +++---- 3 files changed, 63 insertions(+), 110 deletions(-) diff --git a/koha-tmpl/intranet-tmpl/prog/en/modules/rotating_collections/addItems.tt b/koha-tmpl/intranet-tmpl/prog/en/modules/rotating_collections/addItems.tt index 1cfc944..9f60e64 100644 --- a/koha-tmpl/intranet-tmpl/prog/en/modules/rotating_collections/addItems.tt +++ b/koha-tmpl/intranet-tmpl/prog/en/modules/rotating_collections/addItems.tt @@ -29,44 +29,28 @@ [% INCLUDE 'rotating-collections-toolbar.inc' %]

Collection [% collection.colTitle %]

- [% IF ( previousActionAdd ) %] - [% IF ( addSuccess ) %] -
Item with barcode '[% barcode %]' added successfully
- [% ELSE %] -
-

Failed to add item with barcode [% barcode %]: -

- [% IF failureMessage == "NO_ITEM" %] - No item with matching barcode found - [% ELSIF failureMessage == "IN_COLLECTION_OTHER" %] - Item is already in a different rotating collection - [% ELSIF failureMessage == "IN_COLLECTION" %] - Item is already in this collection - [% ELSE %] - [% failureMessage %] - [% END %] -

+ [% IF ( messages ) %] +
+ [% FOR message IN messages %] + [% IF message.code == 'success_adding_item' %] + Item with barcode '[% barcode %]' added successfully
+ [% ELSIF message.code == 'success_removing_item' %] + Item with barcode '[% barcode %]' removed successfully
+ [% END %] + [% END %]
- [% END %] [% END %] - [% IF ( previousActionRemove ) %] - [% IF ( removeSuccess ) %] -
Item with barcode [% barcode %] removed successfully
- [% ELSE %] -
- Failed to remove item with barcode [% barcode %]: -

- [% IF failureMessage == "NO_ITEM" %] - No item with matching barcode found - [% ELSIF failureMessage == "NOT_IN_COLLECTION" %] - Item is not in this collection - [% ELSE %] - [% failureMessage %] - [% END %] -

+ [% IF ( errors ) %] +
+ [% FOR error IN errors %] + [% IF error.code == 'error_adding_item' %] + Failed to add item with barcode '[% barcode %]'
+ [% ELSIF error.code == 'error_removing_item' %] + Failed to remove item with barcode [% barcode %]
+ [% END %] + [% END %]
- [% END %] [% END %]
diff --git a/koha-tmpl/intranet-tmpl/prog/en/modules/rotating_collections/editCollections.tt b/koha-tmpl/intranet-tmpl/prog/en/modules/rotating_collections/editCollections.tt index 9504b61..9a1a942 100644 --- a/koha-tmpl/intranet-tmpl/prog/en/modules/rotating_collections/editCollections.tt +++ b/koha-tmpl/intranet-tmpl/prog/en/modules/rotating_collections/editCollections.tt @@ -3,7 +3,7 @@ [%- IF ( action == "new" ) %] Add a new collection [% ELSE %] - Edit collection [% editColTitle %] + Edit collection [% collection.colTitle %] [% END -%] [% INCLUDE 'doc-head-close.inc' %] @@ -16,7 +16,7 @@ [%- IF ( action == "new" ) %] Add a new collection [% ELSE %] - Collection [% editColTitle %] › Edit + Collection [% collection.colTitle %] › Edit [% END -%]
@@ -25,68 +25,41 @@
- [% IF ( previousActionCreate ) %] - [% IF ( createSuccess ) %] -
-

Collection [% createdTitle %] added successfully

-

Return to rotating collections home

-
- [% ELSE %] -
-

Collection [% createdTitle %] failed to be added

-

- [% IF failureMessage == "NO_TITLE" %] - No title entered. - [% ELSIF failureMessage == "DUPLICATE_TITLE" %] - Title already in use. - [% ELSIF failureMessage == "NO_DESCRIPTION" %] - No description entered. - [% ELSE %] - [% failureMessage %] - [% END %] -

-
- [% END %] - [% END %] - - [% IF ( previousActionDelete ) %] - [% IF ( deleteSuccess ) %] -
-

Collection deleted successfully

-

Return to rotating collections home

-
- [% ELSE %] -
Collection failed to be deleted
- [% END %] + [% IF messages %] +
+ [% FOR message IN messages %] + [% IF message.code == "success_on_insert" %] +

Collection [% createdTitle %] added successfully

+ [% ELSIF message.code == "success_on_delete" %] +

Collection deleted successfully

+ [% ELSIF message.code == "success_on_update" %] +

Collection [% updatedTitle %] updated successfully

+ [% END %] + [% END %] +

Return to rotating collections home

+
[% END %] - [% IF ( previousActionUpdate ) %] - [% IF ( updateSuccess ) %] -
-

Collection [% updatedTitle %] updated successfully

-

Return to rotating collections home

-
- [% ELSE %] -
-

Collection [% updatedTitle %] failed to be updated

-

- [% IF failureMessage == "NO_ID" %] - No collection id given. - [% ELSIF failureMessage == "DUPLICATE_TITLE" %] - Title already in use. - [% ELSE %] - [% failureMessage %] - [% END %] -

+ [% IF errors %] +
+ [% FOR error IN errors %] + [% IF error.code == "error_on_insert" %] +

Collection [% createdTitle %] failed to be added

+ [% ELSIF error.code == "error_on_delete" %] +

Collection failed to be deleted

+ [% ELSIF error.code == "error_on_updated" %] +

Collection [% updatedTitle %] failed to be updated

+ [% END %] + [% END %] +

Return to rotating collections home

- [% END %] [% END %]
[% IF action == "new" || action == "edit" %] [% IF ( previousActionEdit ) %] -

Edit collection [% editColTitle %]

+

Edit collection [% collection.colTitle %]

[% ELSE %]

Add new collection

[% END %] @@ -94,7 +67,7 @@
[% IF ( previousActionEdit ) %] - + [% ELSE %] [% END %] @@ -103,8 +76,8 @@
  1. - [% IF ( editColTitle ) %] - + [% IF ( collection.colTitle ) %] + Required [% ELSE %] @@ -113,8 +86,8 @@
  2. - [% IF (editColDescription ) %] - + [% IF (collection.colDesc ) %] + [% ELSE %] [% END %] diff --git a/rotating_collections/editCollections.pl b/rotating_collections/editCollections.pl index 9290432..1427a57 100755 --- a/rotating_collections/editCollections.pl +++ b/rotating_collections/editCollections.pl @@ -29,6 +29,7 @@ use Koha::RotatingCollections; my $query = new CGI; my $action = $query->param('action'); my @messages; +my @errors; my ( $template, $loggedinuser, $cookie ) = get_template_and_user( { @@ -45,6 +46,7 @@ my ( $template, $loggedinuser, $cookie ) = get_template_and_user( if ( $action eq 'create' ) { my $title = $query->param('title'); my $description = $query->param('description'); + $template->param( createdTitle => $title ); my $collection = Koha::RotatingCollection->new( { colTitle => $title, @@ -55,34 +57,28 @@ if ( $action eq 'create' ) { eval { $collection->store; }; if ($@) { - push @messages, { type => 'error', code => 'error_on_insert' }; + push @errors, { code => 'error_on_insert' }; } else { - push @messages, { type => 'message', code => 'success_on_insert' }; + push @messages, { code => 'success_on_insert' }; } - $action = "list"; - } elsif ( $action eq 'delete' ) { # Delete collection my $colId = $query->param('colId'); my $collection = Koha::RotatingCollections->find($colId); my $deleted = eval { $collection->delete; }; if ( $@ or not $deleted ) { - push @messages, { type => 'error', code => 'error_on_delete' }; + push @errors, { code => 'error_on_delete' }; } else { - push @messages, { type => 'message', code => 'success_on_delete' }; + push @messages, { code => 'success_on_delete' }; } - $action = "list"; - } elsif ( $action eq 'edit' ) { # Edit page of collection my $collection = Koha::RotatingCollections->find($query->param('colId')); $template->param( previousActionEdit => 1, - editColId => $collection->colId, - editColTitle => $collection->colTitle, - editColDescription => $collection->colDesc, + collection => $collection, ); } elsif ( $action eq 'update' ) { # Update collection @@ -90,6 +86,8 @@ if ( $action eq 'create' ) { my $title = $query->param('title'); my $description = $query->param('description'); + $template->param( updatedTitle => $title ); + if ($colId) { my $collection = Koha::RotatingCollections->find($colId); $collection->colTitle($title); @@ -98,19 +96,17 @@ if ( $action eq 'create' ) { eval { $collection->store; }; if ($@) { - push @messages, { type => 'error', code => 'error_on_update' }; + push @errors, { code => 'error_on_update' }; } else { - push @messages, { type => 'message', code => 'success_on_update' }; + push @messages, { code => 'success_on_update' }; } - - $action = "list"; } - } $template->param( action => $action, messages => \@messages, + errors => \@errors, ); output_html_with_http_headers $query, $cookie, $template->output; -- 2.1.4