|
@@ -14,12 +14,7 @@ class ElementController extends Controller
|
14
|
14
|
* @return Muzich\CoreBundle\Entity\Element
|
15
|
15
|
*/
|
16
|
16
|
protected function checkExistingAndOwned($element_id)
|
17
|
|
- {
|
18
|
|
- if (!$this->getRequest()->isXmlHttpRequest())
|
19
|
|
- {
|
20
|
|
- throw $this->createNotFoundException('Not allowed');
|
21
|
|
- }
|
22
|
|
-
|
|
17
|
+ {
|
23
|
18
|
if (!($element = $this->getDoctrine()->getRepository('MuzichCoreBundle:Element')
|
24
|
19
|
->findOneById($element_id)))
|
25
|
20
|
{
|
|
@@ -38,7 +33,7 @@ class ElementController extends Controller
|
38
|
33
|
*
|
39
|
34
|
*/
|
40
|
35
|
public function editAction($element_id)
|
41
|
|
- {
|
|
36
|
+ {
|
42
|
37
|
$element = $this->checkExistingAndOwned($element_id);
|
43
|
38
|
|
44
|
39
|
$element_tags = $element->getTags();
|
|
@@ -51,19 +46,30 @@ class ElementController extends Controller
|
51
|
46
|
$search_tags[$tag->getId()] = $tag->getName();
|
52
|
47
|
}
|
53
|
48
|
|
54
|
|
- $html = $this->render('MuzichCoreBundle:Element:element.edit.html.twig', array(
|
|
49
|
+ $template = 'MuzichCoreBundle:Element:ajax.element.edit.html.twig';
|
|
50
|
+ if (!$this->getRequest()->isXmlHttpRequest())
|
|
51
|
+ {
|
|
52
|
+ $template = 'MuzichCoreBundle:Element:element.edit.html.twig';
|
|
53
|
+ }
|
|
54
|
+
|
|
55
|
+ $response = $this->render($template, array(
|
55
|
56
|
'form' => $form->createView(),
|
56
|
57
|
'form_name' => 'element_'.$element->getId(),
|
57
|
58
|
'element_id' => $element->getId(),
|
58
|
59
|
'search_tags' => $search_tags
|
59
|
|
- ))->getContent();
|
60
|
|
-
|
61
|
|
- return $this->jsonResponse(array(
|
62
|
|
- 'status' => 'success',
|
63
|
|
- 'form_name' => 'element_'.$element->getId(),
|
64
|
|
- 'tags' => $search_tags,
|
65
|
|
- 'html' => $html
|
66
|
60
|
));
|
|
61
|
+
|
|
62
|
+ if ($this->getRequest()->isXmlHttpRequest())
|
|
63
|
+ {
|
|
64
|
+ return $this->jsonResponse(array(
|
|
65
|
+ 'status' => 'success',
|
|
66
|
+ 'form_name' => 'element_'.$element->getId(),
|
|
67
|
+ 'tags' => $search_tags,
|
|
68
|
+ 'html' => $response->getContent()
|
|
69
|
+ ));
|
|
70
|
+ }
|
|
71
|
+
|
|
72
|
+ return $response;
|
67
|
73
|
}
|
68
|
74
|
|
69
|
75
|
/**
|
|
@@ -109,10 +115,31 @@ class ElementController extends Controller
|
109
|
115
|
}
|
110
|
116
|
}
|
111
|
117
|
|
112
|
|
- return $this->jsonResponse(array(
|
113
|
|
- 'status' => $status,
|
114
|
|
- 'html' => $html,
|
115
|
|
- 'errors' => $errors
|
|
118
|
+ if ($this->getRequest()->isXmlHttpRequest())
|
|
119
|
+ {
|
|
120
|
+ return $this->jsonResponse(array(
|
|
121
|
+ 'status' => $status,
|
|
122
|
+ 'html' => $html,
|
|
123
|
+ 'errors' => $errors
|
|
124
|
+ ));
|
|
125
|
+ }
|
|
126
|
+
|
|
127
|
+ if ($status == 'success')
|
|
128
|
+ {
|
|
129
|
+ return $this->redirect($this->generateUrl('home'));
|
|
130
|
+ }
|
|
131
|
+
|
|
132
|
+
|
|
133
|
+ $element->setTagsWithIds(
|
|
134
|
+ $this->getDoctrine()->getEntityManager(),
|
|
135
|
+ json_decode($element->getTags())
|
|
136
|
+ );
|
|
137
|
+
|
|
138
|
+ return $this->render('MuzichCoreBundle:Element:element.edit.html.twig', array(
|
|
139
|
+ 'form' => $form->createView(),
|
|
140
|
+ 'form_name' => 'element_'.$element->getId(),
|
|
141
|
+ 'element_id' => $element->getId(),
|
|
142
|
+ 'search_tags' => $element->getTagsIdsJson()
|
116
|
143
|
));
|
117
|
144
|
}
|
118
|
145
|
|
|
@@ -124,11 +151,21 @@ class ElementController extends Controller
|
124
|
151
|
$em->remove($element);
|
125
|
152
|
$em->flush();
|
126
|
153
|
|
127
|
|
- return $this->jsonResponse(array('status' => 'success'));
|
|
154
|
+ if ($this->getRequest()->isXmlHttpRequest())
|
|
155
|
+ {
|
|
156
|
+ return $this->jsonResponse(array('status' => 'success'));
|
|
157
|
+ }
|
|
158
|
+ $this->setFlash('success', 'element.remove.success');
|
|
159
|
+ return $this->redirect($this->container->get('request')->headers->get('referer'));
|
128
|
160
|
}
|
129
|
161
|
catch(Exception $e)
|
130
|
162
|
{
|
131
|
|
- return $this->jsonResponse(array('status' => 'error'));
|
|
163
|
+ if ($this->getRequest()->isXmlHttpRequest())
|
|
164
|
+ {
|
|
165
|
+ return $this->jsonResponse(array('status' => 'error'));
|
|
166
|
+ }
|
|
167
|
+ $this->setFlash('error', 'element.remove.error');
|
|
168
|
+ return $this->redirect($this->container->get('request')->headers->get('referer'));
|
132
|
169
|
}
|
133
|
170
|
}
|
134
|
171
|
|