luci-app-adblock: revert poll/view class changes
[oweals/luci.git] / applications / luci-app-adblock / htdocs / luci-static / resources / view / adblock / whitelist.js
1 'use strict';
2 'require fs';
3 'require ui';
4
5 return L.view.extend({
6         load: function() {
7                 return L.resolveDefault(fs.read_direct('/etc/adblock/adblock.whitelist'), '');
8         },
9         handleSave: function(ev) {
10                 var value = ((document.querySelector('textarea').value || '').trim().toLowerCase().replace(/\r\n/g, '\n').replace(/[^a-z0-9\.\-\#\n]/g, '')) + '\n';
11                 return fs.write('/etc/adblock/adblock.whitelist', value)
12                         .then(function(rc) {
13                                 document.querySelector('textarea').value = value;
14                                 ui.addNotification(null, E('p', _('Whitelist changes have been saved. Refresh your adblock lists that changes take effect.')), 'info');
15                         }).catch(function(e) {
16                                 ui.addNotification(null, E('p', _('Unable to save changes: %s').format(e.message)));
17                         });
18         },
19         render: function(whitelist) {
20                 return E([
21                         E('p', {},
22                                 _('This is the local adblock whitelist to always allow certain (sub) domains.<br /> \
23                                 Please note: add only one domain per line. Comments introduced with \'#\' are allowed - ip addresses, wildcards and regex are not.')),
24                         E('p', {},
25                                 E('textarea', {
26                                         'style': 'width: 100% !important; padding: 5px; font-family: monospace',
27                                         'spellcheck': 'false',
28                                         'wrap': 'off',
29                                         'rows': 25
30                                 }, [ whitelist != null ? whitelist : '' ])
31                         )
32                 ]);
33         },
34         handleSaveApply: null,
35         handleReset: null
36 });