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
|
function fetchComments(local_id, startIndex) {
params = {
id: local_id,
startIndex: startIndex,
length: 10,
token: Cookies.get("token")
};
params = JSON.stringify(params);
$.ajax({
url: "../get_commenti.php",
data: params,
cache: false,
contentType: false,
processData: false,
type: 'POST',
success: function(data) {
if (data.comments) {
if (data.comments.length > 0) {
for (var i = 0; data.comments.length; i++) {
//per ora test
$("#comment-list").append(data.comments[i]);
}
params = JSON.parse(this.params);
if (data.count < params.startIndex+10) {
$("#more-comments-button").hide();
} else {
$("#more-comments-button").click(function() {
fetchComments(local_id, startIndex+10);
});
$("#more-comments-button").show();
}
} else {
$("#comment-list").html("Non ci sono commenti al locale.");
}
} else {
alert("Errore nel caricare i commenti");
}
},
error: function() {
alert("Errore nel caricare i commenti");
}
});
}
function showComments(local_id) {
$("#comments").show();
if (isEmpty($("#comment-list"))) {
fetchComments(local_id, 0);
}
}
function loadLocalInfo(html_data, local_data) {
$("#cp_workarea").empty();
$("#cp_workarea").append(html_data);
$("#full_local_info #nomelocale")
.html(local_data.nomelocale);
$("#full_local_info #username_owner")
.html(local_data.username_owner);
$("#full_local_info #descrizione")
.html(local_data.descrizione);
$("#full_local_info #tipologia")
.html(local_data.tipologia);
$("#full_local_info #lat")
.html(local_data.lat);
$("#full_local_info #lon")
.html(local_data.lon);
$("#full_local_info #indirizzo")
.html(local_data.indirizzo);
$("#full_local_info #email")
.html(local_data.email);
$("#full_local_info #telefono")
.html(local_data.telefono);
$("#full_local_info #sito")
.html(local_data.sito);
$("#full_local_info #n_punti_ricarica")
.html(local_data.n_punti_ricarica);
//$("#full_local_info").styleTable();
$("#comments-button").click(function() {
showComments(local_data.local_id);
});
}
function showLocalInfo(local_id) {
params = {
local_id: local_id,
token: Cookies.get("token")
};
params = JSON.stringify(params);
$.ajax({
url: "../get_info_full_locale.php",
data: params,
cache: false,
contentType: false,
processData: false,
type: 'POST',
success: function(local_data) {
getHtmlPage("./skeletons/full_local_info.html", function(html_data) {
loadLocalInfo(html_data, local_data);
});
},
error: function() {
alert("Errore nel caricare le info del locale");
}
});
}
function showLocalTable(data) {
$("#cp_workarea").append(data);
var localTable = $('#dt_locallist').DataTable( {
"processing": true,
"serverSide": true,
"ajax": "dt_locallist.php",
"columns": [
{ "data": "nomelocale" },
{ "data": "descrizione" },
{ "data": "tipologia" },
{ "data": "indirizzo" },
{ "data": "email" },
{ "data": "telefono" },
{ "data": "sito" },
{ "data": "n_punti_ricarica" },
{
"data": function(row) {
return "<button value='modifica'>Modifica</button>"
}
}
]
} );
$('#dt_locallist').on( 'click', 'button', function () {
var data = localTable.row( $(this).parents('tr') ).data();
var value = $(this).attr("value");
var local_id = $(this).parents('tr').attr("id").replace("row_", "");
showLocalInfo(local_id);
} );
}
function showLocalList() {
$("#cp_workarea").empty();
getHtmlPage("./skeletons/locallist.html", showLocalTable);
}
|