form.twig 8.4 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
    <div class="form-group">
        <div class="col-xs-12 col-sm-12 col-md-9">
kanellov's avatar
fix #27  
kanellov committed
19
            <input placeholder="{{ label|striptags }}" class="form-control input-sm" min="1"
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">
kanellov's avatar
kanellov committed
79 80 81 82 83
            <p>
                Σε αυτή την καρτέλα θα καταχωρήσετε πληροφορίες που αφορούν στον 
                εξοπλισμό που θέλετε να αναβαθμίσετε ή/και στον νέο εξοπλισμό 
                που θέλετε να αποκτήσετε, υποβάλλοντας και τη σχετική αίτηση.
            </p>
Vassilis Kanellopoulos's avatar
Vassilis Kanellopoulos committed
84
        </div>
kanellov's avatar
kanellov committed
85
        
Vassilis Kanellopoulos's avatar
Vassilis Kanellopoulos committed
86 87 88
        <div class="table-responsive">
            <fieldset>
                <legend>Νέος εξοπλισμός</legend>
89
                <div id="items-list">
90 91 92 93
                    <table class="table table-hover table-striped">
                        <thead>
                            <tr>
                                <th>Πλήθος</th>
94 95
                                <th>Τύπος</th>
                                <th>Χώρος</th>
96 97 98 99
                                <th>Αιτιολογία χρήσης</th>
                                <th></th>
                            </tr>
                        </thead>
100
                        <tbody>
101
                            {% for itemIndex,item in form.values.items %}
102 103
                                <tr>
                                    <td>{{ macros.itemCount('qty', 'Πλήθος', item.qty, loop.index0) }}</td>
104 105 106
                                    <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>
107
                                    <td>
108 109
                                        {% if loop.index0 > 0 %}
                                        <button type="button" class="btn btn-xs text-danger remove-row">
110
                                        <i class="fa fa-remove"></i>
111
                                        {% endif %}
112 113
                                    </button</td>
                                </tr>
114 115 116 117 118 119 120 121
                            {% 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>
122 123
                            {% endfor %}
                        </tbody>
124 125 126 127 128 129 130 131 132 133 134 135
                        <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
136 137
            </fieldset>
        </div>
138 139
        <fieldset>
            <legend>Επιπλέον</legend>
140 141 142 143 144
            {{ 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) }}
145 146 147 148 149 150

        </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
151 152
        <input type="hidden" name="{{ csrf.name_key }}" value="{{ csrf.name }}">
        <input type="hidden" name="{{ csrf.value_key }}" value="{{ csrf.value }}">
153 154
    </form>
    <script type="text/template" id="app-form-item-row-template">
Vassilis Kanellopoulos's avatar
Vassilis Kanellopoulos committed
155
        <td>{{ macros.itemCount('qty', 'Πλήθος') }}</td>
156 157 158
        <td>{{ macros.itemSelect('itemcategory_id', 'Τύπος', type_choices) }}</td>
        <td>{{ macros.itemSelect('lab_id', 'Χώρος', lab_choices) }}</td>
        <td>{{ macros.itemReasons('reasons', 'Αιτιολογία χρήσης') }}</td>
159 160 161 162 163 164 165 166 167 168 169
        <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
170
    <script src="{{ base_url }}/js/application_form/index.js"></script>
171
{% endblock %}