<?php  include('techsyn_header.php'); ?>    
<!-- Main Content Container for side bar and body-->
<div class="main-container ace-save-state" id="main-container">
		<script type="text/javascript">
			try{ace.settings.loadState('main-container')}catch(e){}
		</script>
<?php  include('techsyn_sidebar.php'); ?>    

<!--breadcrumb-->
<div class="main-content">
    <div class="main-content-inner">
        <div class="breadcrumbs ace-save-state" id="breadcrumbs">
            <ul class="breadcrumb">
              
                <li class="#">Data Setup</li><li class="#">User Management</li><li class="active">Roles</li>
            </ul>
        </div>
        <!-- End of breadcrumb -->
            <div class="page-content">
        	<div id="flexigridDiv" class="table-responsive">
			<div>
			
				<form name="f1" method="post" action=""id="flex_form_role">
					<div id="flex1" style="width:100%">
					</div>
					<input type="hidden" name="role_id" id="flex_role_id"/>
				</form>	
			</div>
			</div>
			</div>



    </div><!-- /.page-content -->
</div>
</div><!-- /.main-content -->

                    


<script type="text/javascript">
    $(function () {
    	var w=screen.width*.90;

       	var h =0;
           	 h =(window.innerHeight-($("#navbar").height()+$(".breadcrumbs").height()))*.75;
        $("#flex1").flexigrid({
            url: 'role_list_script.php',
            dataType: 'json',
            colModel: [
                {display: 'Sr', name: 'count', width: w*.04, sortable: false, align: 'left'},
                {display: 'Role ID', name: 'role_id', width: w*.06, sortable: true, align: 'left'},
                {display: 'Role', name: 'role_name', width: w*.15, sortable: true, align: 'left'},
				{display: 'Role Code', name : 'role_code', width : w*.08, sortable : true, align: 'left'},
                {display: 'Role Description', name: 'role_description', width: w*.15, sortable: true, align: 'left'},
				{display: 'Role Home Page', name: 'role_home_page', width: w*.15, sortable: true, align: 'left'},
				{display: 'Icon Colour', name: 'icon_color', width: w*.08, sortable: true, align: 'left'},
				{display: 'Icon Text', name: 'icon_text', width: w*.08, sortable: true, align: 'left'},
				{display: '', name: '', width: w*.14, sortable: false, align: 'left'},
               
            ],
            buttons: [
               
               {name: 'Add', bclass: 'add', onpress : add},
			   {separator: true},
			   {name: 'PDF', bclass: 'print', onpress : pdf},
			   {separator: true},
			   {name: 'Excel', bclass: 'print_excel', onpress : excel},
               {separator: true}
            ],
            searchitems: [
                {display: 'Role ID', name: 'role_id'},
                {display: 'Role', name: 'role_name', isdefault: true},
				
                {display: 'Role Description', name: 'role_description'}
            ],
            sortname: "role_id",
            sortorder: "asc",
            usepager: true, //pagination

            useRp: true,
            rp: 25, //records per page
            showTableToggleBtn: false, //toggle button for the whole table
            resizable: true,
            //width: w,
            height: h,
            singleSelect: true
        });
    });

   
function pdf(){
	window.open('pdf_role.php');
}
function excel(){
	window.location = 'excel_role.php';
}
function add(){
	$(".save_button").show();
	$("#role_id").val("");
	$("#role_name").val("");
	$("#role_code").val("");
	$("#role_description").val("");
	$("#role_home_page").val("");
	$("#icon_color").val("");
	$("#icon_text").val("");
	$('#modal-add-role').modal("show");
}

function delete_role(roleId){
	$("#flex_role_id").val(roleId);
	
	BootstrapDialog.confirm('Are you sure to delete the role?', function(result){
            if(result) {
               $.ajax({
					url : 'delete_role.php',
					type : "POST",
					data : $("#flex_form_role").serialize(),
					success : function(data) {
						if(data.indexOf("SUCCESS")!=-1){
							BootstrapDialog.alert('Role Deleted Successfully.');
							$("#flex1").flexReload();
								
						}else{
							BootstrapDialog.alert('Error Deleting Role');
						}
					return;
					},
					error : function(data) {
						BootstrapDialog.alert('Error Deleting Role');
						return;
					}
			});
            }
        });
	
}

function save_role(){
	$.ajax({
			url : 'save_role.php?role_id='+role_id+' ',
			type : "POST",
			data : $("#role_form").serialize(),
			success : function(data) {
				BootstrapDialog.alert('Role Saved Successfully.');
				$("#flex1").flexReload();
				return;
			},
			error : function(data) {
				BootstrapDialog.alert('Error Saving Role');
				return;
			}
	});
    $('.close').click();
}


var role_id = "";
function open_role(roleId, action) {
		if(action=="V"){
				$(".save_button").hide();

		}else{
				$(".save_button").show();
		}
		$.ajax({
			url : 'select_role.php?roleId='+roleId+' ',
			type : 'POST',
			success : function(data) {
			//alert(data);
			var data = $.parseJSON(data);
			//alert(data);
					role_id = data.role_id;
					$("#role_id").val(data.role_id);
					$("#role_name").val(data.role_name);
					$("#role_code").val(data.role_code);
					$("#role_description").val(data.role_description);
					$("#role_home_page").val(data.role_home_page);
					$("#icon_color").val(data.icon_color);
					$("#icon_text").val(data.icon_text);
					$('#modal-add-role').modal("show");
			},
			error : function(data) {
				BootstrapDialog.alert('Error Populating Vendor');
				return;
			}
		});
}

</script>

<?php  include('techsyn_footer.php'); ?>    
<?php  include('form/add_role.php');?>