new.html.twig
5.81 KB
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
156
157
158
{% extends 'base_app.html.twig' %}
{% block body %}
{% form_theme form 'bootstrap_3_horizontal_layout.html.twig' %}
<h1>PlanificacionSeccion creation</h1>
{{ form_start(form) }}
{{ form_row(form.seccion) }}
{{ form_row(form.idtemaUc) }}
<ul class="contenido" data-prototype="{{ form_widget(form.contenido.vars.prototype)|e('html_attr') }}">
</ul>
<ul class="objetivoEspecifico" data-prototype="{{ form_widget(form.objetivoEspecifico.vars.prototype)|e('html_attr') }}">
</ul>
<input type="submit" value="Create" />
{{ form_end(form) }}
<ul>
<li>
<a href="{{ path('ceapp_docente_planificacion_index') }}">Back to the list</a>
</li>
</ul>
{% endblock %}
{% block javascripts %}
{{ parent() }}
<script type="text/javascript">
var $collectionHolder;
// setup an "add a tag" link
var $addEspecificoLink = $('<a href="#" class="add_especifico_link">Añadir Objetivos Especificos</a>');
var $addContenidoLink = $('<a href="#" class="add_contenido_link">Añadir conceptos</a>');
var $RemoveContenidoLink = $('<a href="#" class="remove_contenido_link">Quitar Conceptos</a>');
var $newLinkLiContenido = $('<li></li>').append($addContenidoLink);
var $newLinkLiEspecifico = $('<li></li>').append($addEspecificoLink);
//$newLinkLi. = $('<li></li>').append($RemoveContenidoLink);
jQuery(document).ready(function() {
// Get the ul that holds the collection of tags
$contenidoHolder = $('ul.contenido');
$especificoHolder = $('ul.objetivoEspecifico');
// add the "add a tag" anchor and li to the tags ul
$contenidoHolder.append($newLinkLiContenido);
$especificoHolder.append($newLinkLiEspecifico);
// count the current form inputs we have (e.g. 2), use that as the new
// index when inserting a new item (e.g. 2)
$contenidoHolder.data('index', $contenidoHolder.find(':input').length);
$especificoHolder.data('index', $especificoHolder.find(':input').length);
$addContenidoLink.on('click', function(e) {
// prevent the link from creating a "#" on the URL
e.preventDefault();
// add a new tag form (see next code block)
addContenidoForm($contenidoHolder, $newLinkLiContenido);
});
$addEspecificoLink.on('click', function(e) {
// prevent the link from creating a "#" on the URL
e.preventDefault();
// add a new tag form (see next code block)
addEspecificoForm($especificoHolder, $newLinkLiEspecifico);
});
function addContenidoForm($contenidoHolder, $newLinkLiContenido) {
// Get the data-prototype explained earlier
var prototype = $contenidoHolder.data('prototype');
// get the new index
var index = $contenidoHolder.data('index');
// Replace '$$name$$' in the prototype's HTML to
// instead be a number based on how many items we have
var newFormContenido = prototype.replace(/__name__/g, index);
// increase the index with one for the next item
$contenidoHolder.data('index', index + 1);
// Display the form in the page in an li, before the "Add a tag" link li
var $newFormLiContenido = $('<li></li>').append(newFormContenido);
// also add a remove button, just for this example
$newFormLiContenido.append('<a href="#" class="remove-tag">x</a>');
$newLinkLiContenido.before($newFormLiContenido);
// handle the removal, just for this example
$('.remove-tag').click(function(e) {
e.preventDefault();
$(this).parent().remove();
return false;
});
}
function addEspecificoForm($especificoHolder, $newLinkLiEspecifico) {
// Get the data-prototype explained earlier
var prototype = $especificoHolder.data('prototype');
// get the new index
var index = $especificoHolder.data('index');
// Replace '$$name$$' in the prototype's HTML to
// instead be a number based on how many items we have
var newFormEspecifico = prototype.replace(/__name__/g, index);
// increase the index with one for the next item
$especificoHolder.data('index', index + 1);
// Display the form in the page in an li, before the "Add a tag" link li
var $newFormLiEspecifico = $('<li></li>').append(newFormEspecifico);
// also add a remove button, just for this example
$newFormLiEspecifico.append('<a href="#" class="remove-tag">x</a>');
$newLinkLiEspecifico.before($newFormLiEspecifico);
// handle the removal, just for this example
$('.remove-tag').click(function(e) {
e.preventDefault();
$(this).parent().remove();
return false;
});
}
});
</script>
{% endblock %}