<?php $__env->startSection('content'); ?>
<div class="row-fluid">
    <div class="span9">
        <h4 class="nametag"><?php echo e(trans($_CONST["LANG_DEST"].".class_title")); ?></h4>

		<a href="<?php echo URL::to('admin/product'); ?>" class="btn btn-success btn-custom" style="margin-top:10px">
			<span class="glyphicon glyphicon-file"></span>
			產品管理
		</a>
		<hr>
        <?php echo Form::open(array( 'action'=>$_CONST["CONTROLLER_ROUTE"].'.store', 'class'=>'form-horizontal well')); ?>

        <div class="input-group">
            <span class="input-group-addon"><?php echo e(trans($_CONST["LANG_DEST"].".new_class_name")); ?>：</span>
            <?php echo Form::text('title', null, array('class' => 'form-control','placeholder'=>'英文','required' => 'required')); ?>

            <?php echo Form::text('title_tw', null, array('class' => 'form-control','placeholder'=>'中文','required' => 'required')); ?>

<?php /*            <span class="input-group-addon">分類順序</span>
            <?php echo Form::text('category_order', null, array('class' => 'form-control','placeholder'=>'順序(1,2,3...)','required' => 'required')); ?>

*/ ?>
            <span class="input-group-addon input-group-btn">
                <input type="submit" href="<?php echo route($_CONST["CONTROLLER_ROUTE"].'.create'); ?>" class="btn btn-primary" value="<?php echo e(trans($_CONST["LANG_DEST"].".class_create_action")); ?>">
            </span>
        </div>
        <?php echo Form::close(); ?>

        <table class="table table-bordered">
            <tr>
                <th>分類英文名稱</th>
                <th>分類中文名稱</th>
                <th>分類順序</th>
                <th class="col-md-4">操作</th>
                <th>刪除</th>
				<th>呈現</th>
            </tr>
            <?php foreach($categories as $category): ?>
                <tr data-id=<?php echo $category->id; ?>>
					<td><?php echo e($category-> name); ?></td>
					<td><?php echo e($category-> name_tw); ?></td>
					<td>
		        	    	<div class="input-group">
		<?php /*			<?php echo Form::model($category, array(
					  'route' => array($_CONST["CONTROLLER_ROUTE"].'.orderchange', $category->id),
					  'method' => 'put'
					)); ?>

		*/ ?>
					<?php echo Form::open(['url' => 'admin/productclass/orderchange/'. $category->id, 'method' => 'get' ]); ?>

				            <?php echo Form::text('category_order', '', array('class' => 'form-control','placeholder'=> $category->order)); ?>

					<input class="btn btn-primary" type='submit'value="調整"/>
					<?php echo Form::close(); ?>

	        			</div>
					</td>
<?php /*
	                <td><a href="<?php echo action($_CONST["SUB_CONTROLLER"].'@'.'show', $category->id); ?>"><?php echo e($category->title); ?></a></td>
*/ ?>
                <td>
					<?php echo Form::model($category, array(
		    			'route' => array($_CONST["CONTROLLER_ROUTE"].'.update', $category->id),
					    'class' =>'form-horizontal',
		    			'method' => 'put'
					)); ?>

        	    	<div class="input-group">
			            <?php echo Form::text('title', '', array('class' => 'form-control','placeholder'=>'英文')); ?>

			            <?php echo Form::text('title_tw', '', array('class' => 'form-control','placeholder'=>'中文')); ?>

			            <span class="input-group-btn">
            		    <input type="submit" style="height:68px"  href="<?php echo route($_CONST["CONTROLLER_ROUTE"].'.create'); ?>" class="btn btn-primary" value="<?php echo e(trans($_CONST["LANG_DEST"].".class_rename_action")); ?>">
            			</span>
        			</div>
					<?php echo Form::close(); ?>

				</td>
                <td>
                    <?php echo Form::open(array(
                        'route'=>array($_CONST["CONTROLLER_ROUTE"].'.destroy', $category->id),
                        'method' => 'delete')
                    ); ?>

				<a href="#"  onclick="if (confirm('<?php echo trans('Myadmin::layout.whether_to_delete'); ?>\n注意！會連同該類別的產品一同刪除！！'))$(this).closest('form').submit()" class="btn btn-danger">
                      <span class="glyphicon glyphicon-remove"></span>
                      刪除
				</a>
<?php /*                    <?php echo Form::submit(trans($_CONST["LANG_DEST"].".class_delete_action"), array("class"=>"delete"));; ?>	*/ ?>
                    <?php echo Form::close(); ?>

                </td>
				<td>
					<div class="input-group">
						<?php if($category->show == '1'): ?>
							<?php echo Form::checkbox('show', null, true, array('class' => 'form-control' , 'style' => 'width:15px')); ?>

						<?php else: ?>
							<?php echo Form::checkbox('show', null, false, array('class' => 'form-control' , 'style' => 'width:15px')); ?>

						<?php endif; ?>
					</div>
				</td>
                </tr>
            <?php endforeach; ?>
			<input type="hidden" value="" class="id-change"></input>
        </table>
    </div>
</div>

<script type="text/javascript" charset="utf-8">
	$(document).ready(function(){
		var c_array = [];
		var unique;
			
			$("[name=show]").change(small_change);


			// store the small changes.	
			$("[name=show]").change(function(){
				console.log("aa");
				var obj = [];
				if(unique != null){
					for (var i = 0 ; i < unique.length ; i++){
						var data = $("tr[data-id="+unique[i]+"]").children("td");//.children("[name=stock_amount]").val();
						obj.push({"id":unique[i].toString(), "checked":data.find("[name=show]").prop('checked')});
					}
					window.location = "<?php echo URL::to('admin/productclass/fix/'); ?>" + "/" + JSON.stringify(obj);
					alert("store success !!");
				}
				else
					alert("nothing has to be stored");
			});

			function small_change(){
				var change = $(this).parents("tr").data("id");
				c_array.push(change);
				unique = c_array.filter(function(item,i,c_array){
					return i==c_array.indexOf(item);
				});
				console.log(unique);
				$(".id-change").val(unique);
			};
			
			$("[name=category_order]").change(function(){
				var cate_order = $("[name=category_order]").val();
				console.log("change order");
				console.log(cate_order);
			});

	});
</script>

<?php $__env->stopSection(); ?>

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