Commit 0220c98356cbc4e91d3dc521f77d1ef2daa8d584
1 parent
a29a7bc219
Exists in
master
añadido el ajax para añadir tutor y de una vez poder seleccionarlo desde la list…
…a de los tutores a la hora de solicitar ascenso
Showing
4 changed files
with
66 additions
and
18 deletions
Show diff stats
app/Resources/views/cea/ascenso_mostar.html.twig
... | ... | @@ -61,8 +61,9 @@ |
61 | 61 | </table> |
62 | 62 | |
63 | 63 | <p ><strong>Escalafón Solicita:</strong> {{ ascenso.idEscalafones.nombre }} </p> |
64 | - {% for tutor in ascenso.tutoresAscenso %} | |
64 | + | |
65 | 65 | <h4>Tutores propuestos</h4> |
66 | + {% for tutor in ascenso.tutoresAscenso %} | |
66 | 67 | <p class="well"> |
67 | 68 | <strong>{{ tutor.nombres }} {{ tutor.apellidos }}:</strong> |
68 | 69 | {{ tutor.institucion }} -> {{ tutor.idEscala.nombre }} | ... | ... |
app/Resources/views/solicitudes/ascenso.html.twig
... | ... | @@ -2,6 +2,7 @@ |
2 | 2 | |
3 | 3 | {% block stylesheets %} |
4 | 4 | {{ parent() }} |
5 | + <link rel="stylesheet" href="{{ asset('assets/vendor/chosen/chosen.min.css') }}"> | |
5 | 6 | |
6 | 7 | <style> |
7 | 8 | .esc_oposicion, .esc_asistente, .esc_agregado, .esc_asociado, .esc_titular{ |
... | ... | @@ -134,6 +135,7 @@ |
134 | 135 | |
135 | 136 | {% block javascripts %} |
136 | 137 | {{ parent() }} |
138 | + <script type="text/javascript" src="{{ asset('assets/vendor/chosen/chosen.jquery.min.js') }}"></script> | |
137 | 139 | <script type="text/javascript"> |
138 | 140 | $('#ascenso_tipoTrabajoInvestigacion').click(function() { |
139 | 141 | |
... | ... | @@ -143,7 +145,7 @@ |
143 | 145 | |
144 | 146 | |
145 | 147 | $(".tutorForm").submit(function(e){ |
146 | - alert("funciona"); | |
148 | + | |
147 | 149 | e.preventDefault(); |
148 | 150 | |
149 | 151 | var formSerialize = $(this).serialize(); |
... | ... | @@ -151,13 +153,23 @@ |
151 | 153 | $.ajax({ |
152 | 154 | method: "POST", |
153 | 155 | url: "{{ url('ajax_registrar_tutor') }}", |
154 | - data: formSerialize | |
156 | + data: formSerialize, | |
157 | + | |
155 | 158 | }) |
156 | 159 | .done(function (data) { |
157 | - if (typeof data.message !== 'undefined') { | |
158 | - alert(data.message); | |
160 | + if (typeof data.response !== 'undefined') { | |
161 | + alert(data.response); | |
162 | + console.log(data.posts); | |
163 | + var posts = JSON.parse(data.posts); | |
164 | + $("#ascenso_tutores_ascenso").find('optgroup[label="UBV"]').append($('<option>', { | |
165 | + value: posts.id, | |
166 | + text: posts.nombres + " " + posts.apellidos | |
167 | + })); | |
168 | + $("#ascenso_tutores_ascenso").trigger("chosen:updated"); | |
169 | + | |
159 | 170 | } |
160 | 171 | }) |
172 | + | |
161 | 173 | .fail(function (jqXHR, textStatus, errorThrown) { |
162 | 174 | if (typeof jqXHR.responseJSON !== 'undefined') { |
163 | 175 | if (jqXHR.responseJSON.hasOwnProperty('form')) { |
... | ... | @@ -209,6 +221,8 @@ |
209 | 221 | |
210 | 222 | }); |
211 | 223 | }); |
224 | + | |
225 | + $("#ascenso_tutores_ascenso").chosen({no_results_text: "<a data-toggle='modal' data-target='#buscarTutores' href='#'>Tutor no registrado, click aquí para registrar!</a>"}); | |
212 | 226 | |
213 | 227 | </script> |
214 | 228 | {% endblock %} | ... | ... |
src/AppBundle/Controller/AjaxController.php
... | ... | @@ -73,6 +73,41 @@ class AjaxController extends Controller { |
73 | 73 | } |
74 | 74 | |
75 | 75 | |
76 | + | |
77 | + /** | |
78 | + * @Route("/ajax/buscar_tutor_select", name="ajax_buscar_tutor_select") | |
79 | + * @Method({"GET"}) | |
80 | + */ | |
81 | + public function buscarTutorSelectAction(Request $request){ | |
82 | + //if($request->isXmlHttpRequest()){ | |
83 | + $encoders = array(new JsonEncoder()); | |
84 | + $normalizers = array(new ObjectNormalizer()); | |
85 | + | |
86 | + $serializer = new Serializer($normalizers, $encoders); | |
87 | + | |
88 | + $term = filter_input(INPUT_GET, 'term', FILTER_SANITIZE_SPECIAL_CHARS); | |
89 | + $repository = $this->getDoctrine() | |
90 | + ->getRepository('AppBundle:TutoresAscenso'); | |
91 | + $query = $repository->createQueryBuilder('p') | |
92 | + ->where('p.nombres LIKE :term') | |
93 | + ->orWhere('p.apellidos LIKE :term') | |
94 | + ->setParameter('term', '%'.$term.'%') | |
95 | + ->getQuery(); | |
96 | + | |
97 | + $posts = $query->getResult(); | |
98 | + | |
99 | + | |
100 | + $response = new JsonResponse(); | |
101 | + $response->setStatusCode(200); | |
102 | + $response->setData(array( | |
103 | + 'items' => $serializer->serialize($posts, 'json') | |
104 | + )); | |
105 | + return $response; | |
106 | + //} | |
107 | + | |
108 | + } | |
109 | + | |
110 | + | |
76 | 111 | /** |
77 | 112 | * @Route("/ajax/buscar_tutor", name="ajax_buscar_tutor") |
78 | 113 | * @Method({"GET"}) |
... | ... | @@ -127,9 +162,15 @@ class AjaxController extends Controller { |
127 | 162 | $em->persist($nuevoTutor); |
128 | 163 | $em->flush(); |
129 | 164 | |
130 | - return new JsonResponse(array('message' => 'Success!'), 200); | |
165 | + $response = new JsonResponse(); | |
166 | + $response->setStatusCode(200); | |
167 | + $response->setData(array( | |
168 | + 'response' => 'success', | |
169 | + 'posts' => $serializer->serialize($nuevoTutor, 'json') | |
170 | + )); | |
171 | + return $response; | |
131 | 172 | } |
132 | - echo $form; | |
173 | + | |
133 | 174 | |
134 | 175 | |
135 | 176 | $response = new JsonResponse( | ... | ... |
src/AppBundle/Form/AscensoType.php
... | ... | @@ -111,22 +111,14 @@ class AscensoType extends AbstractType |
111 | 111 | |
112 | 112 | ->add('tutores_ascenso', EntityType::class, array( |
113 | 113 | 'placeholder' => 'Añadir Tutores...', |
114 | - 'class' => 'AppBundle:TutoresAscenso', | |
115 | - 'label' => false, | |
114 | + 'class' => 'AppBundle:TutoresAscenso', | |
116 | 115 | 'multiple' => true, |
116 | + 'group_by' => 'institucion', | |
117 | 117 | /*'attr' => array( |
118 | 118 | 'disabled' => 'true', |
119 | 119 | )*/ |
120 | 120 | )) |
121 | - | |
122 | - ->add('añadir_tutor', ButtonType::class, array( | |
123 | - 'label' => 'Añadir Tutor', | |
124 | - 'attr' => array( | |
125 | - 'class' => 'btn btn-success btn-sm', | |
126 | - 'data-toggle' => "modal", | |
127 | - 'data-target' => "#buscarTutores" | |
128 | - ) | |
129 | - )) | |
121 | + | |
130 | 122 | |
131 | 123 | |
132 | 124 | ->add('investigacion', FileType::class, array( | ... | ... |