/** * @Route("/users/save", name="spliced_pms_user_save") * @Template("SplicedProjectManagerBundle:User:new.html.twig") * @Method({"POST"}) */ public function saveAction() { $form = $this->createForm(new Forms\UserFormType()); $response = new AjaxJsonResponse(null, array('reset' => false)); $response->setData('modal', $this->render('SplicedProjectManagerBundle:Common:modal.html.twig', array('title' => 'Whoops', 'body' => '<p>There was an error processing the request.</p>'))->getContent(), true); if ($form->bindRequest($this->getRequest()) && $form->isValid()) { $user = $form->getData(); if ($this->getRequest()->isXmlHttpRequest()) { $response->setData('success', true)->setData('modal', $this->render('SplicedProjectManagerBundle:Common:modal.html.twig', array('title' => 'Whoops', 'body' => '<p>User successfully added.</p>'))->getContent(), true); } } else { $response->setData('modal', $this->render('SplicedProjectManagerBundle:Common:modal.html.twig', array('title' => 'Whoops', 'body' => '<p>Form did not pass validation.</p>'))->getContent(), true); } return $this->getRequest()->isXmlHttpRequest() ? $response : array('form' => $form->createView()); }
/** * @Route("/{media}/delete", name="spliced_pms_project_media_delete") */ public function removeAction($project, $media) { $response = new AjaxJsonResponse(null, array('reset' => false)); $response->setData('modal', $this->render('SplicedProjectManagerBundle:Common:modal.html.twig', array('title' => 'Whoops', 'body' => '<p>There was an error processing the request.</p>'))->getContent(), true); try { $project = $this->getDoctrine()->getRepository('SplicedProjectManagerBundle:Project')->findOneByIdWithMedia($project, $media); } catch (\Doctrine\ORM\NoResultException $e) { if ($this->getRequest()->isXmlHttpRequest()) { $response->setContent(json_encode(array_merge($jsonResponse, array('message' => 'Project Not Found.')))); return $response; } throw $this->createNotFoundException('Project and/or Media Not Found'); } foreach ($project->getMedia() as $_media) { $this->getDoctrine()->getManager()->remove($_media); $this->get('event_dispatcher')->dispatch('spliced.project_media_delete', new Event\ProjectMediaDeleteEvent($_media)); } $this->getDoctrine()->getManager()->flush(); if (!$this->getRequest()->isXmlHttpRequest()) { $this->get('session')->getFlashBag()->add('success', 'Media Successfully Deleted'); return $this->redirect($this->generateUrl('project_view', array('id' => $project->getId()))); } $response->setData('message', 'Media Successfully Deleted')->setData('success', true)->setData('remove', true)->setData('remove_target', '.project_media_' . $media)->setData('reset', false)->setData('modal', $this->render('SplicedProjectManagerBundle:Common:modal.html.twig', array('title' => 'Success', 'body' => '<p>Media Successfully Deleted.</p>'))->getContent(), true); return $response; }
/** * @Route("/project/check_slug", name="spliced_pms_project_check_slug") * @Template() * @Method({"POST"}) */ public function checkSlugAction() { if (!$this->getRequest()->isXmlHttpRequest()) { throw $this->createNotFoundException('Invalid Request Type'); } else { if (!$this->getRequest()->query->has('slug')) { throw $this->createNotFoundException('No url slug provided'); } } $response = new AjaxJsonResponse(null, array('exists' => false, 'success' => true)); try { $project = $this->getDoctrine()->getRepository('SplicedProjectManagerBundle:Project')->findOneByUrlSlug($this->getRequest()->query->get('slug')); if ($project instanceof Project) { $response->setData('modal', $this->render('SplicedProjectManagerBundle:Common:modal.html.twig', array('title' => 'Whoops', 'body' => '<p>A Project with this same URL Slug already exists!</p>'))->getContent(), true)->setData('exists', true); } } catch (NoResultException $e) { $response->setData('message', 'Does Not Exist'); } return $response; }