2022-01-28 10:03:57 +00:00
|
|
|
$(document).ready(function() {
|
|
|
|
STORAGE_KEY = 'tag-spec-key';
|
|
|
|
$("#printerType").on("change", change_size);
|
2022-04-27 16:56:15 +00:00
|
|
|
$(".form-check-input").on("change", change_check);
|
2022-01-28 10:03:57 +00:00
|
|
|
change_size();
|
2022-04-27 16:56:15 +00:00
|
|
|
load_settings();
|
|
|
|
change_check();
|
2022-01-28 10:03:57 +00:00
|
|
|
})
|
|
|
|
|
2022-03-16 13:27:55 +00:00
|
|
|
function qr_draw(url, id) {
|
|
|
|
var qrcode = new QRCode($(id)[0], {
|
2022-01-28 10:03:57 +00:00
|
|
|
text: url,
|
|
|
|
width: 128,
|
|
|
|
height: 128,
|
|
|
|
colorDark : "#000000",
|
|
|
|
colorLight : "#ffffff",
|
2022-01-31 09:12:44 +00:00
|
|
|
correctLevel : QRCode.CorrectLevel.Q
|
2022-01-28 10:03:57 +00:00
|
|
|
});
|
|
|
|
}
|
|
|
|
|
2022-04-27 16:56:15 +00:00
|
|
|
function save_settings() {
|
2022-01-28 10:03:57 +00:00
|
|
|
var height = $("#height-tag").val();
|
|
|
|
var width = $("#width-tag").val();
|
|
|
|
var sizePreset = $("#printerType").val();
|
|
|
|
var data = {"height": height, "width": width, "sizePreset": sizePreset};
|
2022-04-27 16:56:15 +00:00
|
|
|
data['dhid'] = $("#dhidCheck").prop('checked');
|
2022-06-08 09:59:47 +00:00
|
|
|
data['sid'] = $("#sidCheck").prop('checked');
|
2022-04-27 16:56:15 +00:00
|
|
|
data['qr'] = $("#qrCheck").prop('checked');
|
|
|
|
data['serial_number'] = $("#serialNumberCheck").prop('checked');
|
|
|
|
data['manufacturer'] = $("#manufacturerCheck").prop('checked');
|
|
|
|
data['model'] = $("#modelCheck").prop('checked');
|
2022-01-28 10:03:57 +00:00
|
|
|
localStorage.setItem(STORAGE_KEY, JSON.stringify(data));
|
|
|
|
}
|
|
|
|
|
2022-04-27 16:56:15 +00:00
|
|
|
function load_settings() {
|
2022-01-28 10:03:57 +00:00
|
|
|
var data = JSON.parse(localStorage.getItem(STORAGE_KEY));
|
|
|
|
if (data){
|
|
|
|
$("#height-tag").val(data.height);
|
|
|
|
$("#width-tag").val(data.width);
|
|
|
|
$("#printerType").val(data.sizePreset);
|
2022-04-27 16:56:15 +00:00
|
|
|
$("#qrCheck").prop('checked', data.qr);
|
|
|
|
$("#dhidCheck").prop('checked', data.dhid);
|
2022-06-08 09:59:47 +00:00
|
|
|
$("#sidCheck").prop('checked', data.sid);
|
2022-04-27 16:56:15 +00:00
|
|
|
$("#serialNumberCheck").prop('checked', data.serial_number);
|
|
|
|
$("#manufacturerCheck").prop('checked', data.manufacturer);
|
|
|
|
$("#modelCheck").prop('checked', data.model);
|
2022-01-28 10:03:57 +00:00
|
|
|
};
|
|
|
|
}
|
|
|
|
|
2022-04-27 16:56:15 +00:00
|
|
|
function reset_settings() {
|
2022-01-28 10:03:57 +00:00
|
|
|
localStorage.removeItem(STORAGE_KEY);
|
|
|
|
$("#printerType").val('brotherSmall');
|
2022-04-27 16:56:15 +00:00
|
|
|
$("#qrCheck").prop('checked', true);
|
|
|
|
$("#dhidCheck").prop('checked', true);
|
2022-06-08 09:59:47 +00:00
|
|
|
$("#sidCheck").prop('checked', true);
|
2022-04-27 16:56:15 +00:00
|
|
|
$("#serialNumberCheck").prop('checked', false);
|
|
|
|
$("#manufacturerCheck").prop('checked', false);
|
|
|
|
$("#modelCheck").prop('checked', false);
|
2022-01-28 10:03:57 +00:00
|
|
|
change_size();
|
2022-04-27 16:56:15 +00:00
|
|
|
change_check();
|
2022-01-28 10:03:57 +00:00
|
|
|
}
|
|
|
|
|
|
|
|
function change_size() {
|
|
|
|
var sizePreset = $("#printerType").val();
|
|
|
|
if (sizePreset == 'brotherSmall') {
|
|
|
|
$("#height-tag").val(29);
|
|
|
|
$("#width-tag").val(62);
|
|
|
|
} else if (sizePreset == 'smallTagPrinter') {
|
|
|
|
$("#height-tag").val(59);
|
|
|
|
$("#width-tag").val(97);
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
2022-04-27 16:56:15 +00:00
|
|
|
function change_check() {
|
|
|
|
if ($("#dhidCheck").prop('checked')) {
|
|
|
|
$(".dhid").show();
|
|
|
|
} else {
|
|
|
|
$(".dhid").hide();
|
|
|
|
}
|
2022-06-08 09:59:47 +00:00
|
|
|
if ($("#sidCheck").prop('checked')) {
|
|
|
|
$(".sid").show();
|
|
|
|
} else {
|
|
|
|
$(".sid").hide();
|
|
|
|
}
|
2022-04-27 16:56:15 +00:00
|
|
|
if ($("#serialNumberCheck").prop('checked')) {
|
|
|
|
$(".serial_number").show();
|
|
|
|
} else {
|
|
|
|
$(".serial_number").hide();
|
|
|
|
}
|
|
|
|
if ($("#manufacturerCheck").prop('checked')) {
|
|
|
|
$(".manufacturer").show();
|
|
|
|
} else {
|
|
|
|
$(".manufacturer").hide();
|
|
|
|
}
|
|
|
|
if ($("#modelCheck").prop('checked')) {
|
|
|
|
$(".model").show();
|
|
|
|
} else {
|
|
|
|
$(".model").hide();
|
|
|
|
}
|
|
|
|
if ($("#qrCheck").prop('checked')) {
|
|
|
|
$(".qr").show();
|
|
|
|
} else {
|
|
|
|
$(".qr").hide();
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
2022-01-28 10:03:57 +00:00
|
|
|
function printpdf() {
|
2022-01-31 09:12:44 +00:00
|
|
|
var border = 2;
|
2022-04-27 16:56:15 +00:00
|
|
|
var line = 5;
|
2022-01-28 11:29:49 +00:00
|
|
|
var height = parseInt($("#height-tag").val());
|
|
|
|
var width = parseInt($("#width-tag").val());
|
2022-04-27 16:56:15 +00:00
|
|
|
var img_side = Math.min(height, width) - 2*border;
|
2022-01-31 09:12:44 +00:00
|
|
|
max_tag_side = (Math.max(height, width)/2) + border;
|
|
|
|
if (max_tag_side < img_side) {
|
2022-04-27 16:56:15 +00:00
|
|
|
max_tag_side = img_side + 2*border;
|
2022-01-31 09:12:44 +00:00
|
|
|
};
|
|
|
|
min_tag_side = (Math.min(height, width)/2) + border;
|
2022-03-16 13:27:55 +00:00
|
|
|
var last_tag_code = '';
|
|
|
|
|
2022-06-08 09:59:47 +00:00
|
|
|
if ($("#sidCheck").prop('checked')) {
|
|
|
|
height += line;
|
|
|
|
};
|
2022-04-27 16:56:15 +00:00
|
|
|
if ($("#serialNumberCheck").prop('checked')) {
|
|
|
|
height += line;
|
|
|
|
};
|
|
|
|
if ($("#manufacturerCheck").prop('checked')) {
|
|
|
|
height += line;
|
|
|
|
};
|
|
|
|
if ($("#modelCheck").prop('checked')) {
|
|
|
|
height += line;
|
|
|
|
};
|
|
|
|
|
2022-03-16 13:27:55 +00:00
|
|
|
var pdf = new jsPDF('l', 'mm', [width, height]);
|
|
|
|
$(".tag").map(function(x, y) {
|
|
|
|
if (x != 0){
|
|
|
|
pdf.addPage();
|
|
|
|
};
|
2022-04-27 16:56:15 +00:00
|
|
|
var space = line + border;
|
|
|
|
if ($("#qrCheck").prop('checked')) {
|
|
|
|
space += img_side;
|
|
|
|
}
|
2022-03-16 13:27:55 +00:00
|
|
|
var tag = $(y).text();
|
|
|
|
last_tag_code = tag;
|
2022-04-27 16:56:15 +00:00
|
|
|
if ($("#qrCheck").prop('checked')) {
|
|
|
|
var imgData = $('#'+tag+' img').attr("src");
|
|
|
|
pdf.addImage(imgData, 'PNG', border, border, img_side, img_side);
|
|
|
|
};
|
|
|
|
|
|
|
|
if ($("#dhidCheck").prop('checked')) {
|
|
|
|
if ($("#qrCheck").prop('checked')) {
|
|
|
|
pdf.setFontSize(15);
|
|
|
|
pdf.text(tag, max_tag_side, min_tag_side);
|
|
|
|
} else {
|
|
|
|
pdf.setFontSize(15);
|
|
|
|
pdf.text(tag, border, space);
|
|
|
|
space += line;
|
|
|
|
}
|
|
|
|
};
|
2022-06-08 09:59:47 +00:00
|
|
|
if ($("#sidCheck").prop('checked')) {
|
|
|
|
var sn = $(y).data('sid');
|
|
|
|
pdf.setFontSize(15);
|
|
|
|
pdf.text(sn, border, space);
|
|
|
|
space += line;
|
|
|
|
};
|
2022-04-27 16:56:15 +00:00
|
|
|
if ($("#serialNumberCheck").prop('checked')) {
|
|
|
|
var sn = $(y).data('serial-number');
|
|
|
|
pdf.setFontSize(12);
|
|
|
|
pdf.text(sn, border, space);
|
|
|
|
space += line;
|
|
|
|
};
|
|
|
|
if ($("#manufacturerCheck").prop('checked')) {
|
|
|
|
var sn = $(y).data('manufacturer');
|
|
|
|
pdf.setFontSize(12);
|
|
|
|
pdf.text(sn, border, space);
|
|
|
|
space += line;
|
|
|
|
};
|
|
|
|
if ($("#modelCheck").prop('checked')) {
|
|
|
|
var sn = $(y).data('model');
|
|
|
|
pdf.setFontSize(8);
|
|
|
|
pdf.text(sn, border, space);
|
|
|
|
space += line;
|
|
|
|
};
|
2022-03-16 13:27:55 +00:00
|
|
|
});
|
|
|
|
|
|
|
|
pdf.save('Tag_'+last_tag_code+'.pdf');
|
2022-01-28 10:03:57 +00:00
|
|
|
}
|