163 lines
7.0 KiB
PHP
163 lines
7.0 KiB
PHP
<div class="tab-pane fade" id="RM-tab">
|
|
<div class="row">
|
|
<div class="col-12">
|
|
<div class="card-body">
|
|
<form role="form" class="parsley-examples" method="post" id="relation_form" enctype="multipart/form-data">
|
|
<input type="hidden" class="form-control" value="<?= csrf_hash() ?>" name="<?= csrf_token() ?>" />
|
|
<input type="hidden" name="PrimaryKey" id="relation_PrimaryKey" value="<?= isset($client['id']) ? $client['id'] : '' ?>"/>
|
|
<input type="hidden" name="client_id" id="client_id_relation" value="<?= isset($client['id']) ? $client['id'] : '' ?>"/>
|
|
<div class="form-group">
|
|
<div class="form-row">
|
|
<div class="form-group col-md-4">
|
|
<label for="emp_code">Account Manager</label>
|
|
<select class="form-control" id="account_manager" name="account_manager[]" multiple>
|
|
<?php foreach($RM as $value) { ?>
|
|
<?php if($value['role'] === '3') { ?>
|
|
<option value="<?= $value['id'] ?>"><?= $value['first_name'] ?></option>
|
|
<?php } ?>
|
|
<?php } ?>
|
|
</select>
|
|
</div>
|
|
<div class="form-group col-md-4">
|
|
<label for="profile">Manager</label>
|
|
<select class="form-control" id="manager" name="manager">user_id
|
|
<option value="">Select Manager</option>
|
|
<?php foreach($RM as $value) { ?>
|
|
<?php if($value['role'] === '2') { ?>
|
|
<option value="<?= $value['id'] ?>"><?= $value['first_name'] ?></option>
|
|
<?php } ?>
|
|
<?php } ?>
|
|
</select>
|
|
</div>
|
|
<div class="form-group col-md-4">
|
|
<label for="profile">Head</label>
|
|
<select class="form-control" id="head" name="head">
|
|
<option value="">Select Head</option>
|
|
<?php foreach($RM as $value) { ?>
|
|
<?php if($value['role'] === '5') { ?>
|
|
<option value="<?= $value['id'] ?>"><?= $value['first_name'] ?></option>
|
|
<?php } ?>
|
|
<?php } ?>
|
|
</select>
|
|
</div>
|
|
</div>
|
|
|
|
</div>
|
|
<div class="form-group text-right m-b-0">
|
|
<button type="submit" class="btn btn-primary waves-effect waves-light mr-1"
|
|
id="btnSubmit">Submit</button>
|
|
<button type="button" class="btn btn-secondary waves-effect btnBack"
|
|
id="btnBack">Cancel</button>
|
|
</div>
|
|
</form>
|
|
</div>
|
|
</div> <!-- end col-->
|
|
</div>
|
|
<!-- end row -->
|
|
</div>
|
|
<!-- end -->
|
|
|
|
<script>
|
|
$(document).ready(function(){
|
|
|
|
var relation_PrimaryKey = $('#relation_PrimaryKey').val()
|
|
|
|
$('#account_manager').multiselect({
|
|
nonSelectedText: 'Select Account Manager',
|
|
enableFiltering: false,
|
|
enableCaseInsensitiveFiltering: false,
|
|
includeSelectAllOption : false,
|
|
buttonWidth:'100%'
|
|
});
|
|
|
|
var data = <?= isset($client_relation) ? json_encode($client_relation) : '[]' ?>;
|
|
if (relation_PrimaryKey !== '') {
|
|
$.each(data, function(index, item) {
|
|
$('#head option[value="' + item.user_id + '"]').prop('selected', true);
|
|
$('#manager option[value="' + item.user_id + '"]').prop('selected', true);
|
|
var $option = $('#account_manager option[value="' + item.user_id + '"]');
|
|
if ($option.length > 0) {
|
|
$option.prop('selected', true);
|
|
}
|
|
$('#account_manager').multiselect('refresh');
|
|
|
|
});
|
|
|
|
}
|
|
|
|
|
|
|
|
$("#relation_form").submit(function(event) {
|
|
event.preventDefault();
|
|
|
|
// Perform validation
|
|
var isValid = validateForm(); // Assuming you have a function for form validation
|
|
var form_action = '';
|
|
|
|
if (isValid) {
|
|
|
|
if(relation_PrimaryKey === ''){
|
|
form_action = '<?= base_url("client/relation/create"); ?>';
|
|
}else{
|
|
form_action = '<?= base_url("client/relation/edit"); ?>';
|
|
}
|
|
|
|
var formData = new FormData($('#relation_form')[0]);
|
|
|
|
$.ajax({
|
|
data: formData,
|
|
url: form_action,
|
|
type: "POST",
|
|
dataType: 'json',
|
|
processData: false,
|
|
contentType: false,
|
|
success: function(res) {
|
|
console.log(res);
|
|
if(relation_PrimaryKey === ''){
|
|
$.toast({
|
|
text: 'Client Relation Info',
|
|
heading: "Submitted Sucessfully",
|
|
position: 'top-right',
|
|
icon: 'success',
|
|
});
|
|
}else{
|
|
$.toast({
|
|
text: 'Client Relation Info',
|
|
heading: "Updated Sucessfully",
|
|
position: 'top-right',
|
|
icon: 'success',
|
|
});
|
|
}
|
|
|
|
},
|
|
error: function(xhr, status, error) {
|
|
console.error(xhr.responseText);
|
|
console.error(status, error);
|
|
}
|
|
});
|
|
|
|
}
|
|
});
|
|
|
|
function validateForm() {
|
|
var isValid = true;
|
|
|
|
// Perform validation for each field
|
|
$('#relation_form input, #relation_form select').each(function() {
|
|
// Check for empty text inputs and selects
|
|
if ($(this).is('input[type="text"]') || $(this).is('select')) {
|
|
if ($.trim($(this).val()) == '') {
|
|
alert('Please fill in all fields');
|
|
isValid = false;
|
|
return false; // Exit the loop early
|
|
}
|
|
}
|
|
|
|
});
|
|
|
|
return isValid;
|
|
}
|
|
|
|
|
|
});
|
|
</script>
|