@extends('adminlte::page')
@section('content_header')
    <h1>Action</h1>
@stop
<script src="//code.jquery.com/jquery.js"></script>
@section('content')
@notifyCss
@notifyJs
@if ($errors->any())
    <div class="alert alert-danger">
        <ul>
            @foreach ($errors->all() as $error)
                <li>{{ $error }}</li>
            @endforeach
        </ul>
    </div>
@endif
@if (session('status'))
    <div class="alert alert-success">
        {{ session('status') }}
    </div>
@endif
@include('notify::messages')
<div class="row">
    <!--row starts-->
    <div class="col-md-12">           
        <div class="panel panel-primary">
            <div class="panel-heading">
                <h3 class="panel-title">
                   Action
                </h3>
            </div>
            <div class="panel-body">
                <form class="form-horizontal" action="{{ url('actionpost') }}" method="post" id="action" onsubmit="return validation();">
                    <!-- CSRF Token -->
                    <input type="hidden" name="_token" value="{{csrf_token()}}">
                    <!-- Name input-->
                    <div class="form-group">
                        <label class="col-md-3 control-label" for="name">Action<span style="color: red;">*</span></label>
                        <div class="col-md-6">
                            <input id="actions" name="actions" type="text" placeholder="Enter the action here..." class="form-control" required>
                        </div>
                    </div>
                    <div class="form-group">
                        <label class="col-md-3 control-label" for="remarks">Description<span style="color: red;">*</span></label>
                        <div class="col-md-6">
                            <textarea class="form-control resize_vertical" id="description" name="description" placeholder="Please enter your description here..." rows="5" required></textarea>
                        </div>
                    </div>
                    <!-- Form actions -->
                    <div class="form-position">
                        <div class="col-md-5 text-right">
                            <button type="submit" class="btn btn-responsive btn-primary btn-sm" id="btn" >Submit</button>
                        </div>
                    </div>
                </form>
            </div>
        </div>
        <div class="panel panel-body">     
            <table class="table table-bordered" id="action_table">
                <thead>
                    <tr>
                        <th>Id</th>
                        <th>Action</th>
                        <th>Description</th>
                        <th>Updated At</th>
                        <th>Actions</th>
                    </tr>
                </thead>
            </table>
        </div>
    </div>
    <!--md-12 ends-->
</div>
<script>
$(function() {

    $('#action_table').DataTable({
        processing: true,
        serverSide: true,
        ajax: '{!! url('actionpostdata') !!}',
        columns: [
            { data: 'id', name: 'id' },
            { data: 'actions', name: 'actions' },
            { data: 'description', name: 'description' },
            { data: 'updated_at', name: 'updated_at' },
            { data: 'action', name: 'action' }
        ]
    });
});

function validation()
{
    if(document.getElementById('actions').value=="")
    {
        alert(" Please enter the Actions");
        document.getElementById('actions').focus();
        return false;
    }
    if(document.getElementById('description').value=="")
    {
        alert(" Please enter the Description");
        document.getElementById('description').focus();
        return false;
    }
    document.getElementById("btn").disabled='true';
    return true;
}
</script>                   
@stop