@extends('layouts.admin-app')

@section('content')

   <!--- <div class="pageheader">
        <h2><i class="fa fa-home"></i> Dashboard <span>Subtitle goes here...</span></h2>
        <div class="breadcrumb-wrapper">
            <span class="label">You are here:</span>
            <ol class="breadcrumb">
                <li class="active">Dashboard</li>
            </ol>
        </div>
    </div> -->

    <div class="contentpanel" smooth: true,>
        <div class="row">

            <div class="col-sm-12 col-lg-12">

                <div class="panel panel-default">
                    <div class="panel-heading">
                        <div class="panel-btns">
                            <a href="" class="panel-close">×</a>
                            <a href="" class="minimize">−</a>
                        </div>
                        <h4 class="panel-title">编辑视频</h4>
                    </div>

                    <form class="form-horizontal form-bordered" action="{{ route('admin.video.update', ['id' => $video->id]) }}" method="POST">
                        @include('admin._partials.errors', ['errors' => $errors])
                        {{ method_field('PATCH') }}
                        <div class="panel-body panel-body-nopadding">

                            <div class="form-group">
                                <label class="col-sm-3 control-label">视频名称</label>

                                <div class="col-sm-6">
                                    <input type="text" class="form-control" name="title" value="{{ $video->title }}">
                                </div>
                            </div>

                            <div class="form-group">
                                <label class="col-sm-3 control-label">关键词</label>

                                <div class="col-sm-6">
                                    <input type="text" class="form-control" name="keywords" value="{{ $video->keywords }}">
                                </div>
                            </div>

                            <div class="form-group">
                                <label class="col-sm-3 control-label">摘要</label>

                                <div class="col-sm-6">
                                    <input type="text" class="form-control" name="synopsis" value="{{ $video->synopsis }}">
                                </div>
                            </div>

                            <div class="form-group">
                                <label class="col-sm-3 control-label">上传视频</label>

                                <div class="col-sm-6">
                                    <input type="file" class="form-control" id="upload_video" name="upload_video" value="">
                                </div>
                            </div>

                            <div class="form-group">
                                <label class="col-sm-3 control-label">或 输入视频地址</label>

                                <div class="col-sm-6">
                                    <input type="text" class="form-control" id="url" name="url" value="{{ $video->url }}">
                                    <input type="hidden" id="path" name="path" value="{{ $video->path }}">
                                    <input type="hidden" id="attachment_id" name="attachment_id" value="{{ $video->attachment_id }}">
                                </div>
                            </div>

                            {{ csrf_field() }}
                        </div><!-- panel-body -->

                        <div class="panel-footer">
                            <div class="row">
                                <div class="col-sm-6 col-sm-offset-3">
                                    <button class="btn btn-primary">保存</button>
                                </div>
                            </div>
                        </div><!-- panel-footer -->

                    </form>
                </div>

            </div><!-- col-sm-9 -->

        </div><!-- row -->
    </div><!-- contentpanel -->

    <!-- 实例化编辑器 -->
    <script>
        $(document).ready(function () {
            $('#upload_video').uploadify({
                "auto": true,
                "buttonText": "上传",
                "fileTypeDesc": "video files",
                "fileTypeExts": "*.mp4;*.png",
                "fileObjName": "video",
                "method": "post",
                "formData": {
                    "timestamp": {{ time() }},
                    "_token": "{{ csrf_token() }}"
                },
                "multi": false,
                "swf": "{{ asset('plugins/uploadify/uploadify.swf') }}",
                "uploader": "{{ route('admin.attachment.upload') }}",
                "onUploadSuccess": function (file, data, response) {
                    data = $.parseJSON(data);
                    if (data.state == 0) {
                        $('#url').val(data.data.url);
                        $('#path').val(data.data.path);
                        $('#attachment_id').val(data.data.aid);
                    } else {
                        $('.message').html(response.message);
                    }
                },
                'onUploadError' : function(file, errorCode, errorMsg, errorString) {
                    alert('The file ' + file.name + ' could not be uploaded: ' + errorString);
                }
            });
        })
    </script>
@endsection

@section('css')
    @parent
    <link rel="stylesheet" href="{{ asset('plugins/uploadify/uploadify.css') }}">
@endsection

@section('js')
    @parent
    <script src="{{ asset('plugins/uploadify/jquery.uploadify.min.js') }}"></script>
@endsection