You can not select more than 25 topics Topics must start with a letter or number, can include dashes ('-') and can be up to 35 characters long.
 
 
 
 
 
 

399 lines
14 KiB

<!-- Content Wrapper. Contains page content -->
<div class="content-wrapper">
<!-- Content Header (Page header) -->
<section class="content-header">
<h1>
Gérer les
<small>Marques</small>
</h1>
<ol class="breadcrumb">
<li><a href="#"><i class="fa fa-dashboard"></i> Accueil</a></li>
<li class="active">Marques</li>
</ol>
</section>
<!-- Main content -->
<section class="content">
<!-- Small boxes (Stat box) -->
<div class="row">
<div class="col-md-12 col-xs-12">
<div id="messages"></div>
<?php if (session()->getFlashdata('success')): ?>
<div class="alert alert-success alert-dismissible" role="alert">
<button type="button" class="close" data-dismiss="alert" aria-label="Close"><span aria-hidden="true">&times;</span></button>
<?php echo session()->getFlashdata('success'); ?>
</div>
<?php elseif (session()->getFlashdata('error')): ?>
<div class="alert alert-error alert-dismissible" role="alert">
<button type="button" class="close" data-dismiss="alert" aria-label="Close"><span aria-hidden="true">&times;</span></button>
<?php echo session()->getFlashdata('error'); ?>
</div>
<?php endif; ?>
<?php if (in_array('createBrand', $user_permission)): ?>
<button class="btn btn-primary" data-toggle="modal" data-target="#addBrandModal">Ajouter un marque</button>
<br /> <br />
<?php endif; ?>
<div class="box">
<div class="box-header">
<h3 class="box-title">Gérer les Marques</h3>
</div>
<!-- /.box-header -->
<div class="box-body">
<table id="manageTable" class="table table-bordered table-striped">
<thead>
<tr>
<th>Nom de marque</th>
<th>Status</th>
<?php if (in_array('updateBrand', $user_permission) || in_array('deleteBrand', $user_permission)): ?>
<th>Action</th>
<?php endif; ?>
</tr>
</thead>
</table>
</div>
<!-- /.box-body -->
</div>
<!-- /.box -->
</div>
<!-- col-md-12 -->
</div>
<!-- /.row -->
</section>
<!-- /.content -->
</div>
<!-- /.content-wrapper -->
<?php if (in_array('createBrand', $user_permission)): ?>
<!-- create brand modal -->
<div class="modal fade" tabindex="-1" role="dialog" id="addBrandModal">
<div class="modal-dialog" role="document">
<div class="modal-content">
<div class="modal-header">
<button type="button" class="close" data-dismiss="modal" aria-label="Close"><span aria-hidden="true">&times;</span></button>
<h4 class="modal-title">Ajouter un marque</h4>
</div>
<form role="form" action="<?php echo base_url('brands/create') ?>" method="post" id="createBrandForm">
<div class="modal-body">
<div class="form-group">
<label for="brand_name">Nom de la marque</label>
<input type="text" class="form-control" id="brand_name" name="brand_name" placeholder="Nom de la marque" autocomplete="off">
</div>
<div class="form-group">
<label for="active">Status</label>
<select class="form-control" id="active" name="active">
<option value="1">Active</option>
<option value="2">Inactive</option>
</select>
</div>
</div>
<div class="modal-footer">
<button type="button" class="btn btn-default" data-dismiss="modal">Fermer</button>
<button type="submit" class="btn btn-primary">Enregistrer</button>
</div>
</form>
</div><!-- /.modal-content -->
</div><!-- /.modal-dialog -->
</div><!-- /.modal -->
<?php endif; ?>
<?php if (in_array('updateBrand', $user_permission)): ?>
<!-- edit brand modal -->
<div class="modal fade" tabindex="-1" role="dialog" id="editBrandModal">
<div class="modal-dialog" role="document">
<div class="modal-content">
<div class="modal-header">
<button type="button" class="close" data-dismiss="modal" aria-label="Close"><span aria-hidden="true">&times;</span></button>
<h4 class="modal-title">Mise à jour de marque</h4>
</div>
<form role="form" action="<?php echo base_url('brands/update') ?>" method="post" id="updateBrandForm">
<div class="modal-body">
<div id="messages"></div>
<div class="form-group">
<label for="edit_brand_name">Nom de la marque</label>
<input type="text" class="form-control" id="edit_brand_name" name="edit_brand_name" placeholder="Nom de la marque" autocomplete="off">
</div>
<div class="form-group">
<label for="edit_active">Status</label>
<select class="form-control" id="edit_active" name="edit_active">
<option value="1">Active</option>
<option value="2">Inactive</option>
</select>
</div>
</div>
<div class="modal-footer">
<button type="button" class="btn btn-default" data-dismiss="modal">Close</button>
<button type="submit" class="btn btn-primary">Save changes</button>
</div>
</form>
</div><!-- /.modal-content -->
</div><!-- /.modal-dialog -->
</div>
<!-- /.modal -->
<?php endif; ?>
<?php if (in_array('deleteBrand', $user_permission)): ?>
<!-- remove brand modal -->
<div class="modal fade" tabindex="-1" role="dialog" id="removeBrandModal">
<div class="modal-dialog" role="document">
<div class="modal-content">
<div class="modal-header">
<button type="button" class="close" data-dismiss="modal" aria-label="Close"><span aria-hidden="true">&times;</span></button>
<h4 class="modal-title">Supprimer la marque</h4>
</div>
<form role="form" action="<?php echo base_url('brands/remove') ?>" method="post" id="removeBrandForm">
<div class="modal-body">
<p>Voulez-vous vraiment supprimer ?</p>
</div>
<div class="modal-footer">
<button type="button" class="btn btn-default" data-dismiss="modal">Fermer</button>
<button type="submit" class="btn btn-primary">Oui</button>
</div>
</form>
</div><!-- /.modal-content -->
</div><!-- /.modal-dialog -->
</div>
<!-- /.modal -->
<?php endif; ?>
<script type="text/javascript">
var manageTable;
$(document).ready(function() {
$("#mainProductNav").addClass('active');
$("#brandNav").addClass('active');
// initialize the datatable
// datatable-fr.js
$.extend(true, $.fn.dataTable.defaults, {
language: {
sProcessing: "Traitement en cours...",
sSearch: "Rechercher&nbsp;:",
sLengthMenu: "Afficher _MENU_ &eacute;l&eacute;ments",
sInfo: "Affichage de l'&eacute;lement _START_ &agrave; _END_ sur _TOTAL_ &eacute;l&eacute;ments",
sInfoEmpty: "Affichage de l'&eacute;lement 0 &agrave; 0 sur 0 &eacute;l&eacute;ment",
sInfoFiltered: "(filtr&eacute; de _MAX_ &eacute;l&eacute;ments au total)",
sLoadingRecords: "Chargement en cours...",
sZeroRecords: "Aucun &eacute;l&eacute;ment &agrave; afficher",
sEmptyTable: "Aucune donn&eacute;e disponible dans le tableau",
oPaginate: {
sFirst: "Premier",
sPrevious: "Pr&eacute;c&eacute;dent",
sNext: "Suivant",
sLast: "Dernier"
},
oAria: {
sSortAscending: ": activer pour trier la colonne par ordre croissant",
sSortDescending: ": activer pour trier la colonne par ordre d&eacute;croissant"
}
}
});
manageTable = $('#manageTable').DataTable({
'ajax': '<?= base_url('brands/fetchBrandData') ?>',
'order': []
});
// submit the create from
$("#createBrandForm").unbind('submit').on('submit', function() {
var form = $(this);
// remove the text-danger
$(".text-danger").remove();
$.ajax({
url: form.attr('action'),
type: form.attr('method'),
data: form.serialize(), // /converting the form data into array and sending it to server
dataType: 'json',
success: function(response) {
manageTable.ajax.reload(null, false);
if (response.success === true) {
$("#messages").html('<div class="alert alert-success alert-dismissible" role="alert">' +
'<button type="button" class="close" data-dismiss="alert" aria-label="Close"><span aria-hidden="true">&times;</span></button>' +
'<strong> <span class="glyphicon glyphicon-ok-sign"></span> </strong>' + response.messages +
'</div>');
// hide the modal
$("#addBrandModal").modal('hide');
// reset the form
$("#createBrandForm")[0].reset();
$("#createBrandForm .form-group").removeClass('has-error').removeClass('has-success');
} else {
if (response.messages instanceof Object) {
$.each(response.messages, function(index, value) {
var id = $("#" + index);
id.closest('.form-group')
.removeClass('has-error')
.removeClass('has-success')
.addClass(value.length > 0 ? 'has-error' : 'has-success');
id.after(value);
});
} else {
$("#messages").html('<div class="alert alert-warning alert-dismissible" role="alert">' +
'<button type="button" class="close" data-dismiss="alert" aria-label="Close"><span aria-hidden="true">&times;</span></button>' +
'<strong> <span class="glyphicon glyphicon-exclamation-sign"></span> </strong>' + response.messages +
'</div>');
}
}
}
});
return false;
});
});
function editBrand(id) {
$.ajax({
url: 'fetchBrandDataById/' + id,
type: 'post',
dataType: 'json',
success: function(response) {
// Populate the modal with data
$("#edit_brand_name").val(response.name);
$("#edit_active").val(response.active);
// Show the modal
$('#editBrandModal').modal('show'); // This line will show the modal
// Submit the edit form
$("#updateBrandForm").unbind('submit').bind('submit', function() {
var form = $(this);
// Remove the text-danger
$(".text-danger").remove();
$.ajax({
url: form.attr('action') + '/' + id,
type: form.attr('method'),
data: form.serialize(), // Converting the form data into array and sending it to server
dataType: 'json',
success: function(response) {
manageTable.ajax.reload(null, false);
if (response.success === true) {
$("#messages").html('<div class="alert alert-success alert-dismissible" role="alert">' +
'<button type="button" class="close" data-dismiss="alert" aria-label="Close"><span aria-hidden="true">&times;</span></button>' +
'<strong> <span class="glyphicon glyphicon-ok-sign"></span> </strong>' + response.messages +
'</div>');
// Hide the modal
$("#editBrandModal").modal('hide');
// Reset the form
$("#updateBrandForm .form-group").removeClass('has-error').removeClass('has-success');
} else {
if (response.messages instanceof Object) {
$.each(response.messages, function(index, value) {
var id = $("#" + index);
id.closest('.form-group')
.removeClass('has-error')
.removeClass('has-success')
.addClass(value.length > 0 ? 'has-error' : 'has-success');
id.after(value);
});
} else {
$("#messages").html('<div class="alert alert-warning alert-dismissible" role="alert">' +
'<button type="button" class="close" data-dismiss="alert" aria-label="Close"><span aria-hidden="true">&times;</span></button>' +
'<strong> <span class="glyphicon glyphicon-exclamation-sign"></span> </strong>' + response.messages +
'</div>');
}
}
}
});
return false;
});
}
});
}
function removeBrand(id) {
if (id) {
// Show the modal when this function is called
$("#removeBrandModal").modal('show'); // This will show the modal
// On form submission, handle the removal of the brand
$("#removeBrandForm").on('submit', function(e) {
e.preventDefault(); // Prevent default form submission
var form = $(this);
// Remove any previous error messages
$(".text-danger").remove();
$.ajax({
url: form.attr('action'),
type: form.attr('method'),
data: {
brand_id: id // Send the brand ID to the server
},
dataType: 'json',
success: function(response) {
// Reload the table after the response
manageTable.ajax.reload(null, false);
if (response.success === true) {
// Show success message
$("#messages").html('<div class="alert alert-success alert-dismissible" role="alert">' +
'<button type="button" class="close" data-dismiss="alert" aria-label="Close"><span aria-hidden="true">&times;</span></button>' +
'<strong> <span class="glyphicon glyphicon-ok-sign"></span> </strong>' + response.messages +
'</div>');
// Hide the modal
$("#removeBrandModal").modal('hide');
} else {
// Show error message
$("#messages").html('<div class="alert alert-warning alert-dismissible" role="alert">' +
'<button type="button" class="close" data-dismiss="alert" aria-label="Close"><span aria-hidden="true">&times;</span></button>' +
'<strong> <span class="glyphicon glyphicon-exclamation-sign"></span> </strong>' + response.messages +
'</div>');
}
}
});
});
}
}
</script>