Skip to content
Snippets Groups Projects
Commit 6435d60a authored by l26yan's avatar l26yan
Browse files

ISTWCMS-5124 Add locations pre-fill menu to service edit and clone pages

parent 61414b8c
No related branches found
No related tags found
4 merge requests!60ISTWCMS-6095 Update maxlength settings for title, text fields and link fields...,!25ISTWCMS-5779 Click update button under...,!8Feature/istwcms 5127 ebremner services blocks gui,!4ISTWCMS-5124 Create service content type
...@@ -11,7 +11,7 @@ field_name: field_uw_service_location_coord ...@@ -11,7 +11,7 @@ field_name: field_uw_service_location_coord
entity_type: node entity_type: node
bundle: uw_ct_service bundle: uw_ct_service
label: 'Location coordinates' label: 'Location coordinates'
description: 'If the address is not sufficient for locating the event, enter its coordinates here. To remove the coordinates, empty or set to zero either latitude or longitude.' description: 'If the address is not sufficient for locating the service, enter its coordinates here. To remove the coordinates, empty or set to zero either latitude or longitude.'
required: false required: false
translatable: false translatable: false
default_value: { } default_value: { }
......
/** /**
* @file * @file
* Javascript for event location presets menu. * Javascript for service location presets menu.
*/ */
(function ($, Drupal, drupalSettings) { (function ($, Drupal, drupalSettings) {
'use strict'; 'use strict';
Drupal.behaviors.uw_ct_event_location_autofill = { Drupal.behaviors.uw_ct_service_location_autofill = {
attach: function (context, drupalSettings) { attach: function (context, drupalSettings) {
var location_select = $('select#edit-location-presets-select'); var location_select = $('select#edit-location-presets-select');
location_select.change(function () { location_select.change(function () {
// Get chosen location. // Get chosen location.
var location = drupalSettings.uwCtEvent[location_select.val()]; var location = drupalSettings.uwCtService[location_select.val()];
// Do nothing when re-selecting the initial value. // Do nothing when re-selecting the initial value.
if (!location) { if (!location) {
return; return;
} }
// Set coordinates and re-center map. // Set coordinates and re-center map.
$('input#lat-edit-field-uw-event-location-coord-0-value').val(location.latitude); $('input#lat-edit-field-uw-service-location-coord-0-value').val(location.latitude);
$('input#lon-edit-field-uw-event-location-coord-0-value').val(location.longitude).change(); $('input#lon-edit-field-uw-service-location-coord-0-value').val(location.longitude).change();
// Set the country if it has changed. // Set the country if it has changed.
var select_country = $('#edit-field-uw-event-location-address-0 select.country'); var select_country = $('#edit-field-uw-service-location-0 select.country');
if (select_country.val() !== location.country_code) { if (select_country.val() !== location.country_code) {
select_country.val(location.country_code).change(); select_country.val(location.country_code).change();
} }
...@@ -47,10 +47,10 @@ ...@@ -47,10 +47,10 @@
if (counter > 50) { if (counter > 50) {
clearInterval(checkExist); clearInterval(checkExist);
} }
else if (!$('.ajax-progress-throbber').length && $('#edit-field-uw-event-location-address-0 input.organization').length) { else if (!$('.ajax-progress-throbber').length && $('#edit-field-uw-service-location-0 input.organization').length) {
clearInterval(checkExist); clearInterval(checkExist);
for (var key in address_fields) { for (var key in address_fields) {
var element = $('#edit-field-uw-event-location-address-0 ' + address_fields[key]); var element = $('#edit-field-uw-service-location-0 ' + address_fields[key]);
if (element.val() !== location[key]) { if (element.val() !== location[key]) {
element.val(location[key]).change(); element.val(location[key]).change();
} }
......
/**
* @file
* Javascript for editing uw_ct_service.
*/
(function ($, Drupal, drupalSettings) {
'use strict';
Drupal.behaviors.uw_ct_service_edit = {
attach: function (context, drupalSettings) {
// Marker at 0,0 means it is blank. Center the map on UW main campus.
$(document).on('geofieldMapInit', function (e, mapid) {
// Field containing the service location.
let service_location_mapid = 'map-edit-field-uw-service-location-coord-0-value';
if (mapid === service_location_mapid && drupalSettings['geofield_map'][mapid].lat === 0 && drupalSettings['geofield_map'][mapid].lng === 0) {
// Get coordinates of the center of UW main campus.
let position = {lat: 43.471, lng: -80.542};
// Center the map.
Drupal.geoFieldMap.mapSetCenter(mapid, position);
}
});
}
}
})(jQuery, Drupal, drupalSettings);
uw_ct_service_edit:
js:
js/uw_ct_service_edit.js: {}
location_autofill:
js:
js/location_autofill.js: {}
...@@ -7,6 +7,16 @@ ...@@ -7,6 +7,16 @@
use Drupal\Core\Form\FormStateInterface; use Drupal\Core\Form\FormStateInterface;
/**
* Implements hook_geofield_map_latlon_element_alter().
*/
function uw_ct_service_geofield_map_latlon_element_alter(array &$map_settings, array &$complete_form, array &$form_state_values) {
// Library for editing uw_ct_service.
if ($map_settings['id'] === 'edit-field-uw-service-location-coord-0-value') {
$complete_form['#attached']['library'][] = 'uw_ct_service/uw_ct_service_edit';
}
}
/** /**
* Load data about UW locations from a JSON file. * Load data about UW locations from a JSON file.
* *
...@@ -95,3 +105,15 @@ function uw_ct_service_form_node_uw_ct_service_form_alter(array &$form, FormStat ...@@ -95,3 +105,15 @@ function uw_ct_service_form_node_uw_ct_service_form_alter(array &$form, FormStat
$form['#attached']['library'][] = 'uw_ct_service/location_autofill'; $form['#attached']['library'][] = 'uw_ct_service/location_autofill';
$form['#attached']['drupalSettings']['uwCtService'] = _uw_ct_service_load_locations(); $form['#attached']['drupalSettings']['uwCtService'] = _uw_ct_service_load_locations();
} }
/**
* Implements hook_form_alter().
*/
function uw_ct_service_form_alter(array &$form, FormStateInterface $form_state, string $form_id): void {
switch ($form_id) {
case 'node_uw_ct_service_edit_form':
case 'node_uw_ct_service_quick_node_clone_form':
uw_ct_service_form_node_uw_ct_service_form_alter($form, $form_state, $form_id);
break;
}
}
0% Loading or .
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment