@@ -, +, @@ - Preview now shows side-by-side comparisons - JavaScript has been movied out of template into separate file - Validation of the add/edit form improved through use of validation plugin - There is now better visual feedback for AJAX form checks - Add a new notice. - Confirm that the form can't be submitted without data in the "code" and "name" fields. - Confirm that the form can't be submitted without filling in at least one message template (subject and body). - Confirm that you cannot submit the form while using an existing notice code. - Confirm that while the form validates this step the submit button shows a loading indicator. - Follow Bug 17981's test plan for testing the preview function. Confirm that the preview loads correctly and looks correct. --- .../intranet-tmpl/prog/en/modules/tools/letter.tt | 228 +++------------------ .../prog/en/modules/tools/preview_letter.tt | 58 ++++-- koha-tmpl/intranet-tmpl/prog/js/letter.js | 166 +++++++++++++++ 3 files changed, 232 insertions(+), 220 deletions(-) create mode 100644 koha-tmpl/intranet-tmpl/prog/js/letter.js --- a/koha-tmpl/intranet-tmpl/prog/en/modules/tools/letter.tt +++ a/koha-tmpl/intranet-tmpl/prog/en/modules/tools/letter.tt @@ -4,209 +4,25 @@ Koha › Tools › Notices[% IF ( add_form or copy_form ) %][% IF ( modify ) %] › Modify notice[% ELSE %] › Add notice[% END %][% END %][% IF ( add_validate or copy_validate) %] › Notice added[% END %][% IF ( delete_confirm ) %] › Confirm deletion[% END %] [% INCLUDE 'doc-head-close.inc' %] + [% INCLUDE 'datatables.inc' %] + var no_op_set = '[% no_op_set %]'; + var interface = '[% interface %]'; + var theme = '[% theme %]'; + var add_form = '[% add_form %]'; + var code = '[% code %]'; + var new_lettercode = '[% new_lettercode %]'; + var new_branchcode = '[% new_branchcode %]'; + var MSG_CODE_EXISTS = _("A default letter with the code '%s' already exists."); + var MSG_CODE_EXISTS_FOR_LIBRARY = _("A letter with the code '%s' already exists for '%s'."); + var MSG_EMPTY_TITLE_AND_CONTENT = _("Please specify title and content for %s"); + var MSG_EMPTY_TEMPLATES = _("Please fill at least one template."); + + + [% INCLUDE 'header.inc' %] [% INCLUDE 'letters-search.inc' %] @@ -330,7 +146,7 @@ $(document).ready(function() { [% IF add_form or copy_form %]

[% IF ( modify ) %]Modify notice[% ELSE %]Add notice[% END %]

