@extends('layouts.master')

@section('content')
<div class="content">
    <div class="row" style="min-height: 500px">
        
        <div class="col-md-8 col-md-offset-2">
            <header class="panel-heading" style="height:50px;">
                <div class="pull-left">
                    {{$title}}
                </div>
                <div>
                     @if(\Auth::user()->utype==1)
                        <a href="{{ url('admin/grade') }}" class="btn btn-sm btn-info pull-right"><i class="fa fa-list"></i> Grade List</a> <br><br>
                    @endif
                </div>
            </header>
        </div>
        <div class="col-md-8 col-md-offset-2">
            <div class="panel panel-default">
                <div class="panel-body">                    
                    {{-- action="{{ url('admin/grade/store') }}" enctype="multipart/form-data" method="POST" role="form" --}}
                    <form>
                    {{ csrf_field() }}
                    <div class="col-md-10 col-md-offset-1">
                        <div class="alert alert-danger print-error-msg" style="display:none">
                            <ul></ul>
                        </div>
                        <div class="form-group {{ $errors->has('name') ? 'has-error' : '' }}">
                            <label for="name">Grade Name <i class="text-danger">*</i></label>
                            <input type='text' name="name" id="name" class="form-control" value="{{ old('name') }}" placeholder="Grade Name">
                            <lebel class="text-danger"> {{ $errors->first('name') }}</lebel>
                        </div>
                    </div>
                    <div class="col-md-10 col-md-offset-1" style="margin-top: 30px;">
                        <a href="{{ url('admin/grade') }}" class="btn btn-default pull-left">
                            <span class="btn-icon"> 
                                <i class="fa fa-times"></i>
                            </span>
                            Cancel
                        </a>
                        <span class="btn btn-inline btn-success pull-right btn-submit">
                            <span class="btn-icon"> 
                                <i class="fa fa-save"></i>
                            </span>
                            Submit
                        </span>
                    </div>
                </div>
            </div>
        </div>

        </form>
    </div>
</div>
@stop


@section('script')
@if(Session::has('msg'))
    <div class="alert alert-success center-block msg_alt" >
        <a class="close" data-dismiss="alert" href="#">&times;</a>
        <strong><i class="fa fa-check"></i></strong>&nbsp;
    {{Session::get('msg')}}
    </div>
@endif
<script type="text/javascript">
    $(document).ready(function() {
        $(".btn-submit").click(function(e){
            e.preventDefault();


            var _token = $("input[name='_token']").val();
            var name = $("input[name='name']").val();


            $.ajax({
                url: "/admin/grade/store",
                type:'POST',
                data: {_token:_token, name:name},
                success: function(data) {
                    if($.isEmptyObject(data.error)){
                        location.href = "/admin/grade";
                    }else{
                        printErrorMsg(data.error);
                    }
                }
            });


        }); 


        function printErrorMsg (msg) {
            $(".print-error-msg").find("ul").html('');
            $(".print-error-msg").css('display','block');
            $.each( msg, function( key, value ) {
                $(".print-error-msg").find("ul").append('<ol>'+value+'</ol>');
            });
        }
    });
</script>

@stop