Added basic book adding functionality

Signed-off-by: Gergely POLONKAI <polesz@w00d5t0ck.info>
This commit is contained in:
Gergely POLONKAI 2012-08-18 11:07:36 +02:00
parent acea821bdb
commit ebb0469ae1
8 changed files with 145 additions and 1 deletions

View File

@ -10,6 +10,7 @@ use Symfony\Component\HttpFoundation\Response;
use KekRozsak\FrontBundle\Entity\Book; use KekRozsak\FrontBundle\Entity\Book;
use KekRozsak\FrontBundle\Entity\BookCopy; use KekRozsak\FrontBundle\Entity\BookCopy;
use KekRozsak\FrontBundle\Form\Type\BookType;
class BookController extends Controller class BookController extends Controller
{ {
@ -28,6 +29,32 @@ class BookController extends Controller
); );
} }
/**
* @Route("/konyvtar/uj-konyv.html", name="KekRozsakFrontBundle_bookNew", options={"expose" = true})
* @Template()
*/
public function newAction()
{
$book = new Book();
$newBookForm = $this->createForm(new BookType(), $book);
$request = $this->getRequest();
if ($request->getMethod() == 'POST') {
$newBookForm->bindRequest($request);
if ($newBookForm->isValid()) {
$em = $this->getDoctrine()->getEntityManager();
$em->persist($book);
$em->flush();
return new Response();
}
}
return array(
'form' => $newBookForm->createView(),
);
}
/** /**
* @Route("/sugo/konyvtar-lista.html", name="KekRozsakFrontBundle_bookListHelp") * @Route("/sugo/konyvtar-lista.html", name="KekRozsakFrontBundle_bookListHelp")
* @Template() * @Template()

View File

@ -273,6 +273,29 @@ class Book
*/ */
protected $commentable; protected $commentable;
/**
* Set commentable
*
* @param boolean $commentable
* @return Book
*/
public function setCommentable($commentable)
{
// TODO: Check if parameter is boolean!
$this->commentable = $commentable;
return $this;
}
/**
* Get commentable
*
* @return boolean
*/
public function isCommentable()
{
return $this->commentable;
}
/** /**
* Collection of Users who would like to borrow a copy * Collection of Users who would like to borrow a copy
* *

View File

@ -0,0 +1,57 @@
<?php
namespace KekRozsak\FrontBundle\Form\Type;
use Symfony\Component\Form\AbstractType;
use Symfony\Component\Form\FormBuilderInterface;
use Symfony\Component\OptionsResolver\OptionsResolverInterface;
class BookType extends AbstractType
{
public function buildForm(FormBuilderInterface $builder, array $options)
{
$builder
->add(
'author',
null,
array(
'label' => 'Szerző',
)
)
->add(
'title',
null,
array(
'label' => 'Cím',
)
)
->add(
'year',
null,
array(
'label' => 'Kiadás éve',
)
)
->add(
'commentable',
null,
array(
'label' => 'Kommentelhető?',
'required' => false
)
)
;
}
public function setDefaultOptions(OptionsResolverInterface $resolver)
{
$resolver->setDefaults(array(
'data_class' => 'KekRozsak\FrontBundle\Entity\Book'
));
}
public function getName()
{
return 'kekrozsak_frontbundle_booktype';
}
}

View File

@ -1,10 +1,11 @@
{# vim: ft=htmljinja {# vim: ft=htmljinja
#} #}
{% extends 'KekRozsakFrontBundle:Default:main_template.html.twig' %} {% extends 'KekRozsakFrontBundle:Default:main_template.html.twig' %}
{% block title %} - Könyvtár{% endblock %} {% block title %} - Könyvtár{% endblock %}
{% block buttonlist %} {% block buttonlist %}
[Új könyv] <span class="gomb new-book-button">[Új könyv]</span>
{% if books|length > 0 %} {% if books|length > 0 %}
[Saját könyveim] [Saját könyveim]
[Nálam lévő kölcsönzött könyvek] [Nálam lévő kölcsönzött könyvek]
@ -168,5 +169,27 @@ $('.book-row').click(function() {
doPopup('', 'Betöltés...', bookUrl, 400, 300, bookCallback); doPopup('', 'Betöltés...', bookUrl, 400, 300, bookCallback);
}); });
function setupAjaxBookForm()
{
$('#new-book-form').ajaxForm();
}
$('.new-book-button').click(function() {
creatorUrl = Routing.generate('KekRozsakFrontBundle_bookNew');
doPopup('Új könyv', 'Betöltés...', creatorUrl, 500, 400, setupAjaxBookForm);
});
$('#new-book-form').on('submit', function(e) {
e.preventDefault();
$(this).ajaxSubmit({
target: '#new-book-form-result',
replaceTarget: true,
success: function(data) {
alert(data);
}
});
});
</script> </script>
{% endblock bottomscripts %} {% endblock bottomscripts %}

View File

@ -0,0 +1,9 @@
{% form_theme form 'KekRozsakFrontBundle:Form:user_form.html.twig' %}
<div id="new-book-form-result">
<form method="POST" action="{{ path('KekRozsakFrontBundle_bookNew') }}" id="new-book-form">
<table>
{{ form_widget(form) }}
</table>
<button id="new-book-save-button" type="submit">Mentés</button>
</form>
</div>

View File

@ -16,6 +16,7 @@
<script type="text/javascript" src="{{ asset('js/jquery.tinyscrollbar.min.js') }}"></script> <script type="text/javascript" src="{{ asset('js/jquery.tinyscrollbar.min.js') }}"></script>
<script type="text/javascript" src="{{ asset('bundles/fosjsrouting/js/router.js') }}"></script> <script type="text/javascript" src="{{ asset('bundles/fosjsrouting/js/router.js') }}"></script>
<script type="text/javascript" src="{{ path('fos_js_routing_js', {callback: 'fos.Router.setData'}) }}"></script> <script type="text/javascript" src="{{ path('fos_js_routing_js', {callback: 'fos.Router.setData'}) }}"></script>
<script type="text/javascript" src="{{ asset('js/jquery-form/jquery.form.js') }}"></script>
{% javascripts 'bundles/kekrozsakfront/js/*' output='js/kekrozsak.js' %} {% javascripts 'bundles/kekrozsakfront/js/*' output='js/kekrozsak.js' %}
<script type="text/javascript" src="{{ asset_url }}"></script> <script type="text/javascript" src="{{ asset_url }}"></script>
{% endjavascripts %} {% endjavascripts %}

View File

@ -1,6 +1,8 @@
#! /bin/sh #! /bin/sh
git pull && \ git pull && \
git submodule init && \
git submodule update && \
(app/console cache:clear --env=prod || rm -rf `dirname $0`/app/cache/prod) && \ (app/console cache:clear --env=prod || rm -rf `dirname $0`/app/cache/prod) && \
(app/console cache:clear || rm -rf `dirname $0`/app/cache/dev) && \ (app/console cache:clear || rm -rf `dirname $0`/app/cache/dev) && \
app/console assets:install && \ app/console assets:install && \

2
web/js/.gitignore vendored
View File

@ -1,2 +1,4 @@
* *
!.git* !.git*
!jquery-cluetip
!jquery-form