assetflow/static/js/editStorages.js

55 lines
1.7 KiB
JavaScript
Raw Normal View History

// Javascript to enable link to tab
// This magic js codes enables anchor links to work with bootstrap tabs
// Taken from https://stackoverflow.com/a/9393768/11317151 (and edited, like a lot)
// Also update on location change
2023-05-16 00:05:39 +02:00
window.addEventListener(
'hashchange',
function () {
var hash = location.hash.replace(/^#/, ''); // ^ means starting, meaning only match the first hash
if (hash) {
bootstrap.Tab.getOrCreateInstance(document.querySelector('#' + hash)).show();
}
},
false
);
var hash = location.hash.replace(/^#/, ''); // ^ means starting, meaning only match the first hash
if (hash) {
2023-05-16 00:05:39 +02:00
bootstrap.Tab.getOrCreateInstance(document.querySelector('#' + hash)).show();
}
// Change hash for page-reload
$('.nav-link').on('click', function (e) {
window.location.hash = e.target.id;
2023-05-16 00:05:39 +02:00
});
function primeCreateNew() {
const form = document.getElementById('storageUnitModalForm');
const form2 = document.getElementById('storageLocationModal');
form.setAttribute('method', 'POST');
form2.setAttribute('method', 'POST');
return true;
}
function primeEdit() {
const form = document.getElementById('storageUnitModalForm');
const form2 = document.getElementById('storageLocationModal');
form.setAttribute('method', 'PATCH');
form2.setAttribute('method', 'PATCH');
return true;
}
function handleSelector(){
const selector = document.getElementById('storageUnitModalLocationSelect')
const value = selector.options[selector.selectedIndex].value;
if(value == "META_CREATENEW") {
$('#storageUnitModalContactInfoCreator').removeClass('d-none')
$('.requireOnCreate').attr('required', true)
} else {
$('#storageUnitModalContactInfoCreator').addClass('d-none')
$('.requireOnCreate').attr('required', false)
}
console.log(value);
}
handleSelector()