From bef90a427dc20698103cafc23d4bae3f80182b2c Mon Sep 17 00:00:00 2001 From: Jesse Weaver Date: Tue, 10 Nov 2015 12:00:41 -0700 Subject: [PATCH] Bug 18823: Rancor - Save overriding warnings Allow saving of record even if invalid To test: Open/create a record with missing mandatory fields Click save Record is not saved and errors are listed Choose the dropdown under the save button and select 'Save overriding warnings' Note record is saved --- koha-tmpl/intranet-tmpl/lib/koha/cateditor/koha-backend.js | 12 +++++++----- koha-tmpl/intranet-tmpl/prog/en/includes/cateditor-ui.inc | 8 +++++--- 2 files changed, 12 insertions(+), 8 deletions(-) diff --git a/koha-tmpl/intranet-tmpl/lib/koha/cateditor/koha-backend.js b/koha-tmpl/intranet-tmpl/lib/koha/cateditor/koha-backend.js index 4f36be8..e010c80 100644 --- a/koha-tmpl/intranet-tmpl/lib/koha/cateditor/koha-backend.js +++ b/koha-tmpl/intranet-tmpl/lib/koha/cateditor/koha-backend.js @@ -245,7 +245,9 @@ define( [ '/cgi-bin/koha/svc/cataloguing/framework?frameworkcode=&callback=defin } ); }, - ValidateRecord: function( frameworkcode, record ) { + ValidateRecord: function( frameworkcode, record, options ) { + options = options || {}; + var errors = []; var mandatoryTags = KohaBackend.GetTagsBy( '', 'mandatory', '1' ); @@ -254,7 +256,7 @@ define( [ '/cgi-bin/koha/svc/cataloguing/framework?frameworkcode=&callback=defin var nonRepeatableSubfields = KohaBackend.GetSubfieldsBy( '', 'repeatable', '0' ); $.each( mandatoryTags, function( tag ) { - if ( !record.hasField( tag ) ) errors.push( { type: 'missingTag', tag: tag } ); + if ( !record.hasField( tag ) && !options.override_warnings ) errors.push( { type: 'missingTag', tag: tag } ); } ); var seenTags = {}; @@ -267,7 +269,7 @@ define( [ '/cgi-bin/koha/svc/cataloguing/framework?frameworkcode=&callback=defin } if ( seenTags[ field.tagnumber() ] && nonRepeatableTags[ field.tagnumber() ] ) { - errors.push( { type: 'unrepeatableTag', line: field.sourceLine, tag: field.tagnumber() } ); + if ( !options.override_warnings ) errors.push( { type: 'unrepeatableTag', line: field.sourceLine, tag: field.tagnumber() } ); return; } @@ -277,7 +279,7 @@ define( [ '/cgi-bin/koha/svc/cataloguing/framework?frameworkcode=&callback=defin $.each( field.subfields(), function( undef, subfield ) { if ( seenSubfields[ subfield[0] ] != null && ( nonRepeatableSubfields[ field.tagnumber() ] || {} )[ subfield[0] ] ) { - errors.push( { type: 'unrepeatableSubfield', subfield: subfield[0], line: field.sourceLine } ); + if ( !options.override_warnings ) errors.push( { type: 'unrepeatableSubfield', subfield: subfield[0], line: field.sourceLine } ); } else { seenSubfields[ subfield[0] ] = subfield[1]; } @@ -285,7 +287,7 @@ define( [ '/cgi-bin/koha/svc/cataloguing/framework?frameworkcode=&callback=defin $.each( mandatorySubfields[ field.tagnumber() ] || {}, function( subfield ) { if ( !seenSubfields[ subfield ] ) { - errors.push( { type: 'missingSubfield', subfield: subfield[0], line: field.sourceLine } ); + if ( !options.override_warnings ) errors.push( { type: 'missingSubfield', subfield: subfield[0], line: field.sourceLine } ); } } ); } ); diff --git a/koha-tmpl/intranet-tmpl/prog/en/includes/cateditor-ui.inc b/koha-tmpl/intranet-tmpl/prog/en/includes/cateditor-ui.inc index 36b2027..3d87a2d 100644 --- a/koha-tmpl/intranet-tmpl/prog/en/includes/cateditor-ui.inc +++ b/koha-tmpl/intranet-tmpl/prog/en/includes/cateditor-ui.inc @@ -395,7 +395,7 @@ require( [ 'koha-backend', 'search', 'macros', 'marc-editor', 'marc-record', 'pr $( 'title', document.head ).html( _("Koha › Cataloging › ") + backend.titleForRecord.format( parts[1] ) ); } - function saveRecord( recid, editor, callback ) { + function saveRecord( recid, editor, callback, options ) { var parts = recid.split('/'); if ( parts.length != 2 ) return false; @@ -410,7 +410,7 @@ require( [ 'koha-backend', 'search', 'macros', 'marc-editor', 'marc-record', 'pr return; } - var errors = KohaBackend.ValidateRecord( '', record ); + var errors = KohaBackend.ValidateRecord( '', record, options ); if ( errors.length ) { state.saving = false; callback( { error: 'invalid', errors: errors } ); @@ -443,7 +443,7 @@ require( [ 'koha-backend', 'search', 'macros', 'marc-editor', 'marc-record', 'pr } if (callback) callback( data ); - } ); + }, options ); } function loadRecord( recid, editor, callback ) { @@ -1151,6 +1151,8 @@ require( [ 'koha-backend', 'search', 'macros', 'marc-editor', 'marc-record', 'pr } } + var options = { override_warnings: $(this).is('#save-with-override') } + $.each( enabledTargets, function() { saveRecord( this.id, editor, finishCb, options ); } ); -- 2.1.4