aboutsummaryrefslogtreecommitdiff
path: root/static/components/edit-rrule.ts
blob: 6be01b76fffbedf101aeb1e86b08d7f265db1d75 (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
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);

        let frag = this.template.content.cloneNode(true) as DocumentFragment
        let body = frag.firstElementChild!
        this.replaceChildren(body);
    }

    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;
        }
    }

}