
<script src="<?= BASE_ASSET; ?>/js/jquery.hotkeys.js"></script>
<script type="text/javascript">
    function domo(){
     
       // Binding keys
       $('*').bind('keydown', 'Ctrl+s', function assets() {
          $('#btn_save').trigger('click');
           return false;
       });
    
       $('*').bind('keydown', 'Ctrl+x', function assets() {
          $('#btn_cancel').trigger('click');
           return false;
       });
    
      $('*').bind('keydown', 'Ctrl+d', function assets() {
          $('.btn_save_back').trigger('click');
           return false;
       });
        
    }
    
    jQuery(document).ready(domo);
</script>
<!-- Content Header (Page header) -->
<section class="content-header">
    <h1>
        Parcels        <small><?= cclang('new', ['Parcels']); ?> </small>
    </h1>
    <ol class="breadcrumb">
        <li><a href="#"><i class="fa fa-dashboard"></i> Home</a></li>
        <li class=""><a  href="<?= site_url('administrator/parcels'); ?>">Parcels</a></li>
        <li class="active"><?= cclang('new'); ?></li>
    </ol>
</section>
<!-- Main content -->
<section class="content">
    <div class="row" >
        <div class="col-md-12">
            <div class="box box-warning">
                <div class="box-body ">
                    <!-- Widget: user widget style 1 -->
                    <div class="box box-widget widget-user-2">
                        <!-- Add the bg color to the header using any of the bg-* classes -->
                        <div class="widget-user-header ">
                            <div class="widget-user-image" style="text-align:left;">
                                <img class="img-circle" style="width:50px;" src="<?= BASE_ASSET; ?>/img/add2.png" alt="User Avatar">
                            </div>
                            <!-- /.widget-user-image -->
                            <h3 class="widget-user-username">Parcels</h3>
                            <h5 class="widget-user-desc"><?= cclang('new', ['Parcels']); ?></h5>
                            <hr>
                        </div>
                        <?= form_open('', [
                            'name'    => 'form_parcels', 
                            'class'   => 'form-horizontal form-step', 
                            'id'      => 'form_parcels', 
                            'enctype' => 'multipart/form-data', 
                            'method'  => 'POST'
                            ]); ?>
                        <?php
                        $user_groups = $this->model_group->get_user_group_ids();
                        ?>
                         
                                                                        <div class="form-group ">
                            <label for="name" class="col-sm-2 control-label">الاسم 
                            <i class="required">*</i>
                            </label>
                            <div class="col-sm-8">
                                <input type="text" class="form-control" name="name" id="name" placeholder="الاسم" value="<?= set_value('name'); ?>">
                                <small class="info help-block">
                                <b>Input Name</b> Max Length : 200.</small>
                            </div>
                        </div>
                        

                                                 
                                                                        <div class="form-group ">
                            <label for="region" class="col-sm-2 control-label">الولاية 
                            </label>
                            <div class="col-sm-8">
                                <input type="text" class="form-control" name="region" id="region" placeholder="الولاية" value="<?= set_value('region'); ?>">
                                <small class="info help-block">
                                <b>Input Region</b> Max Length : 300.</small>
                            </div>
                        </div>
                        

                                                 
                                                                        <div class="form-group ">
                            <label for="gouvernorat" class="col-sm-2 control-label">المعتمدية 
                            </label>
                            <div class="col-sm-8">
                                <input type="text" class="form-control" name="gouvernorat" id="gouvernorat" placeholder="المعتمدية" value="<?= set_value('gouvernorat'); ?>">
                                <small class="info help-block">
                                <b>Input Gouvernorat</b> Max Length : 300.</small>
                            </div>
                        </div>
                        

                                                 
                                                                        <div class="form-group ">
                            <label for="nbr_pieds" class="col-sm-2 control-label">عدد الأشجار 
                            <i class="required">*</i>
                            </label>
                            <div class="col-sm-8">
                                <input type="number" class="form-control" name="nbr_pieds" id="nbr_pieds" placeholder="عدد الأشجار" value="<?= set_value('nbr_pieds'); ?>">
                                <small class="info help-block">
                                <b>Input Nbr Pieds</b> Max Length : 11.</small>
                            </div>
                        </div>
                        

                                                 
                                                                        <div class="form-group ">
                            <label for="mode_culture" class="col-sm-2 control-label">الكثافة 
                            </label>
                            <div class="col-sm-8">
                                <select  class="form-control chosen chosen-select" name="mode_culture" id="mode_culture" data-placeholder="Select الكثافة" >
                                    <option value=""></option>
                                    <option value="6x6">6x6</option>
                                    <option value="6x8">6x8</option>
                                    <option value="5x7">5x7</option>
                                    <option value="7x7">7x7</option>
                                    <option value="10x10">10x10</option>
                                    <option value="12x12">12x12</option>
                                    <option value="17x17">17x17</option>
                                    <option value="24x24">24x24</option>
                                    </select>
                                <small class="info help-block">
                                </small>
                            </div>
                        </div>
                        

                                                 
                                                                        <div class="form-group ">
                            <label for="nbr_hect" class="col-sm-2 control-label">عدد الهكتارات 
                            </label>
                            <div class="col-sm-8">
                                <input type="number" class="form-control" name="nbr_hect" id="nbr_hect" placeholder="عدد الهكتارات" value="<?= set_value('nbr_hect'); ?>">
                                <small class="info help-block">
                                <b>Input Nbr Hect</b> Max Length : 11.</small>
                            </div>
                        </div>
                        

                                                 
                                                                        <div class="form-group  wrapper-options-crud">
                            <label for="mode_de_planteur" class="col-sm-2 control-label">سقوي أو بعلي 
                            </label>
                            <div class="col-sm-8">
                                    <div class="col-md-3 padding-left-0">
                                    <label>
                                    <input type="radio" class="flat-red" name="mode_de_planteur" value="سقوي"> سقوي                                    </label>
                                    </div>
                                    <div class="col-md-3 padding-left-0">
                                    <label>
                                    <input type="radio" class="flat-red" name="mode_de_planteur" value="بعلي"> بعلي                                    </label>
                                    </div>
                                    </select>
                                <div class="row-fluid clear-both">
                                <small class="info help-block">
                                </small>
                                </div>
                            </div>
                        </div>
                        

                                                
                        
                                                <div class="message"></div>
                                                <div class="row-fluid col-md-7 container-button-bottom">
                           <button class="btn btn-flat btn-primary btn_save btn_action" id="btn_save" data-stype='stay' title="<?= cclang('save_button'); ?> (Ctrl+s)">
                            <i class="fa fa-save" ></i> <?= cclang('save_button'); ?>
                            </button>
                            <a class="btn btn-flat btn-info btn_save btn_action btn_save_back" id="btn_save" data-stype='back' title="<?= cclang('save_and_go_the_list_button'); ?> (Ctrl+d)">
                            <i class="ion ion-ios-list-outline" ></i> <?= cclang('save_and_go_the_list_button'); ?>
                            </a>
                            <a class="btn btn-flat btn-default btn_action" id="btn_cancel" title="<?= cclang('cancel_button'); ?> (Ctrl+x)">
                            <i class="fa fa-undo" ></i> <?= cclang('cancel_button'); ?>
                            </a>
                            <span class="loading loading-hide">
                            <img src="<?= BASE_ASSET; ?>/img/loading-spin-primary.svg"> 
                            <i><?= cclang('loading_saving_data'); ?></i>
                            </span>
                        </div>
                                                 <?= form_close(); ?>
                    </div>
                </div>
                <!--/box body -->
            </div>
            <!--/box -->
        </div>
    </div>
