From b57f3f2c9ca384cbee10bcb400898ebf73b72ad6 Mon Sep 17 00:00:00 2001 From: Julian Maurice Date: Mon, 10 Feb 2014 11:18:36 +0100 Subject: [PATCH] Bug 11904: New module Koha::Messages This patch provides a uniform way to send messages to user interface. It uses CGI::Session to store messages and allow to render them thanks to a Template::Toolkit plugin (Koha::Template::Plugin::Messages) and a template include file (messages.inc) This patch doesn't introduce the new template include file anywhere. It will require additional patches to make it work. To use it, simply call messages_set() in a Perl script or module, then put [% INCLUDE 'messages.inc' %] at the right place in the right template file. See POD documentation of Koha::Messages for more information. --- Koha/Messages.pm | 141 +++++++++++++++++++++ Koha/Template/Plugin/Messages.pm | 12 ++ .../intranet-tmpl/prog/en/css/staff-global.css | 29 +++++ .../intranet-tmpl/prog/en/includes/messages.inc | 19 +++ .../intranet-tmpl/prog/img/messages-error.png | Bin 0 -> 709 bytes .../intranet-tmpl/prog/img/messages-error.svg | 139 ++++++++++++++++++++ koha-tmpl/intranet-tmpl/prog/img/messages-ok.png | Bin 0 -> 687 bytes koha-tmpl/intranet-tmpl/prog/img/messages-ok.svg | 127 +++++++++++++++++++ .../intranet-tmpl/prog/img/messages-warning.png | Bin 0 -> 508 bytes .../intranet-tmpl/prog/img/messages-warning.svg | 98 ++++++++++++++ .../opac-tmpl/bootstrap/en/includes/messages.inc | 19 +++ .../opac-tmpl/bootstrap/images/messages-error.png | Bin 0 -> 709 bytes .../opac-tmpl/bootstrap/images/messages-error.svg | 139 ++++++++++++++++++++ .../opac-tmpl/bootstrap/images/messages-ok.png | Bin 0 -> 687 bytes .../opac-tmpl/bootstrap/images/messages-ok.svg | 127 +++++++++++++++++++ .../bootstrap/images/messages-warning.png | Bin 0 -> 508 bytes .../bootstrap/images/messages-warning.svg | 98 ++++++++++++++ koha-tmpl/opac-tmpl/bootstrap/less/opac.less | 25 ++++ 18 files changed, 973 insertions(+) create mode 100644 Koha/Messages.pm create mode 100644 Koha/Template/Plugin/Messages.pm create mode 100644 koha-tmpl/intranet-tmpl/prog/en/includes/messages.inc create mode 100644 koha-tmpl/intranet-tmpl/prog/img/messages-error.png create mode 100644 koha-tmpl/intranet-tmpl/prog/img/messages-error.svg create mode 100644 koha-tmpl/intranet-tmpl/prog/img/messages-ok.png create mode 100644 koha-tmpl/intranet-tmpl/prog/img/messages-ok.svg create mode 100644 koha-tmpl/intranet-tmpl/prog/img/messages-warning.png create mode 100644 koha-tmpl/intranet-tmpl/prog/img/messages-warning.svg create mode 100644 koha-tmpl/opac-tmpl/bootstrap/en/includes/messages.inc create mode 100644 koha-tmpl/opac-tmpl/bootstrap/images/messages-error.png create mode 100644 koha-tmpl/opac-tmpl/bootstrap/images/messages-error.svg create mode 100644 koha-tmpl/opac-tmpl/bootstrap/images/messages-ok.png create mode 100644 koha-tmpl/opac-tmpl/bootstrap/images/messages-ok.svg create mode 100644 koha-tmpl/opac-tmpl/bootstrap/images/messages-warning.png create mode 100644 koha-tmpl/opac-tmpl/bootstrap/images/messages-warning.svg diff --git a/Koha/Messages.pm b/Koha/Messages.pm new file mode 100644 index 0000000..8288ae3 --- /dev/null +++ b/Koha/Messages.pm @@ -0,0 +1,141 @@ +package Koha::Messages; + +# Copyright 2014 BibLibre +# +# This file is part of Koha. +# +# Koha is free software; you can redistribute it and/or modify it +# under the terms of the GNU General Public License as published by +# the Free Software Foundation; either version 3 of the License, or +# (at your option) any later version. +# +# Koha is distributed in the hope that it will be useful, but +# WITHOUT ANY WARRANTY; without even the implied warranty of +# MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the +# GNU General Public License for more details. +# +# You should have received a copy of the GNU General Public License +# along with Koha; if not, see . + +use Modern::Perl; + +use CGI; +use C4::Auth qw( get_session ); + +use base qw( Exporter ); +our @EXPORT = qw( messages_set messages_get ); + +=head1 NAME + +Koha::Messages - Messages in user's session + +=head1 SYNOPSIS + + use Koha::Messages; + + messages_set("Operation succeeded"); + messages_set("Something odd happened", "warning"); + messages_set("Operation failed", "error"); + + my $messages = messages_get(); + +=head1 DESCRIPTION + +This module provides a uniform way to send messages to user interface. + +=head1 FUNCTIONS + +=cut + +sub session { + my $cgi = new CGI; + my $cgisessid = $cgi->cookie('CGISESSID') || ''; + return get_session($cgisessid); +} + +=head2 messages_set + + messages_set($message); + messages_set($message, $type); + +This function store a message into user session with a given type. + +=head3 Parameters + +=over 2 + +=item * $message: The message string to store + +=item * $type: The type of message. Can be one of 'ok', 'warning', or 'error'. +If not given, defaults to 'ok'. + +=back + +=cut + +sub messages_set { + my ($message, $type) = @_; + + return unless $message; + + $type //= 'ok'; + + my $session = session; + my $messages = $session->param('messages') // {}; + $messages->{$type} //= []; + + push @{ $messages->{$type} }, $message; + + $session->param('messages', $messages); + + # Save session + $session->flush; +} + +=head2 messages_get + + $messages = messages_get(); + +This function retrieves all messages in a hashref and remove them from user +session. + +=head3 Return value + +A hashref where keys are the type of messages and values are arrayrefs of +messages. + +Example: + + $messages = { + 'ok' => [ + "Everything is ok", + "Operation succeeded" + ], + 'warning' => [ + "Something odd happended" + ], + }; + +=cut + +sub messages_get { + my $session = session; + + my $messages = $session->param('messages') // {}; + + # Empty messages + $session->param('messages', {}); + + # Save session + $session->flush; + + return $messages; +} + +=head1 SEE ALSO + +Koha::Template::Plugin::Messages + +=cut + +1; diff --git a/Koha/Template/Plugin/Messages.pm b/Koha/Template/Plugin/Messages.pm new file mode 100644 index 0000000..6b2d437 --- /dev/null +++ b/Koha/Template/Plugin/Messages.pm @@ -0,0 +1,12 @@ +package Koha::Template::Plugin::Messages; + +use Modern::Perl; + +use base qw( Template::Plugin ); +use Koha::Messages; + +sub Get { + return messages_get(); +} + +1; diff --git a/koha-tmpl/intranet-tmpl/prog/en/css/staff-global.css b/koha-tmpl/intranet-tmpl/prog/en/css/staff-global.css index d5f9b30..061ad15 100644 --- a/koha-tmpl/intranet-tmpl/prog/en/css/staff-global.css +++ b/koha-tmpl/intranet-tmpl/prog/en/css/staff-global.css @@ -2846,3 +2846,32 @@ td p.error { td p.warn { color: orange; } + +/* Messages */ +div.messages { + background-color: white; + background-position: 5px 5px; + background-repeat: no-repeat; + border: 1px solid #b9d8d9; + border-radius: 4px; + -moz-border-radius: 4px; + -webkit-border-radius: 4px; + color: black; + margin: 10px 0; + padding: 5px 5px 5px 25px; +} + +div.messages.ok { + background-color: #f4f8f9; + background-image: url('../../img/messages-ok.png'); +} + +div.messages.warning { + background-color: #ffff99; + background-image: url('../../img/messages-warning.png'); +} + +div.messages.error { + background-color: #ff7777; + background-image: url('../../img/messages-error.png'); +} diff --git a/koha-tmpl/intranet-tmpl/prog/en/includes/messages.inc b/koha-tmpl/intranet-tmpl/prog/en/includes/messages.inc new file mode 100644 index 0000000..11ddb2a --- /dev/null +++ b/koha-tmpl/intranet-tmpl/prog/en/includes/messages.inc @@ -0,0 +1,19 @@ +[% USE Messages %] +[% contents = Messages.Get() %] + +[% FOREACH type IN contents.keys %] + [% messages = contents.$type %] + [% IF messages.size > 0 %] +
+ [% IF messages.size > 1 %] +
    + [% FOREACH message IN contents.$type %] +
  • [% message %]
  • + [% END %] +
+ [% ELSE %] + [% messages.0 %] + [% END %] +
+ [% END %] +[% END %] diff --git a/koha-tmpl/intranet-tmpl/prog/img/messages-error.png b/koha-tmpl/intranet-tmpl/prog/img/messages-error.png new file mode 100644 index 0000000000000000000000000000000000000000..bf720311f85023a46a9ef06be2164145d9c41b5e GIT binary patch literal 709 zcmV;$0y_PPP)smVMz366tP z?d_JL$o%2Mz5}mAN`-DnegeNVH(SnTRb3h$cCxY2EI5%!xSY$WI`{OcnGk#ho`od$ zp{MGSZ)+Rbe0tdk7;58Vi2@o#<)t=2{$elWc;Oa6r6f9-a2?&O&k!d{I~DY&xy#!o-BbiG&Zqp?&*YEEH7z*w^PR@CJAslBisQ z)HCqIxpOW~O*yn@j}O3m;9ao4qr>^hNnaj4>P_(c%AJGC!4P7H;CUnLT;JTxTrNii z_ytr}-gtde6HC+6Ov8squ)kLep&E>XA;k8=#a(bj;NQ6X5gCP>ui#9t764Ys)jAPE rvIRQpp{*9;Wr&I}G6DTp{!7(w`SXe9Ec??X00000NkvXXu0mjf_OUlU literal 0 HcmV?d00001 diff --git a/koha-tmpl/intranet-tmpl/prog/img/messages-error.svg b/koha-tmpl/intranet-tmpl/prog/img/messages-error.svg new file mode 100644 index 0000000..9a60c1b --- /dev/null +++ b/koha-tmpl/intranet-tmpl/prog/img/messages-error.svg @@ -0,0 +1,139 @@ + + + + + + + + + + + + + + + + + + + + + + + image/svg+xml + + + + + + + + + + + + diff --git a/koha-tmpl/intranet-tmpl/prog/img/messages-ok.png b/koha-tmpl/intranet-tmpl/prog/img/messages-ok.png new file mode 100644 index 0000000000000000000000000000000000000000..712b12ba58bacccda9c2eea98b269704c9caa01d GIT binary patch literal 687 zcmV;g0#N;lP) zXcrL*!7dIj3p;pH2tk$?i9kBq$_|lO10!^HQjuDsF+a$16_;GG&j3mr00*5 zy1q^O(RSLLZ3q!rjVP5&!Et=>glN%Zk)8NGp;RWNrg)QO6w4bdud%^+&}M8#lGG9J z5HGMi$I?R-`dMZK+qKjsNlIptYKS#hUSb2&0h_jINm6&bTRg+^6iXP(eU=^6afJdZ zhQAL}oL6jWifgDVtuyXJZh}=olWTJ6o$Dnq9uS+b%?j@woaZb@IKw7H5)sPt%T0A@ zHQpkxaTo`EbA2?wZQc=X0BOWmh8&!vkP}=bogEG>4N*~0VZ0??X4Yn?AFQ`~E^Y$r zzz0HEliW37s<=)jYY2xNw0K%f&s2|W#_l)GJOg^D8(Hy18=wFH literal 0 HcmV?d00001 diff --git a/koha-tmpl/intranet-tmpl/prog/img/messages-ok.svg b/koha-tmpl/intranet-tmpl/prog/img/messages-ok.svg new file mode 100644 index 0000000..53d9c1f --- /dev/null +++ b/koha-tmpl/intranet-tmpl/prog/img/messages-ok.svg @@ -0,0 +1,127 @@ + + + + + + + + + + + + + + + + + + + image/svg+xml + + + + + + + + + + + + diff --git a/koha-tmpl/intranet-tmpl/prog/img/messages-warning.png b/koha-tmpl/intranet-tmpl/prog/img/messages-warning.png new file mode 100644 index 0000000000000000000000000000000000000000..3ca2d3372627dbfb4b3d7bfaac3163ece2a875f1 GIT binary patch literal 508 zcmVBvAqq!NWo!AjI-YF#$n|_7iO89%dM&1)w4)<7RZ-7F_x4x~^0XXeGW6WsaCdu) z)@o?EOf{LL>tFEnlzmlnXb80|)EM;ekljDQnHdJ|?|E`vbZ`*u??<1X(aTF7ZJWMk zZ>YK6>1no;NqQXz{7`Tluq>?ESvH%!4RCQ$Mr@mTW55`QMj;aM_r`#2vyjhAss)^w zU?&zM_GKI%hE(bs?CvI!$*|q{GF7Eekg;Nsi%5hH*M%T`e8B4~&hatXQc15u0HdR9 zg~N1wr5gje9E^{{`@0VT#N$M>S+)RVZH=jw70yMF<`=H7{pO_8KL@5>$2&P;vaPd| y + + + + + + + + + + + + + + + image/svg+xml + + + + + + + + ! + diff --git a/koha-tmpl/opac-tmpl/bootstrap/en/includes/messages.inc b/koha-tmpl/opac-tmpl/bootstrap/en/includes/messages.inc new file mode 100644 index 0000000..11ddb2a --- /dev/null +++ b/koha-tmpl/opac-tmpl/bootstrap/en/includes/messages.inc @@ -0,0 +1,19 @@ +[% USE Messages %] +[% contents = Messages.Get() %] + +[% FOREACH type IN contents.keys %] + [% messages = contents.$type %] + [% IF messages.size > 0 %] +
+ [% IF messages.size > 1 %] +
    + [% FOREACH message IN contents.$type %] +
  • [% message %]
  • + [% END %] +
+ [% ELSE %] + [% messages.0 %] + [% END %] +
+ [% END %] +[% END %] diff --git a/koha-tmpl/opac-tmpl/bootstrap/images/messages-error.png b/koha-tmpl/opac-tmpl/bootstrap/images/messages-error.png new file mode 100644 index 0000000000000000000000000000000000000000..bf720311f85023a46a9ef06be2164145d9c41b5e GIT binary patch literal 709 zcmV;$0y_PPP)smVMz366tP z?d_JL$o%2Mz5}mAN`-DnegeNVH(SnTRb3h$cCxY2EI5%!xSY$WI`{OcnGk#ho`od$ zp{MGSZ)+Rbe0tdk7;58Vi2@o#<)t=2{$elWc;Oa6r6f9-a2?&O&k!d{I~DY&xy#!o-BbiG&Zqp?&*YEEH7z*w^PR@CJAslBisQ z)HCqIxpOW~O*yn@j}O3m;9ao4qr>^hNnaj4>P_(c%AJGC!4P7H;CUnLT;JTxTrNii z_ytr}-gtde6HC+6Ov8squ)kLep&E>XA;k8=#a(bj;NQ6X5gCP>ui#9t764Ys)jAPE rvIRQpp{*9;Wr&I}G6DTp{!7(w`SXe9Ec??X00000NkvXXu0mjf_OUlU literal 0 HcmV?d00001 diff --git a/koha-tmpl/opac-tmpl/bootstrap/images/messages-error.svg b/koha-tmpl/opac-tmpl/bootstrap/images/messages-error.svg new file mode 100644 index 0000000..9a60c1b --- /dev/null +++ b/koha-tmpl/opac-tmpl/bootstrap/images/messages-error.svg @@ -0,0 +1,139 @@ + + + + + + + + + + + + + + + + + + + + + + + image/svg+xml + + + + + + + + + + + + diff --git a/koha-tmpl/opac-tmpl/bootstrap/images/messages-ok.png b/koha-tmpl/opac-tmpl/bootstrap/images/messages-ok.png new file mode 100644 index 0000000000000000000000000000000000000000..712b12ba58bacccda9c2eea98b269704c9caa01d GIT binary patch literal 687 zcmV;g0#N;lP) zXcrL*!7dIj3p;pH2tk$?i9kBq$_|lO10!^HQjuDsF+a$16_;GG&j3mr00*5 zy1q^O(RSLLZ3q!rjVP5&!Et=>glN%Zk)8NGp;RWNrg)QO6w4bdud%^+&}M8#lGG9J z5HGMi$I?R-`dMZK+qKjsNlIptYKS#hUSb2&0h_jINm6&bTRg+^6iXP(eU=^6afJdZ zhQAL}oL6jWifgDVtuyXJZh}=olWTJ6o$Dnq9uS+b%?j@woaZb@IKw7H5)sPt%T0A@ zHQpkxaTo`EbA2?wZQc=X0BOWmh8&!vkP}=bogEG>4N*~0VZ0??X4Yn?AFQ`~E^Y$r zzz0HEliW37s<=)jYY2xNw0K%f&s2|W#_l)GJOg^D8(Hy18=wFH literal 0 HcmV?d00001 diff --git a/koha-tmpl/opac-tmpl/bootstrap/images/messages-ok.svg b/koha-tmpl/opac-tmpl/bootstrap/images/messages-ok.svg new file mode 100644 index 0000000..53d9c1f --- /dev/null +++ b/koha-tmpl/opac-tmpl/bootstrap/images/messages-ok.svg @@ -0,0 +1,127 @@ + + + + + + + + + + + + + + + + + + + image/svg+xml + + + + + + + + + + + + diff --git a/koha-tmpl/opac-tmpl/bootstrap/images/messages-warning.png b/koha-tmpl/opac-tmpl/bootstrap/images/messages-warning.png new file mode 100644 index 0000000000000000000000000000000000000000..3ca2d3372627dbfb4b3d7bfaac3163ece2a875f1 GIT binary patch literal 508 zcmVBvAqq!NWo!AjI-YF#$n|_7iO89%dM&1)w4)<7RZ-7F_x4x~^0XXeGW6WsaCdu) z)@o?EOf{LL>tFEnlzmlnXb80|)EM;ekljDQnHdJ|?|E`vbZ`*u??<1X(aTF7ZJWMk zZ>YK6>1no;NqQXz{7`Tluq>?ESvH%!4RCQ$Mr@mTW55`QMj;aM_r`#2vyjhAss)^w zU?&zM_GKI%hE(bs?CvI!$*|q{GF7Eekg;Nsi%5hH*M%T`e8B4~&hatXQc15u0HdR9 zg~N1wr5gje9E^{{`@0VT#N$M>S+)RVZH=jw70yMF<`=H7{pO_8KL@5>$2&P;vaPd| y + + + + + + + + + + + + + + + image/svg+xml + + + + + + + + ! + diff --git a/koha-tmpl/opac-tmpl/bootstrap/less/opac.less b/koha-tmpl/opac-tmpl/bootstrap/less/opac.less index 447e255..e9702ea 100644 --- a/koha-tmpl/opac-tmpl/bootstrap/less/opac.less +++ b/koha-tmpl/opac-tmpl/bootstrap/less/opac.less @@ -2508,4 +2508,29 @@ a.reviewlink:visited { cursor: pointer; } +/* Messages */ +div.messages { + background-color: white; + background-position: 5px 5px; + background-repeat: no-repeat; + border: 1px solid #b9d8d9; + .border-radius-all(4px); + color: black; + margin: 10px 20px; + padding: 5px 5px 5px 25px; + + &.ok { + background-color: #f4f8f9; + background-image: url('../images/messages-ok.png'); + } + &.warning { + background-color: #ffff99; + background-image: url('../images/messages-warning.png'); + } + &.error { + background-color: #ff7777; + background-image: url('../images/messages-error.png'); + } +} + @import "responsive.less"; -- 1.9.1