<?php $this->load->view('admin/comman/header');?>

<div class="clearfix"></div>
<div class="content-wrapper">
    <div class="container-fluid">
        <!-- Breadcrumb-->
        <div class="row pt-2 pb-2">
            <div class="col-sm-9">
                <h4 class="page-title">User Edit</h4>
                <ol class="breadcrumb">
                    <li class="breadcrumb-item"><a href="javascript:void(0)">Dashboard</a></li>
                    <li class="breadcrumb-item active" aria-current="page">Page</li>
                </ol>
            </div>

        </div>

        <div class="row">
            <div class="container-fluid">
                <div class="row">
                    <div class="col-lg-12 mx-auto">
                        <div class="card">
                            <div class="card-body">

                 
                                <form id="edit_page_form" enctype="multipart/form-data">

                                    <div class="row col-lg-12">
                                        <div class="form-group  col-sm-12 ">
                                            <label for="Address"> Title </label>
                                            <input type="text" value="<?php echo $page->title; ?>" class="form-control"
                                                name="title" id="title">
                                        </div>
                                    </div>
                                    <div class="row col-lg-12">
                                        <div class=" form-group  col-sm-12 ">
                                            <label for="bio"> Description </label>
                                            <textarea type="text" class="form-control summernote" name="description"
                                                id="description"><?php echo $page->description; ?></textarea>
                                        </div>
                                    </div>
                                    <input type="hidden" name="id" value="<?php echo $page->id; ?>">

                                    <div class="row col-lg-12">
                                        <div class="form-group  col-sm-12 ">
                                            <button type="button" onclick="updatepage()"
                                                class="btn btn-primary shadow-primary px-5">Save</button>
                                        </div>
                                    </div>

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

        <?php
			$this->load->view('admin/comman/footerpage');
			?>
        <script type="text/javascript">
        function updatepage() {

            displayLoader();
            var formData = new FormData($("#edit_page_form")[0]);

            var textareaValue = $('#description').code();
            formData.append("description", textareaValue);


            $.ajax({
                type: 'POST',
                url: '<?php echo base_url(); ?>admin/page/update',
                data: formData,
                cache: false,
                contentType: false,
                processData: false,
                dataType: "json",
                success: function(resp) {
                    hideLoader();
                    if (resp.status == '200') {
                        document.getElementById("edit_page_form").reset();
                        toastr.success(resp.message, 'success');
                        setTimeout(function() {
                            window.location.replace(
                                '<?php echo base_url(); ?>admin/page'
                            );
                        }, 500);
                    } else {
                        var obj = resp.message;
                        $.each(obj, function(i, e) {
                            toastr.error(e);
                        });
                    }
                },
                error: function(XMLHttpRequest, textStatus, errorThrown) {
                    hideLoader();
                    toastr.error(errorThrown.msg, 'failed');
                }
            });
        }
        </script>