



<div class="modal fade" id="<?=$id_modal?>" tabindex="-1" role="dialog" aria-labelledby="exampleModalLongTitle" aria-hidden="true">



  <div class="modal-dialog" role="document">



    <div class="modal-content">



      <form id="tambah">



      <div class="modal-header bg-primary text-light">



        <h5 class="modal-title">Detail Nomor Strategi</h5>



        <button type="button" class="close" data-dismiss="modal" aria-label="Close">



          <span aria-hidden="true">&times;</span>



        </button>



      </div>



      <div class="modal-body">



        



          <div class="row">



            <div class="form-group col-md-12">



                      <label for="exampleInputEmail1">Kode Head</label>



                      <input type="text" class="form-control" id="kode_head" name="kode_head" value="<?=$id_row?>" readonly>



                      <!-- <small id="emailHelp" class="form-text text-muted">Data Akan terisi Otomatis.</small> -->



                    </div>



            <div class="form-group col-md-12">



                <label for="exampleInputEmail1">Nama Head</label>



                <div class="row">



                    <div class="col-md-10">



                    <input type="text" class="form-control" id="head" name="head" value="<?=$id_row2?>" readonly>



                    <!-- <small id="emailHelp" class="form-text text-muted">Data Akan terisi Otomatis.</small> -->



                    </div>



                    <div class="col-md-1">



                    <button type="button" id="edit_head" class="btn btn-info btn-sm"><i class="fas fa-edit"></i></button>  



                    <button type="button" id="update_head" class="btn btn-success btn-sm" style="display: none;"><i class="fas fa-save"></i></button>



                    </div>



                </div>



            </div>



          </div>



          <hr>



          <table class="table table-bordered" id="tabel_nomor_strategi" width="100%" cellspacing="0">



                  <thead>



                    <tr>



                      <th>No</th>



                      <th>Nomor Strategi</th>



                      <th>Keterangan</th>



                      <th>Aksi</th>



                    </tr>



                  </thead>



                  <!-- <tfoot>



                    <tr>



                      <th>Name</th>



                      <th>Position</th>



                      <th>Office</th>



                      <th>Age</th>



                      <th>Start date</th>



                      <th>Salary</th>



                    </tr>



                  </tfoot> -->



                  <tbody>



                  </tbody>



                </table>



                <a href="javascript:void(0)" onclick="tambah('<?=$id_row?>','<?=$id_row2?>')" class="btn btn-success btn-icon-split btn-sm" title="Tambah Nomor Strategi">



                                        <span class="icon text-white-50">



                                          <i class="fas fa-plus"></i>



                                        </span>



                                        <span class="text">Tambah Nomor Strategi</span>



                                      </a>



      </div>



      <div class="modal-footer">



        <button type="button" class="btn btn-secondary" data-dismiss="modal">Tutup</button>



        <!--<button type="submit" class="btn btn-primary"><i class="fas fa-save"></i> Simpan</button>-->



        



      </div>



    </form>



    </div>



  </div>



</div>



