From 99737d565b938fe26db60960daaddb25826bbcd4 Mon Sep 17 00:00:00 2001 From: Bernardo Gonzalez Kriegel Date: Fri, 18 Dec 2015 11:40:02 -0300 Subject: [PATCH] Bug 8643: Add important constraint to marc subfields MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit This fix permits to add an "Important" option to the marc structure pages. Testing: 1) Apply the patch 2) Run updatedatabase.pl 3) Regenerate CSS 4) Define 100 as an "important" field ( Administration » MARC bibliographic framework » MARC structure ( Default Frameword) » Edit ) 5) Define 100$a as an "important" subfield (Administration » MARC bibliographic framework » MARC structure (Default Frameword) » Subfield » Onglet a) 6) Edit a record to clear the field 100 (subfields are all blank) 7) Save the record. 8) Validate the following message: A few important fields are not filled: * tag 100 subfield a Nom de personne in tab * Field 100 is important, at least one of its subfields should be filled. Are you sure you want to save? Sponsored by the CCSR ( http://www.ccsr.qc.ca ) --- C4/Biblio.pm | 12 +- admin/marc_subfields_structure.pl | 12 +- admin/marctagstructure.pl | 16 ++- cataloguing/addbiblio.pl | 9 +- cataloguing/additem.pl | 1 + .../bug-8643-add_important_constraint.perl | 11 ++ installer/data/mysql/kohastructure.sql | 2 + koha-tmpl/intranet-tmpl/prog/css/addbiblio.css | 4 + .../intranet-tmpl/prog/css/src/staff-global.scss | 4 + .../en/modules/admin/marc_subfields_structure.tt | 9 ++ .../prog/en/modules/admin/marctagstructure.tt | 10 ++ .../prog/en/modules/cataloguing/addbiblio.tt | 129 ++++++++++++++++++++- .../prog/en/modules/cataloguing/additem.tt | 34 ++++-- koha-tmpl/intranet-tmpl/prog/js/cataloging.js | 12 ++ 14 files changed, 241 insertions(+), 24 deletions(-) create mode 100644 installer/data/mysql/atomicupdate/bug-8643-add_important_constraint.perl diff --git a/C4/Biblio.pm b/C4/Biblio.pm index c12b108..de4af99 100644 --- a/C4/Biblio.pm +++ b/C4/Biblio.pm @@ -893,25 +893,26 @@ sub GetMarcStructure { my $dbh = C4::Context->dbh; my $sth = $dbh->prepare( - "SELECT tagfield,liblibrarian,libopac,mandatory,repeatable,ind1_defaultvalue,ind2_defaultvalue + "SELECT tagfield,liblibrarian,libopac,mandatory,repeatable,important,ind1_defaultvalue,ind2_defaultvalue FROM marc_tag_structure WHERE frameworkcode=? ORDER BY tagfield" ); $sth->execute($frameworkcode); - my ( $liblibrarian, $libopac, $tag, $res, $tab, $mandatory, $repeatable, $ind1_defaultvalue, $ind2_defaultvalue ); + my ( $liblibrarian, $libopac, $tag, $res, $tab, $mandatory, $repeatable, $important, $ind1_defaultvalue, $ind2_defaultvalue ); - while ( ( $tag, $liblibrarian, $libopac, $mandatory, $repeatable, $ind1_defaultvalue, $ind2_defaultvalue ) = $sth->fetchrow ) { + while ( ( $tag, $liblibrarian, $libopac, $mandatory, $repeatable, $important, $ind1_defaultvalue, $ind2_defaultvalue ) = $sth->fetchrow ) { $res->{$tag}->{lib} = ( $forlibrarian or !$libopac ) ? $liblibrarian : $libopac; $res->{$tag}->{tab} = ""; $res->{$tag}->{mandatory} = $mandatory; + $res->{$tag}->{important} = $important; $res->{$tag}->{repeatable} = $repeatable; $res->{$tag}->{ind1_defaultvalue} = $ind1_defaultvalue; $res->{$tag}->{ind2_defaultvalue} = $ind2_defaultvalue; } $sth = $dbh->prepare( - "SELECT tagfield,tagsubfield,liblibrarian,libopac,tab,mandatory,repeatable,authorised_value,authtypecode,value_builder,kohafield,seealso,hidden,isurl,link,defaultvalue,maxlength + "SELECT tagfield,tagsubfield,liblibrarian,libopac,tab,mandatory,repeatable,authorised_value,authtypecode,value_builder,kohafield,seealso,hidden,isurl,link,defaultvalue,maxlength,important FROM marc_subfield_structure WHERE frameworkcode=? ORDER BY tagfield,tagsubfield @@ -935,13 +936,14 @@ sub GetMarcStructure { while ( ( $tag, $subfield, $liblibrarian, $libopac, $tab, $mandatory, $repeatable, $authorised_value, $authtypecode, $value_builder, $kohafield, $seealso, $hidden, $isurl, $link, $defaultvalue, - $maxlength + $maxlength, $important ) = $sth->fetchrow ) { $res->{$tag}->{$subfield}->{lib} = ( $forlibrarian or !$libopac ) ? $liblibrarian : $libopac; $res->{$tag}->{$subfield}->{tab} = $tab; $res->{$tag}->{$subfield}->{mandatory} = $mandatory; + $res->{$tag}->{$subfield}->{important} = $important; $res->{$tag}->{$subfield}->{repeatable} = $repeatable; $res->{$tag}->{$subfield}->{authorised_value} = $authorised_value; $res->{$tag}->{$subfield}->{authtypecode} = $authtypecode; diff --git a/admin/marc_subfields_structure.pl b/admin/marc_subfields_structure.pl index 2519649..594233b 100755 --- a/admin/marc_subfields_structure.pl +++ b/admin/marc_subfields_structure.pl @@ -191,6 +191,7 @@ if ( $op eq 'add_form' ) { $row_data{isurl} = $data->{isurl}; $row_data{row} = $i; $row_data{link} = $data->{'link'}; + $row_data{important} = $data->{important}; push( @loop_data, \%row_data ); $i++; } @@ -215,6 +216,7 @@ if ( $op eq 'add_form' ) { $row_data{authtypes} = \@authtypes; $row_data{link} = ""; $row_data{row} = $i; + $row_data{important} = ""; push( @loop_data, \%row_data ); $template->param( 'use_heading_flags_p' => 1 ); @@ -238,11 +240,11 @@ elsif ( $op eq 'add_validate' ) { # values (?,?,?,?,?,?,?,?,?,?,?,?,?,?,?,?,?)" # ); my $sth_insert = $dbh->prepare(qq{ - insert into marc_subfield_structure (tagfield,tagsubfield,liblibrarian,libopac,repeatable,mandatory,kohafield,tab,seealso,authorised_value,authtypecode,value_builder,hidden,isurl,frameworkcode, link,defaultvalue,maxlength) - values (?,?,?,?,?,?,?,?,?,?,?,?,?,?,?,?,?,?) + insert into marc_subfield_structure (tagfield,tagsubfield,liblibrarian,libopac,repeatable,mandatory,important,kohafield,tab,seealso,authorised_value,authtypecode,value_builder,hidden,isurl,frameworkcode, link,defaultvalue,maxlength) + values (?,?,?,?,?,?,?,?,?,?,?,?,?,?,?,?,?,?,?) }); my $sth_update = $dbh->prepare(qq{ - update marc_subfield_structure set tagfield=?, tagsubfield=?, liblibrarian=?, libopac=?, repeatable=?, mandatory=?, kohafield=?, tab=?, seealso=?, authorised_value=?, authtypecode=?, value_builder=?, hidden=?, isurl=?, frameworkcode=?, link=?, defaultvalue=?, maxlength=? + update marc_subfield_structure set tagfield=?, tagsubfield=?, liblibrarian=?, libopac=?, repeatable=?, mandatory=?, important=?, kohafield=?, tab=?, seealso=?, authorised_value=?, authtypecode=?, value_builder=?, hidden=?, isurl=?, frameworkcode=?, link=?, defaultvalue=?, maxlength=? where tagfield=? and tagsubfield=? and frameworkcode=? }); my @tagsubfield = $input->multi_param('tagsubfield'); @@ -267,6 +269,7 @@ elsif ( $op eq 'add_validate' ) { my $libopac = $libopac[$i]; my $repeatable = $input->param("repeatable$i") ? 1 : 0; my $mandatory = $input->param("mandatory$i") ? 1 : 0; + my $important = $input->param("important$i") ? 1 : 0; my $kohafield = $kohafield[$i]; my $tab = $tab[$i]; my $seealso = $seealso[$i]; @@ -288,6 +291,7 @@ elsif ( $op eq 'add_validate' ) { $libopac, $repeatable, $mandatory, + $important, $kohafield, $tab, $seealso, @@ -319,6 +323,7 @@ elsif ( $op eq 'add_validate' ) { $libopac, $repeatable, $mandatory, + $important, $kohafield, $tab, $seealso, @@ -401,6 +406,7 @@ else { # DEFAULT $row_data{kohafield} = $results->[$i]{'kohafield'}; $row_data{repeatable} = $results->[$i]{'repeatable'}; $row_data{mandatory} = $results->[$i]{'mandatory'}; + $row_data{important} = $results->[$i]{'important'}; $row_data{tab} = $results->[$i]{'tab'}; $row_data{seealso} = $results->[$i]{'seealso'}; $row_data{authorised_value} = $results->[$i]{'authorised_value'}; diff --git a/admin/marctagstructure.pl b/admin/marctagstructure.pl index e34edd5..d7d7447 100755 --- a/admin/marctagstructure.pl +++ b/admin/marctagstructure.pl @@ -89,7 +89,7 @@ if ($op eq 'add_form') { #---- if primkey exists, it's a modify action, so read values to modify... my $data; if ($searchfield) { - $sth=$dbh->prepare("select tagfield,liblibrarian,libopac,repeatable,mandatory,authorised_value,ind1_defaultvalue,ind2_defaultvalue from marc_tag_structure where tagfield=? and frameworkcode=?"); + $sth=$dbh->prepare("select tagfield,liblibrarian,libopac,repeatable,mandatory,authorised_value,important,ind1_defaultvalue,ind2_defaultvalue from marc_tag_structure where tagfield=? and frameworkcode=?"); $sth->execute($searchfield,$frameworkcode); $data=$sth->fetchrow_hashref; } @@ -108,6 +108,7 @@ if ($op eq 'add_form') { repeatable => $data->{'repeatable'}, mandatory => $data->{'mandatory'}, authorised_value => $data->{authorised_value}, + important => $data->{'important'}, ind1_defaultvalue => $data->{'ind1_defaultvalue'}, ind2_defaultvalue => $data->{'ind2_defaultvalue'} ); # FIXME: move checkboxes to presentation layer @@ -120,17 +121,19 @@ if ($op eq 'add_form') { my $libopac = $input->param('libopac'); my $repeatable = $input->param('repeatable') ? 1 : 0; my $mandatory = $input->param('mandatory') ? 1 : 0; + my $important = $input->param('important') ? 1 : 0; my $authorised_value = $input->param('authorised_value'); my $ind1_defaultvalue = $input->param('ind1_defaultvalue'); my $ind2_defaultvalue = $input->param('ind2_defaultvalue'); if ($input->param('modif')) { $sth = $dbh->prepare( - "UPDATE marc_tag_structure SET liblibrarian=? ,libopac=? ,repeatable=? ,mandatory=? ,authorised_value=?, ind1_defaultvalue=?, ind2_defaultvalue=? WHERE frameworkcode=? AND tagfield=?" + "UPDATE marc_tag_structure SET liblibrarian=? ,libopac=? ,repeatable=? ,mandatory=? ,important=? ,authorised_value=?, ind1_defaultvalue=?, ind2_defaultvalue=? WHERE frameworkcode=? AND tagfield=?" ); $sth->execute( $liblibrarian, $libopac, $repeatable, $mandatory, + $important, $authorised_value, $ind1_defaultvalue, $ind2_defaultvalue, @@ -139,13 +142,14 @@ if ($op eq 'add_form') { ); } else { $sth = $dbh->prepare( - "INSERT INTO marc_tag_structure (tagfield,liblibrarian,libopac,repeatable,mandatory,authorised_value,ind1_defaultvalue,ind2_defaultvalue,frameworkcode) values (?,?,?,?,?,?,?,?,?)" + "INSERT INTO marc_tag_structure (tagfield,liblibrarian,libopac,repeatable,mandatory,important,authorised_value,ind1_defaultvalue,ind2_defaultvalue,frameworkcode) values (?,?,?,?,?,?,?,?,?,?)" ); $sth->execute($tagfield, $liblibrarian, $libopac, $repeatable, $mandatory, + $important, $authorised_value, $ind1_defaultvalue, $ind2_defaultvalue, @@ -216,6 +220,7 @@ if ($op eq 'add_form') { marc_tag_structure.libopac as mts_libopac, marc_tag_structure.repeatable as mts_repeatable, marc_tag_structure.mandatory as mts_mandatory, + marc_tag_structure.important as mts_important, marc_tag_structure.authorised_value as mts_authorized_value, marc_tag_structure.ind1_defaultvalue as mts_ind1_defaultvalue, marc_tag_structure.ind1_defaultvalue as mts_ind2_defaultvalue, @@ -239,6 +244,7 @@ if ($op eq 'add_form') { $row_data{liblibrarian} = $results[$i]->{'mts_liblibrarian'}; $row_data{repeatable} = $results[$i]->{'mts_repeatable'}; $row_data{mandatory} = $results[$i]->{'mts_mandatory'}; + $row_data{important} = $results[$i]->{'mts_important'}; $row_data{authorised_value} = $results[$i]->{'mts_authorised_value'}; $row_data{ind1_defaultvalue} = $results[$i]->{'mts_ind1_defaultvalue'}; $row_data{ind2_defaultvalue} = $results[$i]->{'mts_ind2_defaultvalue'}; @@ -251,6 +257,7 @@ if ($op eq 'add_form') { $subfield_data{kohafield} = $results[$j]->{'kohafield'}; $subfield_data{repeatable} = $results[$j]->{'repeatable'}; $subfield_data{mandatory} = $results[$j]->{'mandatory'}; + $subfield_data{important} = $results[$j]->{'important'}; $subfield_data{tab} = $results[$j]->{'tab'}; $subfield_data{seealso} = $results[$j]->{'seealso'}; $subfield_data{authorised_value} = $results[$j]->{'authorised_value'}; @@ -283,6 +290,7 @@ if ($op eq 'add_form') { $row_data{liblibrarian} = $results->[$i]{'liblibrarian'}; $row_data{repeatable} = $results->[$i]{'repeatable'}; $row_data{mandatory} = $results->[$i]{'mandatory'}; + $row_data{important} = $results->[$i]{'important'}; $row_data{authorised_value} = $results->[$i]{'authorised_value'}; $row_data{ind1_defaultvalue} = $results->[$i]{'ind1_defaultvalue'}; $row_data{ind2_defaultvalue} = $results->[$i]{'ind2_defaultvalue'}; @@ -313,7 +321,7 @@ output_html_with_http_headers $input, $cookie, $template->output; sub StringSearch { my ($searchstring,$frameworkcode)=@_; my $sth = C4::Context->dbh->prepare(" - SELECT tagfield,liblibrarian,libopac,repeatable,mandatory,authorised_value,ind1_defaultvalue,ind2_defaultvalue + SELECT tagfield,liblibrarian,libopac,repeatable,mandatory,authorised_value,important,ind1_defaultvalue,ind2_defaultvalue FROM marc_tag_structure WHERE (tagfield >= ? and frameworkcode=?) ORDER BY tagfield diff --git a/cataloguing/addbiblio.pl b/cataloguing/addbiblio.pl index c4ed49d..51e0fa6 100755 --- a/cataloguing/addbiblio.pl +++ b/cataloguing/addbiblio.pl @@ -305,6 +305,7 @@ sub create_input { marc_lib => $tagslib->{$tag}->{$subfield}->{lib}, tag_mandatory => $tagslib->{$tag}->{mandatory}, mandatory => $tagslib->{$tag}->{$subfield}->{mandatory}, + important => $tagslib->{$tag}->{$subfield}->{important}, repeatable => $tagslib->{$tag}->{$subfield}->{repeatable}, kohafield => $tagslib->{$tag}->{$subfield}->{kohafield}, index => $index_tag, @@ -318,13 +319,15 @@ sub create_input { $subfield_data{z3950_mandatory} = $mandatory_z3950->{$tag.$subfield}; } # Subfield is hidden depending of hidden and mandatory flag, and is always - # shown if it contains anything or if its field is mandatory. + # shown if it contains anything or if its field is mandatory or important. my $tdef = $tagslib->{$tag}; $subfield_data{visibility} = "display:none;" if $tdef->{$subfield}->{hidden} % 2 == 1 && $value eq '' && !$tdef->{$subfield}->{mandatory} && - !$tdef->{mandatory}; + !$tdef->{mandatory} && + !$tdef->{$subfield}->{important} && + !$tdef->{important}; # expand all subfields of 773 if there is a host item provided in the input $subfield_data{visibility} ="" if ($tag eq 773 and $cgi->param('hostitemnumber')); @@ -604,6 +607,7 @@ sub build_tabs { tag_lib => $tagslib->{$tag}->{lib}, repeatable => $tagslib->{$tag}->{repeatable}, mandatory => $tagslib->{$tag}->{mandatory}, + important => $tagslib->{$tag}->{important}, subfield_loop => \@subfields_data, fixedfield => $tag < 10?1:0, random => CreateKey, @@ -650,6 +654,7 @@ sub build_tabs { tag_lib => $tagslib->{$tag}->{lib}, repeatable => $tagslib->{$tag}->{repeatable}, mandatory => $tagslib->{$tag}->{mandatory}, + important => $tagslib->{$tag}->{important}, indicator1 => ( $indicator1 || $tagslib->{$tag}->{ind1_defaultvalue} ), #if not set, try to load the default value indicator2 => ( $indicator2 || $tagslib->{$tag}->{ind2_defaultvalue} ), #use short-circuit operator for efficiency subfield_loop => \@subfields_data, diff --git a/cataloguing/additem.pl b/cataloguing/additem.pl index 7b6d5e4..220bf8b 100755 --- a/cataloguing/additem.pl +++ b/cataloguing/additem.pl @@ -130,6 +130,7 @@ sub generate_subfield_form { $subfield_data{subfield} = $subfieldtag; $subfield_data{marc_lib} ="{lib}."\">".$subfieldlib->{lib}.""; $subfield_data{mandatory} = $subfieldlib->{mandatory}; + $subfield_data{important} = $subfieldlib->{important}; $subfield_data{repeatable} = $subfieldlib->{repeatable}; $subfield_data{maxlength} = $subfieldlib->{maxlength}; diff --git a/installer/data/mysql/atomicupdate/bug-8643-add_important_constraint.perl b/installer/data/mysql/atomicupdate/bug-8643-add_important_constraint.perl new file mode 100644 index 0000000..4a972cd --- /dev/null +++ b/installer/data/mysql/atomicupdate/bug-8643-add_important_constraint.perl @@ -0,0 +1,11 @@ +$DBversion = "XXX"; +if ( CheckVersion($DBversion) ) { + if ( !column_exists( 'marc_subfield_structure', 'important') ){ + $dbh->do("ALTER TABLE marc_subfield_structure ADD COLUMN important TINYINT(4) NOT NULL DEFAULT 0 AFTER mandatory"); + } + if ( !column_exists( 'marc_subfield_structure', 'important') ){ + $dbh->do("ALTER TABLE marc_tag_structure ADD COLUMN important TINYINT(4) NOT NULL DEFAULT 0 AFTER mandatory"); + } + SetVersion($DBversion); + print "Upgrade to $DBversion done (Bug 8643 - Add important constraint to marc subfields)\n"; +} diff --git a/installer/data/mysql/kohastructure.sql b/installer/data/mysql/kohastructure.sql index 76798c3..aaf6c3d 100644 --- a/installer/data/mysql/kohastructure.sql +++ b/installer/data/mysql/kohastructure.sql @@ -1141,6 +1141,7 @@ CREATE TABLE `marc_subfield_structure` ( `libopac` varchar(255) NOT NULL default '', `repeatable` tinyint(4) NOT NULL default 0, `mandatory` tinyint(4) NOT NULL default 0, + `important` tinyint(4) NOT NULL DEFAULT '0', `kohafield` varchar(40) default NULL, `tab` tinyint(1) default NULL, `authorised_value` varchar(32) default NULL, @@ -1171,6 +1172,7 @@ CREATE TABLE `marc_tag_structure` ( `libopac` varchar(255) NOT NULL default '', `repeatable` tinyint(4) NOT NULL default 0, `mandatory` tinyint(4) NOT NULL default 0, + `important` tinyint(4) NOT NULL DEFAULT '0', `authorised_value` varchar(10) default NULL, `ind1_defaultvalue` varchar(1) NOT NULL default '', `ind2_defaultvalue` varchar(1) NOT NULL default '', diff --git a/koha-tmpl/intranet-tmpl/prog/css/addbiblio.css b/koha-tmpl/intranet-tmpl/prog/css/addbiblio.css index 5670a23..1fd4540 100644 --- a/koha-tmpl/intranet-tmpl/prog/css/addbiblio.css +++ b/koha-tmpl/intranet-tmpl/prog/css/addbiblio.css @@ -119,6 +119,10 @@ a.tagnum { .mandatory_marker { color: red; } + +.important_marker { + color: black; +} .linktools { display: block; white-space: nowrap; } .linktools a { font-size : 75%; display:block;text-decoration:none;} .linktools a {margin:0 2px;padding:2px;background-color:#FFF;text-align:center; } diff --git a/koha-tmpl/intranet-tmpl/prog/css/src/staff-global.scss b/koha-tmpl/intranet-tmpl/prog/css/src/staff-global.scss index ee75489..ee29da3 100644 --- a/koha-tmpl/intranet-tmpl/prog/css/src/staff-global.scss +++ b/koha-tmpl/intranet-tmpl/prog/css/src/staff-global.scss @@ -1928,6 +1928,10 @@ dd { background-color: #FFFF99; } +.important_subfield_not_filled { + background-color : #FFFFCC; +} + .content_hidden { display: none; visibility: hidden; // you propably don't need to change this one diff --git a/koha-tmpl/intranet-tmpl/prog/en/modules/admin/marc_subfields_structure.tt b/koha-tmpl/intranet-tmpl/prog/en/modules/admin/marc_subfields_structure.tt index f4d0fef..8edb20b 100644 --- a/koha-tmpl/intranet-tmpl/prog/en/modules/admin/marc_subfields_structure.tt +++ b/koha-tmpl/intranet-tmpl/prog/en/modules/admin/marc_subfields_structure.tt @@ -87,6 +87,14 @@ [% END %] +
  • + + [% IF loo.important %] + + [% ELSE %] + + [% END %] +
  • [% END %]
  • +
  • + [% IF ( important ) %] + + [% ELSE %] + + [% END %] +
  • + (if you select a value here, the indicators will be limited to the authorized value list)
  • + [% IF ( ite.repeatable ) %] Clone [% END %] - [% IF ( ite.mandatory ) %] Required[% END %] + [% IF ( ite.mandatory ) %] Required + [% ELSIF ( ite.important ) %] Important + [% END %]
  • [% END %] diff --git a/koha-tmpl/intranet-tmpl/prog/js/cataloging.js b/koha-tmpl/intranet-tmpl/prog/js/cataloging.js index b685c2a..7a417b4 100644 --- a/koha-tmpl/intranet-tmpl/prog/js/cataloging.js +++ b/koha-tmpl/intranet-tmpl/prog/js/cataloging.js @@ -557,6 +557,18 @@ function CheckMandatorySubfields(p){ return total; } +function CheckImportantSubfields(p){ + var total = 0; + $(p).find(".subfield_line input[name='important'][value='1']").each(function(i){ + var editor = $(this).siblings("[name='field_value']"); + if (!editor.val()) { + editor.addClass("missing"); + total++; + } + }); + return total; +} + $(document).ready(function() { $("input.input_marceditor, input.indicator").addClass('noEnterSubmit'); }); -- 2.7.4