-
Notifications
You must be signed in to change notification settings - Fork 1
/
Copy pathresults_view.js
72 lines (65 loc) · 2.14 KB
/
results_view.js
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
import { View } from "./view.js";
import { createAnchor } from "./utils.js";
import { __ } from "./gettext.js";
export class ResultsView extends View {
constructor() {
super();
this._div = document.createElement('div');
this._backBtn = document.createElement('input');
this._backBtn.setAttribute('type', 'button');
this._backBtn.setAttribute('class', 'rv-button-back');
this._backBtn.setAttribute('value', __('Back'));
this._backBtn.onclick = () => {
super._emitSignal('back');
return false;
};
this._div.appendChild(this._backBtn);
this._div.appendChild(document.createElement('hr'));
this._inner = null;
}
get element() {
return this._div;
}
_setInner(inner) {
if (this._inner !== null)
this._inner.remove();
this._inner = inner;
this._div.appendChild(inner);
}
setResults(data) {
const inner = document.createElement('div');
if (data.length === 0) {
inner.append(__('Nothing found! 😢'));
} else {
inner.append(__('Posts found:'));
inner.appendChild(document.createElement('br'));
const ul = document.createElement('ul');
for (const datum of data) {
const li = document.createElement('li');
const a = createAnchor(datum.link);
const span = document.createElement('span');
if (datum.isNew) {
span.setAttribute('class', 'rv-li-note-new');
span.append(__(' (new)'));
} else {
span.setAttribute('class', 'rv-li-note-old');
span.append(__(' (old)'));
}
li.appendChild(a);
li.appendChild(span);
ul.appendChild(li);
}
inner.appendChild(ul);
}
this._setInner(inner);
}
setError(text) {
const inner = document.createElement('div');
inner.append(text);
this._setInner(inner);
}
mount() {
}
unmount() {
}
}