|
@@ -1,3 +1,27 @@ |
|
1 |
+ |
function openTextareaComment(comment_object) { |
|
2 |
+ |
var comment_content = comment_object.parent().find(".comment-content").html(); |
|
3 |
+ |
comment_object.parent().hide(); //nascondo il corpo del commento |
|
4 |
+ |
|
|
5 |
+ |
htmlToPut = "<div class='comment-textarea-body'>"; |
|
6 |
+ |
htmlToPut += "<textarea class='comment-textarea'>"+comment_content+"</textarea>" |
|
7 |
+ |
htmlToPut += "<div><button value='modifica-2' class='modify-button'>Modifica</button>"; |
|
8 |
+ |
htmlToPut += "<button value='annulla' class='remove-button'>Annulla</button>"; |
|
9 |
+ |
htmlToPut += "</div></div></div>"; |
|
10 |
+ |
|
|
11 |
+ |
comment_object.parent().parent().append(htmlToPut); |
|
12 |
+ |
|
|
13 |
+ |
$(".modify-button[value='modifica-2']").click(function() { |
|
14 |
+ |
var that = $(this); |
|
15 |
+ |
$("#confirm-comment-dialog").data("el", that.closest(".comment")).dialog("open"); |
|
16 |
+ |
}); |
|
17 |
+ |
|
|
18 |
+ |
$(".remove-button[value='annulla']").click(function() { |
|
19 |
+ |
comment_object.parent().show(); |
|
20 |
+ |
$(this).parent().parent().empty(); |
|
21 |
+ |
}) |
|
22 |
+ |
|
|
23 |
+ |
} |
|
24 |
+ |
|
1 |
25 |
|
function fetchComments(local_id, startIndex) { |
2 |
26 |
|
params = { |
3 |
27 |
|
id: local_id, |
|
@@ -23,13 +47,25 @@ |
23 |
47 |
|
//per ora test |
24 |
48 |
|
//$("#comment-list").append(JSON.stringify(data.comments[i])); |
25 |
49 |
|
|
26 |
|
- |
var htmlToPut = "<div id='comment-"+data.comments[i].id+"'>"; |
27 |
|
- |
htmlToPut += "<b>"+data.comments[i].username+"</b> "+data.comments[i].data; |
28 |
|
- |
htmlToPut += "<div id='comment-content'"+data.comments[i].id+"'>"+data.comments[i].descrizione+"</div>" |
|
50 |
+ |
var htmlToPut = "<div comment-id='"+data.comments[i].id+"' class='comment'>"; |
|
51 |
+ |
htmlToPut += "<div class='comment-header'><b>"+data.comments[i].username+"</b> " + data.comments[i].data + "</div>"; |
|
52 |
+ |
htmlToPut += "<div class='comment-body'>"; |
|
53 |
+ |
htmlToPut += "<div id='comment-id-"+data.comments[i].id+"-content' class='comment-content'>"+data.comments[i].descrizione+"</div>" |
|
54 |
+ |
htmlToPut += "<button value='modifica-1' class='modify-button'>Modifica</button>"; |
|
55 |
+ |
htmlToPut += "<button value='rimuovi' class='remove-button'>Rimuovi</button></div>"; |
29 |
56 |
|
htmlToPut += "</div>" |
30 |
57 |
|
|
31 |
58 |
|
$("#comment-list").append(htmlToPut); |
32 |
59 |
|
|
|
60 |
+ |
$("div[comment-id='"+data.comments[i].id+"'] .modify-button[value='modifica-1']").click(function() { |
|
61 |
+ |
openTextareaComment($(this)); |
|
62 |
+ |
}); |
|
63 |
+ |
|
|
64 |
+ |
$("div[comment-id='"+data.comments[i].id+"'] .remove-button[value='rimuovi']").click(function() { |
|
65 |
+ |
var that = $(this); |
|
66 |
+ |
$("#remove-comment-dialog").data("el", that.closest(".comment")).dialog("open"); |
|
67 |
+ |
}); |
|
68 |
+ |
|
33 |
69 |
|
} |
34 |
70 |
|
|
35 |
71 |
|
params = JSON.parse(this.data); |
|
@@ -59,10 +95,16 @@ |
59 |
95 |
|
} |
60 |
96 |
|
|
61 |
97 |
|
function showComments(local_id) { |
62 |
|
- |
$("#comments").show(); |
|
98 |
+ |
if ($("#comments").is(":visible")) { |
|
99 |
+ |
$("#comments").hide(); |
|
100 |
+ |
$("#comments-button").html("Show comments!!!"); |
|
101 |
+ |
} else { |
|
102 |
+ |
$("#comments").show(); |
|
103 |
+ |
$("#comments-button").html("Hide comments!!!"); |
63 |
104 |
|
|
64 |
|
- |
if (isEmpty($("#comment-list"))) { |
65 |
|
- |
fetchComments(local_id, 0); |
|
105 |
+ |
if (isEmpty($("#comment-list"))) { |
|
106 |
+ |
fetchComments(local_id, 0); |
|
107 |
+ |
} |
66 |
108 |
|
} |
67 |
109 |
|
} |
68 |
110 |
|
|
|
@@ -71,38 +113,126 @@ |
71 |
113 |
|
$("#cp_workarea").append(html_data); |
72 |
114 |
|
|
73 |
115 |
|
$("#full_local_info #nomelocale") |
74 |
|
- |
.html(local_data.nomelocale); |
|
116 |
+ |
.html(local_data.nomelocale); |
75 |
117 |
|
$("#full_local_info #username_owner") |
76 |
|
- |
.html(local_data.username_owner); |
|
118 |
+ |
.html(local_data.username_owner); |
77 |
119 |
|
$("#full_local_info #descrizione") |
78 |
|
- |
.html(local_data.descrizione); |
|
120 |
+ |
.html(local_data.descrizione); |
79 |
121 |
|
$("#full_local_info #tipologia") |
80 |
|
- |
.html(local_data.tipologia); |
|
122 |
+ |
.html(local_data.tipologia); |
81 |
123 |
|
$("#full_local_info #lat") |
82 |
|
- |
.html(local_data.lat); |
|
124 |
+ |
.html(local_data.lat); |
83 |
125 |
|
$("#full_local_info #lon") |
84 |
|
- |
.html(local_data.lon); |
|
126 |
+ |
.html(local_data.lon); |
85 |
127 |
|
$("#full_local_info #indirizzo") |
86 |
|
- |
.html(local_data.indirizzo); |
|
128 |
+ |
.html(local_data.indirizzo); |
87 |
129 |
|
$("#full_local_info #email") |
88 |
|
- |
.html(local_data.email); |
|
130 |
+ |
.html(local_data.email); |
89 |
131 |
|
$("#full_local_info #telefono") |
90 |
|
- |
.html(local_data.telefono); |
|
132 |
+ |
.html(local_data.telefono); |
91 |
133 |
|
$("#full_local_info #sito") |
92 |
|
- |
.html(local_data.sito); |
|
134 |
+ |
.html(local_data.sito); |
93 |
135 |
|
$("#full_local_info #n_punti_ricarica") |
94 |
|
- |
.html(local_data.n_punti_ricarica); |
|
136 |
+ |
.html(local_data.n_punti_ricarica); |
95 |
137 |
|
|
96 |
138 |
|
//$("#full_local_info").styleTable(); |
97 |
139 |
|
|
98 |
140 |
|
$("#comments-button").click(function() { |
99 |
|
- |
showComments(local_data.local_id); |
|
141 |
+ |
showComments(local_data.id); |
|
142 |
+ |
}); |
|
143 |
+ |
|
|
144 |
+ |
$("#confirm-comment-dialog").dialog({ |
|
145 |
+ |
autoOpen: false, |
|
146 |
+ |
buttons: [{ |
|
147 |
+ |
text: "Sì", |
|
148 |
+ |
click: function() { |
|
149 |
+ |
var el = $(this).data('el'); |
|
150 |
+ |
$(this).dialog( "close" ); |
|
151 |
+ |
|
|
152 |
+ |
var comment_id = el.attr("comment-id"); |
|
153 |
+ |
var content = el.find("textarea").val(); |
|
154 |
+ |
|
|
155 |
+ |
params = { |
|
156 |
+ |
comment_id: comment_id, |
|
157 |
+ |
content: content, |
|
158 |
+ |
token: Cookies.get("token") |
|
159 |
+ |
}; |
|
160 |
+ |
|
|
161 |
+ |
params = JSON.stringify(params); |
|
162 |
+ |
|
|
163 |
+ |
$.ajax({ |
|
164 |
+ |
url: "../edit_commento.php", |
|
165 |
+ |
data: params, |
|
166 |
+ |
cache: false, |
|
167 |
+ |
contentType: false, |
|
168 |
+ |
processData: false, |
|
169 |
+ |
type: 'POST', |
|
170 |
+ |
success: function(data) { |
|
171 |
+ |
el.find(".comment-textarea-body").remove(); |
|
172 |
+ |
el.find(".comment-body .comment-content").html(data.content); |
|
173 |
+ |
el.find(".comment-body").show(); |
|
174 |
+ |
}, |
|
175 |
+ |
error: function() { |
|
176 |
+ |
alert("Errore nel modificare il commento"); |
|
177 |
+ |
} |
|
178 |
+ |
}); |
|
179 |
+ |
|
|
180 |
+ |
} |
|
181 |
+ |
}, |
|
182 |
+ |
{ |
|
183 |
+ |
text: "No", |
|
184 |
+ |
click: function() { |
|
185 |
+ |
$(this).dialog( "close" ); |
|
186 |
+ |
} |
|
187 |
+ |
}] |
|
188 |
+ |
}); |
|
189 |
+ |
|
|
190 |
+ |
$("#remove-comment-dialog").dialog({ |
|
191 |
+ |
autoOpen: false, |
|
192 |
+ |
buttons: [{ |
|
193 |
+ |
text: "Sì", |
|
194 |
+ |
click: function() { |
|
195 |
+ |
var el = $(this).data('el'); |
|
196 |
+ |
$(this).dialog( "close" ); |
|
197 |
+ |
|
|
198 |
+ |
var comment_id = el.attr("comment-id"); |
|
199 |
+ |
|
|
200 |
+ |
params = { |
|
201 |
+ |
comment_id: comment_id, |
|
202 |
+ |
token: Cookies.get("token") |
|
203 |
+ |
}; |
|
204 |
+ |
|
|
205 |
+ |
params = JSON.stringify(params); |
|
206 |
+ |
|
|
207 |
+ |
$.ajax({ |
|
208 |
+ |
url: "../delete_commento.php", |
|
209 |
+ |
data: params, |
|
210 |
+ |
cache: false, |
|
211 |
+ |
contentType: false, |
|
212 |
+ |
processData: false, |
|
213 |
+ |
type: 'POST', |
|
214 |
+ |
success: function(data) { |
|
215 |
+ |
el.remove(); |
|
216 |
+ |
}, |
|
217 |
+ |
error: function() { |
|
218 |
+ |
alert("Errore nel modificare il commento"); |
|
219 |
+ |
} |
|
220 |
+ |
}); |
|
221 |
+ |
|
|
222 |
+ |
} |
|
223 |
+ |
}, |
|
224 |
+ |
{ |
|
225 |
+ |
text: "No", |
|
226 |
+ |
click: function() { |
|
227 |
+ |
$(this).dialog( "close" ); |
|
228 |
+ |
} |
|
229 |
+ |
}] |
100 |
230 |
|
}); |
101 |
231 |
|
} |
102 |
232 |
|
|
103 |
233 |
|
function showLocalInfo(local_id) { |
104 |
234 |
|
params = { |
105 |
|
- |
local_id: local_id, |
|
235 |
+ |
id: local_id, |
106 |
236 |
|
token: Cookies.get("token") |
107 |
237 |
|
}; |
108 |
238 |
|
|