summaryrefslogtreecommitdiff
path: root/templates/chimere/edit.html
blob: 4b839cfa87807e6fbcab09c02012288f4b4bc338 (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
149
150
151
152
153
154
155
156
157
158
159
160
161
162
163
164
165
166
167
168
169
170
171
172
173
174
175
176
177
178
179
180
181
182
183
184
185
186
187
188
189
190
191
192
193
194
195
196
197
198
199
200
201
202
203
204
205
206
207
208
209
210
211
212
213
214
{% load i18n chimere_tags inline_formset staticfiles bootstrap %}
{% if submited %}{% submited %}{% endif %}
{% if error_message %}<div class='edit errorlist'>
    <legend>{% trans "Error" %}</legend>
    <p>{{ error_message }}</p>
{% endif %}</div>
{% if is_modification and is_superuser %}<div class='warning'><p>{% trans "You are logged as an administrator. Your modifications will be taking into account immediately." %}</p></div>{% endif %}
<div class='edit'>
{% block legend %}{% endblock %}
    <form enctype="multipart/form-data" method='post' action='{% url "editmarker" %}' id='proposition_form'>
        {% csrf_token %}
        <p>* {% trans "indicates a mandatory field" %}</p>

        <div class="container" style="width: 100%;">
            <div class="row">
                <div class="col-xs-6">
                    <label for="id_name">{% trans "Name"%} *</label>
                    {% if form.name.errors %}<div class='errors'>{{ form.name.errors }}</div>{% endif %}
                    {{ form.name }}
                </div>
                <div class="col-xs-6">
                    <label for="id_subcategory">{% if form.categories.label %}{{ form.categories.label }}{% else %}{% trans "Categories" %} *{% endif %}</label>
                    {% if form.categories.errors %}<div class='errors'>{{ form.categories.errors }}</div>{% endif %}
                    {{ form.categories }}
                </div>
            </div>
            <div class="row">
                <div class="col-xs-12">
                    {% block geometry %}
                    {% endblock %}
                </div>
            </div>
            <div class="row">
                <div class="col-xs-12 full">
                    <label for="id_description">{% trans "Description" %}</label>
                    {{ form.description.errors }}
                    {{ form.description }}
                    <p class="help">{{ form.description.help_text }}</p>
                </div>
            </div>
            {% if form.keywords %}
            <div class="row">
                <div class="col-xs-6">
                    <label for="id_keywords">{% trans "Keywords" %}</label>
                    {{ form.keywords.errors }}
                    {{ form.keywords }}
                    <p class="help">{{ form.keywords.help_text }}</p>
                </div>
            </div>{% endif %}
            {% if dated %}
            <div class="row">
                <div class="col-xs-6">
                    <label for="id_start_date">{% trans "Start date" %}</label>
                    {{ form.start_date.errors }}
                    {{ form.start_date }}
                    <p class="help">{{ form.start_date.help_text }}</p>
                </div>
                <div class="col-xs-6">
                    <label for="id_end_date">{% trans "End date" %}</label>
                    {{ form.end_date.errors }}
                    {{ form.end_date }}
                    <p class="help">{{ form.end_date.help_text }}</p>
                </div>
            </div>{% endif %}
            {% for field in form %}{% for property in properties %}{% ifequal field.name property.getNamedId %}
            <div class="row">
                <div class="col-xs-6">
                    <label for="id_{{field.name}}">{% trans field.label %}{% if property.mandatory %} *{% endif %}</label>
                    {% if field.errors %}<div class='errors'>{{ field.errors }}</div>{% endif %}
                    {{ field }}
                </div>
            </div>{% endifequal %}{% endfor %}{% endfor %}
        </div>

        <div class='bottomform'>

            {% inline_formset "Multimedia files" formset_multi %}
            {% inline_formset "Picture files" formset_picture %}

            {% if filtered_properties %}
            <script type='text/javascript'>
                var cat_filters = new Array();
                var cat_to_hide = new Array();
                {% for property in filtered_properties %}
                cat_to_hide.push('#id_{{property.getNamedId}}');
                {% for subcat in property.subcategories.all %}
                if(!cat_filters['{{subcat.id}}']) cat_filters['{{subcat.id}}'] = new Array();
                cat_filters['{{subcat.id}}'].push('#id_{{property.getNamedId}}');
                {% endfor %}
                {% endfor %}
                $('.bsmSelect').change(function(){
                    for (idx in cat_to_hide){
                        $(cat_to_hide[idx]).parent().hide();
                    }
                    var vals = $('#id_categories').val();
                    for (val_id in vals){
                        var val = vals[val_id];
                        for (ids in cat_filters[val]){
                            $(cat_filters[val][ids]).parent().show();
                        }
                    }
                });
                $('.bsmSelect').change();
            </script>
            {% endif %}
        </div>
        <div class='personalform'>
            <h5>{% trans "Personal information"%}</h5>
            <div class="alert alert-info" role="alert">
                {% trans "This fields are not mandatory. If you provided them they not will be made public and they will only used to join you for this project."%}
            </div>
            <div class="container">
                <div class="row">
                    <div class="col-xs-6">
                        <label for="id_submiter_name">{% trans "Your name or nickname"%}</label>
                        {% if form.submiter_name.errors %}<div class='errors'>{{ form.submiter_name.errors }}</div>{% endif %}
                        {{ form.submiter_name }}
                    </div>
                    <div class="col-xs-6">
                        <label for="id_submiter_email">{% trans "Your email"%}</label>
                        {% if form.submiter_email.errors %}<div class='errors'>{{ form.submiter_email.errors }}</div>{% endif %}
                        {{ form.submiter_email }}
                    </div>
                </div>
                <div class="row">
                    <div class="col-xs-12 full">
                        <label for="id_submiter_comment">{% trans "Comments about your submission"%}</label>
                        {% if form.submiter_comment.errors %}<div class='errors'>{{ form.submiter_comment.errors }}</div>{% endif %}
                        {{ form.submiter_comment }}
                    </div>
                </div>
            </div>
        </div>
        {% bootstrap_modal "upload_in_progress" %}
        <script text='text/javascript'>
            var upload = '<p>{% trans "Upload in progress. Please wait..." %}</p>\n';
            upload += "<p><img alt='Ajax loader' src='{{STATIC_URL}}chimere/img/ajax-loader.gif'/></p>";

            function displayProgress(){
                $('#upload_in_progress .modal-body').html(upload);
                $('#upload_in_progress').modal("show");
            }
            var success_msg = "<h3>Merci pour votre contribution au projet !</h3>";
            success_msg += "<p>Votre proposition va être examinée par un modérateur et être validée dans les jours à venir.</p>"
            $(function(){
                if (typeof tinyMCE !== 'undefined'){
                    tinyMCE.init({
                        mode : "textareas",
                        theme: 'modern',
                        editor_selector : "mceEditor",
                        relative_urls : false,
                        toolbar_items_size: 'small',
                        menubar: '',
                        toolbar1: 'bold italic,underline | bullist,numlist',
                        toolbar2: "",
                        toolbar3: ""
                    });
                }
                {% comment %}
                {% if route %}
                var edition_type = 'route';
                {% if itinerary_form %}
                $("#chimere_itinerary_form").appendTo($("#itinerary_field"));
                $('#main_map').chimere('updateRoutingInput');{% endif%}
                {% else %}
                var edition_type = 'marker';
                $('#main_map').chimere('updateMarkerInput');
                {% endif %}
                {% endcomment %}
                $('#modal-edit button.btn-primary').click(function(){
                    // JS tests because if a file is submited there is no way
                    // to refill the form with (browser security issue)
                    if (typeof tinyMCE !== 'undefined') tinyMCE.triggerSave();
                    validation = [{%if route%}
                        'id_route'{%else%}'id_point'{% endif %},
                        'id_name',
                        'id_categories',{% if event %}
                        'id_start_date',{% endif %}
                    ];
                    var validated = true;
                    for (var idx=0; idx<validation.length ;idx++){
                        var input_id = validation[idx];
                        var val = jQuery('#'+input_id).val();
                        if (!val || val == '0' ||
                                (input_id == 'id_submiter_email' &&
                                !isValidEmailAddress(val))){
                            jQuery('#'+input_id).parent().addClass('warning');
                            jQuery('#'+input_id).parent().addClass('error');
                            validated = false;
                        } else {
                            jQuery('#'+input_id).parent().removeClass('warning');
                            jQuery('#'+input_id).parent().removeClass('error');
                        }
                    }
                    if (!validated){
                        alert("{%trans "There are missing/erroneous fields."%}");
                        return false;
                    }
                    $("#proposition_form").ajaxForm();
                    displayProgress();
                    $("#proposition_form").ajaxSubmit({
                        success:function(msg){
                            $('#upload_in_progress').modal("hide");
                            $("#modal-edit").modal("hide");
                            $("#modal-default-message .modal-body").html(success_msg);
                            $('#modal-default-message').modal("show");
                        }
                    });
                    return false;
                });
            });
        </script>
    </form>
</div>