form.twig 8.92 KB
Newer Older
1
2
{% extends "layout.twig" %}

3
4
{% macro itemSelect(name, label, options, selected, index) %}
    <select class="form-control input-sm" name="items[{{ index | default('<%= index %>') | raw }}][{{ name }}]">
5
6
7
8
9
10
11
12
13
    <option value="" disabled selected>{{ label|striptags }}</option>
    {% for option in options %}
        <option value="{{ option.value|e }}"{% if selected == option.value %} selected{% endif %}>
            {{ option.label }}
        </option>
    {% endfor %}
    </select>
{% endmacro %}

14
{% macro itemCount(name, label, value, index) %}
15
16
17
    <div class="form-group">
        <div class="col-xs-12 col-sm-12 col-md-9">
            <input placeholder="{{ label|striptags }}" class="form-control input-sm"
18
                type="number" name="items[{{ index | default('<%= index %>') }}][{{ name }}]" value="{{ value|default('')|raw }}">
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
        </div>
    </div>
{% endmacro %}

{% macro select(name, label, options, selected) %}
    <div class="form-group">
        <label class="control-label hidden-xs hidden-sm" for="el-{{ name }}">{{ label|raw }}</label>
        <select class="form-control" name="{{ name }}" id="el-{{ name }}">
            <option value="" disabled selected>{{ label|striptags }}</option>
            {% for option in options %}
            <option value="{{ option.value|e }}"{% if selected == option.value %} selected{% endif %}>
                {{ option.label }}
            </option>
            {% endfor %}
        </select>
    </div>
{% endmacro %}

37
{% macro yesno(name, label, selected) %}
38
39
40
41
    <div class="form-group">
        <label class="control-label hidden-xs hidden-sm" for="el-{{ name }}">{{ label|raw }}</label>
        <select class="form-control" name="{{ name }}" id="el-{{ name }}">
            <option value="" disabled selected>{{ label|striptags }}</option>
42
43
            <option value="ΝΑΙ"{% if selected == 'ΝΑΙ' %} selected{% endif %}>Ναι</option>
            <option value="ΟΧΙ"{% if selected == 'ΟΧΙ' %} selected{% endif %}>Όχι</option>
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
        </select>
    </div>
{% endmacro %}

{% macro text(name, label, value) %}
    <div class="form-group">
        <label class="control-label hidden-xs hidden-sm" for="el-{{ name }}">{{ label|raw }}</label>
        <textarea class="form-control" name="{{ name }}" id="el-{{ name }}" placeholder="{{ label|striptags }}">{{ value|default('') }}</textarea>
    </div>
{% endmacro %}

{% import _self as macros %}

{% block content %}
<div id="app-form">
    <h1>
    {% block title %}
        Αίτηση <small>για νέο εξοπλισμό</small>
    {% endblock %}
    </h1>
Vassilis Kanellopoulos's avatar
Vassilis Kanellopoulos committed
64
    <form method="post" action="">
65
        <div class="form-group">
Vassilis Kanellopoulos's avatar
Vassilis Kanellopoulos committed
66
67
68
69
            <p>Lorem ipsum dolor sit amet, consectetur adipiscing elit. Praesent pulvinar tincidunt
                    odio, vel pretium mauris imperdiet at. In tempor fermentum enim, euismod posuere
                    purus venenatis sit amet. Sed tincidunt, sapien et varius congue, orci urna rutrum
                    magna, in porttitor tellus ante nec quam. Praesent non ante commodo, ornare tellus
70
71
                    ut, commodo dolor.</p>
        </div>
Vassilis Kanellopoulos's avatar
Vassilis Kanellopoulos committed
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
        <div class="table-responsive">
            <fieldset>
                <legend>Υπάρχον εξοπλισμός</legend>

                    <table class="table table-hover table-striped table-condensed">
                        <thead>
                            <tr>
                                <th>Χώρος</th>
                                <th>Τύπος</th>
                                <th>Πλήθος</th>
                            </tr>
                        </thead>
                        <tbody>
                        {% for asset in assets %}
                            <tr>
87
88
89
                                <td>{{ asset.lab }}</td>
                                <td>{{ asset.type }}</td>
                                <td>{{ asset.qty }}</td>
Vassilis Kanellopoulos's avatar
Vassilis Kanellopoulos committed
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
                            </tr>
                        {% else %}
                            <tr>
                                <td colspan="6" class="text-center">Δεν έχει καταχωρηθεί εξοπλισμός</td>
                            </tr>
                        {% endfor %}
                        </tbody>
                        <tfoot>
                            <tr>
                                <td colspan="6"></td>
                            </tr>
                        </tfoot>
                    </table>

            </fieldset>
        </div>
        <div class="table-responsive">
            <fieldset>
                <legend>Νέος εξοπλισμός</legend>
                <div class="form-group" id="items-list">
