From b18d0e53a85d4054728dd691d63a410fb4b8bd3e Mon Sep 17 00:00:00 2001 From: Indranil Das Gupta Date: Fri, 15 May 2015 19:34:28 +0530 Subject: [PATCH] Bug 14070 Improved handling of Notice saving Addresses the issue of losing already entered data when an user attempts to save a new or existing letter / notice. Happened if the used template's (i.e. email, phone, print or sms) mandatory field(s) i.e. subject or content were left empty. Test plan ========= 1/ Enter a new text for a notice, don't fill the subject line of the template used 2/ Save - a note is shown that not all mandatory fields have been filled in 3/ Verify: You are kicked back to the overview page of notices, your changes have not been saved 4/ apply patch 5/ repeat step #1 and #2 - a note is shown that not all mandatory fields have been filled in. You should remain on the add_form screen without losing data due to redirection back to Notices overview page. 6/ run koha qa tests tool --- .../intranet-tmpl/prog/en/modules/tools/letter.tt | 28 +++++++++++++++++++--- 1 file changed, 25 insertions(+), 3 deletions(-) diff --git a/koha-tmpl/intranet-tmpl/prog/en/modules/tools/letter.tt b/koha-tmpl/intranet-tmpl/prog/en/modules/tools/letter.tt index 3106498..4334acf 100644 --- a/koha-tmpl/intranet-tmpl/prog/en/modules/tools/letter.tt +++ b/koha-tmpl/intranet-tmpl/prog/en/modules/tools/letter.tt @@ -30,6 +30,9 @@ $(document).ready(function() { $("#submit_form").click( function(event) { event.preventDefault(); var at_least_one_exists = 0; + var submit_trigger = 0; + var check_mtt_fieldsets = new Array (); + $("fieldset.mtt").each( function(){ var title = $(this).find('input[name="title"]').val(); var content = $(this).find('textarea[name="content"]').val(); @@ -41,10 +44,12 @@ $(document).ready(function() { var msg = _("Please specify title and content for %s"); msg = msg.replace( "%s", mtt ); at_least_one_exists = 1; - alert(msg) + check_mtt_fieldsets.push("0"); + alert(msg); return false; } else if ( title.length > 0 && content.length > 0 ) { at_least_one_exists = 1; + check_mtt_fieldsets.push("1"); } } ); if ( ! at_least_one_exists ) { @@ -52,6 +57,19 @@ $(document).ready(function() { return false; } + for(var i = 0; i < check_mtt_fieldsets.length; i++) + { + if ( check_mtt_fieldsets[i] !== check_mtt_fieldsets[0] ) + { + submit_trigger = 0; + return false; + } else { + if ( check_mtt_fieldsets[0] == 1 ) { + submit_trigger = 1; + } + } + } + // Test if code already exists in DB var new_lettercode = $("#code").val(); var new_branchcode = $("#branch").val(); @@ -71,13 +89,17 @@ $(document).ready(function() { } return false; } else { - $("#add_notice").submit(); + if ( submit_trigger == 1) { + $("#add_notice").submit(); + } } }, }); [% IF ( add_form and code ) %] } else { - $("#add_notice").submit(); + if ( submit_trigger == 1) { + $("#add_notice").submit(); + } } [% END %] }); -- 1.9.1