News sidebar is now ajax-based, and hidden by default
Signed-off-by: Gergely Polonkai <polesz@w00d5t0ck.info>
This commit is contained in:
parent
3701840045
commit
feda5d7d57
38
src/KekRozsak/FrontBundle/Controller/NewsController.php
Normal file
38
src/KekRozsak/FrontBundle/Controller/NewsController.php
Normal file
@ -0,0 +1,38 @@
|
||||
<?php
|
||||
|
||||
namespace KekRozsak\FrontBundle\Controller;
|
||||
|
||||
use Symfony\Bundle\FrameworkBundle\Controller\Controller;
|
||||
use Sensio\Bundle\FrameworkExtraBundle\Configuration\Route;
|
||||
use Sensio\Bundle\FrameworkExtraBundle\Configuration\Template;
|
||||
use Sensio\Bundle\FrameworkExtraBundle\Configuration\ParamConverter;
|
||||
|
||||
/**
|
||||
* Description of NewsController
|
||||
*
|
||||
* @author polesz
|
||||
*/
|
||||
class NewsController extends Controller
|
||||
{
|
||||
/**
|
||||
* @Route("/newsSideList.html", name="KekRozsakFrontBundle_newsSideList", options={"expose": true})
|
||||
* @Template()
|
||||
*/
|
||||
public function sideListAction()
|
||||
{
|
||||
$newsRepo = $this->getDoctrine()->getRepository('KekRozsakFrontBundle:News');
|
||||
$searchCriteria = array();
|
||||
if (
|
||||
!is_object($this->get('security.context')->getToken())
|
||||
|| !is_object($this->get('security.context')->getToken()->getUser())
|
||||
) {
|
||||
$searchCriteria['public'] = true;
|
||||
}
|
||||
|
||||
$news = $newsRepo->findBy($searchCriteria, array('createdAt' => 'DESC'), 4);
|
||||
|
||||
return array(
|
||||
'news' => $news,
|
||||
);
|
||||
}
|
||||
}
|
@ -2,11 +2,6 @@
|
||||
|
||||
<container xmlns="http://symfony.com/schema/dic/services" xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance" xsi:schemaLocation="http://symfony.com/schema/dic/services http://symfony.com/schema/dic/services/services-1.0.xsd">
|
||||
<services>
|
||||
<service id="kek_rozsak_front.twig_extension.news" class="KekRozsak\FrontBundle\Twig\NewsExtension">
|
||||
<argument type="service" id="doctrine" />
|
||||
<argument type="service" id="security.context" />
|
||||
<tag name="twig.extension" />
|
||||
</service>
|
||||
<service id="kek_rozsak_front.twig_extension.events" class="KekRozsak\FrontBundle\Twig\EventsExtension">
|
||||
<argument type="service" id="doctrine" />
|
||||
<argument type="service" id="security.context" />
|
||||
|
@ -34,6 +34,7 @@ a {
|
||||
color: #c4d3ff;
|
||||
height: 32px;
|
||||
border-bottom: 1px solid #1b3586;
|
||||
z-index: 200;
|
||||
}
|
||||
|
||||
#top-line-padding {
|
||||
@ -69,6 +70,7 @@ a {
|
||||
color: #c4d3ff;
|
||||
height: 32px;
|
||||
border-top: 1px solid #1b3586;
|
||||
z-index: 200;
|
||||
}
|
||||
|
||||
#wrapper {
|
||||
@ -94,7 +96,7 @@ a {
|
||||
#content-outline {
|
||||
color: #3366ff;
|
||||
text-align: justify;
|
||||
width: 740px;
|
||||
width: 955px;
|
||||
float: left;
|
||||
background-color: #c6ecfe;
|
||||
}
|
||||
@ -103,10 +105,30 @@ a {
|
||||
padding: 5px;
|
||||
}
|
||||
|
||||
#news-button {
|
||||
position: relative;
|
||||
top: 7px;
|
||||
background-image: url('../images/news-button.png');
|
||||
width: 20px;
|
||||
height: 57px;
|
||||
left: 955px;
|
||||
z-index: 150;
|
||||
cursor: pointer;
|
||||
}
|
||||
|
||||
#news-close-button {
|
||||
background-image: url('../images/no.png');
|
||||
width: 16px;
|
||||
height: 16px;
|
||||
float: right;
|
||||
cursor: pointer;
|
||||
}
|
||||
|
||||
#hirek {
|
||||
float: right;
|
||||
color: #aaaacc;
|
||||
width: 215px;
|
||||
display: none;
|
||||
}
|
||||
|
||||
#hirek h3 {
|
||||
@ -173,3 +195,8 @@ h3 a {
|
||||
.gomb a {
|
||||
color: inherit !important;
|
||||
}
|
||||
|
||||
.clear {
|
||||
clear: both;
|
||||
float: none;
|
||||
}
|
Binary file not shown.
After Width: | Height: | Size: 888 B |
@ -77,18 +77,11 @@
|
||||
</div>
|
||||
</div>
|
||||
<div id="hirek">
|
||||
<div id="news-close-button"></div><br class="clear" />
|
||||
<h3>Hírek</h3>
|
||||
{% for news in recentNews %}
|
||||
<div class="hir">
|
||||
<p class="hir-cim">{{ news.title }}</p>
|
||||
<p class="hir-szoveg">{{ news.text|raw }}</p>
|
||||
{% if app.user %}
|
||||
<p class="hir-szerzo">{{ news.createdBy|userdataspan }}</p>
|
||||
{% endif %}
|
||||
<p class="hir-datum">{{ news.createdAt|date('Y-m-d H:i') }}</p>
|
||||
</div>
|
||||
{% endfor %}
|
||||
<div id="news-list">Betöltés...</div>
|
||||
</div>
|
||||
<div id="news-button"></div>
|
||||
</div>{# div#content-wrapper #}
|
||||
</div>{# div#wrapper #}
|
||||
<div id="bottom-line-wrapper">
|
||||
@ -178,20 +171,53 @@
|
||||
});
|
||||
}
|
||||
|
||||
$(document).ready(function() {
|
||||
function resizeBoxes()
|
||||
{
|
||||
bottomLineTop = $('#bottom-line').position().top;
|
||||
contentOutlineTop = $('#content-outline').position().top;
|
||||
contentHeight = $('#content-outline').outerHeight();
|
||||
newsHeight = $('#hirek').outerHeight();
|
||||
minHeight = bottomLineTop - contentOutlineTop;
|
||||
// TODO: Resize content to its original small size if news is
|
||||
// hidden
|
||||
|
||||
height = Math.max(contentHeight, newsHeight, minHeight);
|
||||
if ($('#content-outline').outerHeight() < height) {
|
||||
$('#content-outline').css('height', height + 'px');
|
||||
}
|
||||
if ($('#hirek').outerHeight() < height) {
|
||||
if ($('#hirek').is(':visible') && ($('#hirek').outerHeight() < height)) {
|
||||
$('#hirek').css('height', height + 'px');
|
||||
}
|
||||
}
|
||||
|
||||
$(document).ready(function() {
|
||||
resizeBoxes();
|
||||
|
||||
$('#news-button').click(function() {
|
||||
$('#news-button').hide();
|
||||
$('#content-outline').css('width', '740px');
|
||||
$('#hirek').show();
|
||||
$('#news-list').html('Betöltés...');
|
||||
|
||||
$.ajax({
|
||||
method: 'GET',
|
||||
url: Routing.generate('KekRozsakFrontBundle_newsSideList')
|
||||
}).done(function(data) {
|
||||
$('#news-list').html(data);
|
||||
resizeBoxes();
|
||||
}).error(function() {
|
||||
$('#news-list').html('Nem sikerült betölteni a híreket!');
|
||||
resizeBoxes();
|
||||
});
|
||||
});
|
||||
|
||||
$('#news-close-button').click(function() {
|
||||
$('#hirek').html('');
|
||||
$('#hirek').hide();
|
||||
$('#content-outline').css('width', '955px');
|
||||
$('#news-button').show();
|
||||
resizeBoxes();
|
||||
});
|
||||
});
|
||||
</script>
|
||||
{% block bottomscripts %}{% endblock %}
|
||||
|
@ -0,0 +1,10 @@
|
||||
{% for news in recentNews %}
|
||||
<div class="hir">
|
||||
<p class="hir-cim">{{ news.title }}</p>
|
||||
<p class="hir-szoveg">{{ news.text|raw }}</p>
|
||||
{% if app.user %}
|
||||
<p class="hir-szerzo">{{ news.createdBy|userdataspan }}</p>
|
||||
{% endif %}
|
||||
<p class="hir-datum">{{ news.createdAt|date('Y-m-d H:i') }}</p>
|
||||
</div>
|
||||
{% endfor %}
|
@ -1,38 +0,0 @@
|
||||
<?php
|
||||
|
||||
namespace KekRozsak\FrontBundle\Twig;
|
||||
|
||||
use Symfony\Bridge\Doctrine\RegistryInterface;
|
||||
use Symfony\Component\Security\Core\SecurityContextInterface;
|
||||
|
||||
class NewsExtension extends \Twig_Extension
|
||||
{
|
||||
protected $_doctrine;
|
||||
protected $_securityContext;
|
||||
|
||||
public function __construct(RegistryInterface $doctrine, SecurityContextInterface $securityContext)
|
||||
{
|
||||
$this->_doctrine = $doctrine;
|
||||
$this->_securityContext = $securityContext;
|
||||
}
|
||||
|
||||
public function getGlobals()
|
||||
{
|
||||
$newsRepo = $this->_doctrine->getRepository('KekRozsakFrontBundle:News');
|
||||
$searchCriteria = array();
|
||||
if (!is_object($this->_securityContext->getToken()) || !is_object($this->_securityContext->getToken()->getUser()))
|
||||
$searchCriteria['public'] = true;
|
||||
|
||||
$news = $newsRepo->findBy($searchCriteria, array('createdAt' => 'DESC'), 4);
|
||||
|
||||
return array(
|
||||
'recentNews' => $news,
|
||||
);
|
||||
}
|
||||
|
||||
public function getName()
|
||||
{
|
||||
return 'News';
|
||||
}
|
||||
}
|
||||
|
Loading…
Reference in New Issue
Block a user