-
-
Notifications
You must be signed in to change notification settings - Fork 152
/
Copy pathstickers_preview.pt
237 lines (227 loc) · 8.48 KB
/
stickers_preview.pt
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
156
157
158
159
160
161
162
163
164
165
166
167
168
169
170
171
172
173
174
175
176
177
178
179
180
181
182
183
184
185
186
187
188
189
190
191
192
193
194
195
196
197
198
199
200
201
202
203
204
205
206
207
208
209
210
211
212
213
214
215
216
217
218
219
220
221
222
223
224
225
226
227
228
229
230
231
232
233
234
235
236
237
<tal:doctype tal:replace="structure string:<!DOCTYPE html>" />
<html xmlns="http://www.w3.org/1999/xhtml"
xmlns:tal="http://xml.zope.org/namespaces/tal"
xmlns:metal="http://xml.zope.org/namespaces/metal"
xmlns:i18n="http://xml.zope.org/namespaces/i18n"
tal:attributes="lang default_language|default;
xml:lang default_language|default;"
i18n:domain="senaite.core"
tal:define="goback_url python:view.get_back_url();">
<head>
<div tal:replace="structure provider:plone.htmlhead" />
<!-- Generic style -->
<style type="text/css">
#sticker-rule {
color: rgb(51, 51, 51);
height: 10mm;
margin: 0 auto;
overflow: hidden;
display:none;
}
.sticker-rule-tick,
.sticker-rule-tick-odd {
display:table-cell;
width:10mm;
min-width:10mm;
max-width:10mm;
font-size:6pt;
}
.sticker-rule-tick {
border-top:2px solid #666;
}
.sticker-rule-tick-odd {
border-top:1px dotted #666;
}
.sticker {
margin:0 auto;
background-color:#fff;
border-bottom: 1px dotted #cdcdcd;
box-shadow: 1px 2px 5px #cdcdcd;
}
.barcode-hri {
clear:both;
width: 100%;
background-color: #FFFFFF;
color: #000000;
text-align: center;
font-size: 10px;
}
/* Print CSS */
@media print {
html, body {
margin: 0 !important;
padding: 0 !important;
background-color:#fff !important;
}
#sticker-preview-header {display:none !important;}
#stickers-wrapper { margin:0;}
.sticker {
margin:0;
border:none;
box-shadow:none;
border-bottom:none;
}
.page-break, .page-break-after, .page-break-before {
display: block !important;
border:none !important;
padding:0 !important;
margin:0 !important;
background-color:transparent !important;
}
div.page-break,
div.page-break-after {
page-break-after: always;
}
div.page-break-before {
page-break-before: always;
}
#sticker-rule {
display:none !important;
}
}
</style>
<script type="text/javascript">
document.addEventListener("DOMContentLoaded", () => {
$('#print-button').click(function(e) {
e.preventDefault();
printPdf();
window.location = $('#cancel-button').attr('data-url');
});
$('#cancel-button').click(function(e) {
e.preventDefault();
window.location = $(this).attr('data-url');
});
$('select#template').change(function(e) {
reload($('select#template').val(), $('#copies_count').val());
});
$('#copies_count').change(function(e) {
reload($('select#template').val(), $('#copies_count').val());
});
var stickwidth = $('.sticker').first().width();
$('#sticker-rule').css({'width':stickwidth,'max-width':stickwidth});
$('#sticker-rule').fadeIn();
/**
* Re-loads the stickers preview by using the template specified
*/
function reload(template, copies_count) {
var baseurl = $('body').attr('data-itemsurl');
var filter_by_type = $('body').attr('data-filter_by_type');
$('#stickers-wrapper').fadeTo('fast', 0.4);
$.ajax({
url: baseurl,
type: 'POST',
async: true,
data: {"template": template, "copies_count": copies_count, "filter_by_type": filter_by_type}
})
.always(function(data) {
var htmldata = data;
htmldata = $(htmldata).find('#stickers-wrapper').html();
$('#stickers-wrapper').html(htmldata);
$('#stickers-wrapper').fadeTo('fast', 1);
// reload barcoding
// Note: The BarcodeUtils are not propery loaded on template change for QR codes.
// Therefore, we create a new instance here.
// bika.lims.BarcodeUtils.load();
bu = new BarcodeUtils();
bu.load()
var stickwidth = $('.sticker').first().width();
$('#sticker-rule').css({'width':stickwidth,'max-width':stickwidth});
$('#sticker-rule').fadeIn();
});
}
function printPdf() {
var url = window.location.href;
// Get the stickers style
var style = $('#stickers-style').clone().wrap('<div>').parent().html();
var stickershtml = '';
// Get all stickers
$('#stickers-wrapper .sticker').each(function(e) {
stickershtml += $(this).clone().wrap('<div>').parent().html();
});
// Generate the form (POST request to generate PDF)
var form = '<form action="'+url+'" name="topdf" method="post" style="display:none">' +
'<textarea name="html"><div style="padding:0px;"></div>' +
stickershtml + '</textarea>' +
'<input type="hidden" name="pdf" value="1" />' +
'<textarea name="style">' + style + '</textarea>' +
'</form>';
var pdfwindow = window.open();
$(pdfwindow.document.body).html(form);
pdfwindow.document.forms.topdf.submit();
}
// If autoprint=1, render the pdf automatically
if (location.href.indexOf("autoprint=1") != -1) {
printPdf();
window.location = $('#cancel-button').attr('data-url');
}
});
</script>
</head>
<body tal:attributes="data-itemsurl python:view.getItemsURL(); data-filter_by_type python:view.filter_by_type or ''">
<div id="sticker-preview-wrapper" class="container-fluid p-0">
<div id="sticker-preview-header" class="row bg-light">
<div id="options-handler" class="col-sm-3 m-auto no-gutters py-3">
<!-- Template -->
<div id="sticker-template" class="mb-2">
<label for="template" class="mr-4" i18n:translate="">Template</label>
<select id="template" name="template" class="form-control">
<tal:formats tal:repeat="tpl python:view.getAvailableTemplates()">
<option selected
tal:attributes="value tpl/id"
tal:content="tpl/title"
tal:condition="tpl/selected"></option>
<option tal:attributes="value tpl/id"
tal:content="tpl/title"
tal:condition="not:tpl/selected"></option>
</tal:formats>
</select>
</div>
<!-- Number of copies -->
<div id="sticker-copies" class="mb-2">
<label for="copies_count" class="mr-4" i18n:translate="">Number of copies</label>
<input name="copies_count"
id="copies_count"
class="form-control"
type="number"
min="1"
step="1"
i18n:attributes="value"
tal:attributes="value view/get_copies_count"/>
</div>
<!-- Buttons -->
<div id="sticker-buttons">
<!-- go back -->
<input type="button"
id="cancel-button"
value="Back"
class="btn btn-secondary btn-sm"
i18n:attributes="value"
tal:attributes="data-url goback_url;" />
<!-- print -->
<input type="button"
id="print-button"
value="Print"
class="btn btn-primary btn-sm"
i18n:attributes="value" />
</div>
</div>
</div>
<div id="stickers-wrapper">
<style id='stickers-style' type="text/css" tal:content="structure python:view.getSelectedTemplateCSS()"></style>
<div id="sticker-rule">
<div style="font-size:6pt">mm</div>
<tal:tick repeat="mm python:[0,10,20,30,40,50,60,70,80,90,100,110,120,130,140,150,160,170,180,190,210]">
<div tal:define="odd repeat/mm/odd;
css python:'sticker-rule-tick-odd' if odd else 'sticker-rule-tick';"
tal:attributes="class css"
tal:content="mm"></div>
</tal:tick>
</div>
<tal:stickers repeat="item view/items">
<div class='sticker'
tal:content='structure python:view.renderItem(item)'></div>
</tal:stickers>
</div>
</div>
</body>
</html>