Matthias Andreas Benkard | b382b10 | 2021-01-02 15:32:21 +0100 | [diff] [blame] | 1 | var sieve_presetsElem = document.getElementById("sieve_presets"); |
| 2 | |
| 3 | if (sieve_presetsElem) { |
| 4 | $.ajax({ |
| 5 | dataType: 'json', |
| 6 | url: '/api/v1/get/presets/sieve', |
| 7 | jsonp: false, |
| 8 | complete: function (data) { |
| 9 | if (data.responseText !== '{}') { |
| 10 | var sieveMailboxPresets = JSON.parse(data.responseText); |
| 11 | |
| 12 | if (sieveMailboxPresets) { |
| 13 | sieve_presetsElem.innerHTML = ''; |
| 14 | sieveMailboxPresets.forEach(function (item, index) { |
| 15 | var elemID = 'sieve_preset_' + index; |
| 16 | sieve_presetsElem.innerHTML += '<li><a href="#" class="small" id="' + elemID + '">' + lang.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=add_filter] #script_desc').value = item.headline; |
| 25 | document.querySelector('form[data-id=add_filter] .script_data').value = item.content; |
| 26 | return true; |
| 27 | }); |
| 28 | }, 0); |
| 29 | }); |
| 30 | } |
| 31 | } |
| 32 | } |
| 33 | }); |
| 34 | } |