Commit dbd51a4c by Antti Jaakkola Committed by Tuomas Riihimäki

Reserve places using REST directly.

1 parent 1592d6eb
...@@ -18,7 +18,7 @@ ...@@ -18,7 +18,7 @@
</f:metadata> </f:metadata>
<ui:param name="thispage" value="page.place.placemap" /> <ui:param name="thispage" value="page.place.placemap" />
<ui:define name="content"> <ui:define name="content">
<p:growl widgetVar="g" />
<h:form> <h:form>
<!-- update=":fbdiag" --> <!-- update=":fbdiag" -->
<p:remoteCommand name="placeClicker" <p:remoteCommand name="placeClicker"
...@@ -46,7 +46,8 @@ ...@@ -46,7 +46,8 @@
map_id : #{ajaxMapView.map.id}, map_id : #{ajaxMapView.map.id},
onclick : function(d) { onclick : function(d) {
return placeClicker([{name: 'placeId', value: d.id}]); return placeClicker([{name: 'placeId', value: d.id}]);
} },
locale: "#{sessionHandler.locale}"
}); });
</script> </script>
</ui:define> </ui:define>
......
...@@ -38,10 +38,28 @@ function placemap(opts) ...@@ -38,10 +38,28 @@ function placemap(opts)
moyaurl: opts.moyaurl, moyaurl: opts.moyaurl,
map_id: opts.map_id, map_id: opts.map_id,
onclick: opts.onclick, onclick: opts.onclick,
clicked_place: undefined clicked_place: undefined,
locale: opts.locale || 'fi'
}; };
if (px.locale == "und") px.locale == "fi";
px.locales = {};
px.locales['fi'] = {
cannot_reserve: "Ei voitu varata paikkaa",
cannot_release: "Ei voitu vapauttaa paikkaa",
success_reserve: "Varattu paikka",
success_release: "Vapautettu paikka"
};
px.locales['en'] = {
cannot_reserve: "Can't reserve place",
cannot_release: "Can't release place",
success_reserve: "Place reserved",
success_release: "Place released"
};
var guide_layer = map_layer = px.element.append("g").attr("id", "guides"); var guide_layer = map_layer = px.element.append("g").attr("id", "guides");
// Create background // Create background
var background = px.element.append("rect") var background = px.element.append("rect")
...@@ -92,7 +110,7 @@ function placemap(opts) ...@@ -92,7 +110,7 @@ function placemap(opts)
.attr('x2', x2) .attr('x2', x2)
.attr('y2', y2) .attr('y2', y2)
.attr("stroke-width", 1) .attr("stroke-width", 1)
.attr("stroke", "#666") .attr("stroke", "#666");
if (fade == true) if (fade == true)
{ {
guide.transition() guide.transition()
...@@ -174,8 +192,6 @@ function placemap(opts) ...@@ -174,8 +192,6 @@ function placemap(opts)
} }
function show_tooltip(d, i) { function show_tooltip(d, i) {
var object = { var object = {
x: d3.select(this).attr('x'), x: d3.select(this).attr('x'),
...@@ -206,9 +222,11 @@ function placemap(opts) ...@@ -206,9 +222,11 @@ function placemap(opts)
px.clicked_place = data.id; px.clicked_place = data.id;
px.onclick(data); //px.onclick(data);
px.toggle_place(data);
px.update_place(data.id); //px.update_place(data.id);
//if ( != true) return; //if ( != true) return;
...@@ -338,6 +356,44 @@ function placemap(opts) ...@@ -338,6 +356,44 @@ function placemap(opts)
}); });
}; };
px.toggle_place = function(place) {
if (place !== undefined )
{
d3.xhr(px.moyaurl + "/rest/placemap/v1/place/" + place.id)
.header("Content-Type", "application/json")
.post(
JSON.stringify({}),
function(err, rawData){
console.log(rawData);
var data = JSON.parse(rawData.response);
draw_places(data.places);
console.log(data.places[0]);
if (data.places[0].state == place.state)
{
if ( place.state == "F") PF("g").show([{"summary":px.locales[px.locale].cannot_reserve,
"detail":"",
"severity":"warn"}]);
if ( place.state == "T") PF("g").show([{"summary":px.locales[px.locale].cannot_release,
"detail":"",
"severity":"warn"}]);
}
else if (data.places[0].state == "T")
{
PF("g").show([{"summary":px.locales[px.locale].success_reserve,
"detail":"",
"severity":"info"}]);
}
else if (data.places[0].state == "F")
{
PF("g").show([{"summary":px.locales[px.locale].success_release,
"detail":"",
"severity":"info"}]);
}
}
);
}
};
px.update_place = function (place_id) px.update_place = function (place_id)
{ {
if (place_id === undefined) place_id = px.clicked_place; if (place_id === undefined) place_id = px.clicked_place;
......
...@@ -106,6 +106,7 @@ public class PlacemapRestViewV1 { ...@@ -106,6 +106,7 @@ public class PlacemapRestViewV1 {
{ {
placebean.reservePlace(p, eventuser.getSelectedUser()); placebean.reservePlace(p, eventuser.getSelectedUser());
} }
p = placebean.find(placeId);
List <Place> thisplace = new ArrayList<Place>(); List <Place> thisplace = new ArrayList<Place>();
thisplace.add(p); thisplace.add(p);
return SimplePlacelistRoot.wrap(thisplace, eventuser.getSelectedUser()); return SimplePlacelistRoot.wrap(thisplace, eventuser.getSelectedUser());
......
Markdown is supported
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!