View | Details | Raw Unified | Return to bug 18007
Collapse All | Expand All

(-)a/koha-tmpl/intranet-tmpl/prog/en/modules/tools/letter.tt (-207 / +17 lines)
Lines 6-11 Link Here
6
<title>Koha &rsaquo; Tools &rsaquo; Notices[% IF ( add_form or copy_form ) %][% IF ( modify ) %] &rsaquo; Modify notice[% ELSE %] &rsaquo; Add notice[% END %][% END %][% IF ( add_validate or copy_validate) %] &rsaquo; Notice added[% END %][% IF ( delete_confirm ) %] &rsaquo; Confirm deletion[% END %]</title>
6
<title>Koha &rsaquo; Tools &rsaquo; Notices[% IF ( add_form or copy_form ) %][% IF ( modify ) %] &rsaquo; Modify notice[% ELSE %] &rsaquo; Add notice[% END %][% END %][% IF ( add_validate or copy_validate) %] &rsaquo; Notice added[% END %][% IF ( delete_confirm ) %] &rsaquo; Confirm deletion[% END %]</title>
7
[% INCLUDE 'doc-head-close.inc' %]
7
[% INCLUDE 'doc-head-close.inc' %]
8
[% Asset.css("css/datatables.css") %]
8
[% Asset.css("css/datatables.css") %]
9
<style type="text/css">#preview_template .modal-dialog { width : 80%; } .spinner { display: none; } @media (max-width: 767px) { #preview_template { margin: 0; width : auto; } }</style>
9
</head>
10
</head>
10
11
11
<body id="tools_letter" class="tools">
12
<body id="tools_letter" class="tools">
Lines 446-658 Link Here
446
    [% INCLUDE 'datatables.inc' %]
447
    [% INCLUDE 'datatables.inc' %]
447
    [% Asset.js("lib/jquery/plugins/jquery.fixFloat.js") %]
448
    [% Asset.js("lib/jquery/plugins/jquery.fixFloat.js") %]
448
    [% Asset.js("lib/jquery/plugins/jquery.insertatcaret.js") %]
449
    [% Asset.js("lib/jquery/plugins/jquery.insertatcaret.js") %]
449
    <script type="text/javascript">
450
    <script>
