<?php include_once PUBLIC_PATH. '/files_to_include/header_content.php'; ?>
<div class="main-content-wrap sidenav-open d-flex flex-column">
            <!-- ============ Body content start ============= -->
            <div class="main-content">
                <div class="breadcrumb">
                    <h1>Creating roles</h1>
                </div>
                <div class="breadcrumb">
                    
                    <ul>
                        <li><a href="<?php echo $this->url(array('controller'=>'Role','action'=>'index'),null, true);?>">Back to list</a></li>
                        
                    </ul>
                </div>
             
                <div class="table-responsive">
               <form role="form" id="form" method='post' action='' class="col-lg-12">
                   <div class="row"> 
                       <div class="col-sm-2"></div> 
                    <div class="col-sm-4">  
                        <div class="form-group">
                            <label for="label">Role Name:</label><label style=" color : Red;">&nbsp; *&nbsp; </label>
                            <input type="text" class="form-control" id="label" name="label" placeholder="Nom " value="" required>
                        </div>                            
                    </div>
                    <div class="col-sm-4">  
                        <div class="form-group">
                            <label for="name">Role description:</label><label style=" color : Red;">&nbsp; *&nbsp; </label>
                            <input type="text" class="form-control" id="description" name="description" placeholder="Description " value="" required>
                        </div>                            
                    </div>
                        <div class="col-sm-2"></div> 
                    &nbsp; 
                </div>  
            
                   <div>
        
                           <div id="transfer3" class="transfer-demo"></div>
                  </div>
                                 
               
                <hr> 
                <div class="row">
                    <div class="col-sm-2"></div>
                     <div class="col-sm-6">
                         <button type="button" id="submission" name="submit" class="btn btn-info m-1">CREATE ROLE </button>
                </div> 
                <div class="col-sm-2">
                    <button type="reset" id="resetBtn" name="reset" class="btn btn-warning m-1">RESET </button>
                </div>
                    <div class="col-sm-2"></div>
                </div>
                
                <br>
                <div class="clearfix"></div>
            </form>
                           </div>
            </div><!-- Footer Start -->
            <div class="flex-grow-1"></div>
            <div class="app-footer">
                <div class="footer-bottom border-top pt-3 d-flex flex-column flex-sm-row align-items-center">
                    <span class="flex-grow-1"></span>
                    <div class="d-flex align-items-center">
                        <img class="logo" src="<?php echo $this->baseUrl('images/logo.png');?>" alt="">
                        <div>
                            <p class="m-0">&copy; 2021 ASLM</p>
                            <p class="m-0">All rights reserved</p>
                        </div>
                    </div>
                </div>
            </div>
            <!-- fotter end -->
        </div>
    </div><!-- ============ Search UI Start ============= -->
    
    <!-- ============ Search UI End ============= -->
    <script src="<?php echo $this->baseUrl('js/plugins/jquery-3.3.1.min.js');?>"></script>
     <script src="<?php echo $this->baseUrl('js/plugins/bootstrap.bundle.min.js');?>"></script>
    <script src="<?php echo $this->baseUrl('js/plugins/perfect-scrollbar.min.js');?>"></script>
    <script src="<?php echo $this->baseUrl('js/scripts/script.min.js');?>"></script>
    <script src="<?php echo $this->baseUrl('js/scripts/sidebar.large.script.min.js');?>"></script>
    <script src="<?php echo $this->baseUrl('js/plugins/datatables.min.js');?>"></script>
    <script src="<?php echo $this->baseUrl('js/plugins/loadingoverlay.min.js');?>"></script>
    <script src="<?php echo $this->baseUrl('script/jquery.toast.min.js');?>"></script> 
     <script src="<?php echo $this->baseUrl('script/jquery.transfer.js?v=0.0.6');?>"></script>
    
   <script type="text/javascript">
        
        $(document).ajaxSend(function(event, jqxhr, settings){
            $.LoadingOverlay("show");
        });
        
        $(document).ajaxComplete(function(event, jqxhr, settings){
            $.LoadingOverlay("hide");
        });
   listAuth = [];
   function getAuths() {
        var params = {parent: "level"};
        $.ajax({
            url: "<?php echo $this->url(array('controller' => 'Role', 'action' => 'findauth')); ?>",
            dataType: "json",
            type: "POST",
            data: params,
            beforeSend: function () {
                //$("#inputParent").LoadingOverlay("show");
            },
            success: function (response) {
                
               var settings = {
                    dataArray: response,
                    callable: function (items) {
                        listAuth = items;
                        console.log(listAuth);
                 }
                };

        $("#transfer3").transfer(settings);
            },
            complete: function () {
               
            },
            error: function () {

            }
        });

    }
    
    getAuths();
    
    
            $("#submission").click(function(e) {
                e.preventDefault();
                //$("#submission").hide();
                params = {label: $("#label").val(), description: $("#description").val(), listAuth: listAuth}
                
                console.log(params);
                $.ajax({
                    url: "<?php echo $this->url(array('controller' => 'Role', 'action' => 'enregistrer')); ?>",
                    data: params, // {name: name, tableauIdL: tableauIdL, tableauIdE: tableauIdE},
                    cache: false,
                    method: "POST",
                    dataType: "json",
                    error: function(request, error) { 
                    },
                    success: function(data) {
                        // Informe l'utilisateur que l'opération est terminée et renvoie le résultat
                       //$("#submission").show("slow");
                       // var top = $("#submission").offset().top;
                        //var left = $("#submission").offset().left;
                         
                        if (data.type == "error") {
                           $.toast({
                               heading : "statut",
                               text : data.msg,
                               hideAfter : false,
                               stack: false,
                               icon : "error",
                           });
                            
                            
                        } else {
                           $.toast({
                               heading : "statut",
                               text : data.msg,
                               hideAfter : false,
                               stack : false,
                               icon : "success",
                           });
                           $("#resetBtn").trigger("click");
                            //window.location.replace("<?php // echo $this->url(array('controller' => 'Utilisateur', 'action' => 'index')); ?>");
                        }
                    },
                    complete: function() { // Info Debuggage si erreur         
                        //$("#loadueclass").removeClass("fa fa-spinner fa-spin");
                    }
                });
                //---
                return false;
            });
            
            $(".checkall").on("click", function() {
            var $allCheck = $(".checkin[concerne='" + $(this).attr("concerne") + "']");
            for (var i = 0; i < $allCheck.length; i++) {
                if ($(this).prop('checked')) {
                    $allCheck.eq(i).prop('checked', true);
                } else {
                    $allCheck.eq(i).prop('checked', false);
                }
            }
            });
            
           
	</script>
</body>

</html>