@extends('admin.master')

@section('style')
<link href="{{ asset('data/assets/css/selectize.bootstrap3.css') }}" rel="stylesheet">
@endsection

@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::model($category, ['route' => ['admin.case-cate.update', $category->id], 'method'=>'put', 'class'=>'form-horizontal form-detail']) !!}
<div class="tab-content">
	<div role="tabpanel" class="tab-pane in active" id="home">
    	<div class="tab-content">
    			<div role="tabpanel" class="tab-pane active" id="language-{{ $managerLang }}">
					<div class="form-group">
						<label class="col-sm-2 control-label label-width">上级分类：</label>
						<div class="col-sm-5">
							{!! Form::select('parent_id', ['请选择'] + $nest, null, ['class'=>'form-control']) !!}
						</div>
					</div>
    				<div class="form-group {{ $managerLang == config('setting.lang') ? 'form-item-required' : ''}}">
            			<label class="col-sm-2 control-label label-width">标题：</label>
            			<div class="col-sm-5">
            				{!! Form::text("description[{$managerLang}][cname]", isset($descriptions[$managerLang]) ? $descriptions[$managerLang][0]->cname : '', ['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::textarea("description[{$managerLang}][summary]", isset($descriptions[$managerLang]) ? $descriptions[$managerLang][0]->summary : '', ['class'=>'form-control', 'rows'=>3]) !!}
						</div>
					</div>
					<div class="form-group">
						<label class="col-sm-2 control-label label-width">图片：</label>
						<div class="col-sm-5">
							<div class="col-sm-12 row">
								<div class="upload-wrap" data-name="description[{{ $managerLang }}][img]">
									<div class="upload-wrap-btn {{ (isset($descriptions[$managerLang]) && $descriptions[$managerLang][0]->img) ? 'display-none' : ''}}">
										<span class="btn btn-default" data-toggle="modal" data-target="#media-dialog-modal">媒体上传</span>
										<span class="text-muted pl-10">(允许上传的媒体类型：jpg、gif、png)</span>
									</div>
									<ul id="picfram" class="upload-wrap-lists attachments clearfix">
										@if(isset($descriptions[$managerLang]) && $descriptions[$managerLang][0]->img != '')
										<li class="thumbnail" data-img="{{ $descriptions[$managerLang][0]->img }}" >
											<input name="description[{{ $managerLang }}][img]" value="{{ $descriptions[$managerLang][0]->img }}" type="hidden">
											<a class="thumbnail-img"><img src="{{ url($descriptions[$managerLang][0]->img) }}"></a>
											<a class="thumbnail-remove" data-id="fileupload" href="javascript:;">删除</a>
										</li>
										@endif
									</ul>
								</div>
							</div>
						</div>
					</div>
					<div class="form-group">
						<label class="col-sm-2 control-label label-width">页面路径：</label>
						<div class="col-sm-5">
							<div class="input-group">
								<div class="input-group-addon">/case/</div>
								{!! Form::text('slug', null, ['class'=>'form-control']) !!}
							</div>
						</div>
					</div>
					<div id="tags-content" class="form-group">
						<label class="col-sm-2 control-label label-width">标签：</label>
						<div class="col-sm-5 form-select-multiple">
							{!! Form::select('tags[]', $tags, $category->tags->lists('name')->toArray(), ['multiple', 'class'=>'form-control multiple-select', 'placeholder'=>'您最多可以选择3个标签！']) !!}
						</div>
						@if(config('managerLang') == config('setting.lang'))
							<div class="col-sm-5 form-tag-add">
								<a href="javascript:void(0)" class="pt-5" @click="addTag()">
									<i class="iconfont icon-plus"></i>
									添加新标签
								</a>
							</div>
							@include('admin.common.notice')
						@endif
					</div>
					<div class="form-group">
						<label class="col-sm-2 control-label label-width">排序：</label>
						<div class="col-sm-5">
							{!! Form::number('orders', null, ['class'=>'form-control']) !!}
						</div>
					</div>
					<div class="form-group">
						<label class="col-sm-2 control-label label-width">链接URL：</label>
						<div class="col-sm-5">
							{!! Form::text('linkurl', null, ['class'=>'form-control']) !!}
						</div>
					</div>
					<div class="form-group">
						<label class="col-sm-2 control-label label-width">发布状态：</label>
						<div class="col-sm-5">
							<div class="pretty-box">
								<div class="pretty p-default p-round p-smooth">
									{!! Form::radio('flag', 1, null) !!}
									<div class="state p-success-o"><label>发布</label></div>
								</div>
								<div class="pretty p-default p-round p-smooth">
									{!! Form::radio('flag', 0, null) !!}
									<div class="state p-success-o"><label>不发布</label></div>
								</div>
							</div>
						</div>
					</div>
					<div class="form-group form-group-line"></div>
    				<div class="form-group">
            			<label class="col-sm-2 control-label label-width">Meta Tag 标题：</label>
            			<div class="col-sm-5">
            				{!! Form::text("description[{$managerLang}][seo_title]", isset($descriptions[$managerLang]) ? $descriptions[$managerLang][0]->seo_title : '', ['class'=>'form-control']) !!}
            			</div>
            		</div>
    				
    				<div class="form-group">
            			<label class="col-sm-2 control-label label-width">Meta Tag 关键词：</label>
            			<div class="col-sm-5">
            				{!! Form::text("description[{$managerLang}][seo_keywords]", isset($descriptions[$managerLang]) ? $descriptions[$managerLang][0]->seo_keywords : '', ['class'=>'form-control']) !!}
            			</div>
            		</div>
    				
    				<div class="form-group">
            			<label class="col-sm-2 control-label label-width">Meta Tag 描述：</label>
            			<div class="col-sm-5">
            				{!! Form::textarea("description[{$managerLang}][seo_description]", isset($descriptions[$managerLang]) ? $descriptions[$managerLang][0]->seo_description : '', ['class'=>'form-control', 'rows'=>3]) !!}
            			</div>
            		</div>
    			</div>
    		</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('edit_auto_translate') == 1 ? '提交并翻译' : '提交', ['class'=>'btn btn-primary']) !!}
			</div>
		</div>
	</div>
</div>
{!! Form::close() !!}
@endsection

@section('foot')
<script src="{{ asset('data/assets/js/selectize.js') }}"></script>
<script>
$(function(){
	$('.multiple-select').selectize({
		plugins: ['remove_button'],
		maxItems: 3
	});
});

new Vue({
	el: '#tags-content',
	data: {
		tags: {},
		urlLoad: "{{ url('/admin/tag/ajax-update') }}",
	},
	methods: {
		addTag: function() {
			$("#dialog-common").modal('show');
		},
		submitTag: function() {
			var _this = this;
			_this.tags['description'] = {};
			if ($("#tag-en").val() == '') {
				swal({
					title: "", 
					text: "英文标签不能为空！",
					type: "warning",
					showConfirmButton: false,
					timer: 1500,
				});
				return false;
			} else {
				$(".tag-input").each(function() {
					var lang   = $(this).data('lang');
					_this.tags['description'][lang] = {};
					_this.tags['description'][lang]['name'] = $(this).val();
				});
				
				$.ajax({
					type: "POST",
					headers: {
					'X-CSRF-TOKEN': $('meta[name="csrf-token"]').attr('content')
					},
					url: _this.urlLoad,
					data: _this.tags,
					success: function(json) {
						if (json.status == 'sucess') {
							$("#dialog-common").modal('hide');
							$(".tag-input").val('');
							swal({
								title: "", 
								text: "标签添加成功！",
								type: "success",
								showConfirmButton: false,
								timer: 1500,
							});
							control.addOption({value: json.name, text: json.name + '(0)'});
							control.addItem(json.name)
						} else {
                swal({
                    title: "",
                    text: json.message || "添加标签失败，请重新添加！",
                    type: "error",
                    showConfirmButton: false,
                    timer: 1500,
                });
						}
					}
				});
			}

		}
	},
});
</script>
{{--媒体库 start--}}
@include('admin.common.media', ['type' => 'jpg,gif,png'])
{{--媒体库 end--}}
@endsection