<script type="text/javascript">



  $(document).ready(function(){



    var base_url = "<?=base_url()?>";



    var id_modal = "<?=$id_modal?>";



    var kode_head = "<?=$id_row?>";



    // var time = function(){



    //   $('.timepicker').datepicker({



    //       format: 'dd MM yyyy',



    //       todayHighlight:true,



    //       toggleActive:true,



    //       daysOfWeekDisabled:'0',



    //       autoclose:true,



    //       language:'id'



    //   });



    // }



    // time();



    $("#edit_head").click(function(){



      $("#update_head").show();



      $("#edit_head").hide();



      $("#head").attr("readonly",false)



    })



    $("#update_head").click(function(){



      var head = $("#head").val();



      $.ajax({



        url             : base_url + 'strategi/ganti_nama_head/', 



        type            : "POST",



        dataType        : 'json',



        data            : {head:head,kode_head:kode_head},



        mimeType        : 'multipart/form-data',



        success         : function(response){



          if (response==true) {



            Command: toastr["success"]("Anda Berhasil Mengganti Nama Head", "Berhasil");



            $("#update_head").hide();



            $("#edit_head").show();



            $("#head").attr("readonly",true);



            getcontens('page/data_strategi');



          }else{



            Command: toastr["info"]("Anda Gagal Mengganti Nama Head", "info");



          }



        },



        error: function(jqXHR, textStatus, errorThrown) {



          $('#loading').modal('hide');



          Command: toastr["error"](errorThrown, "Error");



        },



        beforeSend: function () {



          $('#loading').modal('show');



        },



        complete: function () {



          $('#loading').modal('hide');



        }



      });



    });



    ambil_nomor_strategi = function(){



      $.ajax({



                url             : base_url + 'strategi/ambil_nomor_strategi/'+kode_head, 



                type            : "POST",



                dataType        : 'json',



                mimeType        : 'multipart/form-data',



                success         : function(response){



                  // alert(JSON.stringify(response))



                  // var kode_head = parseInt(response["max_kode"]);



                  // $("#kode_head").val(kode_head)



                  nomor_strategi = parseInt(response["max_kode"].split(",")[1])+1;



                  $("#kode_strategi").val(kode_head+","+nomor_strategi)



                }



      })



    }



    ambil_nomor_strategi();



    var data_nomor_strategi = function(){



        $('#tabel_produk').hide();



        $.ajax({ 



            url: base_url + 'strategi/data_detail_strategi/'+kode_head,



            type: "post",



            // data:{<?php echo $this->security->get_csrf_token_name(); ?>:'<?php echo $this->security->get_csrf_hash(); ?>'},



            // data:{},



            dataType: "json",



            async : 'false',



            success: function(result){



              // alert(JSON.stringify(result))



              var data = [];



                for ( var i=0 ; i<result.length ; i++ ) {



                  // alert(result[i].kode_pka)



                    var no = i+1;



                    var ket = String(result[i].keterangan);



                    var link_edit = `<a href="javascript:void(0)" onclick="edit('`+result[i].kode_strategi+`','`+ket.replace(/[^a-zA-Z ]/g, "")+`')" class="btn btn-info btn-icon-split btn-sm" title="Edit Nomor Strategi">



                                        <span class="icon text-white-50">



                                          <i class="fas fa-edit"></i>



                                        </span>



                                      </a>`;



                    var link_hapus = `<a href="javascript:void(0)" onclick="hapus('`+result[i].kode_strategi+`');" class="btn btn-danger btn-icon-split btn-sm" title="Hapus Nomor Strategi">



                                        <span class="icon text-white-50">



                                          <i class="fas fa-trash-alt"></i>



                                        </span>



                                      </a>`;



                    var d= '<div class="btn-group" role="group" aria-label="Basic example">';



                    var dd = "</div>";



                    data.push([no,result[i].kode_strategi,result[i].keterangan,d+link_edit+" "+link_hapus+dd]);



                }



                $('#tabel_nomor_strategi').DataTable({



                    //"bJQueryUI"     : true,



                    data                : data,



                    deferRender         : true,



                    processing          : true,



                    ordering            : true,



                    retrieve            : false,



                    paging              : true,



                    deferLoading        : 57,



                    bDestroy            : true,



                    autoWidth           : false,



                    bFilter             : true,



                    iDisplayLength      : 10,



                    responsive: true,



                    language: {



                      searchPlaceholder: 'Cari',



                      sSearch: '',



                      lengthMenu: '_MENU_',



                    },



                });



               



            },



            beforeSend: function () {







            },



            complete: function () {



                // $('#tabel_produk').show();



            }



        });



    }



    data_nomor_strategi();







    $("#tambah").submit(function(){



      var form_data = new FormData($('#tambah')[0]);



      bootbox.confirm("Apakah Anda Yakin Akan Menyimpan Data?", function(result){ 



        if (result==true) {



          $.ajax({



                url             : base_url + 'strategi/simpan_strategi', 



                type            : "POST",



                dataType        : 'json',



                mimeType        : 'multipart/form-data',



                data            : form_data,



                contentType     : false,



                cache           : false,



                processData     : false,



                success         : function(response){



                  // alert(response)



                    if(response == true){



                        $('#'+id_modal).modal('hide');  



                        Command: toastr["success"]("Data Bidang Berhasil Disimpan", "Berhasil");



                        getcontens('page/data_strategi');



                    }else{



                        Command: toastr["error"]("Simpan error, data tidak berhasil disimpan", "Error");



                    }



                },



                error: function(jqXHR, textStatus, errorThrown) {



                  $('#loading').modal('hide');



                  Command: toastr["error"](errorThrown, "Error");



                },



                beforeSend: function () {



                  $('#loading').modal('show');



                },



                complete: function () {



                    $('#loading').modal('hide');



                }



          });



        }



      });



          



        return false;



    })



    edit = function(kode_strategi,keterangan){



      $("#"+id_modal).modal('hide');



      getpopup('Popup/edit_nomor_strategi','popupedit',kode_strategi,keterangan);



    }



    edit_strat = function(u){



        alert(u)



    }



    tambah = function(kode_head,head){



      $("#"+id_modal).modal('hide');



      getpopup('Popup/tambah_nomor_strategi','popupedit',kode_head,head);



    }



    hapus = function(kode_strategi){



      bootbox.confirm("Apakah Anda Yakin Akan Menyimpan Data?", function(result){ 



        if (result==true) {



          $.ajax({



                url             : base_url + 'strategi/hapus_nomor_strategi', 



                type            : "POST",



                dataType        : 'json',



                data            : {kode_strategi:kode_strategi},



                mimeType        : 'multipart/form-data',



                success         : function(response){



                  if(response == true){



                        data_nomor_strategi();



                        Command: toastr["success"]("Data Bidang Berhasil Dihapus", "Berhasil");



                        // getcontens('page/data_strategi');



                    }else{



                        Command: toastr["error"]("Simpan error, data tidak berhasil disimpan", "Error");



                    }



                },



                error: function(jqXHR, textStatus, errorThrown) {



                  $('#loading').modal('hide');



                  Command: toastr["error"](errorThrown, "Error");



                },



                beforeSend: function () {



                  $('#loading').modal('show');



                },



                complete: function () {



                    $('#loading').modal('hide');



                }



          });



        }



      });



    }



  })



</script>