BBnepal-Accounts/application/views/admin/ae_role.php

235 lines
7.4 KiB
PHP
Raw Normal View History

2024-07-10 12:43:19 +00:00
<style>
form label.error, #Nameerr {
color : red;
}
.subject_l {
width : 50%;
}
</style>
<main class="wraper responsive-width" id="main">
<!----admin template role---->
<div class="admin_tempblock" >
<div class="admin_tempsec">
<div class="admin_sec">
<form action="<?php echo base_url() ?>admin/roles/ae-role/<?php echo $id ?>" class="mb-5" method="post" id="roleForm">
<?php if($id == 0) {?>
<div class="subsec_sec">
<div class="subject_l subject_l_full_width" >
<div class="subject_lsec">
<div class="subject_lhead"><?php echo $title ?></div>
<div class="subject_lformarea">
<div class="form-group">
<label for="">Role Name<span class="text-danger font-weight-bold">*</span></label>
<input type="text" onkeypress="return lettersOnly(event)" name="role_name" id="role_name" class="form-control alphaonly" placeholder="Name of the role">
<label id="Nameerr" style="display : none"></label>
</div>
<div class="form-group">
<label for="">Status<span class="text-danger font-weight-bold">*</span></label>
<select name="status" class="form-control">
<option selected disable value="">Choose role status</option>
<option value="Active">Active</option>
<option value="Inactive">Inactive</option>
</select>
</div>
<div class="form-group">
<label for=""> Description</label>
<textarea class="form-control" data-altName="Description" name="role_desc" rows="6" placeholder="Add some description of your course..."></textarea>
</div>
<label class="d-block">Role Permissions<span class="text-danger font-weight-bold">*</span></label>
<div class="row mt-2 mb-3">
<?php foreach($menulist as $key => $value) { ?>
<div class="col-md-6 mt-2">
<div class="form-check">
<input class="form-check-input" type="checkbox" value="<?php echo $value['id'] ?>" name="rolesid[]" id="<?php echo $value['id'] ?>">
<label class="form-check-label" for="<?php echo $value['id'] ?>">
<?php echo $value['menu_name'] ?>
</label>
</div>
</div>
<?php } ?>
<!-- <label id="rolesid[]-error" class="error mb-2" for="rolesid[]"></label>
</div> -->
<div class="common_btn_wrap">
<input type="submit" class="subject_addbtn" value="Save">
<a href="<?= base_url(); ?>admin/roles/list"><button type="button" class="subject_addbtn bg-dark ml-2">Back</button></a>
</div>
</div>
</div>
</div>
</div>
</form>
<?php } else { ?>
<div class="subsec_sec">
<div class="subject_l subject_l_full_width">
<div class="subject_lsec">
<div class="subject_lhead"><?php echo $title ?></div>
<div class="subject_lformarea">
<div class="form-group">
<label for="">Role Name<span class="text-danger font-weight-bold">*</span></label>
<input type="text" id="role_name" onkeypress="return lettersOnly(event)" name="role_name" value="<?php echo $result[0]['role_name'] ?>" class="form-control" placeholder="Name of the role">
<label id="Nameerr" style="display : none"></label>
</div>
<div class="form-group">
<label for="">Status<span class="text-danger font-weight-bold">*</span></label>
<select name="status" class="form-control">
<option selected value="<?php echo $result[0]['status'] ?>"><?php echo $result[0]['status'] ?></option>
<?php if($result[0]['status'] == 'Active') { ?>
<option value="Inactive">Inactive</option>
<?php } else {?>
<option value="Active">Active</option>
<?php } ?>
</select>
</div>
<div class="form-group">
<label for=""> Description</label>
<textarea class="form-control" data-altName="Description" name="role_desc" rows="6" placeholder="Add some description of your course..."><?php echo $result[0]['role_desc'] ?></textarea>
</div>
<label class="d-block">Role Permissions<span class="text-danger font-weight-bold">*</span></label>
<div class="row mt-2 mb-3">
<?php foreach($menulist as $key => $value) {
if(in_array($value['id'],$pre_selected_ids)) { ?>
<div class="col-md-6 mt-2">
<div class="form-check">
<input class="form-check-input" checked type="checkbox" value="<?php echo $value['id'] ?>" name="rolesid[]" id="<?php echo $value['id'] ?>">
<label class="form-check-label" for="<?php echo $value['id'] ?>">
<?php echo $value['menu_name'] ?>
</label>
</div>
</div>
<?php } else { ?>
<div class="col-md-6 mt-2">
<div class="form-check">
<input class="form-check-input" type="checkbox" value="<?php echo $value['id'] ?>" name="rolesid[]" id="<?php echo $value['id'] ?>">
<label class="form-check-label" for="<?php echo $value['id'] ?>">
<?php echo $value['menu_name'] ?>
</label>
</div>
</div>
<?php }
?>
<?php } ?>
<!-- <label id="rolesid[]-error" class="error mb-2" for="rolesid[]"></label> -->
</div>
<div class="common_btn_wrap">
<input type="submit" class="subject_addbtn" value="Update">
<a href="<?= base_url(); ?>admin/roles/list"><button type="button" class="subject_addbtn bg-dark ml-2">Back</button></a>
</div>
</div>
</div>
</div>
</div>
</form>
<?php } ?>
</div>
</div>
</div>
<!----admin template role end---->
</main>
<!--End right-top side-->
<script>
$(document).on('keypress', function(e){
if(e.which==13)
{
$('form').submit();
}
});
$(document).ready(function(){
$("#roleForm").validate({
rules: {
role_name: {
required: true,
minlength: 1
},
status : "required",
// 'rolesid[]' : 'required'
},
messages: {
role_name: {
required: "Please provide a role name",
minlength : "Please enter more than 4 Characters"
},
status : 'Please select the status of role',
// 'rolesid[]' : 'Please select atleast one permission.'
},
submitHandler: function(form) {
var inputValue = $("input[name='role_name']",form).val();
inputValue = inputValue.toLowerCase().trim().replace(/\s\s+/g, ' ');
$("#role_name").val(inputValue);
let flag = false;
$.ajax({
url : '<?php echo base_url() ?>' + 'admin/ajax_validate_role_name',
data : {
value : inputValue,
id : <?php echo $id ?>
},
type : 'POST',
async : false,
success: function(data){
console.log(data);
if(data == 'success'){
flag = true
}
}
});
if(flag) {
form.submit();
} else {
$('#Nameerr').show();
$('#Nameerr').text('This role name already exists.');
}
}
});
});
</script>
<script type="text/javascript">
function lettersOnly()
{
var charCode = event.keyCode;
if ((charCode > 64 && charCode < 91) || (charCode > 96 && charCode < 123) || charCode == 8 || charCode == 32)
return true;
else
return false;
}
</script>