Added basic book adding functionality
Signed-off-by: Gergely POLONKAI <polesz@w00d5t0ck.info>
This commit is contained in:
		| @@ -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() | ||||
|   | ||||
| @@ -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 | ||||
|      * | ||||
|   | ||||
							
								
								
									
										57
									
								
								src/KekRozsak/FrontBundle/Form/Type/BookType.php
									
									
									
									
									
										Normal file
									
								
							
							
						
						
									
										57
									
								
								src/KekRozsak/FrontBundle/Form/Type/BookType.php
									
									
									
									
									
										Normal 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'; | ||||
|     } | ||||
| } | ||||
| @@ -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] | ||||
| <span class="gomb new-book-button">[Új könyv]</span> | ||||
| {% 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); | ||||
|         } | ||||
|     }); | ||||
| }); | ||||
| </script> | ||||
| {% endblock bottomscripts %} | ||||
|   | ||||
| @@ -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> | ||||
| @@ -16,6 +16,7 @@ | ||||
|         <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="{{ 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' %} | ||||
|         <script type="text/javascript" src="{{ asset_url }}"></script> | ||||
| {% endjavascripts %} | ||||
|   | ||||
| @@ -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 && \ | ||||
|   | ||||
							
								
								
									
										2
									
								
								web/js/.gitignore
									
									
									
									
										vendored
									
									
								
							
							
						
						
									
										2
									
								
								web/js/.gitignore
									
									
									
									
										vendored
									
									
								
							| @@ -1,2 +1,4 @@ | ||||
| * | ||||
| !.git* | ||||
| !jquery-cluetip | ||||
| !jquery-form | ||||
|   | ||||
		Reference in New Issue
	
	Block a user