Files
chrani-bot-tng/bot/modules/locations/templates/webmap/location_actions.html
2025-11-21 07:26:02 +01:00

173 lines
5.9 KiB
HTML

// ========================================
// Location Popup Actions
// ========================================
// Edit location from map popup
window.editLocationFromMap = function(dataset, owner, identifier) {
// This follows the exact same pattern as control_edit_link.html
window.socket.emit(
'widget_event',
['locations',
['toggle_locations_widget_view', {
'dom_element_owner': owner,
'dom_element_identifier': identifier,
'dom_element_origin': dataset,
'action': 'edit_location_entry'
}]]
);
console.log('[MAP] Opening edit view for location:', identifier);
};
// Toggle enabled status from map popup
window.toggleLocationEnabled = function(dataset, owner, identifier, isChecked) {
// This follows the exact same pattern as control_enabled_link.html
const action = isChecked ? 'enable_location_entry' : 'disable_location_entry';
window.socket.emit(
'widget_event',
['locations',
['toggle_enabled_flag', {
'dom_element_owner': owner,
'dom_element_identifier': identifier,
'dom_element_origin': dataset,
'action': action
}]]
);
console.log('[MAP] Toggling location enabled status:', identifier, 'to', isChecked);
};
// Move location to new position (relative teleport)
window.moveLocationFromMap = function(locationId) {
const loc = locations[locationId];
if (!loc) {
console.error('[MAP] Location not found:', locationId);
return;
}
// Close any open popups
map.closePopup();
// Create info message
const infoDiv = L.DomUtil.create('div', 'coordinates-display');
infoDiv.style.bottom = '50px';
infoDiv.style.background = 'rgba(102, 204, 255, 0.95)';
infoDiv.style.borderColor = 'var(--lcars-anakiwa)';
infoDiv.style.color = '#000';
infoDiv.style.fontWeight = 'bold';
infoDiv.innerHTML = '📍 Click new location position on map';
document.getElementById('map').appendChild(infoDiv);
// Change cursor
map.getContainer().style.cursor = 'crosshair';
// Wait for click
map.once('click', function(e) {
const newCoords = e.latlng;
const newX = Math.round(newCoords.lat);
const newZ = Math.round(newCoords.lng);
// Calculate offset
const offsetX = newX - loc.coordinates.x;
const offsetZ = newZ - loc.coordinates.z;
// Move teleport_entry relatively if it exists
let newTeleportEntry = loc.teleport_entry || {};
if (newTeleportEntry.x !== undefined && newTeleportEntry.y !== undefined && newTeleportEntry.z !== undefined) {
newTeleportEntry = {
x: (parseFloat(newTeleportEntry.x) || 0) + offsetX,
y: parseFloat(newTeleportEntry.y) || 0, // Y stays same
z: (parseFloat(newTeleportEntry.z) || 0) + offsetZ
};
}
// Call edit_location with ALL fields
window.socket.emit(
'widget_event',
['locations',
['edit_location', {
'location_identifier': loc.identifier,
'location_name': loc.name,
'location_shape': loc.shape,
'location_type': loc.type || [],
'location_coordinates': {
'x': newX,
'y': loc.coordinates.y,
'z': newZ
},
'location_teleport_entry': newTeleportEntry,
'location_dimensions': loc.dimensions || {},
'location_owner': loc.owner,
'is_enabled': loc.is_enabled
}]]
);
console.log('[MAP] Moved location to:', newX, newZ, 'Offset:', offsetX, offsetZ);
// Cleanup
map.getContainer().style.cursor = '';
document.getElementById('map').removeChild(infoDiv);
});
};
// Set teleport coordinates
window.setTeleportFromMap = function(locationId) {
const loc = locations[locationId];
if (!loc) {
console.error('[MAP] Location not found:', locationId);
return;
}
// Close any open popups
map.closePopup();
// Create info message
const infoDiv = L.DomUtil.create('div', 'coordinates-display');
infoDiv.style.bottom = '50px';
infoDiv.style.background = 'rgba(255, 153, 0, 0.95)';
infoDiv.style.borderColor = 'var(--lcars-golden-tanoi)';
infoDiv.style.color = '#000';
infoDiv.style.fontWeight = 'bold';
infoDiv.innerHTML = '🎯 Click teleport destination on map';
document.getElementById('map').appendChild(infoDiv);
// Change cursor
map.getContainer().style.cursor = 'crosshair';
// Wait for click
map.once('click', function(e) {
const teleportCoords = e.latlng;
const tpX = Math.round(teleportCoords.lat);
const tpZ = Math.round(teleportCoords.lng);
// Use current Y coordinate or default to location Y
const tpY = (loc.teleport_entry && loc.teleport_entry.y) || loc.coordinates.y;
// Call edit_location with ALL fields
window.socket.emit(
'widget_event',
['locations',
['edit_location', {
'location_identifier': loc.identifier,
'location_name': loc.name,
'location_shape': loc.shape,
'location_type': loc.type || [],
'location_coordinates': loc.coordinates,
'location_teleport_entry': {
'x': tpX,
'y': tpY,
'z': tpZ
},
'location_dimensions': loc.dimensions || {},
'location_owner': loc.owner,
'is_enabled': loc.is_enabled
}]]
);
console.log('[MAP] Set teleport to:', tpX, tpY, tpZ);
// Cleanup
map.getContainer().style.cursor = '';
document.getElementById('map').removeChild(infoDiv);
});
};