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
var shelfs_table = null;
function init_datatable() {
return $('#shelfs').DataTable({
data: shelfs, // data passed at page loading
rowId: 'id',
columns:[
{data: "id", title:"id", "visible": false},
{
data:"sort_order",
title:"Numéro",
width: "10%",
className:"dt-body-center"
},
{data:"name", title:"Nom"},
{data:"description", title:"Description", orderable: false},
{
data:"date_last_inventory",
title:"Date dernier inventaire",
render: function (data, type, full, meta) {
// Sort on data, not rendering
if (type == "sort" || type == 'type')
return data;
if (data == '0001-01-01')
return "Ce rayon n'a jamais été inventorié !";
else {
var date = new Date(data);
return date.toLocaleDateString('fr-FR');
}
}
},
{data:"p_nb", title:"Nb réfs", width: "5%", className:"dt-body-center"},
{
title:"",
className:"dt-body-center",
width: "15%",
render: function (data, type, full, meta) {
return "<button class='btn--success do_export_sales_data'>Export Ventes</button>";
}
}
],
dom: 'rtip',
order: [
[
1,
"asc"
]
],
iDisplayLength: 25,
language: {url : '/static/js/datatables/french.json'}
});
}
var getRowData = function(clicked) {
var row = shelfs_table.row(clicked.parents('tr'));
return row.data();
};
function go_to_shelf_view() {
openModal();
var clicked = $(this);
var row_data = getRowData(clicked);
// Use local storage to pass data to next page
if (Modernizr.localstorage) {
var stored_shelf = JSON.parse(localStorage.getItem('shelf_' + row_data.id));
// Set local storage if key doesn't exist
if (stored_shelf == null) {
localStorage.setItem("shelf_" + row_data.id, JSON.stringify(row_data));
}
}
document.location.href = "shelf_view/" + row_data.id;
}
function get_shelfs_sales_data() {
try {
$.ajax({
type: 'GET',
url: '/shelfs/get_shelves_sales_data',
dataType:"json",
traditional: true,
contentType: "application/json; charset=utf-8",
success: function(data) {
for (item of data.res) {
var row_data = shelfs_table.row('#'+item.id).data();
row_data.shelf_value = item.shelf_value;
shelfs_table
.row('#'+item.id)
.data(row_data)
.draw();
}
},
error: function(data) {
if (typeof data.responseJSON != 'undefined') {
console.log(data.responseJSON);
}
}
});
} catch (e) {
err = {msg: e.toString(), ctx: 'get_shelfs_sales_data'};
report_JS_error(err, 'shelfs');
}
}
function export_sales_data(event) {
event.stopImmediatePropagation();
var clicked = $(this);
var row_data = getRowData(clicked);
console.log(row_data);
}
$(document).ready(function() {
shelfs_table = init_datatable();
$('#shelfs').on('click', 'button.do_export_sales_data', export_sales_data);
$('#shelfs').on('click', 'tbody td', go_to_shelf_view);
// Search input
$('#search_input').on('keyup', function () {
shelfs_table
.search(jQuery.fn.DataTable.ext.type.search.string(this.value))
.draw();
});
});