text: $(function () {
      var base_url = "<?= base_url() ?>";
      $('#index_users').DataTable();
  
      $('form#frmNewUser').submit(function (e) {
          e.preventDefault();
          var data = new FormData($(this)[0]);
  
          $.ajax({
              contentType: false,
              method: 'post',
              cache: false,
              url: base_url+'admin/new_user',
              processData: false,
              data: data,
              success: function (res)
              {
                  var obj = JSON.parse(res);
                  if (obj.info == true)
                  {
                      Swal.fire({
                          title: 'Success',
                          text: obj.message,
                          type: 'success',
                          confirmButtonText: 'Tutup'
                      });
                      setTimeout(function () {
                          window.location.href = base_url+'admin/user_management';
                      },2000);
                  }
                  else
                  {
                      Swal.fire({
                          title: 'Error !',
                          text: obj.message,
                          type: 'error',
                          confirmButtonText: 'Tutup'
                      });
                  }
              },
              error: function (res)
              {
                  Swal.fire({
                      title: 'Error !',
                      text: 'Kesalahan Tidak Diketahui',
                      type: 'error',
                      confirmButtonText: 'Tutup'
                  });
              }
          });
      });
  
      $('#frmEditUser').on('change', '#edNip', function (e) {
          $.ajax({
              contentType: 'application/x-www-form-urlencoded; charset=UTF-8',
              method: "POST",
              url: base_url+'admin/check_nip',
              cache: false,
              data: {'nip':$('#edNip').val()},
              success: function (res)
              {
                  var obj = JSON.parse(res);
                  if (obj.hasOwnProperty('data'))
                  {
                      $('#edJabatan').empty();
                      $('#edJk').empty();
  
                      $('#edNamaPetugas').val(obj.data[0].nama_petugas);
                      $('#edAlamat').val(obj.data[0].alamat);
                      $('#edTtl').val(obj.data[0].tanggal_lahir);
                      $('#edJk').val(obj.data[0].jenis_kelamin);
                      $('#edJk').append('<option>'+obj.data[0].jenis_kelamin+'</option>');
                      $('#edJk').append('<option>Laki-Laki</option><option>Perempuan</option>');
                      $('#edJabatan').val(obj.data[0].id_jabatan);
                      $('#edJabatan').append('<option>'+obj.data[0].nama_jabatan+'</option>');
                      $.each(obj.data[1], function (key, val) {
                          $('#edJabatan').append('<option value="'+val.id_jabatan+'">'+val.nama_jabatan+'</option>');
                      });
                      $('#edTglJabat').val(obj.data[0].tanggal_menjabat);
                  }
                  else if (obj.hasOwnProperty('info'))
                  {
                      Swal.fire({
                          title: 'Warning !',
                          text: obj.message,
                          type: 'warning',
                          confirmButtonText: 'Tutup'
                      });
                  }
              },
              error: function (res)
              {
                  Swal.fire({
                      title: 'Error !',
                      text: 'Kesalahan Tidak Diketahui',
                      type: 'error',
                      confirmButtonText: 'Tutup'
                  });
              }
          });
      });
  
      $('form#frmEditUser').submit(function (e) {
          e.preventDefault();
          var data = new FormData($(this)[0]);
  
          $.ajax({
              contentType: false,
              method: "POST",
              cache: false,
              url: base_url+'admin/edt_user',
              processData: false,
              data: data,
              success: function (res)
              {
                  var obj = JSON.parse(res);
                  if (obj.info == true)
                  {
                      Swal.fire({
                          title: 'Success',
                          text: obj.message,
                          type: 'success',
                          confirmButtonText: 'Tutup'
                      });
                      setTimeout(function () {
                          window.location.href = base_url+'admin/user_management';
                      },2000);
                  }
                  else
                  {
                      Swal.fire({
                          title: 'Error !',
                          text: obj.message,
                          type: 'error',
                          confirmButtonText: 'Tutup'
                      });
                  }
              },
              error: function (res)
              {
                  Swal.fire({
                      title: 'Error !',
                      text: 'Kesalahan Tidak Diketahui',
                      type: 'error',
                      confirmButtonText: 'Tutup'
                  });
              }
          });
      });
  
      $('#btnDelUser').on('click', function (e) {
          e.preventDefault();
          
          Swal.fire({
              title: 'Warning !',
              text: 'Anda Yakin ? Data akan terhapus secara permanent.',
              type: 'question',
              showConfirmButton: true,
              showCancelButton: true
          }).then(function (isConfirm) {
              if (isConfirm.hasOwnProperty('value'))
              {
                  $.ajax({
                      contentType: 'application/x-www-form-urlencoded; charse=UTF-8;',
                      method: 'POST',
                      cache: false,
                      url: base_url+'admin/del_user',
                      data: {nip:$('#delNip').val()},
                      success: function (res)
                      {
                          var obj = JSON.parse(res);
                          if (obj.hasOwnProperty('info'))
                          {
                              if (obj.info == true)
                              {
                                  Swal.fire({
                                      title: 'Success',
                                      text: obj.message,
                                      type: 'success',
                                      confirmButtonText: 'Tutup'
                                  });
                                  setTimeout(function () {
                                      window.location.href = base_url+'admin/user_management';
                                  },2000);
                              }
                              else
                              {
                                  Swal.fire({
                                      title: 'Error !',
                                      text: obj.message,
                                      type: 'error',
                                      confirmButtonText: 'Tutup'
                                  });
                              }
                          }
                      },
                      error: function (res)
                      {
                          Swal.fire({
                              title: 'Error !',
                              text: 'Kesalahan Tidak Diketahui',
                              type: 'error',
                              confirmButtonText: 'Tutup'
                          });
                      }
                  });
              }
              else if (isConfirm.hasOwnProperty('dismiss'))
              {
                  Swal.fire({
                      title: 'info',
                      text: 'Data Tidak Jadi Terhapus'
                  });
              }
          });
      });
  
      
  
  })