MINI MINI MANI MO

Path : /var/www/html/sistemas/saplxi/resources/views/Administrador/comunicados/
File Upload :
Current File : /var/www/html/sistemas/saplxi/resources/views/Administrador/comunicados/form.blade.php

<link rel="stylesheet" href="{{ asset('vendors/select2/select2.min.css') }}" type="text/css">
<link rel="stylesheet" href="{{ asset('vendors/select2/select2-materialize.css') }}" type="text/css">
<link rel="stylesheet" type="text/css" href="{{ asset('css/pages/form-select2.css') }}">
<div class="section">
    <div class="card">
        <div class="card-content">
            <h5>Comunicados</h5>
            <div class="row">
                <div class="input-field col s3">
                    <div class="form-group">
                        <label class="control-label"style=" color:  #960948;"><strong>Comunicado:</strong></label>
                        {!! Form::text('comunicado', isset($comunicado) ? $comunicado->comunicado : null, ['class' => 'form-control text-uppercase', 'id' => 'comunicado', 'name' => 'comunicado',  'required' => true]) !!}
                    </div>
                </div>
                <div class="input-field col s3">
                    <div class="form-group">
                        <label class="control-label"style=" color:  #960948;"><strong>Fecha:</strong></label>
                        {!! Form::text('fecha',isset($comunicado) ? \Carbon\Carbon::create($comunicado->fecha)->format('d/m/Y') : null, ['class' => 'form-control datepicker', 'placeholder' => 'dd/mm/aaaa', 'id' => 'fecha',  'required' => true]) !!}
                    </div>
                </div>
            </div>
            <div class="row">
                <div class="input-field col s12">
                    <div class="form-group">
                        <label class="control-label"style=" color:  #960948;"><strong>Título:</strong></label>
                        {!! Form::text('titulo', isset($comunicado) ? $comunicado->titulo : null, ['class' => 'form-control text-uppercase', 'id' => 'titulo', 'name' => 'titulo',  'required' => true]) !!}
                    </div>
                </div>
            </div>
            <div class="row">
                <div class="input-field col s12">
                    <div class="form-group">
                        <label class="control-label"style=" color:  #960948;"><strong>Bullet 1:</strong></label>
                        {!! Form::textarea('bullet1', isset($comunicado) ? $comunicado->bullet1 : null, ['class' => 'form-control text-uppercase', 'id' => 'bullet1', 'name' => 'bullet1']) !!}
                    </div>
                </div>
            </div>
            <div class="row">
                <div class="input-field col s12">
                    <div class="form-group">
                        <label class="control-label"style=" color:  #960948;"><strong>Bullet 2:</strong></label>
                        {!! Form::textarea('bullet2', isset($comunicado) ? $comunicado->bullet2 : null, ['class' => 'form-control text-uppercase', 'id' => 'bullet2', 'name' => 'bullet2']) !!}
                    </div>
                </div>
            </div>
            <div class="row">
                <div class="input-field col s12">
                    <div class="form-group">
                        <label class="control-label"style=" color:  #960948;"><strong>Bullet 3:</strong></label>
                        {!! Form::textarea('bullet3', isset($comunicado) ? $comunicado->bullet3 : null, ['class' => 'form-control text-uppercase', 'id' => 'bullet3', 'name' => 'bullet3']) !!}
                    </div>
                </div>
            </div>
            <div class="row">
                <div class="input-field col s12">
                    <div class="form-group">
                        <label class="control-label"style=" color:  #960948;"><strong>Comunicado:</strong></label>
                        {!! Form::textarea('texto', isset($comunicado) ? $comunicado->texto : null, ['class' => 'form-control text-uppercase', 'id' => 'texto', 'name' => 'texto']) !!}
                    </div>
                </div>
            </div>
            <div class="row">
                <div class="input-field col m8 s8">
                    <div class="file-field input-field">
                        <div class="btn">
                            <span>File</span>
                            <input id="filesBaja" name="files[]" type="file" multiple>
                        </div>
                        <div class="file-path-wrapper">
                            <input class="file-path validate" type="text"
                                placeholder="Selecciona imagenes">
                        </div>
                    </div>
                </div>
                <div class="input-field col s4">
                    <div class="form-group">
                        <label class="control-label"style=" color:  #960948;"><strong>Tags:</strong></label>
                        {!! Form::text('tags', null, ['class' => 'form-control text-uppercase', 'id' => 'tags', 'name' => 'tags']) !!}
                    </div>
                </div>
            </div>

            {{-- modal asignar bien --}}
            <div id="modal" class="modal">
                <button class="btn btnLegislatura light waves-effect waves-light right modal-close btnmodalCerrar">
                    Cerrar <span class="right"><i class="material-icons right-align">clear</i></span>
                </button>
                <div class="modal-header">
                    <h5 class="ml-2">Imagenes</h5>
                </div>
                <div class="modal-content">
                    <div class="row">
                        <div class="col s12 m12 l9 pr-0">
                            <div class="col s12 m4 l4" id="datosImg"></div>
                        </div>
                    </div>
                </div>
            </div>

            <div class="row">
                <div class="col s2">
                    <center>
                        <a href="#modal" data-id="{{isset($comunicado) ? $comunicado->id : ""}}" class="btn-modal">
                            <i class="material-icons">remove_red_eye</i>
                          </a>
                    </center>
                </div><br><br><br>
                <div class="col s12">
                    <center>
                         <button class="waves-effect waves-dark btn btn-primary"  id="cancelar" onclick="updateComunicado()">
                    {{--                        <button class="waves-effect waves-dark btn btn-primary">--}}
                            Guardar <i class="material-icons" title="Guardar">save</i>
                        </button>
                    </center>
                </div>
            </div>
        </div>

    </div>
