Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

DRAFT - DO NOT REVIEW UNTIL READY - prevents last toggle from being unselected #162

Open
wants to merge 3 commits into
base: main
Choose a base branch
from
Open
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
2 changes: 1 addition & 1 deletion modules/persistence.py
Original file line number Diff line number Diff line change
Expand Up @@ -54,7 +54,7 @@ def save_settings(raw_source, form_data):
# grab new config name if they entered one:
if "config_name" in form_data:
session["config_name"] = form_data["config_name"]
print(f"recieved config name in form: {session['config_name']}")
print(f"received config name in form: {session['config_name']}")

clean_data = clean_form_data(form_data)

Expand Down
57 changes: 29 additions & 28 deletions static/local-js/015-library_selection.js
Original file line number Diff line number Diff line change
Expand Up @@ -52,17 +52,19 @@ $(document).ready(function () {
type: $(this).data('type')
})
})
document.getElementById('libraries').value = JSON.stringify(selectedLibraries)
updateLibraries(selectedLibraries)
})

// Function to update libraries and create/delete template files
async function updateLibraries (selectedLibraries) {
if (!validateLibrarySelection(selectedLibraries)) {
alert('Please select at least one library.')
$(this).prop('checked', true) // Prevent unselecting the last toggle
return
}

document.getElementById('libraries').value = JSON.stringify(selectedLibraries)
updateLibraries(selectedLibraries)
})

// Function to update libraries and create/delete template files
async function updateLibraries (selectedLibraries) {
try {
const response = await fetch('/update_libraries', {
method: 'POST',
Expand Down Expand Up @@ -105,13 +107,19 @@ function generateTabs (selectedLibraries) {
const tabsContainer = $('#tabs')
const contentContainer = $('#tab-content')

// Clear existing tabs and content
tabsContainer.empty()
contentContainer.empty()

selectedLibraries.forEach((library, index) => {
const tabId = `tab-${library.name.replace(' ', '-')}`
const isActive = index === 0 ? 'active' : ''
const showClass = index === 0 ? 'show active' : ''
selectedLibraries.forEach((library) => {
const libPrefix = library.type === 'movie' ? 'mov' : 'sho'
const libraryId = library.name.replace(/ /g, '-')
const tabId = `${libPrefix}-${libraryId}-libname`
const isActive = tabsContainer.children().length === 0 ? 'active' : ''
const showClass = tabsContainer.children().length === 0 ? 'show active' : ''

const contentHtml = (library.type === 'movie' ? $('#movie-template').html() : $('#show-template').html())
.replace(/LIBID/g, `${libPrefix}-${libraryId}`)

tabsContainer.append(`
<li class="nav-item">
Expand All @@ -121,8 +129,7 @@ function generateTabs (selectedLibraries) {

contentContainer.append(`
<div class="tab-pane fade ${showClass}" id="${tabId}" role="tabpanel" aria-labelledby="${tabId}-tab">
<!-- Include content for ${library.name} here -->
${library.type === 'movie' ? $('#movie-template').html() : $('#show-template').html()}
${contentHtml}
</div>
`)
})
Expand All @@ -146,24 +153,7 @@ function handleCB () {
}
/* eslint-enable no-unused-vars */

/* eslint-disable no-unused-vars */
function librarySelect () {
const T = document.getElementById('library_select')
T.style.display = 'block' // <-- Set it to block
}
/* eslint-enable no-unused-vars */

/* eslint-disable no-unused-vars, camelcase */
function validateForm () {
const selectedLibraries = JSON.parse(document.getElementById('libraries').value.trim())
if (!validateLibrarySelection(selectedLibraries)) {
alert('Please select at least one library.')
return false
}

return true // Allow form submission
}

// Function to reapply event listeners
function reapplyEventListeners () {
document.querySelectorAll('.card-footer').forEach(cardFooter => {
Expand All @@ -180,3 +170,14 @@ function reapplyEventListeners () {
}
})
}

/* eslint-disable no-unused-vars */
function validateForm () {
const selectedLibraries = JSON.parse(document.getElementById('libraries').value.trim())
if (!validateLibrarySelection(selectedLibraries)) {
alert('Please select at least one library.')
return false
}

return true // Allow form submission
}
Loading