/home/mip/mip/storage/framework/views/5b09ad95bcd2c3298cfb3eac03682555.php
<!-- Brand js -->
<script type="text/javascript">
var category_datatable;
$( document ).ready( function() {

	$('#addbutton_category').click( function() {
        var name = $('#post_category_name').val();
		if(name=='') {
			swal("Error!", "Name is required!", "error");
			$('#post_category_name').focus();
			return false;
		} else {
			$("#hide_onclick_modal").hide();
			$("#show_onclick_modal").show();
			$.ajax({
	        	type: "post",
	          	url: "/client/modals/postcategory/store",
	          	data: {
	            	name: $("#post_category_name").val()
	          	},
	          	success: function(result) {
	          		var table = $('#postCategoryTable').DataTable();   
	          		table.ajax.reload(); 	          		   
	          		$("#hide_onclick_modal").show();
					$("#show_onclick_modal").hide();
	            	$('#selectCategory').append($('<option>', {
		                value: result.id,
		                text: result.name,
		                selected: true
		            }));
	            	$('#postCategoryModal').modal('hide');	            
	          	},
	          	error :function( xhr ) {
	                if( xhr.status === 422 ) {
	                    var errors = JSON.parse(xhr.responseText);
	                    alert(errors['name'][0]);	                    
	                } else {
	                	swal("Error!", "Error occured please try again.", "error");
	                }
	                $("#hide_onclick_modal").show();
					$("#show_onclick_modal").hide();
	            }
	        });
		}
    }); 

});
function initializeCategory()
{
		category_datatable = 1;
		table = $('#postCategoryTable').DataTable({
        "processing": true,
        "serverSide": true,
        ajax: {
            url:'/client/modals/postcategory/get-post-category-data', 
            type: 'POST',
        },
		"bAutoWidth": false,
		"iDisplayLength": 10,
		columns: [
			{data: 'name', name: 'name', className:'editable'},
			{data: 'slug', name: 'slug', orderable:false, searchable:false,},
			{data: 'action', name: 'action', orderable:false, searchable:false, width:'60px', className:'text-center'},
		],
		"order": [[0, "asc"]],
		fnDrawCallback: function ( oSettings ) {
			$('#postCategoryTable tbody td.editable').editable('/client/modals/postcategory/update', {
                callback: function( sValue, y ) {
		           table.draw();
				},
				onsubmit: function(settings, original) {
		            if ((original.revert == $('input',this).val()) || $('input',this).val() == "") {
		            	original.reset();
		            	$(original).parents('tr').find('td.hide_me').show();
		            	return false;
		        	}
				},
				submitdata: function (value, settings) {
	            	var id = $(this).parents('tr').find('a.btn-edit').data('id');
			        return {
			              'id':id
			        };
				},
				onerror:  function(settings, original, xhr) {
	                if( xhr.status === 422 ) {
	                      var errors = JSON.parse(xhr.responseText);
	                      alert(errors['name'][0]);
	                      original.reset(); 
	                      $(original).parents('tr').find('td.hide_me').show();
	                } else {
	                    swal("Error!", "Error occured please try again.", "error");
	                }
		        },
				onblur:'submit',
				event:'custom_event',
				height:"30px",
				width:'100%',
				name : 'name'
			});

			$("#postCategoryTable tbody td").on("click", 'a.btn-edit', function() {
  				$(this).parents('tr').find('td.editable').trigger("custom_event");
  				$(this).parent('td').addClass('hide_me').hide();
			});

			$("#postCategoryTable tbody td").on("click", 'a.btn-delete', function() {
				var action = $(this).data('action');
				swal({
                    title: 'Are you sure you want to delete?',
                    text: "This will be permanently deleted",
                    type: 'warning',
                    showCancelButton: true,
                    confirmButtonColor: '#3085d6',
                    cancelButtonColor: '#d33',
                    confirmButtonText: 'Yes'
                    })
					.then(function () {                    
                    $.ajax({
                        type: "GET",
                        url: action,
                        dataType: 'json',
                        success: function(data) {
                           if(data.success == "yes") {
                                table.draw();
                                swal("Deleted!", "Category successfuly deleted!", "success");
                                $("#selectCategory option[value='"+data.id+"']").remove();
                           }else{
                                swal("Error!", "Cannot delete it is being used in database.", "error");
                           }
                        },
                        error :function( jqXhr ) {
                            swal('Unable to delete.', 'Please try again.', 'error')
                        }
                    });
                })  
			});
		}
	});

	$('#post_category_name').val('');
    $('#postCategoryModal').modal({'backdrop':'static'});
}

function doModalAddCategory()
{	
	if(category_datatable != 1) {
		initializeCategory();
	}
	else {
		$('#post_category_name').val('');
    	$('#postCategoryModal').modal({'backdrop':'static'});
	}
}
</script>
<!-- End of Brand js --><?php /**PATH /home/mip/mip/app/Modules/Client/Views/posts/includes/js-modal-category.blade.php ENDPATH**/ ?>