450
        $(document).ready(function() {
451
        var no_op_set = '[% no_op_set %]';
451
            [% IF add_form or copy_form %]
452
        var interface = '[% interface %]';
452
                $('#toolbar').fixFloat();
453
        var theme = '[% theme %]';
453
            [% END %]
454
        var add_form = '[% add_form %]';
454
            $("#lettert:has(tbody tr)").dataTable($.extend(true, {}, dataTablesDefaults, {
455
        var copy_form = '[% copy_form %]';
455
                "sDom": 't',
456
        var code = '[% code %]';
456
                "aoColumnDefs": [
457
        var new_lettercode = '[% new_lettercode %]';
457
                    { "bSortable": false, "bSearchable": false, 'aTargets': [ 'nosort' ] }
458
        var new_branchcode = '[% new_branchcode %]';
458
                ],
459
        var MSG_CODE_EXISTS = _("A default letter with the code '%s' already exists.");
459
                "bPaginate": false
460
        var MSG_CODE_EXISTS_FOR_LIBRARY = _("A letter with the code '%s' already exists for '%s'.");
460
            }));
461
        var MSG_EMPTY_TITLE_AND_CONTENT = _("Please specify title and content for %s");
461
            [% IF no_op_set %]
462
        var MSG_EMPTY_TEMPLATES = _("Please fill at least one template.");
462
                $('#branch').change(function() {
463
        var MSG_LOADING = _("Loading");
463
                    $('#op').val("");
464
     </script>
464
                    $('#selectlibrary').submit();
465
    [% Asset.js("js/letter.js") %]
465
                });
466
                $('#newnotice').click(function() {
467
                    $('#op').val("add_form");
468
                    return true;
469
                });
470
            [% END %]
471
472
            $("#newmodule").on("change",function(){
473
                if( $("#branch").val() == ""){
474
                    var branchcode = "*";
475
                } else {
476
                    var branchcode = $("#branch").val();
477
                }
478
                window.location.href = "/cgi-bin/koha/tools/letter.pl?op=add_form&module=" + $(this).val() + "&branchcode=" + branchcode;
479
            });
480
481
            $("#submit_form").click( function(event) {
482
                event.preventDefault();
483
                var at_least_one_exists = 0;
484
                var are_valid = 1;
485
                $("fieldset.mtt").each( function(){
486
                    var title = $(this).find('input[name="title"]').val();
487
                    var content = $(this).find('textarea[name="content"]').val();
488
                    if (
489
                            ( title.length == 0 && content.length > 0 )
490
                         || ( title.length > 0 && content.length == 0 )
491
                    ) {
492
                        var mtt = $(this).find('input[name="message_transport_type"]').val();
493
                        var msg = _("Please specify title and content for %s");
494
                        msg = msg.replace( "%s", mtt );
495
                        at_least_one_exists = 1;
496
                        alert(msg);
497
                        return are_valid = false;
498
                    } else if ( title.length > 0 && content.length > 0 ) {
499
                        at_least_one_exists = 1;
500
                    }
501
                } );
502
                if ( ! at_least_one_exists ) {
503
                    alert( _("Please fill at least one template.") );
504
                    return false;
505
                }
506
                if ( ! are_valid ) {
507
                    return false;
508
                }
509
510
                // Test if code already exists in DB
511
                var new_lettercode = $("#code").val();
512
                var new_branchcode = $("#branch").val();
513
                [% IF ( add_form and code ) # IF edit %]
514
                    if ( new_lettercode != '[% code %]' ) {
515
                [% END %]
516
                    $.ajax({
517
                        data: { code: new_lettercode, branchcode: new_branchcode },
518
                        type: 'GET',
519
                        url: '/cgi-bin/koha/svc/letters/get/',
520
                        success: function (data) {
521
                             if ( data.letters.length > 0 ) {
522
                                 if( new_branchcode == '' ) {
523
                                     alert( _("A default letter with the code '%s' already exists.").format(new_lettercode) );
524
                                 } else {
525
                                     alert( _("A letter with the code '%s' already exists for '%s'.").format(new_lettercode, new_branchcode) );
526
                                 }
527
                                 return false;
528
                             } else {
529
                                 $("#add_notice").submit();
530
                             }
531
                        },
532
                    });
533
                [% IF ( add_form and code ) %]
534
                    } else {
535
                        $("#add_notice").submit();
536
                    }
537
                [% END %]
538
            });
539
540
            var sms_limit = 160;
541
            $(".content_sms").on("keyup", function(){
542
                var length = $(this).val().length;
543
                var sms_counter = ("#sms_counter_" + $(this).data('lang'));
544
                $(sms_counter).html(length + "/" + sms_limit + _(" characters"));
545
                if ( length  > sms_limit ) {
546
                    $(sms_counter).css("color", "red");
547
                } else {
548
                    $(sms_counter).css("color", "black");
549
                }
550
            });
551
            $( ".transport-types" ).accordion({ collapsible: true, active:false, animate: 200 });
552
            $(".insert").on("click",function(){
553
                var containerid = $(this).data("containerid");
554
                insertValueQuery( containerid );
555
            })
556
557
            $("#tabs").tabs();
558
559
            $("#saveandcontinue").on("click",function(e){
560
                e.preventDefault();
561
                $("#redirect").val("just_save");
562
                $("#submit_form").click();
563
            });
564
565
            $("body").on("click", ".preview_template", function(e){
566
                e.preventDefault();
567
                var mtt = $(this).data("mtt");
568
                var lang = $(this).data("lang");
569
570
                var code = $("#code").val();
571
                var content = $("#content_"+mtt+"_"+lang).val();
572
                var title = $("#title_"+mtt+"_"+lang).val();
573
574
                var is_html = $("#is_html_"+mtt+"_"+lang).val();
575
                var page = $(this).attr("href");
576
                var data_preview = $("#data_preview").val();
577
                page += '?code='+encodeURIComponent(code);
578
                page += '&title='+encodeURIComponent(title);
579
                page += '&content='+encodeURIComponent(content);
580
                page += '&data_preview='+encodeURIComponent(data_preview);
581
                page += '&is_html='+encodeURIComponent(is_html);
582
                $("#preview_template .modal-body").load(page);
583
                $('#preview_template').modal('show');
584
                $("#preview_template_button").attr("href", "/cgi-bin/koha/svc/letters/convert?code="+code+"&mtt="+mtt+"&lang="+lang);
585
            });
586
            $("#preview_template").on("hidden", function(){
587
                $("#preview_template_label").html("");
588
                $("#preview_template .modal-body").html("<div id=\"loading\"><img src=\"[% interface %]/[% theme %]/img/spinner-small.gif\" alt=\"\" /> "+_("Loading")+"</div>");
589
            });
590
            $("body").on("click", "#convert_template", function(e){
591
                e.preventDefault();
592
                var mtt = $(this).data("mtt");
593
                var lang = $(this).data("lang");
594
595
                var code = $("#code").val();
596
                var content = $("#content_"+mtt+"_"+lang).val();
597
                var title = $("#title_"+mtt+"_"+lang).val();
598
599
                var is_html = $("#is_html_"+mtt+"_"+lang).val();
600
                var page = $(this).attr("href");
601
                var data_preview = $("#data_preview").val();
602
                page += '?code='+encodeURIComponent(code);
603
                page += '&title='+encodeURIComponent(title);
604
                page += '&content='+encodeURIComponent(content);
605
                page += '&data_preview='+encodeURIComponent(data_preview);
606
                page += '&is_html='+encodeURIComponent(is_html);
607
                $("#preview_template .modal-body").load(page + " div");
608
                $('#preview_template').modal('show');
609
                $("#preview_template_button").attr("href", "/cgi-bin/koha/svc/letters/convert?code="+code+"&branchcode="+branchcode+"&mtt="+mtt+"&lang="+lang);
610
            });
611
            $("#convert_template").on("hidden", function(){
612
                $("#convert_template_label").html("");
613
                $("#convert_template .modal-body").html("<div id=\"loading\"><img src=\"[% interface %]/[% theme %]/img/spinner-small.gif\" alt=\"\" /> "+_("Loading")+"</div>");
614
            });
615
616
        });
617
        [% IF add_form or copy_form %]
618
            function cancel(f) {
619
                $('#op').val("");
620
                f.method = "get";
621
                f.submit();
622
            }
623
624
            function isNotNull(f,noalert) {
625
              if (f.value.length ==0) {
626
                  return false;
627
              }
628
              return true;
629
            }
630
631
            function isNum(v,maybenull) {
632
                var n = new Number(v.value);
633
                if (isNaN(n)) {
634
                    return false;
635
                }
636
                if (maybenull==0 && v.value==''){
637
                  return false;
638
                }
639
                return true;
640
            }
641
            function insertValueQuery(containerid) {
642
                var fieldset = $("#" + containerid);
643
                var myQuery = $(fieldset).find('textarea[name="content"]');
644
                var myListBox = $(fieldset).find('select[name="SQLfieldname"]');
645
646
                if($(myListBox).find('option').length > 0) {
647
                    $(myListBox).find('option').each( function (){
648
                        if ( $(this).attr('selected') && $(this).val().length > 0 ) {
649
                            $(myQuery).insertAtCaret("<<" + $(this).val() + ">>");
650
                        }
651
                    });
652
                }
653
            }
654
        [% END %]
655
    </script>
656
[% END %]
466
[% END %]
657
467
658
[% INCLUDE 'intranet-bottom.inc' %]
468
[% INCLUDE 'intranet-bottom.inc' %]
(-)a/koha-tmpl/intranet-tmpl/prog/en/modules/tools/preview_letter.tt (-18 / +38 lines)
Lines 29-55 Link Here
29
            [% END %]
29
            [% END %]
30
30
31
            [% IF rendered_message %]
31
            [% IF rendered_message %]
32
                <fieldset class="brief">
32
                <div class="yui-g">
33
                    <legend>Original version</legend>
33
                    <div class="yui-u first">
34
                    <pre>[% original_content | html %]</pre>
34
                        <h3>Original version</h3>
35
                </fieldset>
35
                        <span style="font-family:monospace">
36
36
                            [% FILTER html_line_break %]
37
                <fieldset class="brief">
37
                                [% original_content | html %]
38
                    <legend>Rendered message:</legend>
38
                            [% END %]
39
                    <pre>[% rendered_message.content | html %]</pre>
39
                        </span>
40
                </fieldset>
40
                    </div>
41
                    <div class="yui-u">
42
                        <h3>Original message, rendered:</h3>
43
                        <span style="font-family:monospace">
44
                            [% FILTER html_line_break %]
45
                                [% rendered_message.content | html %]
46
                            [% END %]
47
                        </span>
48
                    </div>
49
                </div>
41
            [% END %]
50
            [% END %]
42
51
43
            [% IF rendered_tt_message %]
44
                <fieldset class="brief">
45
                    <legend>Converted version</legend>
46
                    <pre>[% tt_content | html %]</pre>
47
                </fieldset>
48
52
49
                <fieldset class="brief">
53
            [% IF rendered_tt_message %]
50
                    <legend>Rendered message:</legend>
54
            <hr />
51
                    <pre>[% rendered_tt_message.content | html %]</pre>
55
                <div class="yui-g">
52
                </fieldset>
56
                    <div class="yui-u first">
57
                        <h3>Converted version</h3>
58
                        <span style="font-family:monospace">
59
                            [% FILTER html_line_break %]
60
                                [% tt_content | html %]
61
                            [% END %]
62
                        </span>
63
                    </div>
64
                    <div class="yui-u">
65
                        <h3>Converted message, rendered:</h3>
66
                        <span style="font-family:monospace">
67
                            [% FILTER html_line_break %]
68
                                [% rendered_tt_message.content | html %]
69
                            [% END %]
70
                        </span>
71
                    </div>
72
                </div>
53
            [% END %]
73
            [% END %]
54
        </div>
74
        </div>
55
75
(-)a/koha-tmpl/intranet-tmpl/prog/js/letter.js (-1 / +183 lines)
Line 0 Link Here
0
- 
1
/* Variables defined in letter.tt: */
2
/* global _ module add_form copy_form dataTablesDefaults no_op_set MSG_EMPTY_TITLE_AND_CONTENT MSG_EMPTY_TEMPLATES code MSG_CODE_EXISTS MSG_CODE_EXISTS_FOR_LIBRARY MSG_DT_LOADING_RECORDS interface theme */
3
4
var modal_loading = "<div id=\"loading\"><img src=\"" + interface + "/" + theme + "/img/spinner-small.gif\" alt=\"\" /> "+ MSG_DT_LOADING_RECORDS +"</div>";
5
6
var editing = 0;
7
if( add_form == 1 && code !== '' ){
8
    editing = 1;
9
}
10
11
function checkCodes( new_lettercode, new_branchcode ){
12
    $(".spinner").show();
13
    return $.ajax({
14
        data: { code: new_lettercode, branchcode: new_branchcode },
15
        type: 'GET',
16
        url: '/cgi-bin/koha/svc/letters/get/',
17
        async: !1,
18
        success: function (data) {
19
            if ( data.letters.length > 0 ) {
20
                if( new_branchcode === '' ) {
21
                    alert( MSG_CODE_EXISTS.format(new_lettercode));
22
                } else {
23
                    alert( MSG_CODE_EXISTS_FOR_LIBRARY.format(new_lettercode, new_branchcode) );
24
                }
25
                $(".spinner").hide();
26
            } else {
27
                $(".spinner").hide();
28
            }
29
        }
30
    });
31
}
32
33
$(document).ready(function() {
34
    if( add_form || copy_form ){
35
        $('#toolbar').fixFloat();
36
    }
37
38
    $("#lettert:has(tbody tr)").dataTable($.extend(true, {}, dataTablesDefaults, {
39
        "sDom": 't',
40
        "aoColumnDefs": [
41
            { "bSortable": false, "bSearchable": false, 'aTargets': [ 'nosort' ] }
42
        ],
43
        "bPaginate": false
44
    }));
45
46
    if( no_op_set ){
47
        $('#branch').change(function() {
48
            $('#op').val("");
49
            $('#selectlibrary').submit();
50
        });
51
        $('#newnotice').click(function() {
52
            $('#op').val("add_form");
53
            return true;
54
        });
55
    }
56
57
    $("#newmodule").on("change",function(){
58
        var branchcode;
59
        if( $("#branch").val() === ""){
60
            branchcode = "*";
61
        } else {
62
            branchcode = $("#branch").val();
63
        }
64
        window.location.href = "/cgi-bin/koha/tools/letter.pl?op=add_form&module=" + $(this).val() + "&branchcode=" + branchcode;
65
    });
66
67
    $("#submit_form").on("click",function(){
68
        $("#add_notice").submit();
69
    });
70
71
    $("#add_notice").validate({
72
        submitHandler: function(form){
73
            var at_least_one_exists = 0;
74
            var are_valid = 1;
75
            $("fieldset.mtt").each( function(){
76
                var title = $(this).find('input[name="title"]').val();
77
                var content = $(this).find('textarea[name="content"]').val();
78
                if (
79
                    ( title.length === 0 && content.length > 0 ) || ( title.length > 0 && content.length === 0 )
80
                ) {
81
                    var mtt = $(this).find('input[name="message_transport_type"]').val();
82
                    at_least_one_exists = 1; // Only one template has to be filled in for form to be valid
83
                    alert( MSG_EMPTY_TITLE_AND_CONTENT.format( mtt ) );
84
                    are_valid = 0;
85
                } else if ( title.length > 0 && content.length > 0 ) {
86
                    at_least_one_exists = 1;
87
                }
88
            });
89
90
            if ( ! at_least_one_exists ) {
91
                // No templates were filled out
92
                alert( MSG_EMPTY_TEMPLATES );
93
                return false;
94
            }
95
96
            if ( ! are_valid ){
97
                return false;
98
            }
99
100
            // Test if code already exists in DB
101
            if( editing == 1 ){ // This is an edit operation
102
                // We don't need to check for an existing Code
103
            } else {
104
                var new_lettercode = $("#code").val();
105
                var new_branchcode = $("#branch").val();
106
                var code_check = checkCodes( new_lettercode, new_branchcode );
107
                if( code_check.responseJSON.letters.length > 0 ){
108
                    return false;
109
                }
110
            }
111
            form.submit();
112
        }
113
    });
114
115
    var sms_limit = 160;
116
    $(".content_sms").on("keyup", function(){
117
        var length = $(this).val().length;
118
        var sms_counter = ("#sms_counter_" + $(this).data('lang'));
119
        $(sms_counter).html(length + "/" + sms_limit + _(" characters"));
120
        if ( length  > sms_limit ) {
121
            $(sms_counter).css("color", "red");
122
        } else {
123
            $(sms_counter).css("color", "black");
124
        }
125
    });
126
127
    $( ".transport-types" ).accordion({ collapsible: true, active:false, animate: 200 });
128
129
    $(".insert").on("click",function(){
130
        var containerid = $(this).data("containerid");
131
        insertValueQuery( containerid );
132
    });
133
134
    $("#saveandcontinue").on("click",function(e){
135
        e.preventDefault();
136
        $("#redirect").val("just_save");
137
        $("#submit_form").click();
138
    });
139
140
    $("#tabs").tabs();
141
142
    $("body").on("click", ".preview_template", function(e){
143
        e.preventDefault();
144
        var mtt = $(this).data("mtt");
145
        var lang = $(this).data("lang");
146
147
        var code = $("#code").val();
148
        var content = $("#content_"+mtt+"_"+lang).val();
149
        var title = $("#title_"+mtt+"_"+lang).val();
150
151
        var is_html = $("#is_html_"+mtt+"_"+lang).val();
152
        var page = $(this).attr("href");
153
        var data_preview = $("#data_preview").val();
154
        page += '?code='+encodeURIComponent(code);
155
        page += '&title='+encodeURIComponent(title);
156
        page += '&content='+encodeURIComponent(content);
157
        page += '&data_preview='+encodeURIComponent(data_preview);
158
        page += '&is_html='+encodeURIComponent(is_html);
159
        $("#preview_template .modal-body").load(page + " #main");
160
        $('#preview_template').modal('show');
161
        $("#preview_template_button").attr("href", "/cgi-bin/koha/svc/letters/convert?module="+module+"&code="+code+"&mtt="+mtt+"&lang="+lang);
162
    });
163
164
    $("#preview_template").on("hidden.bs.modal", function(){
165
        $("#preview_template_label").html("");
166
        $("#preview_template .modal-body").html( modal_loading );
167
    });
168
169
    function insertValueQuery(containerid) {
170
        var fieldset = $("#" + containerid);
171
        var myQuery = $(fieldset).find('textarea[name="content"]');
172
        var myListBox = $(fieldset).find('select[name="SQLfieldname"]');
173
174
        if($(myListBox).find('option').length > 0) {
175
            $(myListBox).find('option').each( function (){
176
                if ( $(this).attr('selected') && $(this).val().length > 0 ) {
177
                    $(myQuery).insertAtCaret("<<" + $(this).val() + ">>");
178
                }
179
            });
180
        }
181
    }
182
183
});

Return to bug 18007