Files
kabano/views/d.poi.edit.html

233 lines
7.7 KiB
HTML
Executable File

<!DOCTYPE html>
<html lang="fr">
<? include('blocks/d.head.html'); ?>
<body>
<? include('blocks/d.nav.html'); ?>
<div id="mapid"></div>
<div id="sticky">
<section>
<i id="slide-icon" class="fas fa-chevron-up"></i>
<? if(isset($new) AND $new==1) { ?>
<form class="form" action="<?=$config['rel_root_folder']?>poi/new" method="post">
<? }
else { ?>
<form class="form" action="<?=$config['rel_root_folder']?>poi/<?=$poi->permalink?>/edit" method="post">
<? } ?>
<h1 class="flex_line">
<input type="text" value="<?=$poi->name?>" name="name" id="name" placeholder="Nom de l'hébergement" required>
<select name="locale" id="locale">
<? foreach($locales->objs as $locale) { ?>
<option <?=$poi->locale==$locale->name?'selected':''?> value="<?=$locale->name?>"><?=$locale->display_name?></option>
<? } ?>
</select>
</h1>
<div class="flex_line">
<input type="number" class="noarrow" step="any" value="<?=$poi->lat?>" name="lat" id="lat" placeholder="Latitude" required>
<input type="number" class="noarrow" step="any" value="<?=$poi->lon?>" name="lon" id="lon" placeholder="Longitude" required>
<input type="number" class="noarrow last-child" step="any" value="<?=$poi->ele?>" name="ele" id="ele" placeholder="Altitude">
<div id="elevation_icon" style="display:none;" title="Calculer l'altitude"><i class="fas fa-search-location"></i></div>
</div>
<div class="flex_line" id="type_selector">
<? foreach($poi_types as $type) { ?>
<input type="radio" name="poi_type" value="<?=$type[3]?>" id="<?=$type[3]?>" required
<?=$poi->poi_type == $type[3] ? 'checked' : ''?>>
<label for="<?=$type[3]?>"><img src="<?=$config['views_url']?>img/<?=$type[3]?>.svg"><br><?=$type[0]?></label>
<? } ?>
</div>
<script type="text/javascript">
<?php
$poi_params = $poi->parameters ?? new stdClass();
?>
var poi_params = <?= json_encode($poi_params) ?>;
var current_poi_type = "<?= $poi->poi_type ?>";
var unsaved = false;
// Stocke les abstracts et les squelettes de formulaire
<? foreach($poi_types as $type) { ?>
window["<?=$type[3]?>_abstract"] = "<?=$type[4]?>";
window["<?=$type[3]?>_jsonform"] = <?=json_encode($type[5])?>;
<? } ?>
// 3 états : 0 = non, 1 = intermédiaire, 2 = oui
function update3State(id) {
var input = $("input[name="+id+"]");
var label = $("label[for="+id+"]");
switch (+input.val()) {
case 0:
input.val(1);
label.toggleClass('uncheck intermediate');
break;
case 1:
input.val(2);
label.toggleClass('intermediate check');
break;
default:
input.val(0);
label.toggleClass('check uncheck');
}
unsaved = true;
}
// Génère / met à jour le sous-formulaire selon le type
function updateForm(type) {
$("#abstract").html(window[type + '_abstract']);
var html_form = "";
var jsonform = window[type + '_jsonform'];
$.each(jsonform, function(index, value) {
var prefix = index.charAt(0);
var existing = (poi_params && typeof poi_params[index] !== 'undefined')
? poi_params[index]
: null;
switch (prefix) {
case 'b':
var cls = 'intermediate';
var val = 1;
if (existing === 0 || existing === "0") {
cls = 'uncheck';
val = 0;
} else if (existing === 2 || existing === "2") {
cls = 'check';
val = 2;
}
html_form +=
'<label class="threecb ' + cls + '" for="' + index + '" onclick="update3State(\'' + index + '\')">' +
value +
'</label>' +
'<input value="' + val + '" type="hidden" name="' + index + '" id="' + index + '"><br>';
break;
case 'n':
html_form +=
'<div class="flex_line">' +
'<label for="' + index + '">' + value + '</label>' +
'<input min="0" type="number" name="' + index + '" id="' + index + '" ' +
(existing !== null ? 'value="' + existing + '"' : '') +
'>' +
'</div>';
break;
case 't':
html_form +=
'<textarea name="' + index + '" id="' + index + '" placeholder="' + value + '">';
if (existing !== null) {
html_form += String(existing)
.replace(/&/g, "&amp;")
.replace(/</g, "&lt;")
.replace(/>/g, "&gt;");
}
html_form += '</textarea>';
break;
case 'l':
html_form +=
'<div class="flex_line">' +
'<label for="' + index + '">' + value + '</label>' +
'<input placeholder="https://" type="url" name="' + index + '" id="' + index + '" ' +
(existing ? 'value="' + existing + '"' : '') +
'>' +
'</div>';
break;
default:
console.log("ERROR: " + index + "'s type is not known");
}
});
$("#specific_form").html(html_form);
unsaved = false;
$("#specific_form :input").change(function(){
unsaved = true;
});
}
$(document).ready(function(){
// Au chargement : générer le formulaire du type actuel
if (current_poi_type) {
updateForm(current_poi_type);
}
$('#type_selector label').click(function(){
if (unsaved === true) {
if (!confirm("Des changements ont été apportés et vont être supprimés, voulez-vous continuer ?")) {
return false;
}
}
const type = $(this).attr("for"); // robuste
current_poi_type = type;
updateForm(type);
});
});
</script>
<p id="abstract"></p>
<div id="specific_form"></div>
<label for="is_commentable">
<input type="checkbox" name="is_commentable" id="is_commentable" <?=$poi->is_commentable ? 'checked' : ''?> />
<span>Autoriser les commentaires</span>
</label>
<? if(isset($new) AND $new==1) { ?>
<div id="permalink_container">
<label id="permalink_label" for="permalink"><?=$config['web_root_folder']?>poi/</label>
<input type="text" name="permalink" id="permalink" placeholder="URL" required>
</div>
<? } ?>
<script type="text/javascript">
$( "#name" ).keyup(function() {
permalink = $( "#name" ).val();
permalink = permalink.replace(/ /g,'_');
permalink = permalink.toLowerCase();
permalink = permalink.replace(/[^a-z0-9_]/g,'-');
permalink = permalink.replace(/[_-]+$/g,'');
$( "#permalink" ).val(permalink);
});
$( "#name" ).change(function() {
permalink = $( "#name" ).val();
permalink = permalink.replace(/ /g,'_');
permalink = permalink.toLowerCase();
permalink = permalink.replace(/[^a-z0-9_]/g,'-');
permalink = permalink.replace(/[_-]+$/g,'');
$( "#permalink" ).val(permalink);
});
</script>
<input name="submit" id="submit" type="submit" value="<?= isset($new) && $new == 1 ? "Ajouter l'hébergement" : "Mettre à jour l'hébergement" ?>">
</form>
</section>
<script>
var poi_lat = <?=$poi->lat?>;
var poi_lon = <?=$poi->lon?>;
var poi_type = null;
var poi_mode = "edit";
</script>
<script type="text/javascript">
$( "#slide-icon" ).click(function() {
$( "html, body" ).animate({scrollTop: "300px"});
});
</script>
<? include('blocks/d.footer.html'); ?>
</div>
</body>
</html>