|
8 | 8 | <input type="hidden" name="geolocation[zoom_level]" value="<?php echo $zoom; ?>"> |
9 | 9 | <input type="hidden" name="geolocation[map_type]" value="Leaflet"> |
10 | 10 |
|
| 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 | + |
11 | 27 | <div class="field"> |
12 | 28 | <div id="location_form" class="two columns alpha"> |
13 | 29 | <label for="geolocation_address"><?php echo html_escape($label); ?></label> |
|
16 | 32 | <input type="text" name="geolocation[address]" id="geolocation_address" value="<?php echo $address; ?>"> |
17 | 33 | <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> |
18 | 34 | </div> |
19 | | -</div> |
20 | 35 |
|
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> |
32 | 49 | </div> |
33 | 50 |
|
34 | 51 | <div id="geolocation-sr-alerts" class="sr-only" aria-live="polite" aria-atomic="true"></div> |
|
73 | 90 | }); |
74 | 91 |
|
75 | 92 | // 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'); |
80 | 105 | }); |
81 | 106 | }); |
82 | 107 | </script> |
0 commit comments