Advertisement
jamboljack

POKMAS

Oct 23rd, 2017
215
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
  1. var table;
  2.  
  3. // Untuk Refresh Table
  4. function reload_table() {
  5.     table.ajax.reload(null,false); //reload datatable ajax
  6. }
  7.  
  8. // Ambil ID Pokmas
  9. function getIDPokmas() {
  10.     var pokmas_id = '';
  11.     $.ajax({
  12.         url : "<?php echo site_url('operator/pokmas/get_id_pokmas/'.$this->uri->segment(4).'/'.$this->uri->segment(5).'/'.$this->uri->segment(6))?>",
  13.         type: "GET",
  14.         dataType: "JSON",
  15.         async: false,
  16.         success: function(data) {
  17.             if (data === null) {
  18.                 pokmas_id = '';
  19.             } else {
  20.                 pokmas_id = data.pokmas_id;
  21.             }
  22.         },
  23.         error: function (jqXHR, textStatus, errorThrown) {
  24.             alert('Error get data from ajax');
  25.         }
  26.     });
  27.     return pokmas_id;
  28. }
  29.  
  30. // Show Data Anggota POKMAS
  31. $(document).ready(function() {
  32.     var pokmas_id = getIDPokmas();
  33.     table = $('#tableData').DataTable({
  34.         "paging": false, // HIlangkan Pagination
  35.         "searching": false, // Hilangkan Search        
  36.         "responsive": true,
  37.         "processing": false,
  38.         "serverSide": true,
  39.         "order": [ 1, 'asc'],
  40.         "ajax": {
  41.             "url": "<?php echo site_url('operator/pokmas/data_list_pokmas')?>"+"/"+pokmas_id,
  42.             "type": "POST"
  43.         },
  44.         "columnDefs": [
  45.         {
  46.             "targets": [ 0 ],
  47.             "orderable": false,
  48.         },
  49.         ],
  50.     });    
  51. });
  52.  
  53. // Simpan Data
  54. $(document).ready(function() {
  55.     var form        = $('#formInput');
  56.     var error       = $('.alert-danger', form);
  57.     var success     = $('.alert-success', form);
  58.    
  59.     $("#formInput").validate({
  60.         errorElement: 'span',
  61.         errorClass: 'help-block help-block-error',
  62.         focusInvalid: false,
  63.         ignore: "",
  64.         rules: {
  65.             namapokmas: {
  66.                 required: true, minlength: 5
  67.             }
  68.         },
  69.         messages: {
  70.             namapokmas: {
  71.                 required :'Nama POKMAS harus diisi', minlength:'Minimal 5 Karakter'
  72.             }
  73.         },
  74.  
  75.         invalidHandler: function (event, validator) { //display error alert on form submit              
  76.             success.hide();
  77.             error.show();
  78.             Metronic.scrollTo(error, -200);
  79.         },
  80.  
  81.         errorPlacement: function (error, element) { // render error placement for each input type
  82.             var icon = $(element).parent('.input-icon').children('i');
  83.             icon.removeClass('fa-check').addClass("fa-warning");  
  84.             icon.attr("data-original-title", error.text()).tooltip({'container': 'body'});
  85.         },
  86.  
  87.         highlight: function (element) { // hightlight error inputs
  88.             $(element)
  89.             .closest('.form-group').removeClass("has-success").addClass('has-error'); // set error class to the control group  
  90.         },
  91.  
  92.         unhighlight: function (element) { // revert the change done by hightlight
  93.         },
  94.  
  95.         success: function (label, element) {
  96.             var icon = $(element).parent('.input-icon').children('i');
  97.             $(element).closest('.form-group').removeClass('has-error').addClass('has-success'); // set success class to the control group
  98.             icon.removeClass("fa-warning").addClass("fa-check");
  99.         },
  100.        
  101.         submitHandler: function(form) {
  102.             dataString = $("#formInput").serialize(); // Ambil Value dari Form
  103.  
  104.             $.ajax({
  105.                 url: "<?php echo site_url('operator/pokmas/updatedata'); ?>",
  106.                 type: "POST",
  107.                 data: dataString,
  108.                 success: function(data) {
  109.                     swal({
  110.                         title:"Sukses",
  111.                         text: "Simpan Data Berhasil",
  112.                         showConfirmButton: false,
  113.                         type: "success",
  114.                         timer: 2000
  115.                     });
  116.                     reload_table();
  117.                 },
  118.                 error: function (jqXHR, textStatus, errorThrown) {
  119.                     alert('Error Simpan Data');
  120.                     reload_table();
  121.                 }
  122.             });
  123.         }
  124.     });
  125. });
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement