summaryrefslogtreecommitdiff
path: root/templates/chimere/edit.html
blob: ff832e5cb4c50b0e69bde8cb6ec04431615d536c (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
215
216
217
218
219
220
221
222
223
{% load i18n chimere_tags inline_formset%}
    {% if submited %}{% submited %}{% endif %}
    <div class='edit'>
    {% if event %}<h3>{% trans "Add an event" %}</h3>
    {% else %}
    {% if route %}<h3>{% trans "Add a route" %}</h3>
    {% else %}<h3>{% trans "Add a location" %}</h3>
    {% endif%}{% endif%}
    <div class='notice'>
    {% if event %}
    <p>Vous pouvez utiliser le formulaire ci-dessous pour partager avec nous un événement public à venir sur le territoire. Merci de ne renseigner un événement que lorsqu’il est confirmé, et de nous faire part le plus rapidement possible de toute modification le concernant.  Pensez à indiquer la date de début et de fin.
Les évènements à caractère politique, confessionnel ainsi que ceux relevant de prosélytisme divers ne seront pas affichés sur le site.</p>
    {% else %}
    {% if route %}
    <p>Vous pouvez utiliser le formulaire ci-dessous pour proposer un itinéraire de promenade sur le territoire. Merci de renseigner seulement un itinéraire que vous avez déjà pratiqué à plusieurs reprises et avec succès, afin d’éviter des déconvenues à ceux qui s’en inspireraient.</p>
    {% else %}
    <p>Vous pouvez utiliser le formulaire ci-dessous pour proposer un lieu utile ou remarquable sur le plateau. Merci de vous assurer au préalable de l’exactitude des informations fournies et de visiter les rubriques déjà existantes pour harmoniser les informations soumises.</p>
    {% endif%}{% endif%}
    </div>
    <p class='notice'>* {% trans "indicates a mandatory field" %}</p>
    <form enctype="multipart/form-data" method='post' action='{% if route%}{% url 'edit-route' %}{%else%}{% url 'edit' %}{% endif %}' id='proposition_form'>
    {% csrf_token %}
    {% if not route %}
    <div class="fieldWrapper point_label">
        <label class='error'>{% trans "Select a location for this new site" %}</label>
        <input type='hidden' id='id_point' name='point'/>
    </div>{% endif %}
    <div class="fieldWrapper">
        <label for="id_name">{%if route%}{% trans "Name of the route"%}{% else %}{% if event %}{% trans "Name of the event"%}{% else %}{% trans "Name of the location"%}{% endif %}{% endif %} <span class='mandatory'>*</span></label>
        {% if form.name.errors %}<div class='errors'>{{ form.name.errors }}</div>{% endif %}
        {{ form.name }}
    </div>
    <div class="fieldWrapper">
      <label for="id_subcategory">{% trans "Category" %} <span class='mandatory'>*</span></label>
        {% if form.categories.errors %}<div class='errors'>{{ form.categories.errors }}</div>{% endif %}
      {{ form.categories }}
    </div>
    <hr class='clean'/>
    {% if event %}
    <div class="fieldWrapper" id='div_start_date'>
        <label for="id_start_date">{% trans "Start date" %} <span class='mandatory'>*</span></label>
        {{ form.start_date.errors }}
        {{ form.start_date }}
    </div>
    <div class="fieldWrapper" id='div_end_date'>
        <label for="id_end_date">{% trans "End date" %}</label>
        {{ form.end_date.errors }}
        {{ form.end_date }}
    </div>
    <hr class='clean'/>
    {% endif %}
    {% for field in form %}
        {% for property in properties %}
            {% ifequal field.name property.getNamedId %}
                <div class="fieldWrapper single-line">
                    <label for="id_{{field.name}}">{% trans field.label %}{% if property.mandatory %} <span class='mandatory'>*</span>{% endif %}</label>
                    {% if field.errors %}<div class='errors'>{{ field.errors }}</div>{% endif %}
                    {{ field }}
                </div>
            {%endifequal%}
        {%endfor%}
    {%endfor%}
    <div class="fieldWrapper">
        <label for="id_description">{% trans "Description" %}</label>
        {{ form.description.errors }}
        {{ form.description }}
        <p class="help">{{ form.description.help_text }}</p>
    </div>

    {% 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 %}
        $('#id_categories').change(function(){
            for (idx in cat_to_hide){
                $(cat_to_hide[idx]).parent().hide();
            }
            var vals = $(this).val();
            for (val_id in vals){
                var val = vals[val_id];
                for (ids in cat_filters[val]){
                    $(cat_filters[val][ids]).parent().show();
                }
            }
        });
        $('#id_categories').change();
        // -->
    </script>
    {% endif %}
    {% if route %}
    <h4 id='head_route' class='toggle maximized'>{% trans "Route" context "form" %} <span class='mandatory'>*</span></h4>
    <div id='itinerary_field_contener'>
        <input id='id_route' name='route' type='hidden'/>
        <label class='error'>{% trans "Select a route for this new site (have you submit the search?)" %}</label>
    <div id='itinerary_field'>{% if not itinerary_form %}
    <div class='notice'><p>Cliquez sur la carte pour dessiner le trajet.</p></div>
    {% endif %}</div>
    <hr class='clean'/>
    </div>
    {% endif %}
    <h4 id='head_multimedia'><span>Images, audios, vidéos</span><span id="add_multimedia_list">Ajouter</span></h4>
    {% alternate_multimedia formset_multi formset_picture %}
    <h4 id='head_personalform' class='toggle maximized'>{% trans "Personal information"%}</h4>
    <div id='personalform'>
        <div class="fieldWrapper single-line">
            <label for="id_submiter_email">{% trans "Email"%} <span class='mandatory'>*</span></label>
            {% if form.submiter_email.errors %}<div class='errors'>{{ form.submiter_email.errors }}</div>{% endif %}
            {{ form.submiter_email }}
        </div>
        <div class="fieldWrapper single-line">
            <label for="id_submiter_name">{% trans "Name"%}</label>
            {% if form.submiter_name.errors %}<div class='errors'>{{ form.submiter_name.errors }}</div>{% endif %}
            {{ form.submiter_name }}
        </div>
        <div class="fieldWrapper">
            <label for="id_submiter_comment">{% trans "Comment" %}</label>
            {% if form.submiter_comment.errors %}<div class='errors'>{{ form.submiter_comment.errors }}</div>{% endif %}
            {{ form.submiter_comment }}
        </div>
    </div>
    <div id='upload_in_progress'>
        <p>{% trans "Upload in progress. Please wait..." %}</p>
        <p><img src='{{STATIC_URL}}chimere/img/ajax-loader.gif'/></p>
    </div>
    <p><span id='proposition_form_submit'>{% trans 'Propose'%}</span></p>
    <script text='text/javascript'>
        <!--
        $(function(){
            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: ""
            });
            {% 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 %}
            $('#main_map').chimere('activateEdition', edition_type);
            $('#main_map').chimere('activateDraw');
            $('.toggle').click(function(){
                var div_item = $(this).next();
                div_item.toggle();
                if (div_item.is(":visible")){
                    $(this).removeClass('minified');
                    $(this).addClass('maximized');
                } else {
                    $(this).addClass('minified');
                    $(this).removeClass('maximized');
                }
            });
            $( "#upload_in_progress" ).dialog({
                 modal: true,
                 resizable:false,
                 height:110,
                 autoOpen:false,
                 dialogClass:'alert-box'
                }
            );
            $('#proposition_form_submit').click(function(){
                // JS tests because if a file is submited there is no way
                // to refill the form with (browser security issue)
                tinyMCE.triggerSave();
                validation = [{%if route%}
                    'id_route'{%else%}'id_point'{% endif %},
                    'id_name',
                    'id_categories',{% if event %}
                    'id_start_date',{% endif %}
                    'id_submiter_email'
                ];
                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."%}");
                    $("#panel").scrollTop(0);
                    return false;
                }
                $("#proposition_form").ajaxForm();
                $("#upload_in_progress").dialog('open');
                $("#proposition_form").ajaxSubmit({
                    target:"#frm-edit-marker",
                    success:function(msg){
                        $("#panel").scrollTop(0);
                        $("#upload_in_progress").dialog('close');
                    }
                });
            });
        });
        // -->
    </script>
    </form>
    </div>