<?php $__env->startSection('title'); ?>
Notícias
<?php $__env->stopSection(); ?>

<?php $__env->startSection('content-header'); ?>
Notícias 
<small>
    <?php echo $action; ?>

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

<?php $__env->startSection('breadcrumb'); ?>
<li>
    <a href="<?php echo route('admin.news.index'); ?>">
        Notícias
    </a>
</li>
<li class="active">
    <?php echo $action; ?>

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

<?php $__env->startSection('styles'); ?>
<?php echo HTML::style('assets/vendor/jasny-bootstrap/dist/css/jasny-bootstrap.min.css'); ?>

<?php echo HTML::style('assets/vendor/jquery.filer/css/jquery.filer.css'); ?>

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

<?php $__env->startSection('plugins'); ?>
<?php echo HTML::script('assets/vendor/jasny-bootstrap/dist/js/jasny-bootstrap.min.js'); ?>

<?php echo HTML::script('assets/vendor/jquery.filer/js/jquery.filer.min.js'); ?>

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

<?php $__env->startSection('content'); ?>
<div class="row">
    <div class="col-xs-12">
        <div class="box box-solid">

            <?php echo Form::model($news, $formOptions); ?>

            <div class="box-body">
                <div class="row">

                    <div class="col-sm-12 col-md-8 col-lg-9">
                        <div class="form-group is-required">
                            <?php echo Form::label('title', 'Título'); ?>

                            <?php echo Form::text('title', null, array('class' =>'form-control', 'required' => true)); ?>

                        </div>
                        <div class="form-group is-required">
                            <?php echo Form::label('content', 'Conteúdo da Notícia'); ?>

                            <?php echo Form::textarea('content', null, array('class' =>'form-control ckeditor', 'required' => true)); ?>

                        </div>
                    </div>
                    <div class="col-sm-12 col-md-4 col-lg-3">
                        <div class="form-group">
                            <?php echo Form::label('date', 'Data da Notícia'); ?>

                            <div class="input-group">
                                <span class="input-group-addon"><i class="fa fa-calendar"></i></span>
                                <?php if($news->date): ?>
                                <?php echo Form::text('date', date('Y-m-d', strtotime($news->date)), array('class' =>'form-control datepicker', 'required' => true)); ?>

                                <?php else: ?>
                                <?php echo Form::text('date', date('Y-m-d'), array('class' =>'form-control datepicker', 'required' => true)); ?>

                                <?php endif; ?>
                            </div>
                        </div>

                        <div class="form-group">
                            <?php echo Form::label('image', 'Imagem'); ?>

                            <div class="clearfix"></div>
                                <?php if($news->fileurl): ?>
                                <div class="fileinput fileinput-exists width-100" data-provides="fileinput">
                                <?php else: ?>
                                <div class="fileinput fileinput-new width-100" data-provides="fileinput">
                                <?php endif; ?>
                                    <div class="fileinput-preview thumbnail width-100" data-trigger="fileinput">
                                        <?php if($news->fileurl): ?>
                                        <img src="<?php echo asset($news->fileurl); ?>">
                                        <?php endif; ?>
                                    </div>
                                    <div>
                                        <span class="btn btn-default btn-file">
                                            <span class="fileinput-new">Selecionar</span>
                                            <span class="fileinput-exists btn-change-photo">Alterar</span>
                                            <input type="file" name="image" accept="image/*">
                                        </span>
                                        <a href="#" class="btn btn-danger btn-remove-photo fileinput-exists" data-dismiss="fileinput">Anular</a>
                                        <a href="#" class="btn btn-default btn-reset-photo hidden">Repôr Original</a>
                                    </div>
                                    <?php echo Form::hidden('delete_photo', 0); ?>

                                    <?php if($news->fileurl): ?>
                                    <?php echo Form::hidden('original_fileurl', asset($news->fileurl)); ?>

                                    <?php endif; ?>
                                </div>
                            </div>
                        </div>
                        
                    </div>
                    <div class="row">
                        <div class="col-sm-9">
                            <div class="form-group">
                                <?php echo Form::label('documents', 'Anexar os seguintes documentos'); ?>

                                <?php echo Form::select('documents[]', $documents, @$selectedDocuments, array('class' =>'form-control select2', 'multiple'=>'true')); ?>

                            </div>
                            <div class="form-group jFiler"> 
                                <?php echo Form::label('files', 'Imagens em anexo'); ?> <span class='text-muted'>(Máximo 20 imagens)</span>
                                <button type="button" class="file_input btn btn-default margin-bottom-10">Selecionar imagens</button>
                                <?php echo Form::hidden('deleted_images', '[]'); ?>

                            </div>
                        </div>
                        <div class="col-sm-3">
                            <div class="form-group">
                                <?php echo Form::label('highlight', 'Destaque'); ?>

                                <div class="checkbox">
                                    <label style="padding: 0 !important">
                                        <?php echo Form::checkbox('highlight', 1, false);; ?>

                                        Colocar notícia em destaque
                                    </label>
                                </div>
                            </div>
                        </div>
                    </div>
                    
                    <div class="row">
                        <div class="col-sm-12">
                            <?php echo Form::submit('Gravar', array('class' => 'btn btn-primary' )); ?>

                        </div>
                    </div>
                </div>
                <?php echo Form::close(); ?>

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

