~sirn/fanboi2

ref: 5b482cfc1bfb0bb1e89715cb57c7bac864391768 fanboi2/assets/app/javascripts/views/post_form.ts -rw-r--r-- 2.5 KiB
5b482cfcKridsada Thanabulpong 0.30.0 3 years ago
                                                                                
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
import {VNode, h} from 'virtual-dom';


export class PostForm {
    postFormNode: VNode;

    constructor(defaultText: string = '') {
        this.postFormNode = PostForm.renderForm(defaultText);
    }

    render(): VNode {
        return this.postFormNode;
    }

    private static renderForm(defaultText: string): VNode {
        return h('div', {className: 'js-post-form'}, [
            h('form', {
                className: 'form',
                dataset: {
                    topicInlineReply: true
                }
            }, [
                h('div', {className: 'container'}, [
                    h('div', {className: 'form-item'}, [
                        PostForm.renderBodyFormItemLabel(),
                        PostForm.renderBodyFormItemInput(defaultText),
                    ]),
                    h('div', {className: 'form-item'}, [
                        PostForm.renderPostFormItemButton(),
                        ' ',
                        PostForm.renderPostFormItemBump(),
                    ])
                ])
            ])
        ]);
    }

    private static renderBodyFormItemLabel(): VNode {
        return h('label', {
            className: 'form-item-label',
            htmlFor: 'js-body',
        }, ['Reply']);
    }

    private static renderBodyFormItemInput(defaultText: string): VNode {
        return h('textarea', {
            id: 'js-body',
            className: 'input block content',
            name: 'body',
            rows: 4,
            dataset: {
                formAnchor: true,
            },
        }, [defaultText]);
    }

    private static renderPostFormItemButton(): VNode {
        return h('button', {
            className: 'button green',
            type: 'submit'
        }, ['Post Reply']);
    }

    private static renderPostFormItemBump(): VNode {
        return h('span', {className: 'form-item-inline'}, [
            PostForm.renderPostFormItemBumpInput(),
            ' ',
            PostForm.renderPostFormItemBumpLabel(),
        ]);
    }

    private static renderPostFormItemBumpInput(): VNode {
        return h('input', {
            id: 'js-bumped',
            type: 'checkbox',
            name: 'bumped',
            value: 'y',
            checked: true,
            dataset: {
                topicStateTracker: 'bump',
            }
        }, []);
    }

    private static renderPostFormItemBumpLabel(): VNode {
        return h('label',
            {htmlFor: 'js-bumped'},
            ['Bump this topic']
        );
    }
}