<?php $__env->startSection('content'); ?>

<div>
    <div class="input-prepend input-append">
    </div>
        <h4 class="nametag"><?php echo e(trans($_CONST["LANG_DEST"].".title")); ?></h4>
        <a href="<?php echo route($_CONST["CONTROLLER_ROUTE"].'.create'); ?>" class="btn btn-primary">
            <span class="glyphicon glyphicon-file"></span>
            <?php echo e(trans($_CONST["LANG_DEST"].".create_action")); ?>

        </a>
        <a href="<?php echo action($_CONST["CLASS_CONTROLLER"].'@index'); ?>" class="btn btn-success">
            <span class="glyphicon glyphicon-plus"></span>
			<?php echo e(trans($_CONST["LANG_DEST"].".manage_class")); ?>

        </a>

		<br>
		<div class="col-md-4 pull-right">
			<div class="input-group">
				<input type="text" class="form-control" placeholder="Product's name" id="search_input">
				<span class="input-group-btn">
					<button class="btn btn-default" type="button" name="search">Seach</button>
				</span>
			</div>
		</div>

		<?php /* Notification that number of products in warehouse is smaller than stock threshold!! */ ?>
		<div class="dropdown pull-right">
	        <button class="btn btn-warning" type="button" data-toggle="dropdown" aria-expanded="true">
            <span class="glyphicon glyphicon-bell"></span>
			<?php echo e(trans($_CONST["LANG_DEST"].".notification")); ?>

			</button>
			<ul class="dropdown-menu" role="menu" aria-labelledby="dropdownMenu1">
				<?php foreach($notifications as $noti): ?>
				<li role="presentation" ><a role="menuitem" tabindex="-1" href="#" class="noti_list" value="testvalue"><?php echo $noti; ?></a></li>
				<?php endforeach; ?>	
			</ul>
		</div>
    <hr>
    <?php echo Form::open(array(  'class'=>'form-horizontal well')); ?>

    <div class="input-group">
        <span class="input-group-addon"><?php echo e(trans($_CONST["LANG_DEST"].".select_class")); ?>：</span>
        <?php echo Form::select('id', $categories, 0, array('class' => 'form-control') ); ?>

    </div>
    <?php echo Form::close(); ?>

    <table class="table table-bordered" id="product-table">
		<thead>
	        <tr><th>Product Name</th><th>產品分類</th><th>價格</th><th>商品狀態</th><th>描述</th><th>架上數量</th><th>編輯</th><th>圖片</th></tr>
		</thead>
		<tbody>
        <?php foreach($products as $product): ?> 
        <tr>
            <td style="width:129px" id="td_pro_title"><?php echo $product->title; ?></td>
	    	<td style="width:129px"><?php echo $categories[$product->category_id]; ?></td>
		    <td style="width:100px"><?php echo $product->price; ?></td>
			<td style="width:100px"><?php echo $product->type; ?>

			<?php 
				if($product->type == '集量商品'){
		    		echo "<br><{$product->deal_baseline}></td>";
				}
				else if($product->type == '限時商品'){
		    		echo "<br>{$product->close_date}</td>";
				}
			?>