</section>
<!-- /.content -->
<!-- Page script -->
<script>
    $(document).ready(function(){

                          
      $('#btn_cancel').click(function(){
        swal({
            title: "<?= cclang('are_you_sure'); ?>",
            text: "<?= cclang('data_to_be_deleted_can_not_be_restored'); ?>",
            type: "warning",
            showCancelButton: true,
            confirmButtonColor: "#DD6B55",
            confirmButtonText: "Yes!",
            cancelButtonText: "No!",
            closeOnConfirm: true,
            closeOnCancel: true
          },
          function(isConfirm){
            if (isConfirm) {
              window.location.href = BASE_URL + 'administrator/parcels';
            }
          });
    
        return false;
      }); /*end btn cancel*/
    
      $('.btn_save').click(function(){
        $('.message').fadeOut();
            
        var form_parcels = $('#form_parcels');
        var data_post = form_parcels.serializeArray();
        var save_type = $(this).attr('data-stype');

        data_post.push({name: 'save_type', value: save_type});
    
        $('.loading').show();
    
        $.ajax({
          url: BASE_URL + '/administrator/parcels/add_save',
          type: 'POST',
          dataType: 'json',
          data: data_post,
        })
        .done(function(res) {
          $('form').find('.form-group').removeClass('has-error');
          $('.steps li').removeClass('error');
          $('form').find('.error-input').remove();
          if(res.success) {
            
            if (save_type == 'back') {
              window.location.href = res.redirect;
              return;
            }
    
            $('.message').printMessage({message : res.message});
            $('.message').fadeIn();
            resetForm();
            $('.chosen option').prop('selected', false).trigger('chosen:updated');
                
          } else {
            if (res.errors) {
                
                $.each(res.errors, function(index, val) {
                    $('form #'+index).parents('.form-group').addClass('has-error');
                    $('form #'+index).parents('.form-group').find('small').prepend(`
                      <div class="error-input">`+val+`</div>
                      `);
                });
                $('.steps li').removeClass('error');
                $('.content section').each(function(index, el) {
                    if ($(this).find('.has-error').length) {
                        $('.steps li:eq('+index+')').addClass('error').find('a').trigger('click');
                    }
                });
            }
            $('.message').printMessage({message : res.message, type : 'warning'});
          }
    
        })
        .fail(function() {
          $('.message').printMessage({message : 'Error save data', type : 'warning'});
        })
        .always(function() {
          $('.loading').hide();
          $('html, body').animate({ scrollTop: $(document).height() }, 2000);
        });
    
        return false;
      }); /*end btn save*/
      
       
 
       

      
    
    
    }); /*end doc ready*/
</script>