</div>
</div>

<script src="{{ asset('vendors/select2/select2.full.min.js') }}"></script>
<script src="{{ asset('js/scripts/form-select2.js') }}"></script>
@section('page-script')
    <script type="text/javascript">
        $.ajaxSetup({
            headers: {
                'X-CSRF-TOKEN': $('meta[name="csrf-token"]').attr('content')
            }
        });

        $(document).ready(function(){
            $('.timepicker').datepicker();
        });


        function updateComunicado(){
            if ($("#comunicado").val() === "") {
                swal.fire({
                    icon: "warning",
                    title: "Por favor ingresa el numero del comunicado"
                });
                return false;
            }
            if ($("#fecha").val() === ""){
                swal.fire({
                    icon: "warning",
                    title: "Por favor ingresa la fecha"
                });
                return false;
            }
            $("#cancelar").attr("disabled",true);
            let fd = new FormData();
            var i = 0
            fd.append("comunicado", document.getElementById("comunicado").value)
            fd.append("fecha", document.getElementById("fecha").value)
            fd.append("titulo",  document.getElementById("titulo").value)
            fd.append("bullet1", document.getElementById("bullet1").value)
            fd.append("bullet2", document.getElementById("bullet2").value)
            fd.append("bullet3", document.getElementById("bullet3").value)
            fd.append("texto", document.getElementById("texto").value)
            fd.append("tags", document.getElementById("tags").value)
            $.map($('#filesBaja').get(0).files, function(file) {
                fd.append('imagenes[' + i + ']', file);
                i++
            });
            console.log(fd);
            @if(isset($comunicado))
                fd.append("bandera", 1)
            @endif
            $.ajax({


                url:"{{url('mcg/savecomu')}}",
                type:'post',
                data: fd,
                contentType: false,
                processData: false,
                beforeSend: function() {},
                success:function (response){
                    // console.log(response);
                    if(response.status == 200){
                        window.location.href = "{{ route('mcg.comunicados.index')}}"
                    }
                }
            });
        }

        $(".modal").modal();



        $(".btn-modal").click(function(){
            var id = $(this).attr("data-id");
            $.get("/mcg/img/comunicado/" + id, function(data) {
                var html = '';
                if (data != '') {
                    $.each(data, function (index, element) {
                        html += '<div class="card animate fadeUp">';
                        html += '   <div class="card-content" >';
                        html += '      <img src="/storage/img/fotos/comunicados/'+ element.foto + '" class="responsive-img" alt="">';
                        html += '      <div class="display-flex flex-wrap justify-content-center">';
                        html += '        <a href="javascript:{}" onclick="eliminarFoto('+ element.id + ')" class="waves-effect waves-dark btn btn-primary" href="#modal2"><i class="material-icons">delete</i></a>';
                        html += '       </div> ';
                        html += '   </div> ';
                        html += '</div> ';
                    });

                }
                $("#datosImg").html(html);
                $(".modal").modal('open');

            }).fail(function(data) {
                console.log("error")
            });

        });

        $(".btnmodalCerrar").click(function(e){
            e.preventDefault()
        });



        function eliminarFoto(id){
            console.log(id)
            Swal.fire({
                title: "¿Está seguro?",
                text: "Al oprimir el botón de aceptar se eliminará la foto",
                icon: 'warning',
                showCancelButton: true,
                confirmButtonColor: '#3085d6',
                cancelButtonColor: '#d33',
                confirmButtonText: 'Aceptar'
            }).then((result) => {

                if (result.isConfirmed) {
                    $.get("/mcg/delete/img/comunicado/" + id, function(data) {
                        if(data.status == 200){
                            $(".modal").modal('close');
                        }

                    }).fail(function(data) {
                        console.log("error")
                    });

                }
            })

        }

        $("#comunicado").on("blur", function(e){
            var numero =	$("#comunicado").val();
            console.log(numero);
            jQuery.ajax({
                url: "{{url('mcg/validaComunicado')}}",
                data:{numero},
                type: "GET",
                success:function(response){
                    var json = $.parseJSON(response);
                    if(json[0].existe == '1'){
                        Swal.fire({
                            title: "¡El numero de comunicado existe!",
                            icon: 'warning',
                            dangerMode: true,
                        });
                        document.getElementById('comunicado').value = ''
                    }
                },
                error:function (){}
            });
        });


    </script>
@endsection

OHA YOOOO