Commit f72c7cefa088b415c6b162b15f0e9889acd87185
1 parent
beabbf7f
Exists in
master
and in
5 other branches
Update link template finished [Issue:#122]
Showing
1 changed file
with
57 additions
and
15 deletions
Show diff stats
links/templates/links/update_link.html
@@ -5,29 +5,71 @@ | @@ -5,29 +5,71 @@ | ||
5 | <div class="modal-content"> | 5 | <div class="modal-content"> |
6 | <div class="modal-header"> | 6 | <div class="modal-header"> |
7 | <button type="button" class="close" data-dismiss="modal" aria-label="Close"><span aria-hidden="true">×</span></button> | 7 | <button type="button" class="close" data-dismiss="modal" aria-label="Close"><span aria-hidden="true">×</span></button> |
8 | - <h4 class="modal-title" id="myModalLabel">{% trans 'Links' %}</h4> | 8 | + <h4 class="modal-title" id="myModalLabel">{% trans 'Edit Link' %}</h4> |
9 | </div> | 9 | </div> |
10 | <div class="modal-body"> | 10 | <div class="modal-body"> |
11 | <!-- Card --> | 11 | <!-- Card --> |
12 | + <form class="form-horizontal" method="post" id="form-update-link" enctype="multipart/form-data"> | ||
13 | + {% csrf_token %} | ||
14 | + {% for field in form %} | ||
15 | + <div class="form-group is-empty"> | ||
16 | + <div class="col-md-12"> | ||
17 | + {% if field.field.required %} | ||
18 | + <label for="{{ field.auto_id }}" class="control-label">{{ field.label }}<span>*</span></label> | ||
19 | + {% else %} | ||
20 | + <label for="{{ field.auto_id }}" class=" control-label">{{ field.label }}</label> | ||
21 | + {% endif %} | ||
22 | + {% render_field field class='form-control input-sm' %} | ||
23 | + </div> | ||
24 | + </div> | ||
25 | + {% if field.errors %} | ||
26 | + <div class="alert alert-danger alert-dismissible clearfix" role="alert"> | ||
27 | + <button type="button" class="close" data-dismiss="alert" aria-label="Close"> | ||
28 | + <span aria-hidden="true">×</span> | ||
29 | + </button> | ||
30 | + <ul> | ||
31 | + {% for error in field.errors %} | ||
32 | + <li>{{ error }}</li> | ||
33 | + {% endfor %} | ||
34 | + </ul> | ||
35 | + </div> | ||
36 | + {% endif %} | ||
37 | + {% endfor %} | ||
12 | <div class="form-group"> | 38 | <div class="form-group"> |
13 | - <label class="control-label" for="inputDefault">{% trans 'Name' %}</label> | ||
14 | - <input value="Python" type="text" class="form-control" id="inputDefault"> | 39 | + <button type="button" class="btn btn-danger btn-raised" data-dismiss="modal">{% trans "Cancel" %}</button> |
40 | + <button class="btn btn-raised btn-primary" type="submit">{% trans 'Submit' %}</button> | ||
15 | </div> | 41 | </div> |
16 | - <div class="form-group"> | ||
17 | - <label class="control-label" for="inputDefault">{% trans 'URL' %}</label> | ||
18 | - <input value="https://www.python.org/" type="text" class="form-control" id="inputDefault"> | ||
19 | - </div> | ||
20 | - <div class="form-group is-empty"> | ||
21 | - <label class="control-label" for="inputDefault">{% trans 'Description' %}</label> | ||
22 | - <textarea class="form-control" rows="3"></textarea> | ||
23 | - </div> | ||
24 | - <div class="form-group"> | ||
25 | - <a href="javascript:void(0)" class="btn btn-raised btn-default" data-dismiss="modal">{% trans 'Cancel' %}</a> | ||
26 | - <a href="javascript:void(0)" class="btn btn-raised btn-primary">{% trans 'Submit' %}</a> | ||
27 | - </div> | ||
28 | <!-- .end Card --> | 42 | <!-- .end Card --> |
29 | </div> | 43 | </div> |
30 | </div> | 44 | </div> |
31 | </div> | 45 | </div> |
32 | </div> | 46 | </div> |
33 | <!-- EndModal --> | 47 | <!-- EndModal --> |
48 | +{% block script_link %} | ||
49 | + | ||
50 | + {# // <script src="{% static 'js/links.js' %}"></script> #} | ||
51 | + <script type="text/javascript"> | ||
52 | + $("#form-update-link").submit(function(event) { | ||
53 | + var data = new FormData($('#form-update-link').get(0)); | ||
54 | + $.ajax({ | ||
55 | + url: "{% url 'course:links:update_link' link.slug %}", | ||
56 | + type: $("#form-update-link").attr('method'), | ||
57 | + data: data, | ||
58 | + cache: false, | ||
59 | + processData: false, | ||
60 | + contentType: false, | ||
61 | + success: function(data) { | ||
62 | + $('#linksModalEdit').modal('hide'); | ||
63 | + $('#link_edit_{{ link.slug }}').replaceWith(data); | ||
64 | + $('#link_{{ link.slug }}').replaceWith(data); | ||
65 | + }, | ||
66 | + error: function(data){ | ||
67 | + $('.erro-update').html(data.responseText); | ||
68 | + $('.modal-backdrop').remove(); | ||
69 | + $('#linksModalEdit').modal(); | ||
70 | + } | ||
71 | + }); | ||
72 | + event.preventDefault(); | ||
73 | + }); | ||
74 | + </script> | ||
75 | +{% endblock script_link %} |