public function newAction(Request $request)
    {
        $role = new Role();
        $form = $this->createForm('CoreBundle\Form\RoleType', $role);
        $form->handleRequest($request);

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

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

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