Skip to content

Commit 3cf6173

Browse files
committed
Add inject actions
1 parent 7ed9ed6 commit 3cf6173

File tree

3 files changed

+201
-0
lines changed

3 files changed

+201
-0
lines changed

application/core/MY_Controller.php

Lines changed: 4 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -218,6 +218,10 @@ protected function add_stylesheet($files, $append = TRUE, $media = 'screen')
218218
$this->mStylesheets[$media] = array_merge($files, $this->mStylesheets[$media]);
219219
}
220220

221+
protected function load_inject ($inject, $settings) {
222+
return $this->load->view('inject/'.$inject, $settings, true);
223+
}
224+
221225
// Render template
222226
protected function render($view_file, $layout = 'default')
223227
{
Lines changed: 117 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,117 @@
1+
<?php
2+
/*this a addon for grocery_crud modded
3+
* just do $this->mInjectAfterPageTitle = $this->load_inject('gcplug/between2date', array('column' => 'tot', 'title' => 'Search by date', 'search_button' => 'Search', 'lang' => 'en', 'auto' => true));
4+
or $this->mInjectBeforeFooter = $this->load_inject('gcplug/between2date', array('column' => 'tot', 'title' => 'Search by date', 'search_button' => 'Search', 'lang' => 'en', 'auto' => true));
5+
you could use $colum name or number, mind display_as is a traslated element, by now...
6+
*/
7+
$column = isset($column) ? $column : 0; //<-- you could use $colum name or number, mind display_as is a traslated element, by now...
8+
$title = isset($title) ? $title : 'Search by date';
9+
$search_button = isset($search_button) ? $search_button : 'Search';
10+
$lang = isset($lang) ? $lang : 'en'; //<-- choose lang
11+
$auto = isset($auto) ? $auto : true; //<-- choose if you want automatic or manual search date
12+
?>
13+
14+
<section class="content">
15+
<div class="container-fluid">
16+
<div class="card">
17+
<div class="card-header"><?php echo $title; ?></div>
18+
<div class="card-body">
19+
<div class="row">
20+
<div class="col-md-4">
21+
<div id="min"></div>
22+
</div>
23+
24+
<?php if (!$auto) : ?>
25+
<div class="col-md-2"></div>
26+
<div class="col-md-4">
27+
<div id="max"></div>
28+
</div>
29+
<div class="col-md-2">
30+
<button class="btn btn-default" onclick="doDateSearch()"><?php echo $search_button; ?></button>
31+
</div>
32+
<?php else : ?>
33+
<div class="col-md-4"></div>
34+
<div class="col-md-4">
35+
<div id="max"></div>
36+
</div>
37+
<?php endif; ?>
38+
39+
</div>
40+
</div>
41+
</div>
42+
</div>
43+
</section>
44+
<script>
45+
$dateSearchStart = false;
46+
47+
function indexFromName(searchindex) {
48+
let ret = 0;
49+
let val = parseInt(searchindex.charAt(0));
50+
console.log(val);
51+
if (isNaN(val)) {
52+
$("table.groceryCrudTable > thead > tr[id!=multiSearchToggle] > th").each(function(index) {
53+
if (searchindex.toLowerCase() === $(this).text().toLowerCase()) {
54+
ret = index + 1
55+
};
56+
});
57+
} else {
58+
ret = searchindex;
59+
}
60+
return parseInt(ret);
61+
}
62+
63+
function initdatetime() {
64+
$('#min').datetimepicker({
65+
format: 'L',
66+
inline: true,
67+
locale: '<?php echo $lang; ?>',
68+
sideBySide: true,
69+
defaultDate: '<?php echo date('Y') ?>-01-01'
70+
});
71+
72+
$('#max').datetimepicker({
73+
format: 'L',
74+
inline: true,
75+
locale: '<?php echo $lang; ?>',
76+
sideBySide: true
77+
});
78+
79+
$.fn.dataTable.ext.search.push(
80+
function(settings, data, dataIndex) {
81+
if ($dateSearchStart) {
82+
let min = $('#min').datetimepicker('date').unix();
83+
let max = $('#max').datetimepicker('date').unix();
84+
let datain = data[indexFromName('<?php echo $column; ?>')];
85+
let datafix = datain.slice(6, 10) + '-' + datain.slice(3, 5) + '-' + datain.slice(0, 2);
86+
let age = Date.parse(datafix) / 1000;
87+
if ((isNaN(min) && isNaN(max)) ||
88+
(isNaN(min) && age <= max) ||
89+
(min <= age && isNaN(max)) ||
90+
(min <= age && age <= max)) {
91+
return true;
92+
}
93+
return false;
94+
} else {
95+
return true;
96+
}
97+
}
98+
);
99+
100+
101+
<?php if ($auto) : ?>
102+
$('#min, #max').on("change.datetimepicker", function() {
103+
doDateSearch();
104+
});
105+
<?php endif; ?>
106+
}
107+
108+
async function doDateSearch() {
109+
$dateSearchStart = true;
110+
await oTable.fnDraw();
111+
$dateSearchStart = false;
112+
}
113+
114+
$(document).ready(function() {
115+
initdatetime();
116+
});
117+
</script>
Lines changed: 80 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,80 @@
1+
<?php
2+
/*this a addon for grocery_crud modded
3+
* just do $this->mInjectAfterPageTitle = $this->load_inject('gcplug/total', array('totalString' => 'Total', 'column' => 'Column'));
4+
or $this->mInjectBeforeFooter = $this->load_inject('gcplug/total', array('totalString' => 'Total', 'column' => 'Column'));
5+
6+
*/
7+
$column = isset($column)?$column:0; //<-- you could use $colum name or number, mind display_as is a traslated element, by now...
8+
$totalString = isset($totalString)?$totalString:'Total'; //<-- just traslated string
9+
?>
10+
11+
<section class="content">
12+
<div class="row">
13+
<div class="col-md-10"></div>
14+
<div class="col-md-2">
15+
<div class="callout callout-danger">
16+
<h5><?php echo $totalString;?>: <b id="total_total" class="float-right"></b></h5>
17+
</div>
18+
</div>
19+
</div>
20+
</section>
21+
<script>
22+
var total = [];
23+
var resetpid = true;
24+
function indexFromName(searchindex) {
25+
let ret = 0;
26+
let val = parseInt(searchindex.charAt(0));
27+
console.log(val);
28+
if (isNaN(val)) {
29+
$("table.groceryCrudTable > thead > tr[id!=multiSearchToggle] > th").each(function(index) {
30+
if (searchindex.toLowerCase() === $(this).text().toLowerCase()) {
31+
ret = index + 1
32+
};
33+
});
34+
} else {
35+
ret = searchindex;
36+
}
37+
return parseInt(ret);
38+
}
39+
40+
function sumArray(array) {
41+
let sum = 0,
42+
index = 0,
43+
length = array.length;
44+
for (; index < length; // The "for"-loop condition
45+
sum += array[index++] // Add number on each iteration
46+
);
47+
return sum;
48+
}
49+
50+
function reset_total() {
51+
let index = 0,
52+
length = total.length;
53+
for (; index < length; total[index++] = 0);
54+
}
55+
56+
function do_total() {
57+
if (!resetpid) {
58+
resetpid = true;
59+
reset_total();
60+
setTimeout(function() {
61+
$("#total_total").text(sumArray(total));
62+
resetpid = false
63+
}, 300);
64+
}
65+
}
66+
67+
$.fn.dataTable.ext.search.push(
68+
function(settings, data, dataIndex) {
69+
do_total();
70+
let num = indexFromName('<?php echo $column; ?>');
71+
total[dataIndex] = parseFloat(data[num].replace(",", "."));
72+
return true;
73+
});
74+
75+
setTimeout(function() {
76+
resetpid = false;
77+
reset_total();
78+
oTable.fnDraw();
79+
}, 900);
80+
</script>

0 commit comments

Comments
 (0)