Commit c5423218 authored by Hermann Mayer's avatar Hermann Mayer

Implemented Sidebar Controller Backend (create/update). JityTwig Extension got…

Implemented Sidebar Controller Backend (create/update). JityTwig Extension got now error handling. Page views now splited out usability features to share between new and edit. Fixed Section handling on Page views.
parent 91265299
......@@ -181,8 +181,8 @@ class CategoryController extends Controller
$form->bind($request);
if ($form->isValid()) {
$em = $this->getDoctrine()->getEntityManager();
$entity = $em->getRepository('JityHomepageBundle:Category')->find($id);
$em = $this->getDoctrine()->getEntityManager();
$entity = $em->getRepository('JityHomepageBundle:Category')->find($id);
$defaultEntity = $em->getRepository('JityHomepageBundle:Category')->findOneByName('Default');
if (!$entity || !$defaultEntity) {
......@@ -196,7 +196,7 @@ class CategoryController extends Controller
}
// Update all used Pages
$entity->replaceCategoryOnPages($defaultEntity);
$entity->replaceOnPages($defaultEntity);
$em->remove($entity);
$em->flush();
......
......@@ -176,13 +176,23 @@ class SidebarController extends Controller
$form->bind($request);
if ($form->isValid()) {
$em = $this->getDoctrine()->getManager();
$entity = $em->getRepository('JityHomepageBundle:Sidebar')->find($id);
$em = $this->getDoctrine()->getManager();
$entity = $em->getRepository('JityHomepageBundle:Sidebar')->find($id);
$defaultEntity = $em->getRepository('JityHomepageBundle:Sidebar')->findOneByName('Default');
if (!$entity) {
throw $this->createNotFoundException('Unable to find Sidebar entity.');
}
if ('Default' == $entity->getName()) {
$this->get('session')->setFlash('error', 'Der Default Eintrag kann nicht gelöscht werden.');
return $this->redirect($this->generateUrl('author_sidebar_edit', array('id' => $id)));
}
// Update all used Pages
$entity->replaceOnPages($defaultEntity);
$em->remove($entity);
$em->flush();
}
......
......@@ -96,7 +96,7 @@ class Category
*
* @return void
*/
public function replaceCategoryOnPages(\Jity\HomepageBundle\Entity\Category $category)
public function replaceOnPages(\Jity\HomepageBundle\Entity\Category $category)
{
foreach ($this->pages as $page) {
$page->setCategory($category);
......@@ -112,4 +112,4 @@ class Category
{
$this->pages->removeElement($pages);
}
}
\ No newline at end of file
}
......@@ -40,7 +40,8 @@ class Section
* @ORM\OneToMany(
* targetEntity="SidebarSection",
* mappedBy="section",
* cascade={"persist", "remove"}
* cascade={"persist", "remove"},
* orphanRemoval=true
* )
* @Exclude
*/
......@@ -161,7 +162,8 @@ class Section
// Iterate over all join entities to find the correct
foreach ($this->sidebarSection as $rel) {
if ($rel->getSidebar() === $sidebar) {
$rel->removeElement($sidebar);
$this->sidebarSection->removeElement($rel);
$rel->getSidebar()->removeSection($this);
}
}
}
......
......@@ -26,7 +26,8 @@ class Sidebar
* @ORM\OneToMany(
* targetEntity="SidebarSection",
* mappedBy="sidebar",
* cascade={"persist", "remove"}
* cascade={"persist", "remove"},
* orphanRemoval=true
* )
* @ORM\OrderBy({"position" = "ASC"})
*/
......@@ -119,7 +120,8 @@ class Sidebar
// Iterate over all join entities to find the correct
foreach ($this->sidebarSection as $rel) {
if ($rel->getSection() === $section) {
$rel->removeElement($section);
$this->sidebarSection->removeElement($rel);
$rel->getSection()->removeSidebar($this);
}
}
}
......@@ -172,5 +174,17 @@ class Sidebar
{
return $this->pages;
}
/**
* Replace this Category on all Pages which use this Category
*
* @return void
*/
public function replaceOnPages(\Jity\HomepageBundle\Entity\Sidebar $sidebar)
{
foreach ($this->pages as $page) {
$page->setSidebar($sidebar);
}
}
}
......@@ -24,13 +24,21 @@ class SidebarSection
/**
* @Gedmo\SortableGroup
* @ORM\ManyToOne(targetEntity="Sidebar", inversedBy="sidebarSection")
* @ORM\ManyToOne(
* targetEntity="Sidebar",
* inversedBy="sidebarSection",
* cascade={"persist"}
* )
* @ORM\JoinColumn(name="sidebar_id", referencedColumnName="id", nullable=false)
**/
protected $sidebar;
/**
* @ORM\ManyToOne(targetEntity="Section", inversedBy="sidebarSection")
* @ORM\ManyToOne(
* targetEntity="Section",
* inversedBy="sidebarSection",
* cascade={"persist"}
* )
* @ORM\JoinColumn(name="section_id", referencedColumnName="id", nullable=false)
**/
protected $section;
......
......@@ -2,13 +2,27 @@
{% block base_content %}
{% set sectionsAmount = 0 %}
{% if page is defined and page.sidebar.sections is defined %}
{% set sections = (page.sidebar.sections.isEmpty()) ? false : true %}
{% if sections %}
{% for section in page.sidebar.sections %}
{% if (section.group) and is_granted(section.group.role) %}
{% set sectionsAmount = sectionsAmount + 1 %}
{% endif %}
{% endfor %}
{% endif %}
{% else %}
{% set sections = false %}
{% endif %}
{% if sections %}
{% if sections and sectionsAmount > 0 %}
<div class="span8">
{% else %}
<div class="span12">
......@@ -20,7 +34,7 @@
{% block layout_content %}{% endblock %}
</div>
{% if sections %}
{% if sections and sectionsAmount > 0 %}
<div id="sidebar" class="span4">
<div id="sidebar-wrapper">
{% block sidebar %}{% endblock %}
......
......@@ -14,12 +14,6 @@
{% if (not section.group) or (access) %}
{#
{% if (loop.first != true) %}
<!-- <hr> -->
{% endif %}
#}
<legend>{{ section.title }}</legend>
{{ eval(section.content)|raw }}
......
......@@ -108,7 +108,7 @@
// Replace '__name__' in the prototype's HTML to
// instead be a number based on the current collection's length.
var el = $(
prototype.replace(/__name__/g, coll.children().length)
prototype.replace(/__name__/g, coll.children('.sortable').length)
);
// If we got attr data for our prototype
......@@ -134,6 +134,10 @@
// Add new element to the top of the collection
el.prependTo(coll).hide().slideDown();
// Reorder elements after adding, fixes the order even if we
// never sorted some elements (Adding to the top of a list needs this)
this.reorderWidgetsNames();
},
initSortable: function() {
......
......@@ -39,33 +39,7 @@
{{ form_widget(delete_form) }}
</form>
{% render 'JityHomepageBundle:Editor:build' with {'syncElement': 'textarea[name="jity_homepagebundle_pagetype[content]"]'} %}
{% render 'JityHomepageBundle:Editor:icons' with {'syncElement': 'input[name="jity_homepagebundle_pagetype[icon]"]'} %}
<a name="preview"></a>
<div id="previewCage"></div>
<script type="text/javascript">
$(document).ready(function() {
$('#previewBtn').click(function (){
$.post(
'{{ path('editor_format') }}',
{text: $('#jity_homepagebundle_pagetype_content').val()},
function(data) {
$('#previewCage').html(data).css('display', 'block');
prettyPrint();
$('html,body').animate({scrollTop: $("a[name=preview]").offset().top},'slow');
});
return false;
});
});
</script>
{% include 'JityHomepageBundle:Page:usability.html.twig' %}
{% endblock %}
......@@ -31,33 +31,7 @@
</form>
{% render 'JityHomepageBundle:Editor:build' with {'syncElement': 'textarea[name="jity_homepagebundle_pagetype[content]"]'} %}
{% render 'JityHomepageBundle:Editor:icons' with {'syncElement': 'input[name="jity_homepagebundle_pagetype[icon]"]'} %}
<a name="preview"></a>
<div id="previewCage"></div>
<script type="text/javascript">
$(document).ready(function() {
$('#previewBtn').click(function (){
$.post(
'{{ path('editor_format') }}',
{text: $('#jity_homepagebundle_pagetype_content').val()},
function(data) {
$('#previewCage').html(data).css('display', 'block');
prettyPrint();
$('html,body').animate({scrollTop: $("a[name=preview]").offset().top},'slow');
});
return false;
});
});
</script>
{% include 'JityHomepageBundle:Page:usability.html.twig' %}
{% endblock %}
{% render 'JityHomepageBundle:Editor:build' with {'syncElement': 'textarea[name="jity_homepagebundle_pagetype[content]"]'} %}
{% render 'JityHomepageBundle:Editor:icons' with {'syncElement': 'input[name="jity_homepagebundle_pagetype[icon]"]'} %}
<a name="preview"></a>
<div id="previewCage"></div>
<script>
$(document).ready(function() {
$('#previewBtn').click(function (){
$.post(
'{{ path('editor_format') }}',
{text: $('textarea[id="jity_homepagebundle_pagetype_content"]').val()},
function(data) {
$('#previewCage').html(data).css('display', 'block');
prettyPrint();
$('html,body').animate({scrollTop: $("a[name=preview]").offset().top},'slow');
});
return false;
});
});
</script>
......@@ -4,7 +4,7 @@
{% block layout_content %}
<form novalidate action="{{ path('author_page_update', { 'id': entity.id }) }}" method="post" {{ form_enctype(edit_form) }} class="form-horizontal hero-unit">
<form novalidate action="{{ path('author_sidebar_update', { 'id': entity.id }) }}" method="post" {{ form_enctype(edit_form) }} class="form-horizontal hero-unit">
<legend>Sidebar bearbeiten</legend>
......
......@@ -8,7 +8,7 @@
<a href="{{ path('author_sidebar_new') }}" class="btn btn-danger">
<i class="icon-asterisk icon-white"></i>
Neue Seite erstellen
Neue Sidebar erstellen
</a>
</div>
......
<h1>Sidebar</h1>
<table class="record_properties">
<tbody>
<tr>
<th>Id</th>
<td>{{ entity.id }}</td>
</tr>
<tr>
<th>Name</th>
<td>{{ entity.name }}</td>
</tr>
</tbody>
</table>
<ul class="record_actions">
<li>
<a href="{{ path('author_sidebar') }}">
Back to the list
</a>
</li>
<li>
<a href="{{ path('author_sidebar_edit', { 'id': entity.id }) }}">
Edit
</a>
</li>
<li>
{% extends 'JityHomepageBundle:Default:layout.html.twig' %}
{% block layout_content %}
<div class="hero-unit">
<legend>Details der Sidebar</legend>
<form action="{{ path('author_sidebar_delete', { 'id': entity.id }) }}" method="post">
{{ form_widget(delete_form) }}
<button type="submit">Delete</button>
<a href="{{ path('author_sidebar') }}" class="btn btn-danger">
<i class="icon-share-alt icon-white"></i>
Zurück zur Liste
</a>
<a href="{{ path('author_sidebar_edit', { 'id': entity.id }) }}" class="btn btn-danger">
<i class="icon-edit icon-white"></i>
Bearbeiten
</a>
<button type="submit" class="btn btn-danger">
<i class="icon-remove icon-white"></i>
Löschen
</button>
</form>
</li>
</ul>
</div>
<table class="table table-striped">
<tbody>
<tr>
<th>Id</th>
<td>{{ entity.id }}</td>
</tr>
<tr>
<th>Name</th>
<td>{{ entity.name }}</td>
</tr>
</tbody>
</table>
<table class="table table-striped">
<tbody>
<tr>
<th>
Verbundene Sektionen
</th>
<th>
Sichtbar für
</th>
<th>
Inhalt
</th>
</tr>
{% for section in entity.sections %}
<tr>
<th>
{{ section.title }}
</th>
<td>
{% if (section.group) %}
{{ section.group.name }}
{% else %}
Jeden
{% endif %}
</td>
<td>
{{ eval(section.content)|raw }}
</td>
</tr>
{% endfor %}
</tbody>
</table>
{% endblock %}
......@@ -59,8 +59,15 @@ class JityExtension extends Twig_Extension
$loader = new Twig_Loader_String();
$env->setLoader($loader);
// Render the String
$result = $env->loadTemplate($string)->render($context);
try {
// Render the String
$result = $env->loadTemplate($string)->render($context);
} catch (\Exception $e) {
return $string;
}
// Switch back to the saved loader
$env->setLoader($loaderCopy);
......
Markdown is supported
0% or
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment