This repository was archived by the owner on Dec 17, 2025. It is now read-only.
-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathTVGuideAction.js
More file actions
137 lines (112 loc) · 3.86 KB
/
TVGuideAction.js
File metadata and controls
137 lines (112 loc) · 3.86 KB
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
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
import Dialog from "../../Library/Dialog.js";
import Dropdown from "../../Library/Dropdown.js";
import Confirm from "../../Library/Confirm.js";
export default class TVGuideAction
{
#app;
constructor(app)
{
this.#app = app;
}
async channelGroupDropdown(e, target)
{
let dropdown = new Dropdown(e, target, {
closeOnClickInside: false,
});
if (!Dropdown.isOpen()) {
return;
}
let template = document.getElementById('channel-group-dropdown-content').cloneNode(true);
for (const elm of template.content.querySelectorAll('a, button')) {
elm.addEventListener('click', () => {
Dropdown.close();
});
}
dropdown.setContent(template);
}
async programInfoModal(e, target)
{
e.preventDefault();
let modal = new Dialog(target.textContent, this.#app.loadingElm);
let xhr;
try {
xhr = await this.#app.ajax.post('/modal/tv-guide/program-info', {
program_id: target.dataset.programId
});
} catch (e) {
modal.close();
throw e;
}
modal.setHtmlContent(xhr.response);
let closeButton = document.createElement('button');
closeButton.classList.add('close-button');
closeButton.textContent = _('Close');
closeButton.addEventListener('click', () => {
modal.close();
});
modal.element().append(closeButton);
let program = target.closest('.epg-program.running');
if (program) {
let modalProgress = document.querySelector('dialog .progress .elapsed');
modalProgress.style.width = program.dataset.progress + '%';
}
}
async createChannelGroup(e, target)
{
let modal = new Dialog(_('Create a channel group'), this.#app.loadingElm, {
closeConfirm: true,
closeConfirmText: _('Forget changes?'),
});
let xhr;
try {
xhr = await this.#app.ajax.post('/modal/tv-guide/channel-group/create');
} catch (e) {
modal.close();
throw e;
}
modal.setHtmlContent(xhr.response);
}
async editChannelGroup(e, target)
{
let closeConfirmText = _('Forget changes?')
let modal = new Dialog(_('Edit channel group'), this.#app.loadingElm, {
closeConfirm: true,
closeConfirmText: closeConfirmText,
});
let xhr;
try {
xhr = await this.#app.ajax.post('/modal/tv-guide/channel-group/edit', {
id: target.dataset.groupId
});
} catch (e) {
modal.close();
throw e;
}
modal.setHtmlContent(xhr.response);
}
async deleteChannelGroup(e, target)
{
if (!await (new Confirm(_('Delete this channel group?'))).response()) {
return;
}
Dialog.closeParent(target);
let xhr = await this.#app.ajax.post('/api/tv-guide/channel-group/delete', {
'id': target.dataset.groupId
});
this.#app.toast.success(xhr.response);
document.getElementById('channel-group-dropdown-content').content
.querySelector('[data-group-id="' + target.dataset.groupId + '"]')?.remove();
}
async toggleUpcomingListVisibility(e, target)
{
let broadcastList = target.nextElementSibling;
let numberOf = target.textContent.match(/\d+/)[0] ?? 0;
if (broadcastList.classList.contains('hidden')) {
broadcastList.classList.remove('hidden');
target.textContent = _('Hide upcoming broadcasts') + ' (' + numberOf + ')';
} else {
broadcastList.classList.add('hidden');
target.textContent = _('Show upcoming broadcasts') + ' (' + numberOf + ')';
}
}
}