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

(-)a/koha-tmpl/intranet-tmpl/prog/en/modules/tools/letter.tt (-202 / +26 lines)
Lines 4-212 Link Here
4
<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>
4
<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>
5
[% INCLUDE 'doc-head-close.inc' %]
5
[% INCLUDE 'doc-head-close.inc' %]
6
<link rel="stylesheet" type="text/css" href="[% interface %]/[% theme %]/css/datatables.css" />
6
<link rel="stylesheet" type="text/css" href="[% interface %]/[% theme %]/css/datatables.css" />
7
<style type="text/css">#preview_template .modal-dialog { width : 80%; } .spinner { display: none; } @media (max-width: 767px) { #preview_template { margin: 0; width : auto; } }</style>
7
[% INCLUDE 'datatables.inc' %]
8
[% INCLUDE 'datatables.inc' %]
8
<script type="text/javascript" src="[% interface %]/lib/jquery/plugins/jquery.insertatcaret.js"></script>
9
<script type="text/javascript" src="[% interface %]/lib/jquery/plugins/jquery.insertatcaret.js"></script>
9
<script type="text/javascript">
10
<script type="text/javascript">
10
//<![CDATA[
11
    var no_op_set = '[% no_op_set %]';
11
$(document).ready(function() {
12
    var interface = '[% interface %]';
12
    $("#lettert:has(tbody tr)").dataTable($.extend(true, {}, dataTablesDefaults, {
13
    var theme = '[% theme %]';
13
        "sDom": 't',
14
    var add_form = '[% add_form %]';
14
        "aoColumnDefs": [
15
    var code = '[% code %]';
15
            { "bSortable": false, "bSearchable": false, 'aTargets': [ 'nosort' ] }
16
    var new_lettercode = '[% new_lettercode %]';
16
        ],
17
    var new_branchcode = '[% new_branchcode %]';
17
        "bPaginate": false
18
    var MSG_CODE_EXISTS = _("A default letter with the code '%s' already exists.");
18
    }));
19
    var MSG_CODE_EXISTS_FOR_LIBRARY = _("A letter with the code '%s' already exists for '%s'.");
19
    [% IF no_op_set %]
20
    var MSG_EMPTY_TITLE_AND_CONTENT = _("Please specify title and content for %s");
20
      $('#branch').change(function() {
21
    var MSG_EMPTY_TEMPLATES = _("Please fill at least one template.");
21
            $('#op').val("");
22
</script>
22
            $('#selectlibrary').submit();
23
<script type="text/javascript" src="[% interface %]/[% theme %]/js/letter.js"></script>
23
      });
24
      $('#newnotice').click(function() {
25
            $('#op').val("add_form");
26
            return true;
27
      });
28
    [% END %]
29
30
    $("#newmodule").on("change",function(){
31
        if( $("#branch").val() == ""){
32
            var branchcode = "*";
33
        } else {
34
            var branchcode = $("#branch").val();
35
        }
36
        window.location.href = "/cgi-bin/koha/tools/letter.pl?op=add_form&module=" + $(this).val() + "&branchcode=" + branchcode;
37
    });
38
39
    $("#submit_form").click( function(event) {
40
        event.preventDefault();
41
        var at_least_one_exists = 0;
42
        var are_valid = 1;
43
        $("fieldset.mtt").each( function(){
44
            var title = $(this).find('input[name="title"]').val();
45
            var content = $(this).find('textarea[name="content"]').val();
46
            if (
47
                    ( title.length == 0 && content.length > 0 )
48
                 || ( title.length > 0 && content.length == 0 )
49
            ) {
50
                var mtt = $(this).find('input[name="message_transport_type"]').val();
51
                var msg = _("Please specify title and content for %s");
52
                msg = msg.replace( "%s", mtt );
53
                at_least_one_exists = 1;
54
                alert(msg);
55
                return are_valid = false;
56
            } else if ( title.length > 0 && content.length > 0 ) {
57
                at_least_one_exists = 1;
58
            }
59
        } );
60
        if ( ! at_least_one_exists ) {
61
            alert( _("Please fill at least one template.") );
62
            return false;
63
        }
64
        if ( ! are_valid ) {
65
            return false;
66
        }
67
68
        // Test if code already exists in DB
69
        var new_lettercode = $("#code").val();
70
        var new_branchcode = $("#branch").val();
71
        [% IF ( add_form and code ) # IF edit %]
72
          if ( new_lettercode != '[% code %]' ) {
73
        [% END %]
74
          $.ajax({
75
            data: { code: new_lettercode, branchcode: new_branchcode },
76
            type: 'GET',
77
            url: '/cgi-bin/koha/svc/letters/get/',
78
            success: function (data) {
79
              if ( data.letters.length > 0 ) {
80
                if( new_branchcode == '' ) {
81
                    alert( _("A default letter with the code '%s' already exists.").format(new_lettercode) );
82
                } else {
83
                    alert( _("A letter with the code '%s' already exists for '%s'.").format(new_lettercode, new_branchcode) );
84
                }
85
                return false;
86
              } else {
87
                $("#add_notice").submit();
88
              }
89
            },
90
          });
91
        [% IF ( add_form and code ) %]
92
          } else {
93
            $("#add_notice").submit();
94
          }
95
        [% END %]
96
    });
97
98
    var sms_limit = 160;
99
    $("#content_sms").on("keyup", function(){
100
        var length = $(this).val().length;
101
        $("#sms_counter").html(length + "/" + sms_limit + _(" characters"));
102
        if ( length  > sms_limit ) {
103
            $("#sms_counter").css("color", "red");
104
        } else {
105
            $("#sms_counter").css("color", "black");
106
        }
107
    });
108
    $( ".transport-types" ).accordion({ collapsible: true, active:false, animate: 200 });
109
    $(".insert").on("click",function(){
110
        var containerid = $(this).data("containerid");
111
        insertValueQuery( containerid );
112
    })
113
114
    $("#tabs").tabs();
115
116
    $("body").on("click", ".preview_template", function(e){
117
        e.preventDefault();
118
        var mtt = $(this).data("mtt");
119
        var lang = $(this).data("lang");
120
121
        var code = $("#code").val();
122
        var content = $("#content_"+mtt+"_"+lang).val();
123
        var title = $("#title_"+mtt+"_"+lang).val();
124
125
        var is_html = $("#is_html_"+mtt+"_"+lang).val();
126
        var page = $(this).attr("href");
127
        var data_preview = $("#data_preview").val();
128
        page += '?code='+encodeURIComponent(code);
129
        page += '&title='+encodeURIComponent(title);
130
        page += '&content='+encodeURIComponent(content);
131
        page += '&data_preview='+encodeURIComponent(data_preview);
132
        page += '&is_html='+encodeURIComponent(is_html);
133
        $("#preview_template .modal-body").load(page);
134
        $('#preview_template').modal('show');
135
        $("#preview_template_button").attr("href", "/cgi-bin/koha/svc/letters/convert?module="+module+"&code="+code+"&mtt="+mtt+"&lang="+lang);
136
    });
137
    $("#preview_template").on("hidden", function(){
138
        $("#preview_template_label").html("");
139
        $("#preview_template .modal-body").html("<div id=\"loading\"><img src=\"[% interface %]/[% theme %]/img/spinner-small.gif\" alt=\"\" /> "+_("Loading")+"</div>");
140
    });
141
    $("body").on("click", "#convert_template", function(e){
142
        e.preventDefault();
143
        var mtt = $(this).data("mtt");
144
        var lang = $(this).data("lang");
145
146
        var code = $("#code").val();
147
        var content = $("#content_"+mtt+"_"+lang).val();
148
        var title = $("#title_"+mtt+"_"+lang).val();
149
150
        var is_html = $("#is_html_"+mtt+"_"+lang).val();
151
        var page = $(this).attr("href");
152
        var data_preview = $("#data_preview").val();
153
        page += '?code='+encodeURIComponent(code);
154
        page += '&title='+encodeURIComponent(title);
155
        page += '&content='+encodeURIComponent(content);
156
        page += '&data_preview='+encodeURIComponent(data_preview);
157
        page += '&is_html='+encodeURIComponent(is_html);
158
        $("#preview_template .modal-body").load(page + " div");
159
        $('#preview_template').modal('show');
160
        $("#preview_template_button").attr("href", "/cgi-bin/koha/svc/letters/convert?module="+module+"&code="+code+"&branchcode="+branchcode+"&mtt="+mtt+"&lang="+lang);
161
    });
162
    $("#convert_template").on("hidden", function(){
163
        $("#convert_template_label").html("");
164
        $("#convert_template .modal-body").html("<div id=\"loading\"><img src=\"[% interface %]/[% theme %]/img/spinner-small.gif\" alt=\"\" /> "+_("Loading")+"</div>");
165
    });
166
167
});
168
[% IF add_form or copy_form %]
169
	
170
    function cancel(f) {
171
        $('#op').val("");
172
        f.method = "get";
173
        f.submit();
174
    }
175
176
		function isNotNull(f,noalert) {
177
			if (f.value.length ==0) {
178
	return false;
179
			}
180
			return true;
181
		}
182
183
		function isNum(v,maybenull) {
184
		var n = new Number(v.value);
185
		if (isNaN(n)) {
186
			return false;
187
			}
188
		if (maybenull==0 && v.value=='') {
189
			return false;
190
		}
191
		return true;
192
		}
193
        function insertValueQuery(containerid) {
194
            var fieldset = $("#" + containerid);
195
            var myQuery = $(fieldset).find('textarea[name="content"]');
196
            var myListBox = $(fieldset).find('select[name="SQLfieldname"]');
197
198
            if($(myListBox).find('option').length > 0) {
199
                $(myListBox).find('option').each( function (){
200
                    if ( $(this).attr('selected') && $(this).val().length > 0 ) {
201
                        $(myQuery).insertAtCaret("<<" + $(this).val() + ">>");
202
                    }
203
                });
204
            }
205
        }
206
	[% END %]
207
		//]]>
208
		</script>
209
</head>
24
</head>
25
210
<body id="tools_letter" class="tools">
26
<body id="tools_letter" class="tools">
211
[% INCLUDE 'header.inc' %]
27
[% INCLUDE 'header.inc' %]
212
[% INCLUDE 'letters-search.inc' %]
28
[% INCLUDE 'letters-search.inc' %]
Lines 330-336 $(document).ready(function() { Link Here
330
	
146
	
331
[% IF add_form or copy_form %]
147
[% IF add_form or copy_form %]
332
<h1>[% IF ( modify ) %]Modify notice[% ELSE %]Add notice[% END %]</h1>
148
<h1>[% IF ( modify ) %]Modify notice[% ELSE %]Add notice[% END %]</h1>
333
        <form id="add_notice" name="Aform" method="post" enctype="multipart/form-data" class="validate">
149
        <form id="add_notice" name="Aform" method="post" enctype="multipart/form-data">
334
        [% IF add_form %]
150
        [% IF add_form %]
335
          <input type="hidden" name="op" id="op" value="add_validate" />
151
          <input type="hidden" name="op" id="op" value="add_validate" />
336
        [% ELSE %]
152
        [% ELSE %]
Lines 539-545 $(document).ready(function() { Link Here
539
                        <td class="actions">
355
                        <td class="actions">
540
                            <button type="button" data-containerid="[% letter.message_transport_type %]_[% lang %]" class="btn btn-default btn-sm insert">Insert <i class="fa fa-long-arrow-right"></i></button>
356
                            <button type="button" data-containerid="[% letter.message_transport_type %]_[% lang %]" class="btn btn-default btn-sm insert">Insert <i class="fa fa-long-arrow-right"></i></button>
541
                        </td>
357
                        </td>
542
                      <td><textarea name="content" id="content_[% letter.message_transport_type %]_[% lang %]" cols="80" rows="15">[% letter.content %]</textarea></td>
358
                      <td><textarea name="content" data-lang="[% lang %]" id="content_[% letter.message_transport_type %]_[% lang %]" cols="80" rows="15">[% letter.content %]</textarea></td>
543
                    </tr>
359
                    </tr>
544
                  </table>
360
                  </table>
545
                </li>
361
                </li>
Lines 559-565 $(document).ready(function() { Link Here
559
        [% END %]
375
        [% END %]
560
376
561
        [% IF code.search('DGST') %] <span class="overdue">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.</span> [% END %]
377
        [% IF code.search('DGST') %] <span class="overdue">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.</span> [% END %]
562
        <fieldset class="action"><input type="submit" id="submit_form" value="Submit" class="button" /> <a class="cancel" href="/cgi-bin/koha/tools/letter.pl">Cancel</a></fieldset>
378
        <fieldset class="action">
379
            <button type="submit" id="submit_form">
380
                <span class="spinner" style="display:none">
381
                    <img src="[% interface %]/[% theme %]/img/spinner-small.gif" alt="" />
382
                </span>
383
                Submit
384
            </button>
385
            <a class="cancel" href="/cgi-bin/koha/tools/letter.pl">Cancel</a>
386
        </fieldset>
563
      <input type="hidden" name="searchfield" value="[% searchfield %]" />
387
      <input type="hidden" name="searchfield" value="[% searchfield %]" />
564
    </form>
388
    </form>
565
[% END %]
389
[% END %]
(-)a/koha-tmpl/intranet-tmpl/prog/en/modules/tools/preview_letter.tt (-18 / +40 lines)
Lines 3-9 Link Here
3
    <meta http-equiv="Content-Type" content="text/html; charset=utf-8" />
3
    <meta http-equiv="Content-Type" content="text/html; charset=utf-8" />
4
    </head>
4
    </head>
5
    <body id="preview_letter" class="catalog">
5
    <body id="preview_letter" class="catalog">
6
6
        <div id="main">
7
        <div id="main">
8
7
            [% FOR m IN messages %]
9
            [% FOR m IN messages %]
8
                [%# FIXME The message block does not appear at the top of the modal! %]
10
                [%# FIXME The message block does not appear at the top of the modal! %]
9
                <div class="dialog [% m.type %]">
11
                <div class="dialog [% m.type %]">
Lines 29-55 Link Here
29
            [% END %]
31
            [% END %]
30
32
31
            [% IF rendered_message %]
33
            [% IF rendered_message %]
32
                <fieldset class="brief">
34
                <div class="yui-g">
33
                    <legend>Original version</legend>
35
                    <div class="yui-u first">
34
                    <pre>[% original_content | html %]</pre>
36
                        <h3>Original version</h3>
35
                </fieldset>
37
                        <span style="font-family:monospace">
36
38
                            [% FILTER html_line_break %]
37
                <fieldset class="brief">
39
                                [% original_content | html %]
38
                    <legend>Rendered message:</legend>
40
                            [% END %]
39
                    <pre>[% rendered_message.content | html %]</pre>
41
                        </span>
40
                </fieldset>
42
                    </div>
43
                    <div class="yui-u">
44
                        <h3>Converted version</h3>
45
                        <span style="font-family:monospace">
46
                            [% FILTER html_line_break %]
47
                                [% tt_content | html %]
48
                            [% END %]
49
                        </span>
50
                    </div>
51
                </div>
41
            [% END %]
52
            [% END %]
42
53
43
            [% IF rendered_tt_message %]
54
            <hr />
44
                <fieldset class="brief">
45
                    <legend>Converted version</legend>
46
                    <pre>[% tt_content | html %]</pre>
47
                </fieldset>
48
55
49
                <fieldset class="brief">
56
            [% IF rendered_tt_message %]
50
                    <legend>Rendered message:</legend>
57
                <div class="yui-g">
51
                    <pre>[% rendered_tt_message.content | html %]</pre>
58
                    <div class="yui-u first">
52
                </fieldset>
59
                        <h3>Original message, rendered:</h3>
60
                        <span style="font-family:monospace">
61
                            [% FILTER html_line_break %]
62
                                [% rendered_message.content | html %]
63
                            [% END %]
64
                        </span>
65
                    </div>
66
                    <div class="yui-u">
67
                        <h3>Converted message, rendered:</h3>
68
                        <span style="font-family:monospace">
69
                            [% FILTER html_line_break %]
70
                                [% rendered_tt_message.content | html %]
71
                            [% END %]
72
                        </span>
73
                    </div>
74
                </div>
53
            [% END %]
75
            [% END %]
54
        </div>
76
        </div>
55
77
(-)a/koha-tmpl/intranet-tmpl/prog/js/letter.js (-1 / +166 lines)
Line 0 Link Here
0
- 
1
var modal_loading = "<div id=\"loading\"><img src=\"" + interface + "/" + theme + "/img/spinner-small.gif\" alt=\"\" /> "+ MSG_DT_LOADING_RECORDS +"</div>";
2
3
var editing = 0;
4
if( add_form == 1 && code !== '' ){
5
    editing = 1;
6
}
7
8
function checkCodes( new_lettercode, new_branchcode ){
9
    $(".spinner").show();
10
    return $.ajax({
11
        data: { code: new_lettercode, branchcode: new_branchcode },
12
        type: 'GET',
13
        url: '/cgi-bin/koha/svc/letters/get/',
14
        async: !1,
15
        success: function (data) {
16
            if ( data.letters.length > 0 ) {
17
                if( new_branchcode === '' ) {
18
                    alert( MSG_CODE_EXISTS.format(new_lettercode));
19
                } else {
20
                    alert( MSG_CODE_EXISTS_FOR_LIBRARY.format(new_lettercode, new_branchcode) );
21
                }
22
                $(".spinner").hide();
23
            } else {
24
                $(".spinner").hide();
25
            }
26
        }
27
    });
28
}
29
30
$(document).ready(function() {
31
    $("#lettert:has(tbody tr)").dataTable($.extend(true, {}, dataTablesDefaults, {
32
        "sDom": 't',
33
        "aoColumnDefs": [
34
            { "bSortable": false, "bSearchable": false, 'aTargets': [ 'nosort' ] }
35
        ],
36
        "bPaginate": false
37
    }));
38
39
    if( no_op_set ){
40
      $('#branch').change(function() {
41
            $('#op').val("");
42
            $('#selectlibrary').submit();
43
      });
44
      $('#newnotice').click(function() {
45
            $('#op').val("add_form");
46
            return true;
47
      });
48
    }
49
50
    $("#newmodule").on("change",function(){
51
        var branchcode;
52
        if( $("#branch").val() === ""){
53
            branchcode = "*";
54
        } else {
55
            branchcode = $("#branch").val();
56
        }
57
        window.location.href = "/cgi-bin/koha/tools/letter.pl?op=add_form&module=" + $(this).val() + "&branchcode=" + branchcode;
58
    });
59
60
    $("#add_notice").validate({
61
        submitHandler: function(form){
62
            var at_least_one_exists = 0;
63
            var are_valid = 1;
64
            $("fieldset.mtt").each( function(){
65
                var title = $(this).find('input[name="title"]').val();
66
                var content = $(this).find('textarea[name="content"]').val();
67
                if (
68
                    ( title.length === 0 && content.length > 0 ) || ( title.length > 0 && content.length === 0 )
69
                ) {
70
                    var mtt = $(this).find('input[name="message_transport_type"]').val();
71
                    at_least_one_exists = 1; // Only one template has to be filled in for form to be valid
72
                    alert( MSG_EMPTY_TITLE_AND_CONTENT.format( mtt ) );
73
                    are_valid = 0;
74
                } else if ( title.length > 0 && content.length > 0 ) {
75
                    at_least_one_exists = 1;
76
                }
77
            });
78
79
            if ( ! at_least_one_exists ) {
80
                // No templates were filled out
81
                alert( MSG_EMPTY_TEMPLATES );
82
                return false;
83
            }
84
85
            if ( ! are_valid ){
86
                return false;
87
            }
88
89
            // Test if code already exists in DB
90
            if( editing == 1 ){ // This is an edit operation
91
                // We don't need to check for an existing Code
92
            } else {
93
                var new_lettercode = $("#code").val();
94
                var new_branchcode = $("#branch").val();
95
                var code_check = checkCodes( new_lettercode, new_branchcode );
96
                if( code_check.responseJSON.letters.length > 0 ){
97
                    return false;
98
                }
99
                return false;
100
            }
101
            form.submit();
102
        }
103
    });
104
105
    var sms_limit = 160;
106
    $("#content_sms").on("keyup", function(){
107
        var length = $(this).val().length;
108
        $("#sms_counter").html(length + "/" + sms_limit + _(" characters"));
109
        if ( length  > sms_limit ) {
110
            $("#sms_counter").css("color", "red");
111
        } else {
112
            $("#sms_counter").css("color", "black");
113
        }
114
    });
115
116
    $( ".transport-types" ).accordion({ collapsible: true, active:false, animate: 200 });
117
118
    $(".insert").on("click",function(){
119
        var containerid = $(this).data("containerid");
120
        insertValueQuery( containerid );
121
    });
122
123
    $("#tabs").tabs();
124
125
    $("body").on("click", ".preview_template", function(e){
126
        e.preventDefault();
127
        var mtt = $(this).data("mtt");
128
        var lang = $(this).data("lang");
129
130
        var code = $("#code").val();
131
        var content = $("#content_"+mtt+"_"+lang).val();
132
        var title = $("#title_"+mtt+"_"+lang).val();
133
134
        var is_html = $("#is_html_"+mtt+"_"+lang).val();
135
        var page = $(this).attr("href");
136
        var data_preview = $("#data_preview").val();
137
        page += '?code='+encodeURIComponent(code);
138
        page += '&title='+encodeURIComponent(title);
139
        page += '&content='+encodeURIComponent(content);
140
        page += '&data_preview='+encodeURIComponent(data_preview);
141
        page += '&is_html='+encodeURIComponent(is_html);
142
        $("#preview_template .modal-body").load(page + " #main");
143
        $('#preview_template').modal('show');
144
        $("#preview_template_button").attr("href", "/cgi-bin/koha/svc/letters/convert?module="+module+"&code="+code+"&mtt="+mtt+"&lang="+lang);
145
    });
146
147
    $("#preview_template").on("hidden.bs.modal", function(){
148
        $("#preview_template_label").html("");
149
        $("#preview_template .modal-body").html( modal_loading );
150
    });
151
152
    function insertValueQuery(containerid) {
153
        var fieldset = $("#" + containerid);
154
        var myQuery = $(fieldset).find('textarea[name="content"]');
155
        var myListBox = $(fieldset).find('select[name="SQLfieldname"]');
156
157
        if($(myListBox).find('option').length > 0) {
158
            $(myListBox).find('option').each( function (){
159
                if ( $(this).attr('selected') && $(this).val().length > 0 ) {
160
                    $(myQuery).insertAtCaret("<<" + $(this).val() + ">>");
161
                }
162
            });
163
        }
164
    }
165
166
});

Return to bug 18007