blob: f6d7ad3c06241d67483aca1cfd9ef7ac1b028804 [file] [log] [blame]
Matthias Andreas Benkardb382b102021-01-02 15:32:21 +01001var rspamd_presetsElem = document.getElementById("rspamd_presets");
2
3if (rspamd_presetsElem) {
4 $.ajax({
5 dataType: 'json',
6 url: '/api/v1/get/presets/rspamd',
7 jsonp: false,
8 complete: function (data) {
9 if (data.responseText !== '{}') {
10 var rspamdPresets = JSON.parse(data.responseText);
11
12 if (rspamdPresets) {
13 rspamd_presetsElem.innerHTML = '';
14 rspamdPresets.forEach(function (item, index) {
15 var elemID = 'rspamd_preset_' + index;
16 rspamd_presetsElem.innerHTML += '<li><a href="#" class="small" id="' + elemID + '">' + lang.rsettings_insert_preset.replace('%s', item.headline) + '</a></li>';
17
18 /*
19 we need to define 0-timeout here, to prevent dom not be ready.
20 */
21 setTimeout(function () {
22 document.getElementById(elemID).addEventListener('click', function (e) {
23 e.preventDefault();
24 document.querySelector('form[data-id=rsetting] #adminRspamdSettingsDesc').value = item.headline;
25 document.querySelector('form[data-id=rsetting] #adminRspamdSettingsContent').value = item.content;
26 return true;
27 });
28 }, 0);
29 });
30 }
31 }
32 }
33 });
34}