<?php $__env->startSection('footer_js'); ?>

    <script type="text/javascript">
        $(document).ready(function () {
            $('#sidebar li').removeClass('active');
            $('#sidebar a').removeClass('active');
            $('#sidebar').find('#contents').addClass('active');
            $('#sidebar').find('#page').addClass('active');

            $('.date-picker').datepicker({format: 'yyyy-mm-dd'});

            $('.delete-attachment').click(function (e) {
                e.preventDefault();
                $object = $(this);
                var id = $object.attr('id');
                swal({
                    title: 'Are you sure?',
                    text: "You are going to remove the attachment!",
                    type: 'warning',
                    showCancelButton: true,
                    confirmButtonColor: '#3085d6',
                    cancelButtonColor: '#d33',
                    confirmButtonText: 'Yes, remove it!'
                }).then(function () {
                    $.ajax({
                        type: "PUT",
                        url: "<?php echo e(url('/admin/content/page/remove/attachment/')); ?>",
                        data: {id: id},
                        dataType: 'json',
                        success: function (response) {
                            $object.parent('span').hide();
                            $object.closest('.fileupload').find('.thumbnail > img').attr('src', "<?php echo e(asset('uploads/noimage.jpg')); ?>");
                            swal("Deleted!", response.message, "success");
                        },
                        error: function (e) {
                            swal('Oops...', 'Something went wrong!', 'error');
                        }
                    });
                });
            });

            $('.delete-thumbnail').click(function (e) {
                e.preventDefault();
                $object = $(this);
                var id = $object.attr('id');
                swal({
                    title: 'Are you sure?',
                    text: "You are going to remove the attachment!",
                    type: 'warning',
                    showCancelButton: true,
                    confirmButtonColor: '#3085d6',
                    cancelButtonColor: '#d33',
                    confirmButtonText: 'Yes, remove it!'
                }).then(function () {
                    $.ajax({
                        type: "PUT",
                        url: "<?php echo e(url('/admin/content/page/remove/thumbnail/')); ?>",
                        data: {id: id},
                        dataType: 'json',
                        success: function (response) {
                            $object.parent('span').hide();
                            $object.closest('.fileupload').find('.thumbnail > img').attr('src', "<?php echo e(asset('uploads/noimage.jpg')); ?>");
                            swal("Deleted!", response.message, "success");
                        },
                        error: function (e) {
                            swal('Oops...', 'Something went wrong!', 'error');
                        }
                    });
                });
            });

            $('#pageEditForm').formValidation({
                framework: 'bootstrap',
                excluded: ':disabled',
                icon: {
                    valid: 'glyphicon glyphicon-ok',
                    invalid: 'glyphicon glyphicon-remove',
                    validating: 'glyphicon glyphicon-refresh'
                },
                fields: {
                    attachment: {
                        validators: {
                            file: {
                                extension: 'jpg,jpeg,png',
                                maxSize: 10485760,   // 1 * 1024 * 1024
                                message: 'The selected file is not valid or file size greater than 10 MB.'
                            }
                        }
                    },
                    thumbnail: {
                        validators: {
                            file: {
                                extension: 'jpg,jpeg,png',
                                maxSize: 10485760,   // 1 * 1024 * 1024
                                message: 'The selected file is not valid or file size greater than 10 MB.'
                            }
                        }
                    },
                    heading: {
                        validators: {
                            notEmpty: {
                                message: 'This field is required.'
                            }
                        }
                    },
                    title: {
                        validators: {
                            notEmpty: {
                                message: 'This field is required.'
                            }
                        }
                    },
                    description: {
                        validators: {
                            notEmpty: {
                                message: 'This field is required.'
                            }
                        }
                    },
                }
            }).on('blur', '[name="heading"]', function (e) {
                $('#pageEditForm').formValidation('revalidateField', 'heading');
                $('#pageEditForm').formValidation('revalidateField', 'title');
                $('#pageEditForm').formValidation('revalidateField', 'description');
            }).find('[name="description"]')
                .each(function () {
                    $(this)
                        .ckeditor()
                        .editor
                        .on('change', function (e) {
                            $('#pageEditForm').formValidation('revalidateField', e.sender.name);
                        });
                });
        });
    </script>
