]> git.99rst.org Git - openwrt-luci.git/blob
57756b83e6f4c28a9bbaafa7ba5d36a4062dbfe8
[openwrt-luci.git] /
1 'use strict';
2 'require view';
3 'require form';
4 'require uci';
5 'require ui';
6 'require shadowsocks-libev as ss';
7
8 var conf = 'shadowsocks-libev';
9
10 return view.extend({
11 render: function() {
12 var m, s, o;
13
14 m = new form.Map(conf, _('Remote Servers'),
15 _('Definition of remote shadowsocks servers. \
16 Disable any of them will also disable instances referring to it.'));
17
18 s = m.section(form.GridSection, 'server');
19 s.addremove = true;
20 s.handleLinkImport = function() {
21 var textarea = new ui.Textarea();
22 ui.showModal(_('Import Links'), [
23 textarea.render(),
24 E('div', { class: 'right' }, [
25 E('button', {
26 class: 'btn',
27 click: ui.hideModal
28 }, [ _('Cancel') ]),
29 ' ',
30 E('button', {
31 class: 'btn cbi-button-action',
32 click: ui.createHandlerFn(this, function() {
33 textarea.getValue().split('\n').forEach(function(s) {
34 var config = ss.parse_uri(s);
35 if (config) {
36 var tag = config[1];
37 if (tag && !tag.match(/^[a-zA-Z0-9_]+$/)) tag = null;
38 var sid = uci.add(conf, 'server', tag);
39 config = config[0];
40 Object.keys(config).forEach(function(k) {
41 uci.set(conf, sid, k, config[k]);
42 });
43 }
44 });
45 return uci.save()
46 .then(L.bind(this.map.load, this.map))
47 .then(L.bind(this.map.reset, this.map))
48 .then(L.ui.hideModal)
49 .catch(function() {});
50 })
51 }, [ _('Import') ])
52 ])
53 ]);
54 };
55 s.renderSectionAdd = function(extra_class) {
56 var el = form.GridSection.prototype.renderSectionAdd.apply(this, arguments);
57 el.appendChild(E('button', {
58 'class': 'cbi-button cbi-button-add',
59 'title': _('Import Links'),
60 'click': ui.createHandlerFn(this, 'handleLinkImport')
61 }, [ _('Import Links') ]));
62 return el;
63 };
64
65 o = s.option(form.Flag, 'disabled', _('Disable'));
66 o.editable = true;
67
68 ss.options_server(s);
69
70 return m.render();
71 },
72 addFooter: function() {
73 var p = '#edit=';
74 if (location.hash.indexOf(p) === 0) {
75 var section_id = location.hash.substring(p.length);
76 var editBtn = document.querySelector('#cbi-shadowsocks-libev-' + section_id + ' button.cbi-button-edit');
77 if (editBtn)
78 editBtn.click();
79 }
80 return this.super('addFooter', arguments);
81 }
82 });
git clone https://git.99rst.org/PROJECT