new.html.twig
3.44 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
{% 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>
<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 $addContenidoLink = $('<a href="#" class="add_contenido_link">Añadir conceptos</a>');
var $RemoveContenidoLink = $('<a href="#" class="remove_contenido_link">Quitar Conceptos</a>');
var $newLinkLi = $('<li></li>').append($addContenidoLink);
//$newLinkLi. = $('<li></li>').append($RemoveContenidoLink);
jQuery(document).ready(function() {
// Get the ul that holds the collection of tags
$collectionHolder = $('ul.contenido');
// add the "add a tag" anchor and li to the tags ul
$collectionHolder.append($newLinkLi);
// count the current form inputs we have (e.g. 2), use that as the new
// index when inserting a new item (e.g. 2)
$collectionHolder.data('index', $collectionHolder.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($collectionHolder, $newLinkLi);
});
function addContenidoForm($collectionHolder, $newLinkLi) {
// Get the data-prototype explained earlier
var prototype = $collectionHolder.data('prototype');
// get the new index
var index = $collectionHolder.data('index');
// Replace '$$name$$' in the prototype's HTML to
// instead be a number based on how many items we have
var newForm = prototype.replace(/__name__/g, index);
// increase the index with one for the next item
$collectionHolder.data('index', index + 1);
// Display the form in the page in an li, before the "Add a tag" link li
var $newFormLi = $('<li></li>').append(newForm);
// also add a remove button, just for this example
$newFormLi.append('<a href="#" class="remove-tag">x</a>');
$newLinkLi.before($newFormLi);
// handle the removal, just for this example
$('.remove-tag').click(function(e) {
e.preventDefault();
$(this).parent().remove();
return false;
});
}
});
</script>
{% endblock %}