Add edit form for the location.

This commit is contained in:
Tim Schumacher 2014-09-24 23:26:49 +02:00
parent 1b3fc58d44
commit 9227016086
3 changed files with 245 additions and 5 deletions

View file

@ -118,4 +118,73 @@ class LocationController extends Controller
); );
} }
} }
/**
* Finds and displays a Event entity.
*
* @Route("/{slug}/bearbeiten", name="location_edit")
* @Method("GET")
* @Template()
*/
public function editAction($slug)
{
/** @var EntityManager $em */
$em = $this->getDoctrine()->getManager();
/** @var EntityRepository $repo */
$repo = $em->getRepository('CalciferBundle:Location');
/** @var Location $location */
$location = $repo->findOneBy(['slug' => $slug]);
if (!$location) {
throw $this->createNotFoundException('Unable to find Location entity.');
}
return [
'entity' => $location
];
}
/**
* Finds and displays a Event entity.
*
* @Route("/{slug}/bearbeiten", name="location_update")
* @Method("POST")
*/
public function updateAction(Request $request, $slug) {
/** @var EntityManager $em */
$em = $this->getDoctrine()->getManager();
/** @var EntityRepository $repo */
$repo = $em->getRepository('CalciferBundle:Location');
/** @var Location $location */
$location = $repo->findOneBy(['slug' => $slug]);
if (!$location) {
throw $this->createNotFoundException('Unable to find Location entity.');
}
if ($location->name != $request->get('name')) {
$location->name = $request->get('name');
$location->slug = $location->generateSlug($location->name,$em);
}
$location->streetaddress = $request->get('streetaddress');
$location->streetnumber = $request->get('streetnumber');
$location->zipcode = $request->get('zipcode');
$location->city = $request->get('city');
$latlon = $request->get('geocords');
$latlon = explode(',',$latlon);
if (count($latlon) == 2) {
$location->lat = $latlon[0];
$location->lon = $latlon[1];
}
$em->persist($location);
$em->flush();
return $this->redirect($this->generateUrl('location_show', array('slug' => $location->slug)));
}
} }

View file

@ -44,4 +44,9 @@ form .ui.form {
#map { #map {
height: 20rem; height: 20rem;
.location-edit {
text-decoration: none;
}
} }

View file

@ -0,0 +1,166 @@
{% extends 'CalciferBundle::layout.html.twig' %}
{% block css %}
{% stylesheets filter="compass"
"@CalciferBundle/Resources/assets/css/jquery.datetimepicker.scss"
"@CalciferBundle/Resources/assets/css/events.scss"
"@CalciferBundle/Resources/assets/css/leaflet.scss" %}
<link rel="stylesheet" href="{{ asset_url }}"/>
{% endstylesheets %}
{% endblock %}
{% block javascripts %}
{% javascripts
"@CalciferBundle/Resources/assets/js/jquery.datetimepicker.js"
"@CalciferBundle/Resources/assets/js/events.js"
"@CalciferBundle/Resources/assets/js/leaflet.js" %}
<script src="{{ asset_url }}"></script>
{% endjavascripts %}
{% endblock %}
{% block body -%}
<div class="ui one column page grid">
<div class="ui column">
<h1>Termin bearbeiten</h1>
</div>
</div>
<div class="ui one column page grid">
<div class="ui column">
<form method="post"
action="{{ path('location_update',{'slug':entity.slug}) }}">
<div class="ui form segment">
<div class="field">
<label class="" for="location-name">Name</label>
<div class="ui left labeled input">
<input type="text"
id="location-name"
name="name"
value="{{ entity.name|default('') }}"
required="required"
maxlength="255"
class="form-control">
<div class="ui corner label">
<i class="icon asterisk"></i>
</div>
</div>
</div>
<div class="field">
<label class="control-label required" for="location-description">Beschreibung</label>
<div class="ui left labeled icon input attached-label">
<textarea id="location-description" name="description">{{ entity.description|default('') }}</textarea>
<div class="ui bottom attached label">Du kannst hier <a
href="https://en.wikipedia.org/wiki/Markdown">Markdown</a> benutzen.
</div>
</div>
</div>
<div class="field">
<label class="" for="location-streetaddress">Straße</label>
<div class="ui left labeled input">
<input type="text"
id="location-streetaddress"
name="streetaddress"
value="{{ entity.streetaddress|default('') }}"
required="required"
maxlength="255"
class="form-control">
</div>
</div>
<div class="field">
<label class="" for="location-streetnumber">Hausnummer</label>
<div class="ui left labeled input">
<input type="text"
id="location-streetnumber"
name="streetnumber"
value="{{ entity.streetnumber|default('') }}"
required="required"
maxlength="255"
class="form-control">
</div>
</div>
<div class="field">
<label class="" for="location-zipcode">Postleitzahl</label>
<div class="ui left labeled input">
<input type="text"
id="location-zipcode"
name="zipcode"
value="{{ entity.zipcode|default('') }}"
required="required"
maxlength="255"
class="form-control">
</div>
</div>
<div class="field">
<label class="" for="location-city">Ort</label>
<div class="ui left labeled input">
<input type="text"
id="location-city"
name="city"
value="{{ entity.city|default('') }}"
required="required"
maxlength="255"
class="form-control">
</div>
</div>
<div class="field">
<label class="control-label required" for="location-geocords">Geokoordinaten</label>
<div class="ui left labeled icon input attached-{% if entity.location.lat|default(0) > 0 %}geo-{% endif %}label">
<input type="text"
id="location-geocords"
name="geocords"
maxlength="255"
value="{{ entity.lat|default('0') }},{{ entity.lon|default('0') }}"
class="form-control">
<i class="icon map marker"></i>
<div class="ui bottom attached label">
Gebe entweder Breitengrad und Längengrad (Mit Punkten!) kommasepariert ein oder <a href="#" class="add_geo">wähle einen Punkt auf der Karte aus</a>.
</div>
<div class="ui modal geo chooser">
<i class="close icon"></i>
<div class="header">
Wähle einen Punkt auf der Karte
</div>
<div class="content">
<div id="map"></div>
</div>
<div class="actions">
<div class="ui button cancel">
Cancel
</div>
<div class="ui button ok">
Okay
</div>
</div>
</div>
</div>
</div>
<input type="submit" class="ui button blue" value="Speichern"/>
</div>
</form>
</div>
</div>
{% endblock %}