<!----- Modal Update Group -------->
{{Form::open(array('url'=>'/admin/update-group','method'=>'POST','id'=>'update_group_form','class'=>'form-horizontal'))}}
<!-- Form Name -->
<!-- Text input-->
<div class="control-group">
    <label class="control-label" for="textinput"> Group Image:</label>
    <img src="{{($group->image_path=='')?'http://placehold.it/600x350':$group->image_path}}" id="edit_img" class="img-responsive">
    {{Form::hidden('home_page_slider[]',($group->image_path=='')?'http://placehold.it/600x350':$group->image_path,array('id'=>'edit_name','name'=>'image_path'))}}
    <div class="clearfix">&nbsp;</div>
    <a class="btn btn-default btn-sm" id="loadMedia" href="javascript:void(0)" data-toggle="modal" data-target="#MediaLib"><i class="fa fa-image"></i> Change Image </a>
    <div class="clearfix">&nbsp;</div>
    <label class="control-label" for="textinput"> Quiz :</label>
    <div class="controls">
        {{Form::text('group_name',$group->group_name, array('id'=>'textinput','placeholder'=>'Group name','class'=>'form-control input-sm'))}}
        <h5>Quiz group active / inactive </h5>
        {{Form::checkbox('status',1,($group->status==1)?'checked':'')}} Checked to Active
    </div>
    <div class="controls">
        {{Form::checkbox('is_public',1,($group->is_public==1)?'checked':'')}}   Public
    </div>
</div>
<div class="clearfix">&nbsp;</div>
<div class="row">
    <div class="col-lg-3">
        <input type="hidden" name="group_id" value="{{$group->group_id}}">
    </div>
</div>
<div class="clearfix optn-rmv">&nbsp;</div>
<!-- Button -->
<div class="control-group text-right">
    <label class="control-label" for="singlebutton"></label>
    <div class="controls">
        <span class="update-loader"></span>
        {{Form::button('Close',array('class'=>'btn btn-default btn-sm','type'=>'reset', 'data-dismiss'=>'modal'))}}
        {{Form::button('Update group',array('class'=>'btn btn-info btn-sm','type'=>'button','name'=>'update_group','id'=>'update_group'))}}
    </div>
</div>
{{Form::close()}}
<!----- // End Modal Update Group -------->
<script>
    $('#update_group').click(function()
    {
        $('#update_group_form').submit();
        $('.update-loader').html('');
        $('.update-loader').removeClass('animated flash');

    });

    $('#update_group_form').submit(function(e)
    {
        $('.update-loader').html('<i class="fa fa-spinner fa-spin"></i>');
        var action = $(this).attr('action');
        var data = $(this).serializeArray();
        $.post(action, data, function(d) {
            if (d.success == 1) {
                $('.update-loader').html(d.msg);
                $('.update-loader').addClass('animated flash');
                /// Change html data by updated text
                var group_id = $('input[name="group_id"]').val();
                var html = '.id_' + group_id;
                $(html).removeClass('animated flash');
                $(html).addClass('animated flash');
                $(html).html($('#textinput').val());

            } else
            {
                $('.update-loader').html(d.msg);
            }
        });
        e.preventDefault(); // Prevent form default action
    });

    $('#loadMedia').click(function() {
        var btn = $(this);
        btn_content = btn.html();
        btn.html('<i class="fa fa-spinner fa-spin"></i>');
        $('.mediaLibBody').html('');
        $.ajax('/admin/load-ajax-media-files').done(function(obj) {
            if (obj.success == 1) {
                $('.mediaLibBody').html(obj.msg);
                btn.html(btn_content);
            } else
            {
                window.location.reload();
            }
            $('.add-img').on('click', function() {
                var img_url = $(this).attr('img');
                $('#edit_name').val(img_url);
                $('#edit_img').attr('src', img_url);
                $('#poll_img').removeClass('hide');
                $('#MediaLib .close').click();
            });
        });
    });
</script>
