102 lines
3.0 KiB
JavaScript
102 lines
3.0 KiB
JavaScript
var EmailMessages = {
|
|
|
|
attachmentSelector: '[data-attachment]',
|
|
|
|
attachmentTypes: null,
|
|
attachmentUrls: null,
|
|
|
|
getAttachmentUrl: function(type) {
|
|
return this.attachmentUrls[type];
|
|
},
|
|
|
|
getAttachmentName: function(type) {
|
|
return this.attachmentTypes[type];
|
|
},
|
|
|
|
getServerSidePlaceholders: function() {
|
|
return [
|
|
'KOD', 'STAV', 'CENA', 'ZAPLATIT', 'ODKAZ', 'ODKAZ_PLATBA', 'DATUM', 'CAS', 'POLOZKY_OBJEDNAVKY',
|
|
'POPIS_ZPUSOBU_DORUCENI', 'POPIS_PLATBY', 'POPIS_DOPRAVY', 'QR_PLATBA', 'POUKAZY', 'KOD_VRATKY',
|
|
'ODKAZ_VRATKY', 'ODKAZ_VRATKA','VRATKA_INSTRUKCE', 'KOD_REKLAMACE', 'ODKAZ_REKLAMACE', 'REKLAMACE_INSTRUKCE',
|
|
'ZPUSOB_VYRIZENI', 'ODKAZ_OBJEDNAVKA', 'KOD_OBJEDNAVKY', 'CISLO_UCTU', 'PACKAGE_LABEL', 'POSUDEK',
|
|
'FAKTURACNI_ADRESA', 'DODACI_ADRESA', 'ODKAZ_PDF', 'DATUM_SPLATNOSTI', 'ODKAZ_FAKTURA', 'WEB',
|
|
'ODKAZ_SLEDOVANI_BALIKU', 'BALIKY', 'POLOZKY_EXCEL', 'DATUM_OBJEDNAVKY', 'CAS_OBJEDNAVKY'
|
|
// Nedávej sem BALIK_ID, logika je uvnitř replacePlaceholders.
|
|
];
|
|
},
|
|
|
|
findPlaceholders: function(message) {
|
|
var symbols = message.match(/\{[^}]+\}/g);
|
|
var symbol_set = [];
|
|
for (var i in symbols) {
|
|
var re = /([^{:}]+)(}|:([^{:}]+))/;
|
|
var parts = re.exec(symbols[i]);
|
|
if (parts == null) {
|
|
continue;
|
|
}
|
|
|
|
if (symbol_set[parts[1]]) {
|
|
continue;
|
|
}
|
|
|
|
symbol_set[parts[1]] = { 'orig': symbols[i], 'default': parts[3] ? parts[3] : '' };
|
|
}
|
|
|
|
return symbol_set;
|
|
},
|
|
|
|
replacePlaceholders: function(message, balik_id) {
|
|
|
|
var placeholders = this.findPlaceholders(message);
|
|
|
|
for (var i in placeholders) {
|
|
if(i[0] === '!'){
|
|
message = message.replace(i, i.replace("!", ""))
|
|
continue;
|
|
}
|
|
if (this.getServerSidePlaceholders().indexOf(i) >= 0) {
|
|
continue;
|
|
}
|
|
|
|
if ((i == 'BALIK_ID') && (balik_id)) {
|
|
continue;
|
|
}
|
|
|
|
var value = window.prompt(i, placeholders[i]['default']);
|
|
|
|
gtag('event', 'select_content', {
|
|
'content_type': 'placeholder',
|
|
'content_id': i
|
|
});
|
|
|
|
if (value == null) {
|
|
return;
|
|
}
|
|
|
|
message = message.replace(new RegExp(placeholders[i]['orig'], 'g'), value);
|
|
}
|
|
|
|
return message;
|
|
},
|
|
|
|
renderAttachments: function(attachments) {
|
|
var $attachment = $(this.attachmentSelector),
|
|
me = this;
|
|
|
|
if (attachments) {
|
|
attachments = JSON.parse(attachments);
|
|
attachments = attachments.map(function(type) {
|
|
if (me.attachmentUrls !== null) {
|
|
return '<a href="' + me.getAttachmentUrl(type) + '" target="_blank">' + me.getAttachmentName(type) + '</a>';
|
|
}
|
|
|
|
return me.getAttachmentName(type);
|
|
});
|
|
$attachment.html('<i class="glyphicon glyphicon-paperclip m-r-1"></i>Přílohy: ' + attachments.join(', ')).show();
|
|
} else {
|
|
$attachment.html('').hide();
|
|
}
|
|
}
|
|
|
|
};
|