// Menu Highlight Scripts const menuItems = document.getElementsByClassName('nav-link'); for(let i = 0; i < menuItems.length; i++) { if(menuItems[i].pathname == window.location.pathname) { menuItems[i].classList.add('active'); } } const dropdownItems = document.getElementsByClassName('dropdown-item'); for(let i = 0; i< dropdownItems.length; i++) { if(dropdownItems[i].pathname == window.location.pathname) { dropdownItems[i].classList.add('active'); $( "#" + dropdownItems[i].id ).closest( '.dropdown' ).find('.dropdown-toggle').addClass('active'); } } // Form Processing Scripts $('form[name=form-register]').submit(function(event) { var $form = $(this); var alert = document.getElementById('alert-box'); var data = $form.serialize(); alert.innerHTML = '' $.ajax({ url: window.location.pathname, type: 'POST', data: data, dataType: 'json', success: function(response) { window.location.href = "/admin/login/"; }, error: function(response) { if (typeof response.responseJSON.error === 'string' || response.responseJSON.error instanceof String) { alert.innerHTML = alert.innerHTML + ` `; } else if (response.responseJSON.error instanceof Array) { for (var i = 0; i < response.responseJSON.error.length; i ++) { alert.innerHTML = alert.innerHTML + ` `; } } } }); event.preventDefault(); }); $('form[name=form-login]').submit(function(event) { var $form = $(this); var alert = document.getElementById('alert-box'); var data = $form.serialize(); alert.innerHTML = '' $.ajax({ url: window.location.pathname, type: 'POST', data: data, dataType: 'json', success: function(response) { window.location.href = "/admin/dashboard/"; }, error: function(response) { if (typeof response.responseJSON.error === 'string' || response.responseJSON.error instanceof String) { alert.innerHTML = alert.innerHTML + ` `; } else if (response.responseJSON.error instanceof Array) { for (var i = 0; i < response.responseJSON.error.length; i ++) { alert.innerHTML = alert.innerHTML + ` `; } } } }); event.preventDefault(); }); $('form[name=form-reset]').submit(function(event) { var $form = $(this); var alert = document.getElementById('alert-box'); var data = $form.serialize(); alert.innerHTML = '' $.ajax({ url: window.location.pathname, type: 'POST', data: data, dataType: 'json', success: function(response) { window.location.href = "/admin/login/"; }, error: function(response) { if (typeof response.responseJSON.error === 'string' || response.responseJSON.error instanceof String) { alert.innerHTML = alert.innerHTML + ` `; } else if (response.responseJSON.error instanceof Array) { for (var i = 0; i < response.responseJSON.error.length; i ++) { alert.innerHTML = alert.innerHTML + ` `; } } } }); event.preventDefault(); }); $('form[name=form-update-password]').submit(function(event) { var $form = $(this); var alert = document.getElementById('alert-box'); var data = $form.serialize(); console.log(data) alert.innerHTML = '' $.ajax({ url: window.location.pathname, type: 'POST', data: data, dataType: 'json', success: function(response) { window.location.href = "/admin/login/"; }, error: function(response) { if (typeof response.responseJSON.error === 'string' || response.responseJSON.error instanceof String) { alert.innerHTML = alert.innerHTML + ` `; } else if (response.responseJSON.error instanceof Array) { for (var i = 0; i < response.responseJSON.error.length; i ++) { alert.innerHTML = alert.innerHTML + ` `; } } } }); event.preventDefault(); }); $('form[name=form-create-user]').submit(function(event) { var $form = $(this); var alert = document.getElementById('alert-box'); var data = $form.serialize(); alert.innerHTML = '' $.ajax({ url: window.location.pathname, type: 'POST', data: data, dataType: 'json', success: function(response) { window.location.reload(); }, error: function(response) { if (typeof response.responseJSON.error === 'string' || response.responseJSON.error instanceof String) { alert.innerHTML = alert.innerHTML + ` `; } else if (response.responseJSON.error instanceof Array) { for (var i = 0; i < response.responseJSON.error.length; i ++) { alert.innerHTML = alert.innerHTML + ` `; } } } }); event.preventDefault(); }); $('form[name=form-delete-user]').submit(function(event) { var $form = $(this); var alert = document.getElementById('alert-box'); var data = $form.serialize(); alert.innerHTML = '' $.ajax({ url: window.location.pathname, type: 'POST', data: data, dataType: 'json', success: function(response) { window.location.href = '/admin/settings/users/'; }, error: function(response) { if (typeof response.responseJSON.error === 'string' || response.responseJSON.error instanceof String) { alert.innerHTML = alert.innerHTML + ` `; } else if (response.responseJSON.error instanceof Array) { for (var i = 0; i < response.responseJSON.error.length; i ++) { alert.innerHTML = alert.innerHTML + ` `; } } } }); event.preventDefault(); }); $('form[name=form-update-user]').submit(function(event) { var $form = $(this); var alert = document.getElementById('alert-box'); var data = $form.serialize(); alert.innerHTML = '' $.ajax({ url: window.location.pathname, type: 'POST', data: data, dataType: 'json', success: function(response) { window.location.href = '/admin/settings/users'; }, error: function(response) { if (typeof response.responseJSON.error === 'string' || response.responseJSON.error instanceof String) { alert.innerHTML = alert.innerHTML + ` `; } else if (response.responseJSON.error instanceof Array) { for (var i = 0; i < response.responseJSON.error.length; i ++) { alert.innerHTML = alert.innerHTML + ` `; } } } }); event.preventDefault(); }); $('form[name=form-update-account]').submit(function(event) { var $form = $(this); var alert = document.getElementById('alert-box'); var data = $form.serialize(); alert.innerHTML = '' $.ajax({ url: window.location.pathname, type: 'POST', data: data, dataType: 'json', success: function(response) { window.location.href = '/admin/dashboard/'; }, error: function(response) { if (typeof response.responseJSON.error === 'string' || response.responseJSON.error instanceof String) { alert.innerHTML = alert.innerHTML + ` `; } else if (response.responseJSON.error instanceof Array) { for (var i = 0; i < response.responseJSON.error.length; i ++) { alert.innerHTML = alert.innerHTML + ` `; } } } }); event.preventDefault(); }); $('form[name=form-create-test]').submit(function(event) { var $form = $(this); var alert = document.getElementById('alert-box'); var data = $form.serialize(); console.log(data) alert.innerHTML = '' $.ajax({ url: window.location.pathname, type: 'POST', data: data, dataType: 'json', success: function(response) { window.location.reload(); }, error: function(response) { console.log(response.responseJSON) if (typeof response.responseJSON.error === 'string' || response.responseJSON.error instanceof String) { alert.innerHTML = alert.innerHTML + ` `; } else if (response.responseJSON.error instanceof Array) { for (var i = 0; i < response.responseJSON.error.length; i ++) { alert.innerHTML = alert.innerHTML + ` `; } } } }); event.preventDefault(); }); // Dismiss Cookie Alert $('#dismiss-cookie-alert').click(function(event){ console.log('Foo') $.ajax({ url: '/cookies/', type: 'GET', data: { time: Date.now() }, dataType: 'json', success: function(response){ console.log(response) }, error: function(response){ console.log(response) } }) event.preventDefault() })