From d8d2eb6d1bd5886a83f93f6bd7af59f92c6c35a3 Mon Sep 17 00:00:00 2001 From: Jonathan Druart Date: Thu, 29 Aug 2013 13:32:30 +0200 Subject: [PATCH] Bug 10855: interface configuration for adding new fields to subscriptions This patch adds an interface configuration for adding fields to subscriptions. Test plan: - go to serials/serials-home.pl - click on the "Add subscription fields" link on the left of the screen - try to add/update/delete new fields You are not abble to add a field with an authorised value category and a marcfield. Columns are sortable - for the rest, you should have, at least: * a new field named af1, sortable, linked to a category * a new field named af2, sortable, linked to a marcfield * a new field named af3, not sortable --- .../prog/en/modules/serials/add_fields.tt | 178 ++++++++++++++++++++ serials/add_fields.pl | 126 ++++++++++++++ 2 files changed, 304 insertions(+) create mode 100644 koha-tmpl/intranet-tmpl/prog/en/modules/serials/add_fields.tt create mode 100755 serials/add_fields.pl diff --git a/koha-tmpl/intranet-tmpl/prog/en/modules/serials/add_fields.tt b/koha-tmpl/intranet-tmpl/prog/en/modules/serials/add_fields.tt new file mode 100644 index 0000000..6e1a290 --- /dev/null +++ b/koha-tmpl/intranet-tmpl/prog/en/modules/serials/add_fields.tt @@ -0,0 +1,178 @@ +[% INCLUDE 'doc-head-open.inc' %] +Koha › Serials › Manage new fields for subscriptions + [% IF op == "list" %] › List of fields + [% ELSIF op == "add_form" %] + [% IF field %] › Modify field + [% ELSE %] › Add field + [% END %] + [% END %] + +[% INCLUDE 'doc-head-close.inc' %] + + +[% INCLUDE 'datatables-strings.inc' %] + + + + + + [% INCLUDE 'header.inc' %] + [% INCLUDE 'serials-search.inc' %] + + + +
+
+
+
+ [% IF op == 'list' %] + + [% END %] + + [% IF messages %] + [% FOR message IN messages %] + [% IF message.code == 'insert' %] + [% IF message.number > 0 %] +
The field has been inserted
+ [% ELSE %] +
The field has not been inserted (name still exist?)
+ [% END %] + [% ELSIF message.code == 'update' %] + [% IF message.number > 0 %] +
The field has been updated
+ [% ELSE %] +
The field has not been updated (name still exist?)
+ [% END %] + [% ELSIF message.code == 'delete' %] + [% IF message.number > 0 %] +
The field has been deleted
+ [% ELSE %] +
The field has not been deleted
+ [% END %] + [% END %] + [% END %] + [% END %] + + [% IF op == 'list' %] +

Additional fields for subscriptions

+ [% IF fields %] + + + + + + + + + + + + [% FOR field IN fields %] + + + + + + + + [% END %] + +
NameAuthorised value categoryMarc fieldSearchableActions
[% field.name %][% field.authorised_value_category %][% field.marcfield %] + [% IF field.searchable %]Yes[% ELSE %]No[% END %] + + Edit + Delete +
+ [% ELSE %] + There is no field defined. + [% END %] + [% ELSIF op == 'add_form' %] + [% IF field %] +

Modify field

+ [% ELSE %] +

Add field

+ [% END %] +
+
+
    +
  1. + + +
  2. +
  3. + + +
  4. +
  5. + + +
  6. +
  7. + + [% IF field.searchable %] + + [% ELSE %] + + [% END %] +
  8. +
+
+
+ [% IF field %] + + [% END %] + + + Cancel +
+
+ [% END %] + +
+
+ +
+[% INCLUDE 'serials-menu.inc' %] +
+
+[% INCLUDE 'intranet-bottom.inc' %] diff --git a/serials/add_fields.pl b/serials/add_fields.pl new file mode 100755 index 0000000..9451a1b --- /dev/null +++ b/serials/add_fields.pl @@ -0,0 +1,126 @@ +#!/usr/bin/perl + +# This file is part of Koha. +# +# Copyright 2013 BibLibre +# +# 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; +use C4::Koha; +use C4::Output; +use Koha::AdditionalField; + +my $input = new CGI; + +my ( $template, $loggedinuser, $cookie ) = get_template_and_user( + { + template_name => "serials/add_fields.tt", + query => $input, + type => "intranet", + authnotrequired => 0, + flagsrequired => { serials => '*' }, + debug => 1, + } +); + +my $op = $input->param('op') // 'list'; +my $field_id = $input->param('field_id'); +my @messages; + +if ( $op eq 'add' ) { + my $name = $input->param('name') // q{}; + my $authorised_value_category = $input->param('authorised_value_category') // q{}; + my $marcfield = $input->param('marcfield') // q{}; + my $searchable = $input->param('searchable') ? 1 : 0; + if ( $field_id and $name ) { + my $updated = 0; + eval { + my $af = Koha::AdditionalField->new({ + id => $field_id, + name => $name, + authorised_value_category => $authorised_value_category, + marcfield => $marcfield, + searchable => $searchable, + }); + $updated = $af->update; + }; + push @messages, { + code => 'update', + number => $updated, + }; + } elsif ( $name ) { + my $inserted = 0; + eval { + my $af = Koha::AdditionalField->new({ + tablename => 'subscription', + name => $name, + authorised_value_category => $authorised_value_category, + marcfield => $marcfield, + searchable => $searchable, + }); + $inserted = $af->insert; + }; + push @messages, { + code => 'insert', + number => $inserted, + }; + } else { + push @messages, { + code => 'insert', + number => 0, + }; + } + $op = 'list'; +} + +if ( $op eq 'delete' ) { + my $deleted = 0; + eval { + my $af = Koha::AdditionalField->new( { id => $field_id } ); + $deleted = $af->delete; + $deleted = 0 if $deleted eq '0E0'; + }; + push @messages, { + code => 'delete', + number => $deleted, + }; + $op = 'list'; +} + +if ( $op eq 'add_form' ) { + my $categories = C4::Koha::GetAuthorisedValueCategories(); + my $field; + if ( $field_id ) { + $field = Koha::AdditionalField->new( { id => $field_id } )->fetch; + } + + $template->param( + field => $field, + categories => $categories, + ); +} + +if ( $op eq 'list' ) { + my $fields = Koha::AdditionalField->all( { tablename => 'subscription' } ); + $template->param( fields => $fields ); +} + +$template->param( + op => $op, + messages => \@messages, +); + +output_html_with_http_headers $input, $cookie, $template->output; -- 1.7.10.4