<?php /*
		    <td style="width:100px"><?php echo $product->type; ?><br><div style=display:none><?php echo $product->deal_baseline; ?></div><br><div style=display:none><?php echo $product->close_date; ?></div></td>
*/ ?>
	    	<td style="width:300px"><?php echo $product->description; ?></td>
		    <td style="width:100px"><?php echo $product->available_amount; ?></td>

            <td style="width:200px">
                <?php echo Form::open(array(
                    'route'=>array('admin.product.destroy', $product->id),
                    'method' => 'delete')
                ); ?>

                <a href="#" onclick="AddOperating('<?php echo $product->is_available; ?>','<?php echo $product->available_amount; ?>','<?php echo $product->stock_amount; ?>');" class="btn btn-primary">
                    <span class="glyphicon glyphicon-pencil"></span>
                    操作
                </a>
                <a href="#" onclick="Broadcast()" class="btn btn-primary">
                    <span class="glyphicon glyphicon-pencil"></span>
                    推播
                </a>
                <a href="<?php echo route('admin.product.edit', $product->id); ?>" class="btn btn-primary">
                    <span class="glyphicon glyphicon-pencil"></span>
                    設定
                </a>

                <a href="#" onclick="if (confirm('<?php echo trans('Myadmin::layout.whether_to_delete'); ?>'))$(this).closest('form').submit()" class="btn btn-danger">
                    <span class="glyphicon glyphicon-remove"></span>
                    刪除
                </a>
                <?php echo Form::close(); ?>

            </td>

			<td><img src="<?php echo e(img_upload_url($product->img_path)); ?>" width="200px"></td>
        </tr>
        <?php endforeach; ?>
		</tbody>
    </table>
    <div class="pagination">
        <?php echo $products->links(); ?>

    </div>

	<script type="text/javascript" charset="utf-8">
		function AddOperating(status,aAmount,sAmount){
//			alert(status);
//			alert(aAmount);
//			alert(sAmount);
			var allow = sAmount-aAmount;
			var str = "補貨操作 \n商品狀態 : " + status + "\n上架數量 : " + aAmount + " / " + sAmount + "\n許可數量 : " + allow;
			var add = prompt(str,'多少數量?');
			if(!isNaN(add)){
<?php /*				var test = "<?php echo action('admin.product@test'); ?>"; 	*/ ?>
				alert(add);
			}
			else
				alert("Not a number!!");
		};
		function Broadcast(){
			var uploadcast = confirm("上架通知?");
			if(uploadcast)
				alert("上架通知!");
			var editcast = confirm("調整通知?");
			if(editcast)
				alert("調整通知!");
		}
	</script>

    <script type="text/javascript" charset="utf-8">
		
        $(document).ready(function(){
            var base_url = "<?php echo route('admin.product.index'); ?>";

			/* select class to redirect the pages */
            $("select[name=id]").change(function(){
                var t = $("select[name=id]").val();
                var base_url = "<?php echo route($_CONST["CONTROLLER_ROUTE"].".index"); ?>";
                if (t==0) {
                    var target = base_url;
                }else {
                    var target = base_url + '/' + t;
                }
                window.location = target;
            });

			$("#search_input").keyup(function(){
				// When value of the input is not blank
				if( $(this).val() != ""){
				// Show only matching TR, hide rest of them
					console.log($(this).val());
//					console.log($("#td_pro_title").val());
			 		$("#product-table tbody>tr").hide();
					$("#product-table #td_pro_title:contains-ci('"+$(this).val()+"')").parent("tr").show();
		 		}
		 		else{
			 		// When there is no input or clean again, show everything back
			 		$("#product-table tbody>tr").show();
		 		}
			});

			$(".noti_list").click(function(){
				console.log("test noti!!");
				console.log($(this).text());
				if( $(this).text() != ""){
				// Show only matching TR, hide rest of them
			 		$("#product-table tbody>tr").hide();
					$("#product-table #td_pro_title:contains-ci('"+$(this).text()+"')").parent("tr").show();
		 		}
		 		else{
			 		// When there is no input or clean again, show everything back
			 		$("#product-table tbody>tr").show();
		 		}
			});
        });

		$.extend($.expr[":"],
		{
			"contains-ci": function(elem, i, match, array)
			{
				return (elem.textContent || elem.innerText || $(elem).text() || "").toLowerCase().indexOf((match[3] || "").toLowerCase()) >= 0;
			}
		});
    </script>
</div>
<?php $__env->stopSection(); ?>



<?php echo $__env->make('Myadmin::layout.basic', array_except(get_defined_vars(), array('__data', '__path')))->render(); ?>