From b7a4b532be805573821b672e82df71b9411da7a7 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 | 8 +- 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/right-to-left.css | 4 +- .../intranet-tmpl/prog/css/src/staff-global.scss | 10 ++ .../prog/en/includes/str/cataloging_additem.inc | 2 + .../en/modules/admin/marc_subfields_structure.tt | 9 ++ .../prog/en/modules/admin/marctagstructure.tt | 9 ++ .../prog/en/modules/cataloguing/addbiblio.tt | 120 +++++++++++++++++++++ .../prog/en/modules/cataloguing/additem.tt | 5 +- koha-tmpl/intranet-tmpl/prog/js/cataloging.js | 14 ++- .../intranet-tmpl/prog/js/cataloging_additem.js | 30 ++++-- 16 files changed, 241 insertions(+), 21 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 55a2c01..a038cd7 100644 --- a/C4/Biblio.pm +++ b/C4/Biblio.pm @@ -863,25 +863,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 @@ -905,13 +906,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 cdefc25..0dce186 100755 --- a/admin/marc_subfields_structure.pl +++ b/admin/marc_subfields_structure.pl @@ -187,6 +187,7 @@ if ( $op eq 'add_form' ) { $row_data{authtypecode} = $data->{'authtypecode'}; $row_data{repeatable} = $data->{repeatable}; $row_data{mandatory} = $data->{mandatory}; + $row_data{important} = $data->{important}; $row_data{hidden} = $data->{hidden}; $row_data{isurl} = $data->{isurl}; $row_data{row} = $i; @@ -208,6 +209,7 @@ if ( $op eq 'add_form' ) { $row_data{hidden} = ""; $row_data{repeatable} = 0; $row_data{mandatory} = 0; + $row_data{important} = 0; $row_data{isurl} = 0; $row_data{kohafields} = \@kohafields; $row_data{authorised_values} = \@authorised_values; @@ -234,7 +236,7 @@ elsif ( $op eq 'add_validate' ) { my $dbh = C4::Context->dbh; $template->param( tagfield => "$input->param('tagfield')" ); 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'); @@ -259,6 +261,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]; @@ -280,6 +283,7 @@ elsif ( $op eq 'add_validate' ) { $libopac, $repeatable, $mandatory, + $important, $kohafield, $tab, $seealso, @@ -312,6 +316,7 @@ elsif ( $op eq 'add_validate' ) { libopac => $libopac, repeatable => $repeatable, mandatory => $mandatory, + important => $important, kohafield => $kohafield, tab => $tab, seealso => $seealso, @@ -394,6 +399,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..b5d7004 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,important,authorised_value,ind1_defaultvalue,ind2_defaultvalue from marc_tag_structure where tagfield=? and frameworkcode=?"); $sth->execute($searchfield,$frameworkcode); $data=$sth->fetchrow_hashref; } @@ -107,6 +107,7 @@ if ($op eq 'add_form') { libopac => $data->{'libopac'}, repeatable => $data->{'repeatable'}, mandatory => $data->{'mandatory'}, + important => $data->{'important'}, authorised_value => $data->{authorised_value}, ind1_defaultvalue => $data->{'ind1_defaultvalue'}, ind2_defaultvalue => $data->{'ind2_defaultvalue'} @@ -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,important,authorised_value,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 00b2501..30a547a 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')); @@ -607,6 +610,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, @@ -653,6 +657,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 ce12b0a..b906aff 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..8965642 --- /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_tag_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 f637d27..672dd41 100644 --- a/installer/data/mysql/kohastructure.sql +++ b/installer/data/mysql/kohastructure.sql @@ -1043,6 +1043,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, @@ -1073,6 +1074,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/right-to-left.css b/koha-tmpl/intranet-tmpl/prog/css/right-to-left.css index 043c65d..06ccea8 100644 --- a/koha-tmpl/intranet-tmpl/prog/css/right-to-left.css +++ b/koha-tmpl/intranet-tmpl/prog/css/right-to-left.css @@ -68,6 +68,7 @@ fieldset.rows textarea, ol.bibliodetails, ol.bibliodetails span.label, span.required, +span.important, #marcDocsSelect, #toplevelnav, .ui-tabs-nav li, @@ -140,7 +141,8 @@ div.patroninfo h5, margin-left: 0.5em; } fieldset.rows img, -span.required +span.required, +span.important { margin-right: 0.5em; } 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 c9bc9a7..6de7857 100644 --- a/koha-tmpl/intranet-tmpl/prog/css/src/staff-global.scss +++ b/koha-tmpl/intranet-tmpl/prog/css/src/staff-global.scss @@ -1777,6 +1777,10 @@ input[type='text']:read-only:focus { 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 @@ -3654,6 +3658,12 @@ span { margin-left: .5em; } + &.important { + color: #EAC117; + font-style: italic; + margin-left: .5em; + } + &[class*=" label-"] { color: #FFF; display: inline; diff --git a/koha-tmpl/intranet-tmpl/prog/en/includes/str/cataloging_additem.inc b/koha-tmpl/intranet-tmpl/prog/en/includes/str/cataloging_additem.inc index 97cadb9..22355bc 100644 --- a/koha-tmpl/intranet-tmpl/prog/en/includes/str/cataloging_additem.inc +++ b/koha-tmpl/intranet-tmpl/prog/en/includes/str/cataloging_additem.inc @@ -9,9 +9,11 @@ var LABEL_DELETE_ITEM = _("Delete item"); var MSG_FORM_NOT_SUBMITTED = _("Form not submitted because of the following problem(s)"); var MSG_MANDATORY_FIELDS_EMPTY = _("%s mandatory fields empty (highlighted)"); + var MSG_IMPORTANT_FIELDS_EMPTY = _("%s important fields empty (highlighted)"); var MSG_ADD_MULTIPLE_ITEMS = _("You are about to add %s items. Continue?"); var MSG_ENTER_NUM_ITEMS = _("Please enter a number of items to create."); var MSG_CONFIRM_DELETE_ITEM = _("Are you sure you want to delete this item?"); var MSG_CONFIRM_ADD_ITEM = _("Are you sure you want to add a new item? Any changes made on this page will be lost."); + var MSG_CONFIRM_SAVE = _("Are you sure you want to save?"); var columns_settings = [% ColumnsSettings.GetColumns( 'cataloguing', 'additem', 'itemst', 'json' ) | $raw %]; 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 %] +
  • @@ -176,6 +183,7 @@ Lib Repeatable Mandatory + Important Auth value Indicator 1 Indicator 2 @@ -199,6 +207,7 @@ [% IF ( loo.repeatable ) %]Yes[% ELSE %]No[% END %] [% IF ( loo.mandatory ) %]Yes[% ELSE %]No[% END %] + [% IF ( loo.important ) %]Yes[% ELSE %]No[% END %] [% loo.authorised_value | html %] [% loo.ind1_defaultvalue | html %] [% loo.ind2_defaultvalue | html %] diff --git a/koha-tmpl/intranet-tmpl/prog/en/modules/cataloguing/addbiblio.tt b/koha-tmpl/intranet-tmpl/prog/en/modules/cataloguing/addbiblio.tt index 635b6cc..693b3c4 100644 --- a/koha-tmpl/intranet-tmpl/prog/en/modules/cataloguing/addbiblio.tt +++ b/koha-tmpl/intranet-tmpl/prog/en/modules/cataloguing/addbiblio.tt @@ -385,6 +385,13 @@ function Check(){ var StrAlert = AreMandatoriesNotOk(); if( ! StrAlert ){ + var StrWarning = AreImportantsNotOk(); + if (StrWarning){ + var r=confirm(StrWarning); + if (! r){ + return false; + } + } document.f.submit(); return true; } else { @@ -394,6 +401,115 @@ } /** + * check if important subfields are written + */ + function AreImportantsNotOk(){ + var importants = new Array(); + var importantsfields = new Array(); + var tab = new Array(); + var label = new Array(); + var flag=0; + var tabflag= new Array(); + [% FOREACH BIG_LOO IN BIG_LOOP %] + [% FOREACH innerloo IN BIG_LOO.innerloop %] + [% IF ( innerloo.important ) %] + importantsfields.push(new Array("[% innerloo.tag | html %]","[% innerloo.index | html %][% innerloo.random | html %]","[% innerloo.index | html %]")); + [% END %] + [% FOREACH subfield_loo IN innerloo.subfield_loop %] + [% IF ( subfield_loo.important ) %]importants.push("[% subfield_loo.id | html %]"); + tab.push("[% BIG_LOO.number | html %]"); + label.push("[% subfield_loo.marc_lib | $raw %]"); + [% END %] + [% END %] + [% END %] + [% END %] + var StrWarning = _("A few important fields are not filled:"); + StrWarning += "\n\n"; + for(var i=0,len=importants.length; i= 10){ + elem = document.getElementById(divid); + eleminputs = elem.getElementsByTagName('input'); + for(var j=0,len2=eleminputs.length; j + [% ELSIF ( subfield_loo.important ) %] + [% ELSE %] [% END %] @@ -797,6 +915,8 @@ [% END # /IF (mv.type...) %] [% IF ( subfield_loo.mandatory ) %] Required + [% ELSIF ( subfield_loo.important ) %] + Important [% END %] [% IF ( subfield_loo.repeatable ) %] diff --git a/koha-tmpl/intranet-tmpl/prog/en/modules/cataloguing/additem.tt b/koha-tmpl/intranet-tmpl/prog/en/modules/cataloguing/additem.tt index 25fcf73..edfaaf4 100644 --- a/koha-tmpl/intranet-tmpl/prog/en/modules/cataloguing/additem.tt +++ b/koha-tmpl/intranet-tmpl/prog/en/modules/cataloguing/additem.tt @@ -196,12 +196,15 @@ + [% 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 b26c45b..89571d8 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; } -$(document).ready(function() { +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'); }); diff --git a/koha-tmpl/intranet-tmpl/prog/js/cataloging_additem.js b/koha-tmpl/intranet-tmpl/prog/js/cataloging_additem.js index 8c28e83..e3e7467 100644 --- a/koha-tmpl/intranet-tmpl/prog/js/cataloging_additem.js +++ b/koha-tmpl/intranet-tmpl/prog/js/cataloging_additem.js @@ -76,8 +76,10 @@ $(document).ready(function(){ }); function Check(f) { - var total_errors = CheckMandatorySubfields(f); - if (total_errors==0) { + var total_mandatory = CheckMandatorySubfields(f); + var total_important = CheckImportantSubfields(f); + var alertString2; + if (total_mandatory==0) { // Explanation about this line: // In case of limited edition permission, we have to prevent user from modifying some fields. // But there is no such thing as readonly attribute for select elements. @@ -85,14 +87,30 @@ function Check(f) { // So we "un-disable" the elements just before submitting. // That's a bit clumsy, and if someone comes up with a better solution, feel free to improve that. $("select[name=field_value]").prop('disabled', false); - return true; } else { - var alertString2 = MSG_FORM_NOT_SUBMITTED; + alertString2 = MSG_FORM_NOT_SUBMITTED; alertString2 += "\n------------------------------------------------------------------------------------\n"; - alertString2 += "\n- " + "%s " + MSG_MANDATORY_FIELDS_EMPTY.format(total_errors); - alert(alertString2); + alertString2 += "\n- " + "%s " + MSG_MANDATORY_FIELDS_EMPTY.format(total_mandatory); + } + if(total_important > 0){ + if( !alertString2 ){ + alertString2 = ""; + } + alertString2 += "\n\n " + MSG_IMPORTANT_FIELDS_EMPTY.format(total_important); + alertString2 += "\n\n " + MSG_CONFIRM_SAVE; + } + if(alertString2){ + if(total_mandatory){ + alert(alertString2); + }else{ + var a = confirm(alertString2); + if( a ){ + return true; + } + } return false; } + return true; } function CheckMultipleAdd(f) { -- 2.7.4