<!-- Page Heading -->

          <!-- <h1 class="h3 mb-2 text-gray-800">Tables</h1>

          <p class="mb-4">DataTables is a third party plugin that is used to generate the demo table below. For more information about DataTables, please visit the <a target="_blank" href="https://datatables.net">official DataTables documentation</a>.</p> -->



          <!-- DataTales Example -->





          <div class="card shadow mb-4">

            <div class="card-header py-3 bg-primary">

              <h6 class="m-0 font-weight-bold text-light">Header & Footer</h6>

            </div>

            <div class="card-body">

              <div class="row">

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

                  <form id="form_header">

                    <input type="hidden" id="id_template_email" name="id_template_email">

                    <div class="form-group">

                      <label>Header</label>

                      <textarea id="header" class="form-control" name="header"></textarea>

                    </div>

                  <div class="form-group">

                    <input type="hidden" id="id_template_email2" name="id_template_email2">

                    <label for="exampleFormControlTextarea1">Footer</label>

                    <textarea class="form-control" id="footer" name="footer" rows="6"></textarea>

                    <hr>

                    

                  </div>

                  </form>

                  <div class="btn-group float-right" role="group" aria-label="Basic example">

                    <a href="javascript:void(0)" class="btn btn-info btn-sm" id="test_header"><i class="fas fa-vial"></i> Test</a>

                    <a href="javascript:void(0)" class="btn btn-primary btn-sm" id="update_header_footer"><i class="fas fa-edit"></i> Update Header & Footer</a>

                  </div>

                </div>

              </div>

            </div>

          </div>

<script type="text/javascript">

$(document).ready(function(){

    

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

    var kode_user = "<?=$this->session->userdata("kode_user")?>";

    $('#header').summernote({placeholder: 'Silahkan isi disini',

            tabsize: 2,

            height: 150,

            dialogsInBody: true,

            toolbar: [

                ['style', ['bold', 'italic', 'underline', 'clear']],

                ['font', ['strikethrough', 'superscript', 'subscript']],

                ['fontsize', ['fontsize']],

                ['color', ['color']],

                ['para', ['ul', 'ol', 'paragraph','style']],

                ['height', ['height']]

            ]

    });

  

    $('#footer').summernote({placeholder: 'Silahkan isi disini',

            tabsize: 2,

            height: 150,

            dialogsInBody: true,

            toolbar: [

                ['style', ['bold', 'italic', 'underline', 'clear']],

                ['font', ['strikethrough', 'superscript', 'subscript']],

                ['fontsize', ['fontsize']],

                ['color', ['color']],

                ['para', ['ul', 'ol', 'paragraph','style']],

                ['height', ['height']]

            ]

    });



    template_email = function(){

      $.ajax({ 

              url: base_url + 'template_email/ambil_header_footer',

              type: "post",

              data:{},

              dataType: "json",

              async : 'false',

              success: function(response){

                $('#header').summernote('code', response.header_email);

                $('#footer').summernote('code', response.footer_email);

                $('#id_template_email').val(response.id_template_email);

                $('#id_template_email2').val(response.id_template_email);

              },

              error: function(jqXHR, textStatus, errorThrown) {

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

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

              },

              beforeSend: function () {

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

              },

              complete: function () {

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

              }

      })

    }

    template_email();

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

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

      bootbox.confirm("Apakah Anda Yakin Akan Meng-Update?", function(result){ 

          if (result==true) {

            

            $.ajax({ 

              url: base_url + 'template_email/update_header_footer',

              type            : "POST",

                dataType        : 'json',

                mimeType        : 'multipart/form-data',

                data            : form_data,

                contentType     : false,

                cache           : false,

                processData     : false,

              success: function(response){

                // alert(JSON.stringify(response))

                if (response == true) {

                  Command: toastr["success"]("Anda Berhasil Mengupdate", "success");

                }

              },

              error: function(jqXHR, textStatus, errorThrown) {

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

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

              },

              beforeSend: function () {

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

              },

              complete: function () {

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

              }

            })

          }

      })

    })

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

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

      bootbox.confirm("Apakah Anda Yakin Akan Mengetes Header Dan Footer?", function(result){ 

          if (result==true) {

            

            $.ajax({ 

              url: base_url + 'template_email/test_header_footer',

              type            : "POST",

                dataType        : 'json',

                mimeType        : 'multipart/form-data',

                data            : form_data,

                contentType     : false,

                cache           : false,

                processData     : false,

              success: function(response){

                // alert(JSON.stringify(response))

                if (response == true) {

                  Command: toastr["success"]("Anda Berhasil Mengetes Header & Footer", "success");

                }

              },

              error: function(jqXHR, textStatus, errorThrown) {

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

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

              },

              beforeSend: function () {

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

              },

              complete: function () {

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

              }

            })

          }

      })

    })

  });

</script>

