Bug 25079: Add a 'edit' functionality to the Clubs tool in the staff interface

A club enrollment can be cancel but it can't be edited
This patch add a 'edit' functionality to the Clubs tool in the staff interface

Test plan
1. Create a club template
    1.1. Go to Tools > Patron clubs
    1.2. Click on 'New Club Template'
    1.3. Fill the form
    1.4. on the 'Club fields' section, Click on Add new field
    1.5. Fill in the form
    1.6. on the 'Enrollment fields' section, Click on Add new field
    1.7. Fill in the form
    1.8. Click on Save button

2. Creation of the club
    2.1. Go to Tools > Patron clubs > 'Clubs' section (bottom)
    2.2. Click on the 'New Club' button and select the club template create on step 1
    2.3. Fill in the form
    2.4. Click on Save button

3. Club enrollement
    On the intranet
    3.1. Search for a pratron and open the patron folder
    3.2. Click on the 'Clubs' tab
    3.3. Find the name of the club and click on 'Enroll'
    3.4. Fill the questionnaire
    3.5. Confirm registration
        ---> Note that the enrollement can be canceled but it cannot be modified

4.  Apply the patch
5. Click one more time on the 'Clubs' tab
   ---> Note that the enrollement can now be modified

Signed-off-by: Sam Lau <samalau@gmail.com>
Signed-off-by: Kyle M Hall <kyle@bywatersolutions.com>
Signed-off-by: Tomas Cohen Arazi <tomascohen@theke.io>
This commit is contained in:
Hammat Wele 2023-04-12 00:32:02 +00:00 committed by Tomas Cohen Arazi
parent 45852c950e
commit ee24e53a66
No known key found for this signature in database
GPG Key ID: 0A272EA1B2F3C15F
5 changed files with 66 additions and 10 deletions

View File

