EVOLUTION-NINJA
Edit File: sub_categories.php
<?php echo view('includes/admin_header.php') ?> <!-- Content Wrapper. Contains page content --> <div class="content-wrapper"> <!-- Content Header (Page header) --> <section class="content-header"> <h1 style="padding-bottom:10px;border-bottom:2px dashed #468662;margin-bottom:20px; font-weight: bold;"> SUB CATEGORIES <small></small> </h1> </section> <!-- Main content --> <section class="content"> <a href="javascript:history.back()" class="btn btn-primary" style="float: right;">Back</a> <!-- Button trigger modal --> <button type="button" class="btn btn-primary btn-sm access_add_btn" data-toggle="modal" data-target="#myModal"> Add Sub Category </button> <!-- Modal --> <div class="modal fade" id="myModal" tabindex="-1" role="dialog" aria-labelledby="myModalLabel"> <div class="modal-dialog" role="document"> <div class="modal-content"> <div class="modal-header"> <button type="button" class="close" data-dismiss="modal" aria-label="Close"><span aria-hidden="true">×</span></button> <h4 class="modal-title" id="myModalLabel">Add Sub Category</h4> </div> <div class="modal-body"> <form id="land_owner" class="form-horizontal category_form" enctype="multipart/form-data"> <input type="hidden" class="form-control col-sm-8" name="login_id" value="<?= session()->get('login_id'); ?>"> <input type="hidden" class="form-control col-sm-8" name="user_type_id" value="<?= session()->get('user_type_id'); ?>"> <div class="row land_owner_a"> <div class="form-group col-xs-9 col-sm-10 col-md-8"> <label class="col-sm-4 hidden-xs">Category</label> <div class="col-sm-8"> <select class="form-control" name="domain_id" required="required"> <option value="">Select Category</option> <?php foreach ($categories as $val) { ?> <option value="<?php echo $val->domain_id; ?>"><?php echo $val->domain_name; ?></option> <?php } ?> </select> </div> </div> <!-- <div class="form-group col-xs-3 col-sm-2 col-md-4"> <button type="button" class="btn btn-default center-block add_fields">Add</button> </div> --> </div> <!-- row 1--> <div class="row land_owner_a"> <div class="form-group col-xs-9 col-sm-10 col-md-8"> <label class="col-sm-4 hidden-xs">Sub Category</label> <div class="col-sm-8"> <input type="text" class="form-control" pattern="^[^\s]+.*$" name="sub_domain" required="required"> </div> </div> </div> <!-- row 1--> <div class="multiple_fields"></div> <div class="row land_owner_a"> <div class="col-sm-4 col-md-4"></div> <div class="col-sm-4 col-md-4"> <div class="cato_but"> <div class="row"></div> <div class="col-sm-6"> <button type="submit" class="btn btn-primary center-block submit submit_1">Submit</button> </div> </div> </div> <div class="col-sm-4 col-md-4"></div> </div> <!-- row 6--> </form> </div> </div> </div> </div> <div class="row"> <div id="loading" style="display:none;width:80px;height:89px;position:absolute;top:30%;left:55%;padding:2px;z-index: 1;"><img src="<?php echo base_url(); ?>public/assets/images/loader.gif" width="64" height="64" /><br> </div> <div class="col-md-2"></div> <div class="col-md-9" style="width: 60%; margin-left:3%;"> <table class="table table-striped table-hover list_table"> <thead> <tr class=""> <th class="col-xs-1">Sl No</th> <th class="col-xs-3">Category</th> <th class="col-xs-3">Sub Category</th> <th class="col-xs-1">Action</th> </tr> </thead> <tbody id="table_body"> </tbody> </table> </div> </div> <!-- Modal --> <div class="modal fade" id="edit_modal" tabindex="-1" role="dialog" aria-labelledby="myModalLabel"> <div class="modal-dialog" role="document"> <div class="modal-content"> <div class="modal-header"> <button type="button" class="close" data-dismiss="modal" aria-label="Close"><span aria-hidden="true">×</span></button> <h4 class="modal-title" id="myModalLabel">Update Sub Category</h4> </div> <div class="modal-body"> <form id="land_owner" class="form-inline update_form" enctype="multipart/form-data"> <input type="hidden" class="form-control col-sm-8 sub_domain_id_pk" name="sub_domain_id" required="required"> <div class="row land_owner_a"> <div class="form-group col-sm-12 col-md-8"> <label class="col-sm-4">Category</label> <select class="form-control category_list" name="domain_id" required="required"> <option value="">Select Category</option> <?php foreach ($categories as $val) { ?> <option value="<?php echo $val->domain_id; ?>"><?php echo $val->domain_name; ?></option> <?php } ?> </select> </div> </div> <!-- row 1--> <div class="row land_owner_a"> <div class="form-group col-sm-12 col-md-8"> <label class="col-sm-4">Sub Category</label> <input type="text" class="form-control col-sm-8 sub_domain" pattern="^[^\s]+.*$" name="sub_domain" required="required"> </div> </div> <!-- row 1--> <div class="row land_owner_a"> <div class="col-sm-4 col-md-4"></div> <div class="col-sm-4 col-md-4"> <div class="upd_but"> <div class="row"></div> <div class="col-sm-6"> <button type="submit" class="btn btn-primary center-block submit update_submit">Update</button> </div> </div> </div> <div class="col-sm-4 col-md-4"></div> </div> <!-- row 6--> </form> </div> </div> </div> </div> </section> <!-- /.content --> </div> <style> .form-control { border-radius: 5px; } .content-wrapper{ background-image: url(public/assets/website_assets/images/banner.png); background-size:cover; } </style> <script type="text/javascript"> $(document).ready(function() { var datatable; var tbody = $('#table_body'); datatable = $('.table').DataTable({ // "scrollY": 350, // "scrollX": true, }); $('.add_fields').click(function(e) { $('.multiple_fields').append('<div class="row land_owner_a"><div class="form-group col-xs-9 col-sm-10 col-md-8"><label class="col-sm-4 hidden-xs">Sub Category</label><div class="col-sm-8"><input type="text" class="form-control" name="sub_domain[]" required="required" placeholder="Sub Category"></div></div><div class="form-group col-xs-3 col-sm-2 col-md-4"><a href="javascript:void(0);" class="remove_fields"><span class="glyphicon glyphicon-remove"></span></a></div></div>'); $(".remove_fields").click(function() { $(this).closest('.row').remove(); }); }); $('.category_form').submit(function(e) { e.preventDefault(); $("#loading").show(); formdata = new FormData($(this)[0]); $(".submit").attr('disabled', 'disabled'); $(".submit").text("Submitting..."); $.ajax({ type: 'post', url: '<?php echo site_url("add_sub_domain") ?>', data: formdata, contentType: false, processData: false, success: function(response) { // response=jQuery.parseJSON(response); console.log(response); if (response.result == 1) { $("#loading").hide(); $("#myModal").modal("hide"); $(".multiple_fields").empty(); toastr["success"](response.message); SubCategoryList(); $('.category_form')[0].reset(); $(".submit").text("Submit"); $(".submit").removeAttr('disabled'); } else if (response.result == 2) { $("#loading").hide(); toastr["error"](response.message); $(".submit").text("Submit"); $(".submit").removeAttr('disabled'); } else { $("#loading").hide(); toastr["error"](response.message); $(".submit").text("Submit"); $(".submit").removeAttr('disabled'); } } }); }); SubCategoryList(); function SubCategoryList() { $("#loading").show(); tbody.empty(); var table_row = []; $.ajax({ type: 'get', url: '<?php echo site_url("get_sub_categories_list") ?>', success: function(response) { //response=jQuery.parseJSON(response); console.log(response); if (response.result == 1) { $("#loading").hide(); var slno = 1; var index = 1; $.each(response.sub_categories_list, function(idx, vx) { var row = []; row.push(slno); row.push(vx.domain_name); row.push(vx.sub_domain); var table_content = ''; table_content += '<div style="float:left;">'; table_content += '<a data-toggle="tooltip" title="Edit" class="edit" sub_domain_id="' + vx.sub_domain_id + '" sub_domain="' + vx.sub_domain + '" domain_id="' + vx.domain_id + '" href="javascript:void(0);"><span class="glyphicon glyphicon-edit"></span></a> '; table_content += '<a data-toggle="tooltip" title="Delete" class="delete" sub_domain_id="' + vx.sub_domain_id + '" href="javascript:void(0);"><span class="glyphicon glyphicon-trash"></span></a>'; table_content += '</div>' row.push(table_content); table_row.push(row); slno++; index++; }); datatable.clear(); datatable.rows.add(table_row).draw(); datatable.draw(); $('[data-toggle="tooltip"]').tooltip(); $(".list_table").on("click", ".delete", function() { var sub_domain_id = $(this).attr('sub_domain_id'); var test = $(this); var row = $(this).closest('tr'); $.ajax({ type: 'post', url: '<?php echo site_url("check_subcategory_course_existes") ?>', data: { sub_domain_id: sub_domain_id }, success: function(response) { // response=jQuery.parseJSON(response); console.log(response); if (response.result == 1) { swal("Courses are added to this category!") } else { swal({ title: "Are you sure?", text: "You will not be able to recover this data!", type: "warning", showCancelButton: true, confirmButtonColor: "#DD6B55", confirmButtonText: "Yes, delete it!", cancelButtonText: "No, cancel plz!", closeOnConfirm: false, closeOnCancel: false }, function(isConfirm) { if (isConfirm) { $(".sweet-alert").hide(); $(".sweet-overlay").hide(); test.attr('disabled', 'disabled'); test.text("Deleting..."); $.ajax({ type: 'post', url: '<?php echo site_url("delete_sub_domain") ?>', data: { sub_domain_id: sub_domain_id }, success: function(response) { // response=jQuery.parseJSON(response); console.log(response); if (response.result == 1) { toastr["success"](response.message); SubCategoryList(); } } }); } else { $(".sweet-alert").hide(); $(".sweet-overlay").hide(); } }); } } }) }); $(".list_table").on("click", ".edit", function() { var sub_domain_id = $(this).attr('sub_domain_id'); var sub_domain = $(this).attr('sub_domain'); var domain_id = $(this).attr('domain_id'); $(".sub_domain_id_pk").val(sub_domain_id); $(".sub_domain").val(sub_domain); $(".category_list").val(domain_id); $("#edit_modal").modal("show"); }); } else { $("#loading").hide(); } } }); } $('.update_form').submit(function(e) { e.preventDefault(); $("#loading").show(); formdata = new FormData($(this)[0]); $(".update_submit").attr('disabled', 'disabled'); $(".update_submit").text("Updating..."); $.ajax({ type: 'post', url: '<?php echo site_url("update_sub_domain") ?>', data: formdata, contentType: false, processData: false, success: function(response) { // response=jQuery.parseJSON(response); console.log(response); if (response.result == 1) { $("#loading").hide(); $("#edit_modal").modal("hide"); SubCategoryList(); toastr["success"](response.message); $('.update_form')[0].reset(); $(".update_submit").text("Submit"); $(".update_submit").removeAttr('disabled'); } else if (response.result == 2) { $("#loading").hide(); toastr["error"](response.message); $(".update_submit").text("Submit"); $(".update_submit").removeAttr('disabled'); } else { $("#loading").hide(); toastr["error"](response.message); $(".update_submit").text("Submit"); $(".update_submit").removeAttr('disabled'); } } }); }); }); </script> <?php echo view('includes/admin_footer.php') ?>