From ebb0469ae1b1aff8ba717ec92181dc577f815892 Mon Sep 17 00:00:00 2001 From: Gergely POLONKAI Date: Sat, 18 Aug 2012 11:07:36 +0200 Subject: [PATCH] Added basic book adding functionality Signed-off-by: Gergely POLONKAI --- .../FrontBundle/Controller/BookController.php | 27 +++++++++ src/KekRozsak/FrontBundle/Entity/Book.php | 23 ++++++++ .../FrontBundle/Form/Type/BookType.php | 57 +++++++++++++++++++ .../Resources/views/Book/list.html.twig | 25 +++++++- .../Resources/views/Book/new.html.twig | 9 +++ .../views/Default/main_template.html.twig | 1 + update.sh | 2 + web/js/.gitignore | 2 + 8 files changed, 145 insertions(+), 1 deletion(-) create mode 100644 src/KekRozsak/FrontBundle/Form/Type/BookType.php create mode 100644 src/KekRozsak/FrontBundle/Resources/views/Book/new.html.twig diff --git a/src/KekRozsak/FrontBundle/Controller/BookController.php b/src/KekRozsak/FrontBundle/Controller/BookController.php index 818b6c8..22b2440 100644 --- a/src/KekRozsak/FrontBundle/Controller/BookController.php +++ b/src/KekRozsak/FrontBundle/Controller/BookController.php @@ -10,6 +10,7 @@ use Symfony\Component\HttpFoundation\Response; use KekRozsak\FrontBundle\Entity\Book; use KekRozsak\FrontBundle\Entity\BookCopy; +use KekRozsak\FrontBundle\Form\Type\BookType; 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") * @Template() diff --git a/src/KekRozsak/FrontBundle/Entity/Book.php b/src/KekRozsak/FrontBundle/Entity/Book.php index 705bb73..f59c7c3 100644 --- a/src/KekRozsak/FrontBundle/Entity/Book.php +++ b/src/KekRozsak/FrontBundle/Entity/Book.php @@ -273,6 +273,29 @@ class Book */ 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 * diff --git a/src/KekRozsak/FrontBundle/Form/Type/BookType.php b/src/KekRozsak/FrontBundle/Form/Type/BookType.php new file mode 100644 index 0000000..c583a2d --- /dev/null +++ b/src/KekRozsak/FrontBundle/Form/Type/BookType.php @@ -0,0 +1,57 @@ +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'; + } +} diff --git a/src/KekRozsak/FrontBundle/Resources/views/Book/list.html.twig b/src/KekRozsak/FrontBundle/Resources/views/Book/list.html.twig index 69665cd..45fc4f3 100644 --- a/src/KekRozsak/FrontBundle/Resources/views/Book/list.html.twig +++ b/src/KekRozsak/FrontBundle/Resources/views/Book/list.html.twig @@ -1,10 +1,11 @@ {# vim: ft=htmljinja #} {% extends 'KekRozsakFrontBundle:Default:main_template.html.twig' %} + {% block title %} - Könyvtár{% endblock %} {% block buttonlist %} -[Új könyv] +[Új könyv] {% if books|length > 0 %} [Saját könyveim] [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); }); + +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); + } + }); +}); {% endblock bottomscripts %} diff --git a/src/KekRozsak/FrontBundle/Resources/views/Book/new.html.twig b/src/KekRozsak/FrontBundle/Resources/views/Book/new.html.twig new file mode 100644 index 0000000..4ae3168 --- /dev/null +++ b/src/KekRozsak/FrontBundle/Resources/views/Book/new.html.twig @@ -0,0 +1,9 @@ +{% form_theme form 'KekRozsakFrontBundle:Form:user_form.html.twig' %} +
+
+ + {{ form_widget(form) }} +
+ +
+
\ No newline at end of file diff --git a/src/KekRozsak/FrontBundle/Resources/views/Default/main_template.html.twig b/src/KekRozsak/FrontBundle/Resources/views/Default/main_template.html.twig index f698893..529b529 100644 --- a/src/KekRozsak/FrontBundle/Resources/views/Default/main_template.html.twig +++ b/src/KekRozsak/FrontBundle/Resources/views/Default/main_template.html.twig @@ -16,6 +16,7 @@ + {% javascripts 'bundles/kekrozsakfront/js/*' output='js/kekrozsak.js' %} {% endjavascripts %} diff --git a/update.sh b/update.sh index 7bcd3f0..a97cde0 100755 --- a/update.sh +++ b/update.sh @@ -1,6 +1,8 @@ #! /bin/sh 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 || rm -rf `dirname $0`/app/cache/dev) && \ app/console assets:install && \ diff --git a/web/js/.gitignore b/web/js/.gitignore index 4ce1c7b..59b8172 100644 --- a/web/js/.gitignore +++ b/web/js/.gitignore @@ -1,2 +1,4 @@ * !.git* +!jquery-cluetip +!jquery-form