110
111
112
113
114
115
116
117
118
119
                    <table class="table table-hover table-striped">
                        <thead>
                            <tr>
                                <th>Χώρος</th>
                                <th>Τύπος</th>
                                <th>Πλήθος</th>
                                <th>Αιτιολογία χρήσης</th>
                                <th></th>
                            </tr>
                        </thead>
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
                        <tbody>
                            {% for item in form.values.items %}
                                <tr>
                                    <td>{{ macros.itemSelect('lab_id', 'Χώρος', lab_choices, item.lab_id, loop.index0 ) }}</td>
                                    <td>{{ macros.itemSelect('itemcategory_id', 'Τύπος', type_choices, item.itemcategory_id, loop.index0) }}</td>
                                    <td>{{ macros.itemCount('qty', 'Πλήθος', item.qty, loop.index0) }}</td>
                                    <td>
                                        <textarea class="form-control input-sm" 
                                                  rows="1" cols="20" 
                                                  name="items[{{ loop.index0 }}][reasons]" 
                                                  placeholder="Αιτιολογία χρήσης">
                                            {{ item.reasons }}
                                        </textarea>
                                    </td>
                                    <td><button type="button" class="btn btn-xs text-danger remove-row">
                                        <i class="fa fa-remove"></i>
                                    </button</td>
                                </tr>
                            {% endfor %}
                        </tbody>
140
141
142
143
144
145
146
147
148
149
150
151
                        <tfoot>
                            <tr>
                                <td colspan="5" class="text-right">
                                    <button type="button" class="btn btn-sm btn-primary add-row">
                                        <i class="fa fa-plus"></i>
                                        Προσθήκη εξοπλισμού
                                    </button>
                                </td>
                            </tr>
                        </tfoot>
                    </table>
                </div>
Vassilis Kanellopoulos's avatar
Vassilis Kanellopoulos committed
152
153
            </fieldset>
        </div>
154
155
        <fieldset>
            <legend>Επιπλέον</legend>
156
157
158
159
160
            {{ macros.select('apply_for', 'Αίτημα του σχολείου για', 
                apply_for_choices, form.values.apply_for) }}
            {{ macros.yesno('new_lab_perspective', 'Ύπαρξη - προοπτική αίθουσας για δημιουργία νέου εργαστηρίου',
                form.values.new_lab_perspective)}}
            {{ macros.text('comments', 'Σχόλια/Παρατηρήσεις', form.value.comments) }}
161
162
163
164
165
166

        </fieldset>
        <hr>
        <div class="form-group text-center">
            <button name="submit" value="submit" type="submit" class="btn btn-lg btn-primary">Υποβολή</button>
        </div>
Vassilis Kanellopoulos's avatar
Vassilis Kanellopoulos committed
167
168
        <input type="hidden" name="{{ csrf.name_key }}" value="{{ csrf.name }}">
        <input type="hidden" name="{{ csrf.value_key }}" value="{{ csrf.value }}">
169
170
    </form>
    <script type="text/template" id="app-form-item-row-template">
Vassilis Kanellopoulos's avatar
Vassilis Kanellopoulos committed
171
172
173
        <td>{{ macros.itemSelect('lab_id', 'Χώρος', lab_choices) }}</td>
        <td>{{ macros.itemSelect('itemcategory_id', 'Τύπος', type_choices) }}</td>
        <td>{{ macros.itemCount('qty', 'Πλήθος') }}</td>
174
175
176
        <td><textarea class="form-control input-sm" rows="1" cols="20" 
                name="items[<%= index %>][reasons]" 
                placeholder="Αιτιολογία χρήσης"></textarea></td>
177
178
179
180
181
182
183
184
185
186
187
        <td><button type="button" class="btn btn-xs text-danger remove-row">
            <i class="fa fa-remove"></i>
        </button</td>
    </script>
</div>
{% endblock %}

{% block inlinejs %}
    {{ parent() }}
    <script src="https://cdnjs.cloudflare.com/ajax/libs/underscore.js/1.8.3/underscore-min.js"></script>
    <script src="https://cdnjs.cloudflare.com/ajax/libs/backbone.js/1.2.3/backbone-min.js"></script>
Vassilis Kanellopoulos's avatar
Vassilis Kanellopoulos committed
188
    <script src="{{ base_url }}/js/application_form/index.js"></script>
189
{% endblock %}