<script src="<?= BASE_ASSET; ?>/js/jquery.hotkeys.js"></script>

<script type="text/javascript">
    //This page is a result of an autogenerated content made by running test.html with firefox.

    function domo() {
        // Binding keys
        $('*').bind('keydown', 'Ctrl+s', function assets() {
            $('#btn_save').trigger('click');
            return false;
        });

        $('*').bind('keydown', 'Ctrl+x', function assets() {
            $('#btn_cancel').trigger('click');
            return false;
        });

        $('*').bind('keydown', 'Ctrl+d', function assets() {
            $('.btn_save_back').trigger('click');
            return false;
        });

    }

    jQuery(document).ready(domo);
</script>

<!-- Content Header (Page header) -->
<section class="content-header">
    <h1>
      Menu Type
      <small>New Menu Type</small>
   </h1>
    <ol class="breadcrumb">
        <li><a href="#"><i class="fa fa-dashboard"></i> Home</a>
        </li>
        <li class=""><a href="<?= site_url('administrator/menu_type'); ?>">Menu Type</a>
        </li>
        <li class="active">New</li>
    </ol>
</section>
<!-- Main content -->
<section class="content">
    <div class="row">

        <div class="col-md-12">
            <div class="box box-warning">
                <div class="box-body ">
                    <!-- Widget: user widget style 1 -->
                    <div class="box box-widget widget-user-2">
                        <!-- Add the bg color to the header using any of the bg-* classes -->
                        <div class="widget-user-header ">
                            <div class="widget-user-image">
                                <img class="img-circle" src="<?= BASE_ASSET; ?>/img/add2.png" alt="Menu Type Avatar">
                            </div>
                            <!-- /.widget-menu_type-image -->
                            <h3 class="widget-user-username">Menu Type</h3>
                            <h5 class="widget-user-desc">New Menu Type</h5>
                            <hr>
                        </div>
                        <?=form_open( '', [ 'name'=> 'form_menu_type', 'class' => 'form-horizontal', 'id' => 'form_menu_type', 'method' => 'POST' ]); ?>
                            <div class="form-group ">
                                <label for="name" class="col-sm-2 control-label">Name <i class="required">*</i>
                                </label>
                                <div class="col-sm-8">
                                    <input type="text" class="form-control" name="name" id="name" placeholder="Name" value="<?= set_value('name'); ?>">
                                    <small class="info help-block">The name of menu type <i>alpha numeric, spaces</i>.</small>
                                </div>
                            </div>

                            <div class="form-group ">
                                <label for="definition" class="col-sm-2 control-label">Definition </label>
                                <div class="col-sm-8">
                                    <input type="text" class="form-control" name="definition" id="definition" placeholder="Definition" value="<?= set_value('definition'); ?>">
                                    <small class="info help-block">The definition of menu type.</small>
                                </div>
                            </div>
                            <div class="message">
                            </div>

                            <div class="row-fluid col-md-7">
                                <button class="btn btn-flat btn-primary btn_save btn_action" id="btn_save" data-stype='stay' title="save (Ctrl+s)"><i class="fa fa-save"></i> Save</button>
                                <a class="btn btn-flat btn-info btn_save btn_action btn_save_back" id="btn_save" data-stype='back' title="save and back to the list (Ctrl+d)"><i class="ion ion-ios-list-outline" ></i> Save and Go to The List</a>
                                <a class="btn btn-flat btn-default btn_action" id="btn_cancel" title="cancel (Ctrl+x)"><i class="fa fa-undo" ></i> Cancel</a>
                                <span class="loading loading-hide"><img src="<?= BASE_ASSET; ?>/img/loading-spin-primary.svg"> <i>Loading, Saving data</i></span>
                            </div>
                            <?=form_close(); ?>
                    </div>
                </div>
                <!--/box body -->
            </div>
            <!--/box -->
        </div>
    </div>
</section>
<!-- /.content -->

<script src="https://cdn.ckeditor.com/4.5.7/standard/ckeditor.js"></script>
<!-- Page script -->
<script>
    $(document).ready(function() {
     $('#btn_cancel').click(function() {
         swal({
                 title: "Are you sure?",
                 text: "the data that you have created will be in the exhaust!",
                 type: "warning",
                 showCancelButton: true,
                 confirmButtonColor: "#DD6B55",
                 confirmButtonText: "Yes!",
                 cancelButtonText: "No!",
                 closeOnConfirm: true,
                 closeOnCancel: true
             },
             function(isConfirm) {
                 if (isConfirm) {
                     window.location.href = HTTP_REFERER;
                 }
             });

         return false;
     }); /*end btn cancel*/
     $('.btn_save').click(function() {
         $('.message').fadeOut();
         var form_menu_type = $('#form_menu_type');
         var data_post = form_menu_type.serializeArray();
         var save_type = $(this).attr('data-stype');

         data_post.push({
             name: 'save_type',
             value: save_type
         });

         $('.loading').show();

         $.ajax({
                 url: BASE_URL + '/administrator/menu_type/add_save',
                 type: 'POST',
                 dataType: 'json',
                 data: data_post,
             })
             .done(function(res) {
                 if (res.success) {
                     var id = $('#menu_type_avatar_galery').find('li').attr('qq-file-id');

                     if (save_type == 'back') {
                         window.location.href = res.redirect
                         return;
                     }

                     $('.message').printMessage({
                         message: res.message
                     });

                     $('.message').fadeIn();

                     $('form input[type != hidden], form textarea, form select').val('');

                 } else {

                     $('.message').printMessage({
                         message: res.message,
                         type: 'warning'
                     });

                     $('.message').fadeIn();
                 }
             })
             .fail(function() {
                 $('.message').printMessage({
                     message: 'Gagal menyimpan data',
                     type: 'warning'
                 });

             })
             .always(function() {
                 $('.loading').hide();
                 $('html, body').animate({
                     scrollTop: $(document).height()
                 }, 1000);
             });
         return false;

     }); /*end btn save*/
 }); /*end doc ready*/
</script>