-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathgenre.php
183 lines (164 loc) · 5.65 KB
/
genre.php
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
156
157
158
159
160
161
162
163
164
165
166
167
168
169
170
171
172
173
174
175
176
177
178
179
180
181
182
183
<?php
use Pico\Data\Entity\Genre;
use Pico\Database\PicoPagable;
use Pico\Database\PicoPage;
use Pico\Database\PicoSortable;
use Pico\Pagination\PicoPagination;
use Pico\Request\PicoFilterConstant;
use Pico\Request\PicoRequest;
use Pico\Utility\SpecificationUtil;
require_once "inc/auth-with-login-form.php";
require_once "inc/header.php";
$inputGet = new PicoRequest(INPUT_GET);
?>
<div class="filter-container">
<form action="" method="get">
<div class="filter-group">
<span>Name</span>
<input class="form-control" type="text" name="name" id="name" autocomplete="off" value="<?php echo $inputGet->getName(PicoFilterConstant::FILTER_SANITIZE_SPECIAL_CHARS);?>">
</div>
<input class="btn btn-success" type="submit" value="Show">
<input class="btn btn-primary add-data" type="button" value="Add">
`
</form>
</div>
<?php
$orderMap = array(
'name'=>'name',
'genreId'=>'genreId',
'genre'=>'genreId',
'sortOrder'=>'sortOrder',
'active'=>'active'
);
$defaultOrderBy = 'sortOrder';
$defaultOrderType = 'asc';
$pagination = new PicoPagination($cfg->getResultPerPage());
$spesification = SpecificationUtil::createGenreSpecification($inputGet);
$sortable = new PicoSortable($pagination->getOrderBy($orderMap, $defaultOrderBy), $pagination->getOrderType($defaultOrderType));
$pagable = new PicoPagable(new PicoPage($pagination->getCurrentPage(), $pagination->getPageSize()), $sortable);
$genreEntity = new Genre(null, $database);
$rowData = $genreEntity->findAll($spesification, $pagable, $sortable, true);
$result = $rowData->getResult();
?>
<script>
$(document).ready(function(e){
let pg = new Pagination('.pagination', '.page-selector', 'data-page-number', 'page');
pg.init();
$(document).on('change', '.filter-container form select', function(e2){
$(this).closest('form').submit();
});
});
</script>
<?php
if(!empty($result))
{
?>
<div class="pagination">
<div class="pagination-number">
<?php
foreach($rowData->getPagination() as $pg)
{
?><span class="page-selector<?php echo $pg['selected'] ? ' page-selected':'';?>" data-page-number="<?php echo $pg['page'];?>"><a href="#"><?php echo $pg['page'];?></a></span><?php
}
?>
</div>
</div>
<table class="table">
<thead>
<tr>
<th scope="col" width="20"><i class="ti ti-edit"></i></th>
<th scope="col" width="20"><i class="ti ti-trash"></i></th>
<th scope="col" width="20">#</th>
<th scope="col" class="col-sort" data-name="name">Name</th>
<th scope="col" class="col-sort" data-name="sort_order">Order</th>
<th scope="col" class="col-sort" data-name="active">Active</th>
</tr>
</thead>
<tbody>
<?php
$no = $pagination->getOffset();
foreach($result as $genre)
{
$no++;
$genreId = $genre->getGenreId();
$linkEdit = basename($_SERVER['PHP_SELF'])."?action=edit&genre_id=".$genreId;
$linkDetail = basename($_SERVER['PHP_SELF'])."?action=detail&genre_id=".$genreId;
$linkDelete = basename($_SERVER['PHP_SELF'])."?action=delete&genre_id=".$genreId;
?>
<tr data-id="<?php echo $genreId;?>">
<th scope="row"><a href="<?php echo $linkEdit;?>" class="edit-data"><i class="ti ti-edit"></i></a></th>
<th scope="row"><a href="<?php echo $linkDelete;?>" class="delete-data"><i class="ti ti-trash"></i></a></th>
<th scope="row"><?php echo $no;?></th>
<td><a href="<?php echo $linkDetail;?>"><?php echo $genre->getName();?></a></td>
<td><?php echo $genre->getSortOrder();?></td>
<td><?php echo $genre->isActive() ? 'Yes' : 'No';?></td>
</tr>
<?php
}
?>
</tbody>
</table>
<div class="lazy-dom modal-container modal-add-data" data-url="lib.ajax/genre-add-dialog.php"></div>
<div class="lazy-dom modal-container modal-update-data" data-url="lib.ajax/genre-update-dialog.php"></div>
<script>
let addGenreModal;
let updateGenreModal;
$(document).ready(function(e){
$(document).on('click', '.add-data', function(e2){
e2.preventDefault();
e2.stopPropagation();
let dialogSelector = $('.modal-add-data');
dialogSelector.load(dialogSelector.attr('data-url'), function(data){
let addGenreModalElem = document.querySelector('#addGenreDialog');
addGenreModal = new bootstrap.Modal(addGenreModalElem, {
keyboard: false
});
addGenreModal.show();
})
});
$(document).on('click', '.edit-data', function(e2){
e2.preventDefault();
e2.stopPropagation();
let genreId = $(this).closest('tr').attr('data-id') || '';
let dialogSelector = $('.modal-update-data');
dialogSelector.load(dialogSelector.attr('data-url')+'?genre_id='+genreId, function(data){
let updateGenreModalElem = document.querySelector('#updateGenreDialog');
updateGenreModal = new bootstrap.Modal(updateGenreModalElem, {
keyboard: false
});
updateGenreModal.show();
})
});
$(document).on('click', '.save-add-genre', function(){
let dataSet = $(this).closest('form').serializeArray();
$.ajax({
type:'POST',
url:'lib.ajax/genre-add.php',
data:dataSet,
dataType:'html',
success: function(data)
{
addGenreModal.hide();
window.location.reload();
}
})
});
$(document).on('click', '.save-edit-genre', function(){
let dataSet = $(this).closest('form').serializeArray();
$.ajax({
type:'POST',
url:'lib.ajax/genre-update.php',
data:dataSet,
dataType:'html',
success: function(data)
{
updateGenreModal.hide();
}
})
});
});
</script>
<?php
}
require_once "inc/footer.php";
?>