<script src="<?php echo THEME_PATH ?>js/jquery-barcode.js"></script>
<script src="<?php echo THEME_PATH ?>js/jQuery.print.js"></script>
<style>
.switch {
  position: relative;
  display: inline-block;
  width: 60px;
  height: 34px;
}

.switch input { 
  opacity: 0;
  width: 0;
  height: 0;
}

.slider {
  position: absolute;
  cursor: pointer;
  top: 0;
  left: 0;
  right: 0;
  bottom: 0;
  background-color: #ccc;
  -webkit-transition: .4s;
  transition: .4s;
}

.slider:before {
  position: absolute;
  content: "";
  height: 26px;
  width: 26px;
  left: 4px;
  bottom: 4px;
  background-color: white;
  -webkit-transition: .4s;
  transition: .4s;
}

input:checked + .slider {
  background-color: #2196F3;
}

input:focus + .slider {
  box-shadow: 0 0 1px #2196F3;
}

input:checked + .slider:before {
  -webkit-transform: translateX(26px);
  -ms-transform: translateX(26px);
  transform: translateX(26px);
}

/* Rounded sliders */
.slider.round {
  border-radius: 34px;
}

.slider.round:before {
  border-radius: 50%;
}
</style>
<div id="Barcode" ></div>
<div class="container-fluid container-fixed-lg bg-white">
    <div class="panel panel-transparent">
        <div class="panel-heading">
            <div id="color_alert"></div>
 
            <div class="panel-title"> <?php print CommonLanguage::getMessage('production_color'); ?></div>
        </div>
        <div class="panel-heading">
             <div class="panel-title"> 
                 <label class="switch">
                    <input id="check_bar" type="checkbox" checked>
                    <span class="slider round"></span>
                </label>
             </div>
        </div>
        <div class="panel-body">
        <form id="add_color_form" method="POST" onsubmit="return false">   
            <div class="row m-b-20 form-group">
            <div class="col-md-2 ">
                    <label><?php print CommonLanguage::getMessage('position'); ?></label> 
                    <input type="text"  id="position" name="position" class="form-control  position position_change"/>
                </div>
            <div class="col-md-2">
                    <label><?php print CommonLanguage::getMessage('color_name'); ?></label> 
                    <input type="color" value=""  id="color_name" name="color_name" class="form-control  ">
                </div>
                
               
                 
            </div>
        </form>
             
            
            <div class="row m-t-10">
                <div class="col-md-4 col-md-offset-4">                        
                    <button class=" btn btn-primary btn-cons  pull-right" id="printbtn" type="button" style="margin-top:24px;"><i class="pg-form"></i> <span class="bold"><?php print CommonLanguage::getMessage('Save'); ?></span></button>
                </div>
            </div>
        </div>
    </div>
</div>

<script>
             
    $(function () {
          
        $("#check_bar").on("change", function () {
        if(document.getElementById('check_bar').checked) {
            
            $("#s2id_position").remove();

            $(".position_change").attr("type", "text");
            $(".position_change").addClass('form-control');
            $(".position_change").removeClass('full-width');
            $(".position_change").css('display','block')
            $(".position_change").addClass("id", "position_change1");
            $(".position_change1").removeClass("id", "position_change");

        } else {

            $(".position_change1").attr("type", "hidden");
            $(".position_change1").addClass("id", "position_change");
            $(".position_change").removeClass("id", "position_change1");

            $(".position_change").attr("type", "hidden");
            $(".position_change").addClass('full-width');
            $(".position_change").removeClass('form-control');

            build_select2($("#position"), 'xhr/commonSearch?table=tbl_production_color&col_id=position_name&col_name=position_name');

        }
        });
         $("#position").on("change", function () {
            var position =$('#position').val();
            
            $.ajax({
              url: "InventoryAjax/get_production_color",
              data: {position:position},
              dataType: "JSON",
              complete: function(jqXHR, status) {
                  if (status == 'success') {
                      if (jqXHR.responseJSON[1] == "success") {
                          
                      }                 

                         $("#color_name").val(jqXHR.responseJSON['data'][0]['color_name']);

                    }
                   
              }
          });
        });
        $("#printbtn").on("click", function () {
            var bar_code = [];
//            if ($(".color_name").attr("data-code") == '') {
            if ($("#color_name").val() == '') {
                
                $("#color_alert").attr("class", "alert alert-danger").html(Required_Fields);
                return false;
            }
             
            var data_param = { 
                color_name: $("#color_name").val(),
                position: $("#position").val(),
            };
             

            
            $('.template_div').removeClass('hidden')
             
               var Data = new FormData(document.getElementById("add_color_form"));
                $.ajax({
                    url: "InventoryAjax/submit_production_color",
                    method: "POST",
                    data: Data,
                    processData: false,
                    contentType: false,
                    dataType: "JSON",
                    complete: function (jqXHR, status) {
                        if (status == 'success') {
                            if (jqXHR.responseJSON[1] == "success") {
                              $("#color_alert").attr("class", "alert alert-success").html('<?php print CommonLanguage::getMessage('add_position_color_successfully'); ?>');
                             }
                         }
                     }
                });
            
         });
         
         
    });
  </script>
