HEX
Server: Apache
System: Linux br80.hostgator.com.br 4.19.286-203.ELK.el7.x86_64 #1 SMP Wed Jun 14 04:33:55 CDT 2023 x86_64
User: bloga741 (1102)
PHP: 8.3.30
Disabled: NONE
Upload Files
File: /home1/bloga741/public_html/likedreams/test/js/category.panel.js
$(document).ready(function (e) {
	
	// ON CHANGE LIST ITEM STATUS
	$('.list-view .toggle-button').on('switchChange.bootstrapSwitch', function (event, state) {
		
		var newStatus = '0';
		if (state == true) {
			newStatus = '1';
		}
		
		$.post(base_url('ajax/toggleActive'), {
			className: 'Category',
			objectId: this.getAttribute('data-id'),
			newStatus: newStatus
		}, function (response) {
			console.log(response);
		});
	});
	
	// ON CHANGE NEW ITEM STATUS
	$('.add-item .toggle-button').on('switchChange.bootstrapSwitch', function (event, state) {
		
		var newStatus = '0';
		if (state == true) {
			newStatus = '1';
		}
		
		// get id
		var thisId = this.getAttribute('id');
		
		$('input[name=' + thisId + ']').val(newStatus);
	});
	
	// DELETE ITEM
	$('.delete-panel-item').click(function (event) {
		var ok = confirm("Deseja mesmo excluir este item?\nEsta ação é irreversível.");
		if (ok) {
			
			$.isLoading({ text: "Excluindo" });
			
			$.ajax({
				url: base_url('ajax/deleteItem'),
				method: 'post',
				data: {
					className: 'Category',
					objectId: this.getAttribute('data-id'),
				},
				success: function (response) {
					console.log(response);
					switch (response) {
					case '0':
						$.isLoading( "hide" );
						alert('Ops! Ocorreu um erro, tente novamente.');
						break;
					
					case '1':
						location.reload();
						break;
						
					case '2':
						$.isLoading( "hide" );
						alert('Ops! Você não tem permissão para esta ação.');
						break;
						
					default:
						$.isLoading( "hide" );
						alert(response);
						break;
					}
				},
				error: function (response) {
					console.log(error, response);
				}
			});
		}
	});
	
	// HANDLE NEW FORM SUBMIT
	$('#new-form').submit(function (event) {
		
		$.isLoading({ text: "Salvando" });
		
		var name = $('#name').val();
		
		if (name == '' || name == null) {
			$.isLoading( "hide" );
			alert('Por favor, preencha o campo "Nome" antes de prosseguir.');
			event.preventDefault();
			return false;
		}
		else {
			return true;
		}
	});
});