<?php defined('BASEPATH') or exit('No direct script access allowed');?>
<?php echo form_open(current_url(), 'class="form-horizontal"');?>
  <div class="form-group">
    <label class="col-sm-2 control-label">Nama</label>
    <div class="col-sm-10">
      <input type="text" class="form-control" name="title" required="required" placeholder="Produk Promo" value="<?php echo set_value('title', $title);?>" maxlength="64"/>
    </div>
  </div>
  <div class="form-group">
    <label class="col-sm-2 control-label">Orientasi</label>
    <div class="col-sm-10">
      <select class="form-control" name="orientation">
        <option value="vertical"<?php echo set_select('orientation','vertical', $orientation == 'vertical' ? true : false);?>>Vertikal</option>
        <option value="horizontal"<?php echo set_select('orientation','horizontal', $orientation == 'horizontal' ? true : false);?>>Horisontal</option>
      </select>
    </div>
  </div>
  <div class="form-group">
    <label class="col-sm-2 control-label">Produk</label>
    <div class="col-sm-10">
      <div class="row">
        <div class="col-xs-6"><a href="<?php echo site_url('admin/modules/aplikasi-android/select-product');?>" data-toggle="modal" data-target="#myModal" class="btn btn-link btn-sm" type="button"><i class="fa fa-plus"></i> Tambah</a></div>
      </div>
      <ul class="list-group" id="items" style="max-height: 225px; overflow-y: scroll; margin-bottom: 0; <?php echo $products ? 'margin-top: 10px' : '';?>"><?php if ($products):?><?php foreach ($products as $product):?><li class="list-group-item"><a href="#" style="background-color: #a94442;" title="Hapus" class="badge delete" data-id="<?php echo $product['id'];?>"><i class="fa fa-times"></i></a><span class="badge"><?php echo $product['price'];?></span><h5 class="list-group-item-heading"><?php echo html_escape($product['name']);?></h5><p class="list-group-item-text"><?php echo html_escape($product['category']);?> &gt; <?php echo html_escape($product['provider']);?></p></li><?php endforeach;?><?php endif;?></ul>
    </div>
  </div>
  <div class="form-group" style="margin-bottom:0">
    <div class="col-sm-offset-2 col-sm-10">
      <button type="submit" class="btn btn-primary"><i class="fa fa-check"></i> Simpan</button>
      &nbsp;
      <a href="<?php echo site_url('admin/modules/aplikasi-android/main-page');?>" class="btn btn-default" data-dismiss="modal"><i class="fa fa-remove"></i> Batal</a>
    </div>
  </div>
  <input type="hidden" name="products" value="" />
<?php echo form_close();?>
<script>function escapeHtml(unsafe){return unsafe.replace(/&/g,"&amp;").replace(/</g,"&lt;").replace(/>/g,"&gt;").replace(/"/g,"&quot;").replace(/'/g,"&#039;");}var items=<?php echo json_encode($data);?>;$(document).on("click","#select-product-btn",function(){var productName=$(this).attr("data-product");var providerName=$(this).attr("data-provider");var products=JSON.parse(atob($(this).attr("data-values")));for(var i=0;i<products.length;i++){if(items.length<100&&items.indexOf(products[i].id)<0){items.push(products[i].id);var item='<li class="list-group-item"><a href="#" style="background-color: #a94442;" title="Hapus" class="badge delete" data-id="'+products[i].id+'"><i class="fa fa-times"></i></a><span class="badge">'+products[i].price+'</span><h5 class="list-group-item-heading">'+escapeHtml(products[i].name)+'</h5><p class="list-group-item-text">'+escapeHtml(productName)+' &gt; '+escapeHtml(providerName)+'</p></li>';$("#items").append(item);}}if(items.length>0){$("#items").css({"margin-top":"10px"});}else{$("#items").css({"margin-top":"0"});}$('[name="products"]').val(JSON.stringify(items));});$(document).on("click",".list-group-item>.badge.delete",function(){var index=items.indexOf($(this).attr('data-id'));if(index>=0){items.splice(index,1);$(this).parent().remove();if(items.length>0){$("#items").css({"margin-top":"15px"});}else{$("#items").css({"margin-top":"0"});}$('[name="products"]').val(JSON.stringify(items));}return false;});$(document).ready(function(){if(items.length!=0){$('[name="products"]').val(JSON.stringify(items));}});</script>