<?php $__env->startSection('css_page_level'); ?>
<link rel="stylesheet" type="text/css" href="<?php echo e(asset('assets/global/plugins/datatables/plugins/bootstrap/dataTables.bootstrap.css')); ?>"/>
<?php $__env->stopSection(); ?>

<?php $__env->startSection('page-content-wrapper'); ?>
	<div class="page-content-wrapper" id="main">
		<div class="page-content">
			<!-- BEGIN PAGE HEADER-->
			<h3 class="page-title">
			<?php $setting = app('anlutro\LaravelSettings\Facade'); ?>
			<?php echo e($setting::get('system_name','全方位建築智慧化管理系統')); ?> <small><?php echo e($setting::get('company_name','新保科技')); ?></small>
			</h3>
			<div class="page-bar">
				<ul class="page-breadcrumb">
					<li>
						<i class="fa fa-home"></i>
						<a href="<?php echo e(route('manage::index')); ?>">首頁</a>
						<i class="fa fa-angle-right"></i>
					</li>
					<li>
						<a href="javascript:;">社區平台管理</a>
						<i class="fa fa-angle-right"></i>
					</li>
					<li>
						<a href="<?php echo e(action('Manage\Platform\FactoryController@index')); ?>">廠戶介紹</a>
					</li>
				</ul>
				<div class="page-toolbar">
				</div>
			</div>
			<!-- END PAGE HEADER-->
			<!-- BEGIN DASHBOARD STATS -->
			<div class="row">
				<div class="col-md-12">
					<!-- BEGIN EXAMPLE TABLE PORTLET-->
					<div class="portlet light bordered">
						<div class="portlet-body">
							<div class="table-toolbar">
								<div class="row">
									<div class="col-md-6">
										<div class="btn-group">
											<a href="<?php echo e(action('Manage\Platform\FactoryController@create')); ?>" class="btn green">
											新增 <i class="fa fa-plus"></i>
											</a>
											<button id="btn_mass_delete" class="btn red" style="display:none;">刪除 <i class="fa fa-trash"></i></button>
										</div>
									</div>
								</div>
							</div>
							<table class="table table-striped table-bordered table-hover" id="table_list">
							<thead>
							<tr>
								<th class="table-checkbox">
									<input type="checkbox" class="group-checkable" data-set="#table_list .checkboxes"/>
								</th>
								<th style="width:8%">
									 編號
								</th>
								<th style="width:8%">
									 標誌
								</th>
								<th style="width:46%">
									 標題
								</th>
								<th style="width:30%">
									 發佈時間
								</th>
								<th style="width:8%">
									 動作
								</th>
							</tr>
							</thead>
							<tbody>
							<?php foreach($factory as $one): ?>
							<tr class="odd gradeX">
								<td>
									<input type="checkbox" class="checkboxes" value="<?php echo e($one->id); ?>"/>
								</td>
								<td>
									<?php echo e($one->id); ?>

								</td>
								<td>
									<?php if(!empty($one->cover_img) ): ?>
									<img src="<?php echo e($one->cover_img); ?>?fit_w=20&fit_h=20" alt=""/>
									<?php endif; ?>
								</td>
								<td>
									<a href="<?php echo e(action('Manage\Platform\FactoryController@show',['id'=>$one->id])); ?>"><?php echo e($one->title); ?></a>
								</td>
								<td>
									<?php echo e($one->created_at); ?>

								</td>
								<td>
									<div class="btn-group">
										<button class="btn btn-default btn-xs dropdown-toggle" type="button" data-toggle="dropdown" aria-expanded="false">
										動作 <i class="fa fa-angle-down"></i>
										</button>
										<ul class="dropdown-menu pull-right" role="menu">
											<li>
												<a  href="<?php echo e(action('Manage\Platform\FactoryController@edit',['id'=>$one->id])); ?>">
												<i class="fa fa-pencil"></i>
												編輯 </a>
											</li>
											<li class="divider">
											</li>
											<li>
												<a class="btn_delete_one" utitle="<?php echo e($one->title); ?>" uid="<?php echo e($one->id); ?>" href="javascript:;">
												<i class="fa fa-trash-o"></i>
												刪除 </a>
											</li>
										</ul>
									</div>
								</td>
							</tr>
							<?php endforeach; ?>
							</tbody>
							</table>
						</div>
					</div>
					<!-- END EXAMPLE TABLE PORTLET-->
				</div>
			</div>
		</div>

	<input type="hidden" id="_token" name="_token" value="<?php echo e(csrf_token()); ?>">
<?php $__env->stopSection(); ?>