<?php $__env->startSection('scripts'); ?>
<script>
    //remove photo
    $('.btn-remove-photo').on('click', function(){
        if($('input[name=original_fileurl]').length > 0) {
            $('.btn-reset-photo').removeClass('hidden');
            $('input[name=delete_photo]').val(1);
        }
    });
    
    //reset original photo
    $('.btn-reset-photo').on('click', function(e){
        e.preventDefault();
        $(this).addClass('hidden');
        $('input[name=delete_photo]').val('');
        $('.fileinput-preview').html('<img src="' + $('input[name=original_fileurl]').val() + '">');
        $('.fileinput').removeClass('fileinput-new').addClass('fileinput-exists');
        $('input[name=image]').val('');
    })
    
    $('.file_input').filer({
            showThumbs: true,
            limit: 20,
            name: 'attachments',
            maxSize: 5,
            extensions: ['jpg', 'png', 'jpeg'],
            templates: {
            box: '<ul class="jFiler-item-list"></ul>',
                    item: '<?php echo $__env->make("admin.partials.filer-template", array_except(get_defined_vars(), array('__data', '__path')))->render(); ?>',
                    itemAppend: '<?php echo $__env->make("admin.partials.filer-template", array_except(get_defined_vars(), array('__data', '__path')))->render(); ?>',
                    progressBar: '<div class="bar"></div>',
                    itemAppendToEnd: true,
                    removeConfirmation: false,
                    _selectors: {
                    list: '.jFiler-item-list',
                            item: '.jFiler-item',
                            progressBar: '.bar',
                            remove: '.jFiler-item-trash-action',
                    }
            },
            addMore: true,
            files: <?php echo json_encode(@$attachments); ?>,
            onRemove: function(el, file){
                //put deleted images in a array of ids
               if(typeof file.id === 'number') {

                   $input = $('input[name="deleted_images"]');

                   var deleted = $.parseJSON($input.val());

                   deleted.push(file.id);

                   $input.val(JSON.stringify(deleted));
                }

            },
            captions: {
            button: "Selecionar ficheiros",
                    feedback: "Choose files To Upload",
                    feedback2: "files were chosen",
                    drop: "Drop file here to Upload",
                    removeConfirmation: "Are you sure you want to remove this file?",
                    errors: {
                    filesLimit: "Apenas são permitidas {{fi-limit}} imagens.",
                            filesType: "Apenas são permitidas imagens (jpg e png).",
                            filesSize: "A imagem {{fi-name}} é demasiado grande, max: {{fi-maxSize}} MB.",
                            filesSizeAll: "Files you've choosed are too large! Please upload files up to {{fi-maxSize}} MB."
                    },
            }
    });
</script>
<?php $__env->stopSection(); ?>

