summaryrefslogtreecommitdiff
diff options
context:
space:
mode:
authorÉtienne Loks <etienne.loks@iggdrasil.net>2017-09-13 15:54:54 +0200
committerÉtienne Loks <etienne.loks@iggdrasil.net>2017-09-13 15:54:54 +0200
commita7091bedbcf32295662a80db71bbcf5d09c88010 (patch)
tree1b10810517ae2c6ffa13705ba2c7a02bc342904e
parentfd3afacbcc89b7b0ecbae7f0e73ff0919786f539 (diff)
downloadChimère - projet Saclay-a7091bedbcf32295662a80db71bbcf5d09c88010.tar.bz2
Chimère - projet Saclay-a7091bedbcf32295662a80db71bbcf5d09c88010.zip
Ajax submission of forms
-rw-r--r--templates/chimere/blocks/submited.html23
-rw-r--r--templates/chimere/edit.html75
-rw-r--r--templates/chimere/main_map.html8
3 files changed, 70 insertions, 36 deletions
diff --git a/templates/chimere/blocks/submited.html b/templates/chimere/blocks/submited.html
index b0d2dac..e69de29 100644
--- a/templates/chimere/blocks/submited.html
+++ b/templates/chimere/blocks/submited.html
@@ -1,23 +0,0 @@
-{% load i18n %}
- <div class='edit' id='submited-window'>
-<h2>Merci</h2>
-<h3>pour votre contribution au projet !</h3>
-
-<p>En proposant un nouvel élément, vous contribuez à enrichir la carte avec des données libres. Une fois validée, votre contribution sera disponible selon les termes de la licence <a href='https://creativecommons.org/licenses/by-sa/3.0/fr/'>Creative Commons Paternité - Pas d’Utilisation Commerciale 2.0 France</a>. Vous devez être l’auteur des éléments que vous nous faites partager ou bien vous être assuré de l’accord de leur auteur pour cette mise à disposition. Ceci concerne les textes, photos et tout contenu multimedia.</p>
-{% if contact_email %}<p>N’hésitez pas à nous contacter pour toute question : <a href='mailto:{{contact_email}}'>{{contact_email}}</a>.</p>{% endif%}
- </div>
- <script type='text/javascript'>
- <!--
- $(function(){
- $("#submited-window").dialog({
- modal: true,
- dialogClass:'no-titlebar-small',
- width:280,
- resizable:false,
- beforeClose: function() {
- window.location = "{{index_url}}";
- }
- });
- });
- // -->
- </script>
diff --git a/templates/chimere/edit.html b/templates/chimere/edit.html
index 6795d3f..4b839cf 100644
--- a/templates/chimere/edit.html
+++ b/templates/chimere/edit.html
@@ -7,7 +7,7 @@
{% 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='.'>
+ <form enctype="multipart/form-data" method='post' action='{% url "editmarker" %}' id='proposition_form'>
{% csrf_token %}
<p>* {% trans "indicates a mandatory field" %}</p>
@@ -140,10 +140,75 @@
$('#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>
-
- {% comment %}
- <p><input type='submit' onclick='saveExtent();displayProgress();' value="{% trans 'Propose'%}"/></p>
- {% endcomment %}
</form>
</div>
diff --git a/templates/chimere/main_map.html b/templates/chimere/main_map.html
index 0ea577b..378b5e1 100644
--- a/templates/chimere/main_map.html
+++ b/templates/chimere/main_map.html
@@ -63,14 +63,6 @@
</form>
{% routing %}
</div>
- <div id='edit-panel'>
- <div id='frm-edit-marker'>{# dynamic content #}
- </div>
- <div id='frm-edit-route'>{# dynamic content #}
- </div>
- <div id='frm-edit-event'>{# dynamic content #}
- </div>
- </div>
</div>
<div id='back-categories'>
<i class="fa fa-arrow-circle-left" aria-hidden="true"></i> <p>REVENIR AUX CATÉGORIES</p>