Skip to content

Commit 05d7732

Browse files
committed
Add metadata retrieval and insertion logic
Signed-off-by: Christos Sidiropoulos <dev@csidirop.de>
1 parent 0da165f commit 05d7732

2 files changed

Lines changed: 48 additions & 16 deletions

File tree

views/shared/css/geolocation-marker.css

Lines changed: 7 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -10,6 +10,13 @@
1010
button#geolocation_find_location_by_address {
1111
float: none;
1212
}
13+
#geolocation_metadata_select {
14+
width: 80%;
15+
}
16+
#geolocation_metadata_select_label {
17+
font-weight: bold;
18+
margin-right: 5px;
19+
}
1320

1421
div#geolocation {
1522
clear: both;

views/shared/map/input-partial.php

Lines changed: 41 additions & 16 deletions
Original file line numberDiff line numberDiff line change
@@ -8,6 +8,22 @@
88
<input type="hidden" name="geolocation[zoom_level]" value="<?php echo $zoom; ?>">
99
<input type="hidden" name="geolocation[map_type]" value="Leaflet">
1010

11+
<?php
12+
$metadata = [];
13+
14+
if (($item = get_current_record('Item')) instanceof Item) {
15+
$texts = $item->getAllElementTexts();
16+
17+
foreach ($texts as $textRecord) {
18+
$element = $item->getElementById($textRecord->element_id);
19+
// Build a label like "Title: My Item Title" and store it in the metadata array:
20+
$metadata[] = sprintf('%s: %s', $element->name, substr($tmp = $textRecord->text, 0, 40) . (strlen($tmp) > 40 ? '...' : ''));
21+
}
22+
23+
$metadata = array_unique($metadata);
24+
}
25+
?>
26+
1127
<div class="field">
1228
<div id="location_form" class="two columns alpha">
1329
<label for="geolocation_address"><?php echo html_escape($label); ?></label>
@@ -16,19 +32,20 @@
1632
<input type="text" name="geolocation[address]" id="geolocation_address" value="<?php echo $address; ?>">
1733
<button type="button" name="geolocation_find_location_by_address" id="geolocation_find_location_by_address" data-success-message="<?php echo __('Location found.'); ?>"><?php echo __('Find'); ?></button>
1834
</div>
19-
</div>
2035

21-
<div class="metadata-location-picker">
22-
<label for="metadata-location-select">Get location from metadata: </label>
23-
<select id="metadata-location-select">
24-
<!-- TODO: get metadata -->
25-
<?php foreach ($metadata as $md): ?>
26-
<option value="<?php echo html_escape($md); ?>">
27-
<?php echo html_escape($md); ?>
28-
</option>
29-
<?php endforeach; ?>
30-
</select>
31-
<button type="button" id="metadata-load-btn">Load</button>
36+
<div class="two columns alpha">
37+
<label id="geolocation_metadata_select_label" for="geolocation_metadata_select"><?php echo __('Get location from metadata:');?></label>
38+
</div>
39+
<div class="inputs five columns omega">
40+
<select id="geolocation_metadata_select">
41+
<?php foreach ($metadata as $md): ?>
42+
<option value="<?php echo html_escape($md); ?>">
43+
<?php echo html_escape($md); ?>
44+
</option>
45+
<?php endforeach; ?>
46+
</select>
47+
<button type="button" id="geolocation_metadata_load_btn"><?php echo __('Load');?></button>
48+
</div>
3249
</div>
3350

3451
<div id="geolocation-sr-alerts" class="sr-only" aria-live="polite" aria-atomic="true"></div>
@@ -73,10 +90,18 @@
7390
});
7491

7592
// Make the metadata load button set the hidden form fields the plugin uses.
76-
jQuery('#metadata-load-btn').on('click', function (event) {
77-
var metadata = $('#metadata-location-select').val();
78-
if (!metadata) return;
79-
$('input[name="location]').val(metadata);
93+
jQuery('#geolocation_metadata_load_btn').on('click', function (event) {
94+
event.preventDefault();
95+
96+
// Get the raw selected option text, e.g. "Title: My Awesome Place"
97+
var selected = jQuery('#geolocation_metadata_select').val();
98+
if (!selected) return;
99+
100+
// Split off the part after the first ": "
101+
var parts = selected.split(': ');
102+
var address = parts.slice(1).join(': ');
103+
104+
jQuery('#geolocation_address').val(address).trigger('change');
80105
});
81106
});
82107
</script>

0 commit comments

Comments
 (0)