Files
PetitTetonMeteor/imports/ui/PrintLabel.js

42 lines
1.2 KiB
JavaScript
Raw Normal View History

import './PrintLabel.html';
import QRCode from '/imports/util/qrcode/qrcode';
2020-01-16 09:31:12 -08:00
import LabelFormats from '/imports/LabelFormats.js';
Template.PrintLabel.onCreated(function() {
2020-01-16 09:31:12 -08:00
});
Template.PrintLabel.onRendered(function() {
function getUrlVars() {
let vars = {};
let parts = window.location.href.replace(/[?&]+([^=&]+)=([^&]*)/gi, function(m,key,value) {
vars[key] = decodeURIComponent(value);
});
return vars;
}
2020-01-16 09:31:12 -08:00
function setupDisplay(vars) {
$('.label').removeClass().addClass("label " + vars.format);
$('.title1').html(vars['title1']);
$('.title2').html(vars['title2'] === undefined ? "" : vars['title2']);
$('.ingredientsList').html(vars['ingredients']);
$('.date').html(vars['date']);
$('.size').html(vars['size']);
}
2020-01-16 09:31:12 -08:00
let _this = this;
//Use the reactive variables if this is being rendered as part of the client's view (a preview of what will be printed). Otherwise take the URL parameters as the vars for rendering.
if(Blaze.getData(_this.view).vars) {
Tracker.autorun(function() {
let vars = Blaze.getData(_this.view).vars;
setupDisplay(vars);
});
}
else {
let vars = getUrlVars();
setupDisplay(vars);
}
new QRCode(document.getElementById("qrcode"), {text: "1234567890", width: 60, height: 60});
});