-
+ [% IF add_form %] [% ELSE %] @@ -539,7 +355,7 @@ $(document).ready(function() { - + @@ -559,7 +375,15 @@ $(document).ready(function() { [% END %] [% IF code.search('DGST') %] Warning, this is a template for a Digest, as such, any references to branch data ( e.g. branches.branchname ) will refer to the borrower's home branch. [% END %] -
Cancel
+
+ + Cancel +
[% END %] --- a/koha-tmpl/intranet-tmpl/prog/en/modules/tools/preview_letter.tt +++ a/koha-tmpl/intranet-tmpl/prog/en/modules/tools/preview_letter.tt @@ -3,7 +3,9 @@ +
+ [% FOR m IN messages %] [%# FIXME The message block does not appear at the top of the modal! %]
@@ -29,27 +31,47 @@ [% END %] [% IF rendered_message %] -
- Original version -
[% original_content | html %]
-
- -
- Rendered message: -
[% rendered_message.content | html %]
-
+
+
+

Original version

+ + [% FILTER html_line_break %] + [% original_content | html %] + [% END %] + +
+
+

Converted version

+ + [% FILTER html_line_break %] + [% tt_content | html %] + [% END %] + +
+
[% END %] - [% IF rendered_tt_message %] -
- Converted version -
[% tt_content | html %]
-
+
-
- Rendered message: -
[% rendered_tt_message.content | html %]
-
+ [% IF rendered_tt_message %] +
+
+

Original message, rendered:

+ + [% FILTER html_line_break %] + [% rendered_message.content | html %] + [% END %] + +
+
+

Converted message, rendered:

+ + [% FILTER html_line_break %] + [% rendered_tt_message.content | html %] + [% END %] + +
+
[% END %]
--- a/koha-tmpl/intranet-tmpl/prog/js/letter.js +++ a/koha-tmpl/intranet-tmpl/prog/js/letter.js @@ -0,0 +1,166 @@ +var modal_loading = "
\"\" "+ MSG_DT_LOADING_RECORDS +"
"; + +var editing = 0; +if( add_form == 1 && code !== '' ){ + editing = 1; +} + +function checkCodes( new_lettercode, new_branchcode ){ + $(".spinner").show(); + return $.ajax({ + data: { code: new_lettercode, branchcode: new_branchcode }, + type: 'GET', + url: '/cgi-bin/koha/svc/letters/get/', + async: !1, + success: function (data) { + if ( data.letters.length > 0 ) { + if( new_branchcode === '' ) { + alert( MSG_CODE_EXISTS.format(new_lettercode)); + } else { + alert( MSG_CODE_EXISTS_FOR_LIBRARY.format(new_lettercode, new_branchcode) ); + } + $(".spinner").hide(); + } else { + $(".spinner").hide(); + } + } + }); +} + +$(document).ready(function() { + $("#lettert:has(tbody tr)").dataTable($.extend(true, {}, dataTablesDefaults, { + "sDom": 't', + "aoColumnDefs": [ + { "bSortable": false, "bSearchable": false, 'aTargets': [ 'nosort' ] } + ], + "bPaginate": false + })); + + if( no_op_set ){ + $('#branch').change(function() { + $('#op').val(""); + $('#selectlibrary').submit(); + }); + $('#newnotice').click(function() { + $('#op').val("add_form"); + return true; + }); + } + + $("#newmodule").on("change",function(){ + var branchcode; + if( $("#branch").val() === ""){ + branchcode = "*"; + } else { + branchcode = $("#branch").val(); + } + window.location.href = "/cgi-bin/koha/tools/letter.pl?op=add_form&module=" + $(this).val() + "&branchcode=" + branchcode; + }); + + $("#add_notice").validate({ + submitHandler: function(form){ + var at_least_one_exists = 0; + var are_valid = 1; + $("fieldset.mtt").each( function(){ + var title = $(this).find('input[name="title"]').val(); + var content = $(this).find('textarea[name="content"]').val(); + if ( + ( title.length === 0 && content.length > 0 ) || ( title.length > 0 && content.length === 0 ) + ) { + var mtt = $(this).find('input[name="message_transport_type"]').val(); + at_least_one_exists = 1; // Only one template has to be filled in for form to be valid + alert( MSG_EMPTY_TITLE_AND_CONTENT.format( mtt ) ); + are_valid = 0; + } else if ( title.length > 0 && content.length > 0 ) { + at_least_one_exists = 1; + } + }); + + if ( ! at_least_one_exists ) { + // No templates were filled out + alert( MSG_EMPTY_TEMPLATES ); + return false; + } + + if ( ! are_valid ){ + return false; + } + + // Test if code already exists in DB + if( editing == 1 ){ // This is an edit operation + // We don't need to check for an existing Code + } else { + var new_lettercode = $("#code").val(); + var new_branchcode = $("#branch").val(); + var code_check = checkCodes( new_lettercode, new_branchcode ); + if( code_check.responseJSON.letters.length > 0 ){ + return false; + } + return false; + } + form.submit(); + } + }); + + var sms_limit = 160; + $("#content_sms").on("keyup", function(){ + var length = $(this).val().length; + $("#sms_counter").html(length + "/" + sms_limit + _(" characters")); + if ( length > sms_limit ) { + $("#sms_counter").css("color", "red"); + } else { + $("#sms_counter").css("color", "black"); + } + }); + + $( ".transport-types" ).accordion({ collapsible: true, active:false, animate: 200 }); + + $(".insert").on("click",function(){ + var containerid = $(this).data("containerid"); + insertValueQuery( containerid ); + }); + + $("#tabs").tabs(); + + $("body").on("click", ".preview_template", function(e){ + e.preventDefault(); + var mtt = $(this).data("mtt"); + var lang = $(this).data("lang"); + + var code = $("#code").val(); + var content = $("#content_"+mtt+"_"+lang).val(); + var title = $("#title_"+mtt+"_"+lang).val(); + + var is_html = $("#is_html_"+mtt+"_"+lang).val(); + var page = $(this).attr("href"); + var data_preview = $("#data_preview").val(); + page += '?code='+encodeURIComponent(code); + page += '&title='+encodeURIComponent(title); + page += '&content='+encodeURIComponent(content); + page += '&data_preview='+encodeURIComponent(data_preview); + page += '&is_html='+encodeURIComponent(is_html); + $("#preview_template .modal-body").load(page + " #main"); + $('#preview_template').modal('show'); + $("#preview_template_button").attr("href", "/cgi-bin/koha/svc/letters/convert?module="+module+"&code="+code+"&mtt="+mtt+"&lang="+lang); + }); + + $("#preview_template").on("hidden.bs.modal", function(){ + $("#preview_template_label").html(""); + $("#preview_template .modal-body").html( modal_loading ); + }); + + function insertValueQuery(containerid) { + var fieldset = $("#" + containerid); + var myQuery = $(fieldset).find('textarea[name="content"]'); + var myListBox = $(fieldset).find('select[name="SQLfieldname"]'); + + if($(myListBox).find('option').length > 0) { + $(myListBox).find('option').each( function (){ + if ( $(this).attr('selected') && $(this).val().length > 0 ) { + $(myQuery).insertAtCaret("<<" + $(this).val() + ">>"); + } + }); + } + } + +}); --