Bug 29002: (follow-up) Use $patron_to_html function
[koha.git] / koha-tmpl / intranet-tmpl / prog / en / modules / labels / barcode-print.tt
1 [% USE raw %]
2 [% USE Asset %]
3 [% PROCESS 'i18n.inc' %]
4 [% SET footerjs = 1 %]
5 [% INCLUDE 'doc-head-open.inc' %]
6 <title>[% FILTER collapse %]
7     [% t("Barcode image generator") | html %] &rsaquo;
8     [% t("Cataloging") | html %] &rsaquo;
9     [% t("Koha") | html %]
10 [% END %]</title>
11 [% INCLUDE 'doc-head-close.inc' %]
12 [% Asset.css("css/humanmsg.css") | $raw %]
13 [% FILTER collapse %]
14     <style>
15         input[type='range'] {
16             display: inline-block;
17             width: auto;
18         }
19         #barcode_container {
20             background-color:#FFF;
21             min-height:200px;
22             overflow: scroll;
23             padding:2em;
24             text-align:center;
25         }
26         #barcode_image {
27             border:1px dashed #B9D8D9;
28             display: block;
29             margin: 1em auto;
30             padding: 1em;
31         }
32         #modulesize_text {
33             background-color: #FFF;
34             border: 1px solid #EEE;
35             border-radius: 2px;
36             padding: .2em .4em;
37         }
38         #urltext {
39             border:1px solid #B9D8D9;
40             border-radius:2px;
41             margin:1em 0;
42             padding:.5em;
43         }
44     </style>
45 [% END %]
46 </head>
47
48 <body id="labels_spinelabel-home" class="tools labels">
49 [% WRAPPER 'header.inc' %]
50     [% INCLUDE 'cat-search.inc' %]
51 [% END %]
52
53 [% WRAPPER 'sub-header.inc' %]
54     [% WRAPPER breadcrumbs %]
55         [% WRAPPER breadcrumb_item %]
56             <a href="/cgi-bin/koha/cataloguing/cataloging-home.pl">Cataloging</a>
57         [% END %]
58         [% WRAPPER breadcrumb_item bc_active= 1 %]
59             <span>Barcode image generator</span>
60         [% END %]
61     [% END #/ WRAPPER breadcrumbs %]
62 [% END #/ WRAPPER sub-header.inc %]
63
64 <div class="main container-fluid">
65     <div class="row">
66         <div class="col-sm-10 col-sm-push-2">
67             <main>
68                 <h2>Barcode image generator</h2>
69
70                 <form action="/cgi-bin/koha/svc/barcode" method="post" id="barcodegen">
71                     <fieldset class="brief">
72                         <div class="row">
73                             <div class="col-sm-6">
74                                 <ol>
75                                     <li>
76                                         <label for="type">Barcode type:</label>
77                                         <select name="type" id="type">
78                                             <option value="Code39">Code39</option>
79                                             <option value="COOP2of5">COOP2of5</option>
80                                             <option value="EAN13">EAN13</option>
81                                             <option value="EAN8">EAN8</option>
82                                             <option value="IATA2of5">IATA2of5</option>
83                                             <option value="Industrial2of5">Industrial2of5</option>
84                                             <option value="ITF">ITF</option>
85                                             <option value="Matrix2of5">Matrix2of5</option>
86                                             <option value="NW7">NW7</option>
87                                             <option value="QRcode">QRcode</option>
88                                             <option value="UPCA">UPCA</option>
89                                             <option value="UPCE">UPCE</option>
90                                         </select>
91                                     </li>
92                                     <li class="qrcode">
93                                         <label for="modulesize">QR Code module size:</label>
94                                         <input name="modulesize" id="modulesize" type="range" min="1" max="10" value="3" />
95                                         <span id="modulesize_text">3</span>
96                                         <div class="hint">Module size refers to the pixel dimensions of each black or white square in the generated QR code.</div>
97                                     </li>
98                                     <li class="bcode">
99                                         <label for="notext">Hide text <input type="checkbox" id="notext" name="notext" value="1" /></label>
100                                     </li>
101                                     <li class="bcode">
102                                         <label for="height">Barcode height:</label>
103                                         <input type="text" id="height" name="height" value="50" />
104                                     </li>
105                                     <li>
106                                         <label class="bcode" for="barcode">Barcode: </label>
107                                         <label class="qrcode" for="barcode">Text, URL, or barcode, etc: </label>
108                                         <input type="text" name="barcode" id="barcode" size="50" />
109                                         <div class="hint qrcode">Actual dimensions of the QR code depend on the amount of characters being encoded.</div>
110                                         <div class="hint bcode">Barcode text must be numeric (0-9)</div>
111                                     </li>
112                                 </ol>
113                                 <fieldset class="action">
114                                     <input type="submit" class="btn btn-primary" value="Show barcode" />
115                                 </fieldset>
116                             </div>
117                             <div class="col-sm-6">
118                                 <div id="barcode_container">
119                                     <img id="barcode_image" />
120                                     <textarea readonly="readonly" rows="5" cols="40" id="urltext"></textarea>
121                                 </div>
122                             </div>
123                         </div>
124                     </fieldset>
125                 </form>
126             </main>
127         </div> <!-- /.col-sm-10.col-sm-push-2 -->
128
129         <div class="col-sm-2 col-sm-pull-10">
130             <aside>
131                 [% INCLUDE 'cat-menu.inc' %]
132             </aside>
133         </div> <!-- /.col-sm-2.col-sm-pull-10 -->
134      </div> <!-- /.row -->
135
136 [% MACRO jsinclude BLOCK %]
137     [% Asset.js("lib/jquery/plugins/humanmsg.js") | $raw %]
138     <script>
139         var base_url = "[% Koha.Preference('staffClientBaseURL') | html %]";
140
141         function showBarcodeText( path, dimensions ){
142             var params = new URLSearchParams( path );
143             var tag = '<img src="' + path + '" alt="' + params.get("barcode") + '" width="' + dimensions.width + '" height="' + dimensions.height + '" />';
144             $("#urltext").show().text( tag );
145             if( Number( dimensions.width  ) > 250 ){
146                 $("#urltext").css("width", dimensions.width )
147             }
148         }
149
150         function showBarcode( barcodeform ){
151             if( $("#barcode").val() == "" ){
152                 $("#barcode_container").hide();
153             } else {
154                 var url = barcodeform.attr("action");
155                 var params = barcodeform.serialize();
156                 $("#barcode_container").show();
157                 $("#barcode_image").attr("src", url + "?" + params );
158             }
159         }
160
161         function showQrcodeOptions( type ){
162             if( type.val() == "QRcode" ){
163                 $(".qrcode").show().find("input,range").prop("disabled", false );
164                 $(".bcode").hide().find("input").prop("disabled", true );
165             } else {
166                 $(".qrcode").hide().find("input,range").prop("disabled", true );
167                 $(".bcode").show().find("input").prop("disabled", false );
168             }
169         }
170         $(document).ready(function(){
171             showQrcodeOptions( $("#type") );
172             showBarcode( $("#barcodegen") );
173             $("#type").on("change", function(){
174                 showQrcodeOptions( $(this) );
175             })
176             $("#barcodegen").on("change submit", function(e){
177                 e.preventDefault();
178                 showBarcode( $(this) );
179             });
180             $("#modulesize").on("input", function(){
181                 $("#modulesize_text").text( $(this).val() );
182             });
183             $("#urltext").on("click", function(){
184                 $(this).select();
185                 var text = $(this).text();
186                 navigator.clipboard.writeText( text ).then(function() {
187                     /* clipboard successfully set */
188                     humanMsg.displayAlert( _("HTML copied to the clipboard") );
189                 }, function() {
190                     /* clipboard write failed */
191                     humanMsg.displayAlert( _("Could not copy HTML automatically to the clipboard") );
192                 });
193             });
194             $("#barcode_image")[0].onload = function (){
195                 showBarcodeText( this.src, { width: this.width, height: this.height } );
196             }
197             $("#barcode_image")[0].onerror = function(){
198                 var barcodetype = $("#type").val();
199                 if( barcodetype !== "QRcode" ){
200                     if( Number.isNaN( Number( $("#barcode").val() ) ) ){
201                         humanMsg.displayAlert( _("Barcodes of type %s must be numeric").format( barcodetype ) );
202                     } else {
203                         humanMsg.displayAlert( _("There was an unknown error generating the barcode image. Please check that your barcode is correct for the barcode type" ) );
204                     }
205                 } else {
206                     humanMsg.displayAlert( _("There was an unknown error generating the barcode image") );
207                 }
208             }
209         });
210     </script>
211 [% END %]
212
213 [% INCLUDE 'intranet-bottom.inc' %]