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

3
{% macro itemSelect(name, label, options, selected, index) %}
4
5
6
7
8
9
10
11
12
13
    <div class="form-group">
        <select class="form-control input-sm" name="items[{{ index | default('<%= index %>') | raw }}][{{ 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>
14
15
{% endmacro %}

16
{% macro itemCount(name, label, value, index) %}
17
18
19
    <div class="form-group">
        <div class="col-xs-12 col-sm-12 col-md-9">
            <input placeholder="{{ label|striptags }}" class="form-control input-sm"
20
                type="number" name="items[{{ index | default('<%= index %>') | raw }}][{{ name }}]" value="{{ value|default('')|raw }}">
21
22
23
24
        </div>
    </div>
{% endmacro %}

25
26
27
28
29
30
31
32
{% macro itemReasons(name, label, value, index) %}
    <div class="form-group">
        <textarea class="form-control input-sm" name="items[{{ index | default('<%= index %>') | raw }}][{{ name }}]"
                  placeholder="{{ label|striptags }}"
                  rows="1" cols="20">{{ value|default('') }}</textarea>
    </div>
{% endmacro %}

33
34
35
36
37
38
39
40
41
42
43
44
45
46
{% 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 %}

47
{% macro yesno(name, label, selected) %}
48
49
50
51
    <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>
52
53
            <option value="ΝΑΙ"{% if selected == 'ΝΑΙ' %} selected{% endif %}>Ναι</option>
            <option value="ΟΧΙ"{% if selected == 'ΟΧΙ' %} selected{% endif %}>Όχι</option>
54
55
56
57
58
59
60
        </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>
61
62
63
        <textarea class="form-control" name="{{ name }}" 
                  id="el-{{ name }}" 
                  placeholder="{{ label|striptags }}">{{ value|default('') }}</textarea>
64
65
66
67
68
69
70
71
72
73
74
75
    </div>
{% endmacro %}

{% import _self as macros %}

{% block content %}
<div id="app-form">
    <h1>
    {% block title %}
        Αίτηση <small>για νέο εξοπλισμό</small>
    {% endblock %}
    </h1>
76
77
    <form method="post" action="" data-is-valid="{{ form.is_valid | default(true) ? '1' : '0' }}"
          data-messages="{{ form.messages|default({})|json_encode }}">
78
        <div class="form-group">
Vassilis Kanellopoulos's avatar
Vassilis Kanellopoulos committed
79
80
81
82
            <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
83
84
                    ut, commodo dolor.</p>
        </div>
Vassilis Kanellopoulos's avatar
Vassilis Kanellopoulos committed
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
        <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>
100
101
102
                                <td>{{ asset.lab }}</td>
                                <td>{{ asset.type }}</td>
                                <td>{{ asset.qty }}</td>
Vassilis Kanellopoulos's avatar
Vassilis Kanellopoulos committed
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
                            </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>
122
                <div id="items-list">
123
124
125
126
                    <table class="table table-hover table-striped">
                        <thead>
                            <tr>
                                <th>Πλήθος</th>
127
128
                                <th>Τύπος</th>
                                <th>Χώρος</th>
129
130
131
132
                                <th>Αιτιολογία χρήσης</th>
                                <th></th>
                            </tr>
                        </thead>
133
                        <tbody>
134
                            {% for itemIndex,item in form.values.items %}
135
136
                                <tr>
                                    <td>{{ macros.itemCount('qty', 'Πλήθος', item.qty, loop.index0) }}</td>
137
138
139
                                    <td>{{ macros.itemSelect('itemcategory_id', 'Τύπος', type_choices, item.itemcategory_id, loop.index0) }}</td>
                                    <td>{{ macros.itemSelect('lab_id', 'Χώρος', lab_choices, item.lab_id, loop.index0 ) }}</td>
                                    <td>{{ macros.itemReasons('reasons', 'Αιτιολογία χρήσης', item.reasons, loop.index0) }}</td>
140
                                    <td>
141
142
                                        {% if loop.index0 > 0 %}
                                        <button type="button" class="btn btn-xs text-danger remove-row">
143
                                        <i class="fa fa-remove"></i>
144
                                        {% endif %}
145
146
                                    </button</td>
                                </tr>
147
148
149
150
151
152
153
154
                            {% else %}
                                <tr>
                                    <td>{{ macros.itemCount('qty', 'Πλήθος', '', 0) }}</td>
                                    <td>{{ macros.itemSelect('itemcategory_id', 'Τύπος', type_choices, '', 0) }}</td>
                                    <td>{{ macros.itemSelect('lab_id', 'Χώρος', lab_choices, '', 0 ) }}</td>
                                    <td>{{ macros.itemReasons('reasons', 'Αιτιολογία χρήσης', '', 0) }}</td>
                                    <td></td>
                                </tr>
155
156
                            {% endfor %}
                        </tbody>
157
158
159
160
161
162
163
164
165
166
167
168
                        <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
169
170
            </fieldset>
        </div>
171
172
        <fieldset>
            <legend>Επιπλέον</legend>
173
174
175
176
177
            {{ 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) }}
178
179
180
181
182
183

        </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
184
185
        <input type="hidden" name="{{ csrf.name_key }}" value="{{ csrf.name }}">
        <input type="hidden" name="{{ csrf.value_key }}" value="{{ csrf.value }}">
186
187
    </form>
    <script type="text/template" id="app-form-item-row-template">
Vassilis Kanellopoulos's avatar
Vassilis Kanellopoulos committed
188
        <td>{{ macros.itemCount('qty', 'Πλήθος') }}</td>
189
190
191
        <td>{{ macros.itemSelect('itemcategory_id', 'Τύπος', type_choices) }}</td>
        <td>{{ macros.itemSelect('lab_id', 'Χώρος', lab_choices) }}</td>
        <td>{{ macros.itemReasons('reasons', 'Αιτιολογία χρήσης') }}</td>
192
193
194
195
196
197
198
199
200
201
202
        <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
203
    <script src="{{ base_url }}/js/application_form/index.js"></script>
204
{% endblock %}