<?php $__env->startSection('plugins_page_level'); ?>
<script type="text/javascript" src="<?php echo e(asset('assets/global/plugins/datatables/media/js/jquery.dataTables.min.js')); ?>"></script>
<script type="text/javascript" src="<?php echo e(asset('assets/global/plugins/datatables/plugins/bootstrap/dataTables.bootstrap.js')); ?>"></script>
<script type="text/javascript" src="<?php echo e(asset('assets/global/plugins/bootbox/bootbox.min.js')); ?>"></script>
<?php $__env->stopSection(); ?>

<?php $__env->startSection('js_page_level'); ?>
<script>
$(document).ready(function(){
	$('#table_list').dataTable({
		// Internationalisation. For more info refer to http://datatables.net/manual/i18n
		"language": {
		    "aria": {
		        "sortAscending": ": activate to sort column ascending",
		        "sortDescending": ": activate to sort column descending"
		    },
		    "emptyTable": "此列表目前沒有資料",
		    "info": "顯示第 _START_ 到第 _END_ 則 共有 _TOTAL_ 則",
		    "infoEmpty": "沒有找到符合的資料",
		    "infoFiltered": "(從 _MAX_ 筆資料中過濾)",
		    "lengthMenu": "顯示 _MENU_ 則",
		    "search": "快速篩選:",
		    "zeroRecords": "目前沒有任何資料",
		    "paginate": {
		        "previous":"上一頁",
		        "next": "下一頁",
		        "last": "最後",
		        "first": "最前"
		    }
		},

		"bStateSave": false, // save datatable state(pagination, sort, etc) in cookie.

		"lengthMenu": [
		    [10, 20, 50, -1],
		    [10, 20, 50, "All"] // change per page values here
		],
		// set the initial value
		"pageLength": 10,            
		"pagingType": "bootstrap_full_number",
		"columnDefs": [{  // set default column settings
		    'orderable': false,
		    'targets': [0]
		}, {
		    "searchable": false,
		    "targets": [0]
		}]
	});

	$(document).on('click','.btn_delete_one',function(){
		var id = $(this).attr('uid');
		var title = $(this).attr('utitle');
		bootbox.confirm("<h5>確定刪除"+title+"這個廠戶介紹?</h5>", function(result) {
	       if(result === true){
	       		$.ajax({
	       			type  : 'DELETE',
	       			url   : "<?php echo e(action('Manage\Platform\FactoryController@destroy' ,['id'=>''])); ?>/"+id,
	       			dataType : 'json',
	       			data  : {
	       				_token   : $('#_token').val(),
	       				id : id
	       			},
	       			success : function(){
	       				toastr['success']('刪除廠戶介紹成功');
	       				window.location.reload();
	       			},
	       			error   : function(){
	       				toastr['error']('刪除廠戶介紹失敗');
	       			}
	       		});
	       }
	    });
	});

	$('#table_list').find('.group-checkable').change(function () {
        var set = jQuery(this).attr("data-set");
        var checked = jQuery(this).is(":checked");
        jQuery(set).each(function () {
            if (checked) {
                $(this).attr("checked", true);
            } else {
                $(this).attr("checked", false);
            }
        });
        jQuery.uniform.update(set);
    });
	
	$(document).on('change','#table_list .checkboxes',function(){
    	var checkedNum = $('.checkboxes:checked').length;
		if(checkedNum>0){
			$('#btn_mass_delete').show();
		}else{
			$('#btn_mass_delete').hide();
		}
	});
	$(document).on('change','.group-checkable',function(){
		var checkedNum = $('.checkboxes:checked').length;
		if(checkedNum>0){
			$('#btn_mass_delete').show();
		}else{
			$('#btn_mass_delete').hide();
		}
	});

	$(document).on('click','#btn_mass_delete',function(){
		var ids = $.map($('input:checkbox:checked'), function(n, i){
		      return n.value;
		}).join(',');
		bootbox.confirm("您確定要刪除所選擇的項目?", function(result) {
			if(result == true){
				$.ajax({
					type : 'DELETE',
					dataType : 'json',
					url  : "<?php echo e(action('Manage\Platform\FactoryController@destroy' ,['id'=>''])); ?>/"+ids,
					data : {
						_token   : $('#_token').val(),
						id : ids
					},
					success : function(sendback){
						toastr['success']('刪除成功');
						window.location.reload();
					},
					error : function(sendback){
						toastr['error']('刪除失敗，請重新整理後再試');
					}
				});
			}
		});
	});
});

</script>
<?php $__env->stopSection(); ?>
<?php echo $__env->make('layout.manage', array_except(get_defined_vars(), array('__data', '__path')))->render(); ?>