blob: a361bdeef223f28e51851f60eb55562095bff3fb (
plain)
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
|
export { EditRRule }
import { ComponentVEvent } from './vevent'
import { VEvent } from '../vevent'
import { vcal_objects } from '../globals'
import { RecurrenceRule } from '../vevent'
/* <vevent-edit-rrule/>
Tab for editing the recurrence rule of a component
*/
class EditRRule extends ComponentVEvent {
constructor(uid?: string) {
super(uid);
if (!this.template) {
throw 'vevent-edit-rrule template required';
}
let frag = this.template.content.cloneNode(true) as DocumentFragment
let body = frag.firstElementChild!
this.replaceChildren(body);
for (let el of this.querySelectorAll('[name]')) {
el.addEventListener('input', () => {
// console.log(this);
let data = vcal_objects.get(this.uid)!;
let rrule = data.getProperty('rrule')
if (!rrule) {
console.warn('RRUle missing from object');
return;
}
rrule = rrule as RecurrenceRule
console.log(el.getAttribute('name'), (el as any).value);
rrule[el.getAttribute('name')!] = (el as any).value;
data.setProperty('rrule', rrule);
});
}
}
connectedCallback() {
this.redraw(vcal_objects.get(this.uid)!)
}
redraw(data: VEvent) {
let rrule = data.getProperty('rrule')
if (!rrule) return;
rrule = rrule as RecurrenceRule
for (let el of this.querySelectorAll('[name]')) {
/*
el ought to be one of the tag types:
<input/>, <input-list/>, <select/>, and <date-time-input/>
Which all have `name` and `value` fields, allowing the code
below to work.
*/
let name = el.getAttribute('name')
if (!name) {
console.warn(`Input without name, ${el}`)
continue
}
let value: any = rrule[name];
if (value)
(el as any).value = value;
}
}
}
|