<h3>Otros: Consultas</h3>
<br>
<form method="POST" action="{{ URL::to('/') }}/forms/store/other" accept-charset="UTF-8" >
    <input type="hidden" name="_token" value="{{ csrf_token() }}">

    <input type="hidden" name="type" value="email">

    <h4><i class="fa fa-pencil-square-o" aria-hidden="true"></i> &nbsp;Seleccionar Perfil</h4>

    <hr>

    @include('task.forms.shared.profile-select-create')

    <hr>
    <br>
    <br>
    <br>
    <h4><i class="fa fa-pencil-square-o" aria-hidden="true"></i> &nbsp;Datos de la consulta</h4>

    <hr>

    <div class="col-md-12"><h4></h4>

        <div class="form-group">
            <label for="" >Título</label><br>
            <input type="text" name="title" value="{{ old('title') }}" class="form-control">
        </div>
        <div class="form-group">

            <label for="description" class="control-label">Descripción</label>
            <p id="" style="font-size:12px;color:#969696;" class="help-block">Campo de texto para asiento de cambios y opción de carga de archivos.</p>

            <textarea class="form-control summer_other_create" name="description" cols="50" rows="10"
                      id="description">{{ old('description') }}</textarea>

        </div>

        {{--<div class="form-group">--}}

            {{--<label for="other_deadline" class="control-label">Deadline:</label>--}}
            {{--<input class="form-control" name="other_deadline" type="text" id="deadline" value="{{ old('other_deadline') }}">--}}
        {{--</div>--}}

        <div class="form-group">
            <label for="adjuntos" class="control-label">Adjuntos:</label><br>
            <div class="task_text_borrador"></div>
        <div class="task_temporal_progress">
            <progress class="barProgress_task" max="100" value="0" style="display: none;margin-bottom: 6px"><span id="textProgress_task">22</span></progress>
            <ul id="file-upload-progress_task">
            </ul>
            <ul id="file-upload-list" class="list-unstyled file-upload-list_task" data-type="task" >
            </ul>
        </div>
            <input type="hidden" name ="_token" value ="{{ csrf_token() }}" />
            <input type="hidden" name="jsonIdAttachments" id="jsonIdAttachments_task" value='<?php echo !empty(old("jsonIdAttachments"))?old("jsonIdAttachments"):""; ?>' >

            <span class="btn btn-success fileinput-button">
                <i class="icon-plus icon-white"></i>
                <span>Subir Archivos</span>
                <input id="fileupload" class="fileupload" data-type="task" multiple type="file" name="file" data-url="{{ url('upload') }}" style="display: inline;">
            </span>

        </div>
        <hr>

        <div class="form-group">  <!-- Terms Checkbox !-->
            <div class="checkbox">
                <label>
                    <input type="checkbox" class="draft" name="draft" {{ old('draft') == '1' ? 'checked="checked"' : '' }}> Guardar como borrador
                </label>
                <p id="" style="font-size:12px;color:#969696;" class="">Si envía el formulario con este campo
                    tildado, el contenido del formulario se guardará pero no será enviado para su procesamiento.</p>

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

    <hr>

    <input type="button" class="form-control"  value="Enviar" onclick="form.submit()">

</form>
<style>/*
    .subattach:last-child{

        margin-bottom: 20px;
        
    }*/
    .bdn{
        color: #979797;
        height: 20px;
        font-size: 14px;
    /*  margin-bottom: 10px */
    }
    .stack_deleted{

        position: absolute !important;
        margin-left: 20px;
        line-height: 8px;
        height: 14px;
        font-size: 11px;
        width: 14px;
        padding-left: 3px;

    }
    .sub_enseptiembre{
        margin-bottom: 2px;
    }

    .subattachtask_element:first-child {
    margin-top: 6px;
    }

    .datin{
            margin-left: 6px;
            font-size: 14px;
            font-style: inherit;
            color: #979797;
            opacity: 0.7;
    }

</style>

<script>




    $(document).ready(function(){



    <?php if(!empty(old('jsonIdAttachments'))){ ?>

        //    console.log("aaaaaaaaaad");


            $.ajax({
                data:{attachid:<?php echo !empty(old('jsonIdAttachments'))?old('jsonIdAttachments'):""; ?> },
                url:"{{ URL::to('/') }}/tasks/getoldattach",
                type: "post",
                dataType: "json",
                headers: {
                    'X-CSRF-TOKEN': $('meta[name="csrf-token"]').attr('content')
                },
                success: function(result) {
                   
                //   console.log(result);

                $.each(result.data, function (index, value) {


                    var d = new Date(value.created_at); 
                    // var f = new Date(from[2], from[1] - 1, from[0]);

                    datt = d.getDate()+"/"+(parseInt(d.getMonth())+1)+"/"+d.getFullYear();


                    element = '<div data-fileatta="'+value.filename+'" data-dateatta="'+datt+'" data-nameatta="'+value.original_name+'" class="bdn subattachtask_element suboption_subattachtask_'+value.id+' subattachtask_'+value.id+'"><a href="{{ URL::to('/') }}/uploads/'+value.filename+'" target="_blank" style="font-size:11px" >'+value.original_name+'<span class="minidatetask_'+value.id+'" style="margin-left: 6px;font-size: 11px;font-style: inherit;">'+datt+'</span></a><button type="button" onclick="deleteAttach('+value.id+')" class="btn btn-danger btn-xs stack_deleted elementTheTask">x</button></div>';

                    $(".task_text_borrador").before(element);

                    });
                }
            });
        <?php } ?>


    });




    function deleteAttach(id_item){

        

        swal({
          title: 'Confirmar',
          text: "Estas seguro de eliminar el archivo?",
          type: 'warning',
          showCancelButton: true,
          confirmButtonColor: '#d33',
          cancelButtonColor: '#3085d6',
          confirmButtonText: 'Eliminar'
        }).then((result) => {
          if (result.value) {


                tt = JSON.parse($("#jsonIdAttachments_task").val());

                tt.forEach( function(valor, indice, array) {

                    if(valor.id==id_item){

                        tt.splice(indice, 1);

                    }
                 });


                jsonObj_task.forEach( function(valor, indice, array) {

                        if(valor.id==id_item){

                            jsonObj_task.splice(indice, 1);

                        }
                });


                $("#jsonIdAttachments_task").val(JSON.stringify(tt));


                $(".subattachtask_"+id_item).remove();

                if($(".elementTheTask").length==0){

                    $(".nuevo_div").css("height","38px");
                    $("#buttonDownload").hide();

                }




          }
        })


        $(".swal2-confirm").attr("class","btn btn-danger swal2-confirm");
    //  $("swal2-popup").css("width","400px");
        $(".swal2-cancel").css("margin-left","6px");
        $(".swal2-cancel").attr("class","btn btn-primary swal2-cancel");
        $(".swal2-warning").css("width","66px");
        $(".swal2-warning").css("height","66px");
        $(".swal2-icon.swal2-warning").css("line-height","70px");

    }

</script>    
