File indexing completed on 2024-12-29 04:51:05
0001 /* 0002 SPDX-FileCopyrightText: 2021 Volker Krause <vkrause@kde.org> 0003 SPDX-License-Identifier: LGPL-2.0-or-later 0004 */ 0005 0006 function readDateTime(pass, fieldName) { 0007 const f = pass.field[fieldName]; 0008 if (!f) 0009 return undefined; 0010 const v = f.value; 0011 if (typeof v === "string") 0012 return JsonLd.toDateTime(v, ['dd.MM.yyyy hh:mm', 'dd.MM.yyyy'], 'de'); 0013 return v; 0014 } 0015 0016 function parsePass(content, node) { 0017 var res = node.result[0]; 0018 res.reservationFor.name = content.field['eventName'].value; 0019 res.reservationFor.startDate = readDateTime(content, 'doorsOpen'); 0020 res.reservationFor.endDate = readDateTime(content, 'doorsClose'); 0021 res.reservationFor.doorTime = readDateTime(content, 'doorsAdmission'); 0022 res.reservationFor.url = content.field['website'].value; 0023 if (content.field['name']) { 0024 res.underName = JsonLd.newObject('Person'); 0025 res.underName.name = content.field['name'].value; 0026 } 0027 res.reservationNumber = content.field['orderCode'].value; 0028 res.reservedTicket.name = content.field['ticket'].value; 0029 return res; 0030 } 0031 0032 // only works for unstyled PDFs common for smaller events 0033 function parsePdf(pdf, node, barcode) { 0034 let res = JsonLd.newEventReservation(); 0035 const text = pdf.pages[barcode.location].textInRect(0.0, 0.0, 1.0, 0.4); 0036 const dt = text.match(/(\d{4}.\d\d.\d\d \d\d:\d\d|\d\d.\d\d.\d{4} \d\d:\d\d)\n/); 0037 res.reservationFor.startDate = JsonLd.toDateTime(dt[1], ['dd.MM.yyyy hh:mm', 'yyyy-MM-dd hh:mm'], 'en'); 0038 0039 const data1 = text.substr(0, dt.index).trim().split(/\n/); 0040 res.reservationFor.name = data1.slice(0, Math.max(data1.length - 2, 1)).join(' '); 0041 0042 const data2 = text.substr(dt.index + dt[0].length).trim().split(/\n/); 0043 res.reservationFor.location.name = data2.slice(0, data2.length - 1).join(' '); 0044 res.reservationNumber = data2[data2.length - 1].match(/(\S+) /)[1]; 0045 0046 res.reservedTicket.ticketToken = 'qrcode:' + barcode.content; 0047 return res; 0048 }