@extends('admin.master')

@section('top')
<div class="top-breadcrumb pull-left">
    <h5>添加广告</h5>
    <a class="btn btn-xs btn-default goback" onclick="javascript:history.go(-1);">
        <i class="iconfont icon-back-copy"></i><span>返回</span>
    </a>
</div>
@endsection

@section('content')
{!! Form::open(['route' => 'admin.ad.store', 'class'=>'form-horizontal form-detail']) !!}
<div class="tab-content">
	<div class="form-group form-item-required">
		<label class="col-sm-2 control-label label-width">标题：</label>
		<div class="col-sm-5">
			{!! Form::text('name', '', ['class'=>'form-control']) !!}
		</div>
	</div>
	<div class="form-group">
		<label class="col-sm-2 control-label label-width">尺寸：</label>
		<div class="col-sm-5 form-inline">
			{!! Form::text("size[width]", '', ['class'=>'form-control len150']) !!} x 
			{!! Form::text("size[height]", '', ['class'=>'form-control len150']) !!}
		</div>
	</div>
	<div class="tab-content" id="min-wd-height">
		<div role="tabpanel" class="tab-pane active" id="language-{{ $managerLang }}">
			<table class="table table-hover menu-content">
				<thead>
					<tr>
						<th width="90">排序</th>
						<th width="180" class="text-center">图片</th>
						<th>标题</th>
						<th>链接</th>
						<th>描述</th>
						<th width="90"></th>
					</tr>
				</thead>
				<tbody></tbody>
				<tfoot>
					<tr>
						<td colspan="6" class="text-right">
							@if(config('managerLang') == config('setting.lang'))
								<button type="button" onclick="addImage('{{$managerLang}}');" data-toggle="tooltip" title="添加广告" class="btn btn-primary mr-20">
									<i class="fa fa-plus-circle"></i>
									增加
								</button>
							@endif
						</td>
					</tr>
				</tfoot>
			</table>
		</div>
	</div>
	<div class="form-send-height">
	<div class="form-send-box">
		<div class="form-group">
			<label class="col-sm-3 control-label label-width"></label>
			<div class="col-sm-5">
        {!! Form::submit(inject('setting')->config('auto_translate') == 1 ? '提交并翻译' : '提交', ['class'=>'btn btn-primary']) !!}
			</div>
		</div>
	</div>
</div>
{!! Form::close() !!}
@endsection

@section('foot')
<script>
window.onload = function() {
	$('[data-toggle="tooltip"]').tooltip();
}
document.getElementById('min-wd-height').style.minHeight = (document.documentElement.clientHeight - 296) + 'px'
window.onresize = function () {
	document.getElementById('min-wd-height').style.minHeight = (document.documentElement.clientHeight - 296) + 'px'
}
var image_row = 0;
function addImage(langSlug) {
	var imgId = 'ad-image' + image_row;
	var imageRow = 'image-row' + image_row;
	html  = '<tr id="' + imageRow + '">';
	html += '<td><input type="text" name="description[' + langSlug + '][' + image_row + '][order]" value="0" class="form-control" /></td>';
	html += '<td class="text-center"><img id="' + imgId + '" src="'+ HOME_URL +'/data/assets/images/nopic.jpg" width="140" height="120" style="border: 1px solid #ecebeb;cursor: pointer;" data-toggle="tooltip" title="上传图片"><input type="hidden" name="description[' + langSlug + '][' + image_row + '][img]" value="" class="input-image" /></td>';
    html += '<td class="text-left"><input type="text" name="description[' + langSlug + '][' + image_row + '][title]" value="" placeholder="标题" class="form-control" /></td>';	
	html += '<td class="text-left"><input type="text" name="description[' + langSlug + '][' + image_row + '][url]" value="" placeholder="链接" class="form-control" /></td>';
	html += '<td class="text-left"><textarea class="form-control" name="description[' + langSlug + '][' + image_row + '][summary]" placeholder="描述" rows="4"></textarea></td>';
	html += '<td class="text-left"><button type="button" onclick="$(\'#image-row' + image_row  + ', .tooltip\').remove();" data-toggle="tooltip" title="移除" class="btn btn-danger"><i class="fa fa-minus-circle"></i></button></td>';
	html += '</tr>';
	$('#language-' + langSlug + ' tbody').append(html);
	
	image_row++;
	$('.btn-primary').tooltip('hide');
	$('[data-toggle="tooltip"]').tooltip();
}

$("#min-wd-height").on('click', 'img', function (e) {
	e.stopPropagation();
	window.adImgId = $(this).attr('id')
	window.mediaType = "ad"
	$("#media-dialog-modal").modal('show')
})
</script>
{{--媒体库 start--}}
@include('admin.common.media', ['type' => 'jpg,gif,png'])
{{--媒体库 end--}}
@endsection