<?php $__env->stopSection(); ?>
<?php $__env->startSection('dynamicdata'); ?>

    <div class="row">
        <div class="col-md-12">

            <div data-collapsed="0" class="panel">
                <header class="panel-heading">
                    Edit Page
                </header>

                <div class="panel-body">

                    <?php echo $__env->make('layout.backend.alert', array_except(get_defined_vars(), array('__data', '__path')))->render(); ?>

                    <form id="pageEditForm" action="<?php echo e(route('admin.content.page.update', $page->id)); ?>"
                          method="post" enctype="multipart/form-data">

                        <div class="form-group col-md-6 col-xs-11">
                            <label for="">Parent *</label>
                            <select name="parent_id" class="form-control">
                                <option value="0">Parent Itself</option>
                                <?php foreach($parents as $parent): ?>
                                    <option value="<?php echo $parent->id; ?>"
                                            <?php if($parent->id == $page->parent_id): ?> selected="selected" <?php endif; ?>><?php echo $parent->heading; ?></option>
                                <?php endforeach; ?>
                            </select>
                        </div>
                        <div class="clearfix"></div>


                        <div class="form-group col-md-6 col-xs-11">
                            <label for="moduleSlug">Heading *</label>
                            <input type="text" name="heading"
                                   class="form-control heading"
                                   value="<?php echo $page->heading; ?>"
                                   placeholder="Enter Heading"/>
                        </div>
                        <div class="form-group col-md-6 col-xs-11">
                            <label for="moduleSlug">Page Title *</label>
                            <input type="text" name="title"
                                   class="form-control title"
                                   value="<?php echo $page->title; ?>"
                                   placeholder="Enter Title"/>
                        </div>
                        <div class="form-group col-md-12 col-xs-11">
                            <label for="moduleSlug">Meta Tags</label>
                            <input type="text" name="meta_tags"
                                   class="form-control meta_tags"
                                   value="<?php echo $page->meta_tags; ?>"
                                   placeholder="Enter Meta Tags"/>
                        </div>
                        <div class="form-group col-md-12 col-xs-11">
                            <label for="moduleSlug">Meta Description</label>
                            <input type="text" name="meta_description"
                                   class="form-control meta_description"
                                   value="<?php echo $page->meta_description; ?>"
                                   placeholder="Enter Meta Description"/>
                        </div>
                        <div class="form-group col-md-12 col-xs-11">
                            <label for="moduleSlug">Short Description</label>
                            <input type="text" name="short_description"
                                   class="form-control short_description"
                                   value="<?php echo $page->short_description; ?>"
                                   placeholder="Enter Short Description"/>
                        </div>
                        <div class="form-group col-md-12 col-xs-11">
                            <label for="moduleSlug">Description</label>
                            <textarea class="form-control" name="description"
                                      rows="6"><?php echo $page->description; ?></textarea>
                        </div>

                        <div class="form-group col-md-6 col-xs-11">
                            <label for="">Show In</label>
                            <?php /**/ $prevArray = explode(',', $page->show_in) /**/ ?>
                            <?php foreach($show_in as $key=>$value): ?>
                                <input type="checkbox" name="show_in[]" value="<?php echo $key; ?>"
                                       <?php if(in_array($key, $prevArray)): ?> checked="checked" <?php endif; ?>>
                                <?php echo $value; ?>

                            <?php endforeach; ?>
                        </div>
                        <div class="clearfix"></div>

                        <div class="form-group col-md-6 col-xs-11">
                            <label for="">Status</label>
                            <select name="is_active" class="form-control">
                                <option value="0" <?php echo ($page->is_active == '0')? 'selected="selected"' : ''; ?> >
                                    Unpublished
                                </option>
                                <option value="1" <?php echo ($page->is_active == '1' || $page->is_active == '')? 'selected="selected"' : ''; ?> >
                                    Published
                                </option>
                            </select>
                        </div>
                        <div class="clearfix"></div>

                        <div class="form-group col-md-6 col-xs-11">
                            <label for="attachment">Attachment</label>

                            <div class="fileupload fileupload-new" data-provides="fileupload">
                                <div class="fileupload-new thumbnail" style="width: 200px; height: 150px;">
                                    <?php if(file_exists('uploads/pages/'.$page->attachment) && $page->attachment!=''): ?>
                                        <img src="<?php echo e(asset('uploads/pages/'.$page->attachment)); ?>" alt="">
                                    <?php else: ?>
                                        <img src="<?php echo e(asset('uploads/noimage.jpg')); ?>" alt="">
                                    <?php endif; ?>
                                </div>
                                <div class="fileupload-preview fileupload-exists "
                                     style="max-width: 200px; max-height: 150px; line-height: 20px;"></div>
                                <div>
                                    <span class="btn btn-white btn-file">
                                        <span class="fileupload-new"><i class="fa fa-paper-clip"></i> Select image</span>
                                        <span class="fileupload-exists"><i class="fa fa-undo"></i> Change</span>
                                        <input type="file" name="attachment" class="default"/>
                                    </span>
                                    <?php if(file_exists('uploads/pages/'.$page->attachment) && $page->attachment!=''): ?>
                                        <span class=""><i class="fa fa-undo"></i>
                                            <a href="javascript:void(0)" class="delete-attachment" id="<?php echo e($page->id); ?>">Delete
                                            Attachment</a>
                                        </span>
                                    <?php endif; ?>
                                </div>

                            </div>
                            <span class="label label-danger">NOTE!</span>
                            <span>Valid file extensions are jpg,jpeg and png.</span>

                        </div>

                        <div class="form-group col-md-6 col-xs-11">
                            <label for="attachment">Thumbnail</label>

                            <div class="fileupload fileupload-new" data-provides="fileupload">
                                <div class="fileupload-new thumbnail" style="width: 200px; height: 150px;">
                                    <?php if(file_exists('uploads/pages/'.$page->thumbnail) && $page->thumbnail!=''): ?>
                                        <img src="<?php echo e(asset('uploads/pages/'.$page->thumbnail)); ?>" alt="">
                                    <?php else: ?>
                                        <img src="<?php echo e(asset('uploads/noimage.jpg')); ?>" alt="">
                                    <?php endif; ?>
                                </div>
                                <div class="fileupload-preview fileupload-exists thumbnail"
                                     style="max-width: 200px; max-height: 150px; line-height: 20px;"></div>
                                <div>
                                    <span class="btn btn-white btn-file">
                                        <span class="fileupload-new"><i class="fa fa-paper-clip"> </i> Select thumbnail / icon image</span>
                                        <span class="fileupload-exists"><i class="fa fa-undo"> </i> Change</span>
                                        <input type="file" name="thumbnail" class="default"/>
                                    </span>
                                    <?php if(file_exists('uploads/pages/'.$page->thumbnail) && $page->thumbnail!=''): ?>
                                        <span class=""><i class="fa fa-undo"></i>
                                            <a href="javascript:void(0)" class="delete-thumbnail" id="<?php echo e($page->id); ?>">Delete
                                            Thumbnail</a>
                                        </span>
                                    <?php endif; ?>
                                </div>

                            </div>
                            <span class="label label-danger">NOTE!</span>
                            <span>Valid file extensions are jpg,jpeg and png.</span>

                        </div>
                        <div class="clearfix"></div>

                        <?php echo csrf_field(); ?>

                        <button type="submit" class="btn btn-info">Submit</button>
                        <input type="hidden" name="_method" value="PUT"/>
                    </form>

                </div>

            </div>

        </div>
    </div>
<?php $__env->stopSection(); ?>

<?php echo $__env->make('layout.backend.containerform', array_except(get_defined_vars(), array('__data', '__path')))->render(); ?>