EVOLUTION-NINJA
Edit File: mapping_form.php
<?php echo view('includes/header');?> <section class="content-header"> <h1>Add Site Maps</h1> </section> <!--- section 1 --> <section class="content"> <form id="land_owner" class="form-inline hobli_sketch_form" enctype="multipart/form-data"> <div class="row land_owner_a"> <div class="form-group col-sm-12 col-md-3"> <select class="hobli_list" style="width:100% !important" name="id" required="required"> <option value="">Select Project</option> <?php foreach($project as $val) { ?> <option value="<?php echo $val->project_id;?>" ><?php echo $val->project_name;?></option> <?php } ?> </select> </div> <div class="form-group col-sm-12 col-md-3"> <input type="file" name="hobli_sketch" style="width:100% !important;" class="form-control" required="required"/> </div> <div class="col-sm-4 col-md-2"> <button type="submit" class="btn btn-primary center-block add_button submit" style="margin-top: -1px;"> Submit</button> </div> </div> </form> <div class="row"></div> <div class="row"> <div class="col-sm-2"></div> <div class="col-sm-7 table-responsive"> <table class="table table-responsive table-bordered table-striped table-hover list_table"> <thead> <tr> <th class="col-sm-2">Sl No</th> <th class="col-sm-4">Project</th> <th class="col-sm-2">Action</th> </tr> </thead> <tbody id="table_body"> </tbody> </table> </div> </div> <!-- Modal --> <div class="modal fade" id="edit_modal" role="dialog"> <div class="modal-dialog modal-md"> <div class="modal-content"> <div class="modal-header"> <button type="button" class="close" data-dismiss="modal">×</button> <h4 class="modal-title">Update project details</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 hobli_sketch_id_fk" name="hobli_sketch_id" required="required"> <div class="row land_owner_a"> <div class="form-group col-sm-12 col-md-6"> <select class="hobli_list1" style="width:110% !important" name="id" required="required"> <option value="">Select Project</option> <?php foreach($mappings as $val) { ?> <option value="<?php echo $val->project_id;?>"><?php echo $val->project_name;?></option> <?php } ?> </select> </div> </div> <div class="row land_owner_a"> <div class="form-group col-sm-12 col-md-6"> <input type="file" name="hobli_sketch" style="width:110% !important;" class=""/> <div id="uploaded_sketch_div"></div> </div> </div> <div class="row land_owner_a"> <div class="col-sm-4 col-md-4"></div> <div class="col-sm-4 col-md-4"> <button type="submit" class="btn btn-primary center-block update_btn submit">Update</button> </div> <div class="col-sm-4 col-md-4"></div> </div><!-- row 6--> </form> </div> </div> </div> </div> </section> <!--- section 2 --> <?php echo view('includes/footer');?> <script> $(document).ready(function(){ var datatable; var tbody = $('#table_body'); datatable = $('.table').DataTable({ }); $('.hobli_sketch_form').submit(function(e){ e.preventDefault(); $(".add_button").attr('disabled', 'disabled'); $(".add_button").text("Submitting..."); formdata = new FormData($(this)[0]); $.ajax({ type : 'post', url : '<?php echo site_url("add_mapping_sketch")?>', data : formdata, contentType: false, processData: false, success:function(response){ // response=jQuery.parseJSON(response); console.log(response); if(response.result==1) { GetHobliData(); toastr["success"](response.message); $('.hobli_sketch_form')[0].reset(); $(".add_button").text("Submit"); $(".add_button").removeAttr('disabled'); } else if(response.result==2) { toastr["error"](response.message); $(".add_button").text("Submit"); $(".add_button").removeAttr('disabled'); } else { toastr["error"](response.message); $(".add_button").text("Submit"); $(".add_button").removeAttr('disabled'); } } }); }); GetHobliData(); function GetHobliData() { tbody.empty(); var table_row = []; $.ajax({ type : 'get', url : '<?php echo site_url('get_project_sketches');?>', success:function(response){ // response=jQuery.parseJSON(response); if(response.result==1) { var table_content = ''; var sl_no = 1; $.each(response.sketch_list,function(key,val){ var row = []; row.push(sl_no); row.push(val.project_name); row.push('<a data-toggle="tooltip" title="Map view" class="" href="<?php echo site_url("mapping-sketch")?>/'+val.sketch_id+'"/><span class="glyphicon glyphicon-search"></span></a> <a data-toggle="tooltip" title="Edit Sketch" class="edit" hobli_sketch_id="'+val.sketch_id+'" href="javascript:void(0);"><span class="glyphicon glyphicon-edit"></span></a> <a data-toggle="tooltip" title="Edit Mapping" class="edit" hobli_id="'+val.project_id+'" href="<?php echo site_url('update_area_coordinate_mapping');?>/'+val.sketch_id+'"><span class="glyphicon glyphicon-edit"></span></a> <a data-toggle="tooltip" title="Delete" class="delete" hobli_sketch_id="'+val.sketch_id+'" href="javascript:void(0);"><span class="glyphicon glyphicon-trash"></span></a>'); table_row.push(row); sl_no++; }); datatable.clear(); datatable.rows.add(table_row).draw(); datatable.draw(); $(".list_table").on("click", ".delete", function(){ var sketch_id = $(this).attr('hobli_sketch_id'); var test = $(this); var row = $(this).closest('tr'); 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_site_sketch")?>', data : {sketch_id:sketch_id}, success:function(response) { // response=jQuery.parseJSON(response); console.log(response); if(response.result == 1) { toastr["success"](response.message); GetHobliData(); } } }); } else { $(".sweet-alert").hide(); $(".sweet-overlay").hide(); } }); }); $(".list_table").on("click", ".edit", function(){ var sketch_id = $(this).attr('hobli_sketch_id'); $.ajax({ type : 'post', url : '<?php echo site_url("get_map_sketch_data")?>', data : {sketch_id:sketch_id}, success:function(response) { // response=jQuery.parseJSON(response); console.log(response); if(response.result == 1) { $(".hobli_sketch_id_fk").val(response.sketch_data.sketch_id); $(".hobli_list1 option[value='"+response.sketch_data.project_id+"']").attr("selected","selected"); $("#uploaded_sketch_div").html('<a style="color:red;" target="_blank" href="<?php echo base_url('public/mapping_image')?>/'+response.sketch_data.image+'">Click here to view sketch</a>'); $("#edit_modal").modal("show"); } else { $("#uploaded_sketch_div").empty(); } } }); }); } else { } } }); } $('.update_form').submit(function(e){ e.preventDefault(); formdata = new FormData($(this)[0]); $(".update_btn").attr('disabled', 'disabled'); $(".update_btn").text("Updating..."); $.ajax({ type : 'post', url : '<?php echo site_url("update_map_sketch")?>', data : formdata, contentType: false, processData: false, success:function(response){ // response=jQuery.parseJSON(response); console.log(response); if(response.result == 1) { $("#edit_modal").modal("hide"); GetHobliData(); toastr["success"](response.message); $('.update_form')[0].reset(); $(".update_btn").text("Submit"); $(".update_btn").removeAttr('disabled'); } else if(response.result == 2) { toastr["error"](response.message); $(".update_btn").text("Submit"); $(".update_btn").removeAttr('disabled'); } else if(response.result == 3) { toastr["error"](response.message); $(".update_btn").text("Submit"); $(".update_btn").removeAttr('disabled'); } else { toastr["error"](response.message); $(".update_btn").text("Submit"); $(".update_btn").removeAttr('disabled'); } } }); }); }); </script>