Adds views script handling during global AJAX navigation

This commit is contained in:
BinaryAlley committed 2024-11-17 11:46:48 +02:00
1 parent 1eeb6661ca
commit a840364483
8 files changed
+183 -34

No files matched your search

@@ -3,9 +3,12 @@
*@
@using Lumina.Presentation.Web.Common.Models.Libraries
@using Lumina.Presentation.Web.Common.Services
@{
var id = Context.Request.RouteValues["id"] as string;
// generate a unique id for the scripts section of this view, so it can be dynamically loaded/unloaded by the global AJAX navigator handler
var scriptId = ScriptIdentifierHelper.GenerateScriptId();
}
@model LibraryModel
@@ -84,7 +87,8 @@
</form>
</div>
@section Scripts {
<script type="text/javascript" defer>
<script type="text/javascript" data-form="@scriptId" defer>
document.getElementById('add-media-library-form').addEventListener('keypress', async (event) => {
if (event.key === 'Enter') {
event.preventDefault();
@@ -118,6 +122,12 @@
showFileSystemBrowserDialogAsync('C:\\Users\\', true, false, addNewPaths); // TODO: take path and include hidden elements from settings
});
document.querySelectorAll('.remove-form-table-row-icon').forEach(icon => {
icon.addEventListener('click', function () {
this.parentElement.remove();
});
});
function addNewPaths(selectedPaths) {
// get the form table where the new paths will be added
const formTable = document.querySelector('.form-table');