@ -24,6 +24,7 @@ use CGI;
use C4::Auth qw( get_template_and_user );
use C4::Output qw( output_html_with_http_headers );
use Koha::Clubs;
use Koha::Club::Enrollment::Fields;
my $cgi = CGI->new;
@ -38,12 +39,16 @@ my ( $template, $loggedinuser, $cookie ) = get_template_and_user(
my $id = $cgi->param('id');
my $borrowernumber = $cgi->param('borrowernumber');
my $enrollent_id = scalar $cgi->param('enrollent_id');
my $club = Koha::Clubs->find($id);
my @club_enrollment_fields = Koha::Club::Enrollment::Fields->search({'club_enrollment_id'=> $enrollent_id})->as_list;
$template->param(
club => $club,
borrowernumber => $borrowernumber,
club => $club,
borrowernumber => $borrowernumber,
enrollent_id => $enrollent_id || 0,
club_enrollment_fields => \@club_enrollment_fields,
);
output_html_with_http_headers( $cgi, $cookie, $template->output );

View File

@ -21,6 +21,9 @@
<td>[% e.date_enrolled | $KohaDates %]</td>
[% IF CAN_user_clubs_enroll %]
<td>
<button class="btn btn-xs btn-default" onclick="loadEnrollmentForm([% e.club.id %],[% e.id %])">
<i class="fa fa-edit"></i>Modify enrollment
</button>
<button class="btn btn-xs btn-default" onclick="cancelEnrollment( [% e.id | html %] )">
<i class="fa fa-times"></i> Cancel enrollment
</button>
@ -72,9 +75,9 @@ $("#table_clubnoenrollmemnts, #table_clubenrollments").dataTable($.extend(true,
}));
[% IF CAN_user_clubs_enroll %]
function loadEnrollmentForm( id ) {
function loadEnrollmentForm( id, enrollent_id = 0 ) {
$("body").css("cursor", "progress");
$('#clubs_panel').load('/cgi-bin/koha/clubs/patron-enroll.pl?borrowernumber=[% borrowernumber | html %]&id=' + id, function() {
$('#clubs_panel').load('/cgi-bin/koha/clubs/patron-enroll.pl?borrowernumber=[% borrowernumber | html %]&id=' + id +'&enrollent_id='+ enrollent_id, function() {
$("body").css("cursor", "default");
});

View File

@ -1,6 +1,6 @@
[% USE AuthorisedValues %]
<h1>
<h1 id="heading">
Enroll in <em>[% club.name | html %]</em>
</h1>
@ -8,8 +8,30 @@
<form id="patron-enrollment-form">
<input type="hidden" name="id" value="[% club.id | html %]" />
<input type="hidden" name="borrowernumber" value="[% borrowernumber | html %]" />
<input type="hidden" name="enrollent_id" value="[% enrollent_id | html %]" />
<fieldset class="rows">
<ol>
[% IF club_enrollment_fields %]
[% FOREACH f IN club.club_template.club_template_enrollment_fields %]
[% FOREACH c IN club_enrollment_fields %]
[% IF f.id == c.club_template_enrollment_field_id %]
<li>
<label>[% f.name %]</label>
[% IF f.authorised_value_category %]
<select name="[% f.id %]">
[% FOREACH a IN AuthorisedValues.Get( f.authorised_value_category ) %]
<option value="[% a.authorised_value %]" [% IF a.authorised_value == c.value %]selected="selected"[% END %]>[% a.lib %]</option>
[% END %]
</select>
[% ELSE %]
<input type="text" name="[% f.id %]" value="[% c.value %]"/>
[% END %]
<span class="hint">[% f.description %]</span>
</li>
[% END %]
[% END %]
[% END %]
[% ELSE %]
[% FOREACH f IN club.club_template.club_template_enrollment_fields %]
<li>
<label>[% f.name | html %]</label>
@ -25,7 +47,7 @@
<span class="hint">[% f.description | html %]</span>
</li>
[% END %]
[% END %]
<li>
<a href="#" class="btn btn-sm btn-default" onclick="addEnrollment(); return false;">Finish enrollment</a>
<a class="cancel" href="#" onclick="showClubs(); return false;">Cancel</a>
@ -36,6 +58,9 @@
</div>
<script>
if([% enrollent_id %]){
$("#heading").html(_("Modifying enrollment")+" <em>[% club.name %]</em>");
}
function addEnrollment() {
$("body").css("cursor", "progress");
$.ajax({

View File

@ -64,7 +64,7 @@ if ( $borrowernumber && $id ) {
{
club_enrollment_id => $enrollment->id(),
club_template_enrollment_field_id => $e->id(),
value => $cgi->param( $e->id() ),
value => scalar $cgi->param( $e->id() ),
}
)->store();
}

View File

@ -38,11 +38,29 @@ if ( $auth_status ne "ok" ) {
my $id = $cgi->param('id');
my $borrowernumber = $cgi->param('borrowernumber');
my $enrollent_id = scalar $cgi->param('enrollent_id');
my $club = Koha::Clubs->find($id);
my $enrollment;
if ($club) {
my @club_enrollment_fields;
if($enrollent_id){
my @enrollment_fields = $club->club_template()->club_template_enrollment_fields()->as_list;
@club_enrollment_fields = Koha::Club::Enrollment::Fields->search({'club_enrollment_id'=> $enrollent_id})->as_list;
foreach my $club_enrollment_field (@club_enrollment_fields){
foreach my $e (@enrollment_fields){
if($e->id()==$club_enrollment_field->club_template_enrollment_field_id){
my $value = $cgi->param( $e->id() );
$club_enrollment_field->value($value);
$club_enrollment_field->update();
}
}
}
}
elsif ($club) {
$enrollment = Koha::Club::Enrollment->new(
{
club_id => $club->id(),
@ -61,7 +79,7 @@ if ($club) {
{
club_enrollment_id => $enrollment->id(),
club_template_enrollment_field_id => $e->id(),
value => $cgi->param( $e->id() ),
value => scalar $cgi->param( $e->id() ),
}
)->store();
}
@ -71,4 +89,9 @@ if ($club) {
binmode STDOUT, ':encoding(UTF-8)';
print $cgi->header( -type => 'text/plain', -charset => 'UTF-8' );
print to_json( { success => $enrollment ? 1 : 0 } );
if($enrollent_id){
print to_json( { success => @club_enrollment_fields ? 1 : 0 } );
}
else{
print to_json( { success => $enrollment ? 1 : 0 } );
}