public function newAction(Request $request)
    {
        $page = new Page();
        $form = $this->createForm('CoreBundle\Form\PageType', $page, array('translator'=>$this->get('translator')));
        $form->handleRequest($request);

        if ($form->isSubmitted() && $form->isValid()) {
            $em = $this->getDoctrine()->getManager();
            $em->persist($page);
            $em->flush($page);

            //if come from popup
            if ($request->isXMLHttpRequest()) {         
                return new JsonResponse(array(
                            'id' => $page->getId(), 
                        ));
            }
            $this->get('session')->getFlashBag()->add('success', 'page.created');
            
            return $this->redirectToRoute('core_page_index');
        }

        return array(
            'page' => $page,
            'form' => $form->createView(),
        );
    }