summaryrefslogtreecommitdiff
path: root/templates/index.html
blob: c83d78cbbdacd974eb5b68881e767cd75f391607 (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
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
138
139
140
141
142
143
144
145
146
147
148
<!doctype html>
<html lang="de">
<head>
    <title>Lehrerspruch-Wahlplattform</title>
    <link rel="stylesheet" type="text/css" href="/static/materialize.min.css">
    <link rel="stylesheet" type="text/css" href="https://fonts.googleapis.com/icon?family=Material+Icons">
    <meta charset="utf-8">
    <meta name="viewport" content="width=device-width,initial-scale=1.0,maximum-scale=1.0" />
</head>
<body>
    <script type="text/javascript" src="/static/jquery.min.js"></script>
    <script type="text/javascript" src="/static/smoothstate.min.js"></script>
    <script type="text/javascript" src="/static/materialize.min.js"></script>
    <div class="container" id="main">
        <header class="row">
            <h3>Lehrersprüche</h3>
            <div class="section">
                {% if user.loggedin %}
                <form action="/logout" method="post">
                    <button class="btn" type="submit">Logout ({{ user.name }})</button>
                </form>
                {% else %}
                <form action="/login" method="post">
                    <div class="col s6 m4 l3 input-field">
                        <label for="user">Benutzer</label>
                        <input type="text" name="user">
                    </div>
                    <div class="col s6 m4 l3 input-field">
                        <label for="user">Passwort</label>
                        <input type="password" name="password">
                    </div>
                    <div class="col s6 m4 l2">
                        <button class="btn col s12" type="submit">Anmelden</button>
                    </div>
                </form>
                {% endif %}
                <div class="col s2 m12 l2 right">
                    <a class="btn-floating btn-large right" href="/export{% if query %}?{{ query }}{% endif %}"><i class="material-icons">file_download</i></a>
                </div>
            </div>
        </header>
        <main>
            {% with msgs = get_flashed_messages() %}
                {% if msgs %}
            <div>
                {% for msg in msgs %}
                <p>{{ msg }}</p>
                {% endfor %}
            </div>
                {% endif %}
            {% endwith %}
            {% if tag %}
            <div class="chip">
                {{ tag }}
                <a href="/"><i class="material-icons">close</i></a>
            </div>
            {% endif %}
            <ul class="collection">
                {% for joke in jokes[currentpage*perpage:(currentpage+1)*perpage] %}
                <li class="collection-item row valign-wrapper">
                    <div class="col s4 m2 valign">
                        {% if not joke.deleted %}
                        <div>
                            <i class="material-icons">whatshot</i> <span class="right">{{ joke.score }} Punkte</span>
                        </div>
                        <form action="/upvote" method="post">
                            <input type="hidden" name="id" value="{{ joke.id }}">
                            <button class="btn{% if joke.upvoted %} disabled{% endif %}" type="submit" style="width: 100%;">
                                <i class="material-icons">thumb_up</i>
                            </button>
                        </form>
                        <form action="/downvote" method="post">
                            <input type="hidden" name="id" value="{{ joke.id }}">
                            <button class="btn{% if joke.downvoted %} disabled{% endif %}" type="submit" style="width: 100%;">
                                <i class="material-icons">thumb_down</i>
                            </button>
                        </form>
                        {% else %}
                        <form action="/undelete" method="post">
                            <input type="hidden" name="id" value="{{ joke.id }}">
                            <button class="btn-flat" type="submit" style="width: 100%;">
                                <i class="material-icons">delete undo</i>
                            </button>
                        </form>
                        {% endif %}
                    </div>
                    <div class="joke flow-text col s8 m10{% if joke.deleted %} grey-text{% endif %}" style="line-height: 1.5">
                        {% if joke.mine %}
                        <form action="/edit" method="post">
                            <input type="hidden" name="id" value="{{ joke.id }}">
                            <button type="button" class="btn-floating right blue noteditor" onclick="openEditor(this)"><i class="material-icons">edit</i></button>
                            <div class="input-field hide editor">
                                <label for="text">Spruch bearbeiten</label>
                                <textarea class="materialize-textarea" name="text">{{ joke.text }}</textarea>
                                <button type="submit" class="btn-floating right blue"><i class="material-icons">done</i></button>
                            </div>
                        </form>
                        {% endif %}
                        <div class="textfield noteditor">
                            {{ joke.html|safe }}
                        </div>
                        {% if joke.mine and not joke.deleted %}
                        <form action="/delete" method="post">
                            <input type="hidden" name="id" value="{{ joke.id }}">
                            <button class="btn-floating right red noteditor" type="submit"><i class="material-icons">delete</i></button>
                        </form>
                        {% endif %}
                    </div>
                </li>
                {% endfor %}
            </ul>
            <div class="section center">
                <ul class="pagination">
                    <li{% if currentpage==0 %} class="disabled"{% endif %}><a href="/page/{{ currentpage-1 }}{% if query %}?{{ query }}{% endif %}"><i class="material-icons">chevron_left</i></a></li>
                    {% for page in range((jokes|length/perpage)|round(0, 'ceil')|int) %}
                    <li{% if currentpage==loop.index0 %} class="active"{% endif %}><a href="/page/{{ loop.index0 }}{% if query %}?{{ query }}{% endif %}">{{ loop.index }}</a></li>
                    {% endfor %}
                    <li{% if currentpage==loop.length-1 %} class="disabled"{% endif %}><a href="/page/{{ currentpage+1 }}{% if query %}?{{ query }}{% endif %}"><i class="material-icons">chevron_right</i></a></li>
                </ul>
            </div>
            <div class="divider"></div>
            <div class="section">
                <form action="/submit" method="post">
                    <div class="row">
                        <div class="col s12 m9 input-field">
                            <label for="text">Neuen Spruch hinzufügen</label>
                            <textarea class="materialize-textarea" name="text"></textarea>
                        </div>
                        <div class="col s12 m3">
                            <input type="submit" class="btn" value="hinzufügen">
                        </div>
                    </div>
                </form>
            </div>
        </main>
    </div>
    <script type="text/javascript">
        $(document).ready(function() {
            $('#main').smoothState({prefetch: true, locationHeader: 'X-SmoothState-Location'});
        });
        function openEditor(me) {
            var joke = $(me).closest('.joke');
            $('.editor', joke).removeClass('hide');
            $('.noteditor', joke).addClass('hide');
        }
    </script>
</body>
</html>