Commit 18ecd386664951197561827a01f02061773a014a
1 parent
6b64f04b
Exists in
master
and in
5 other branches
Fixed errors and included alertify for error and for success [Issue:#120]
Showing
1 changed file
with
43 additions
and
40 deletions
Show diff stats
links/templates/links/create_link.html
@@ -12,27 +12,27 @@ | @@ -12,27 +12,27 @@ | ||
12 | <!-- Card --> | 12 | <!-- Card --> |
13 | <form method="post" action="" id="form-link" enctype="multipart/form-data"> | 13 | <form method="post" action="" id="form-link" enctype="multipart/form-data"> |
14 | {% csrf_token %} | 14 | {% csrf_token %} |
15 | - {% if messages %} | ||
16 | - {% for message in messages %} | ||
17 | - <div class="alert alert-{{ message.tags }} alert-dismissible" role="alert"> | ||
18 | - <button type="button" class="close" data-dismiss="alert" aria-label="Close"> | ||
19 | - <span aria-hidden="true">×</span> | ||
20 | - </button> | ||
21 | - <p>{{ message }}</p> | ||
22 | - </div> | ||
23 | - {% endfor %} | ||
24 | - {% endif %} | ||
25 | {% for field in form %} | 15 | {% for field in form %} |
26 | {% if field.field.required %} | 16 | {% if field.field.required %} |
27 | <label for="{{ field.auto_id }}">{{ field.label }}<span>*</span></label> | 17 | <label for="{{ field.auto_id }}">{{ field.label }}<span>*</span></label> |
28 | - {% else %} | ||
29 | - <label for="{{ field.auto_id }}">{{ field.label }}</label> | ||
30 | {% endif %} | 18 | {% endif %} |
31 | - {% render_field field class='form-control' %} | 19 | + {% render_field field class='form-control input-sm' %} |
20 | + {% if field.errors %} | ||
21 | + <div class="alert alert-danger alert-dismissible clearfix" role="alert"> | ||
22 | + <button type="button" class="close" data-dismiss="alert" aria-label="Close"> | ||
23 | + <span aria-hidden="true">×</span> | ||
24 | + </button> | ||
25 | + <ul> | ||
26 | + {% for error in field.errors %} | ||
27 | + <li>{{ error }}</li> | ||
28 | + {% endfor %} | ||
29 | + </ul> | ||
30 | + </div> | ||
31 | + {% endif %} | ||
32 | {% endfor %} | 32 | {% endfor %} |
33 | <div class="form-group"> | 33 | <div class="form-group"> |
34 | <a href="javascript:void(0)" class="btn btn-raised btn-default" data-dismiss="modal">{% trans 'Cancel' %}</a> | 34 | <a href="javascript:void(0)" class="btn btn-raised btn-default" data-dismiss="modal">{% trans 'Cancel' %}</a> |
35 | - <button class="btn btn-raised btn-primary" type="submit">{% trans 'Submit' %]</button> | 35 | + <button class="btn btn-raised btn-primary" type="submit">{% trans 'Submit' %}</button> |
36 | </div> | 36 | </div> |
37 | <!-- .end Card --> | 37 | <!-- .end Card --> |
38 | </div> | 38 | </div> |
@@ -40,29 +40,32 @@ | @@ -40,29 +40,32 @@ | ||
40 | </div> | 40 | </div> |
41 | </div> | 41 | </div> |
42 | <!-- EndModal --> | 42 | <!-- EndModal --> |
43 | - | ||
44 | -{# // <script src="{% static '/links.js' %}"></script> #} | ||
45 | -<script type="text/javascript"> | ||
46 | - $("#form-link").submit(function(event) { | ||
47 | - var data = new FormData($('#form-link').get(0)); | ||
48 | - $.ajax({ | ||
49 | - url: "{% url 'course:links:create_link' topic.slug %}", | ||
50 | - type: $("#form-link").attr('method'), | ||
51 | - data: data, | ||
52 | - cache: false, | ||
53 | - processData: false, | ||
54 | - contentType: false, | ||
55 | - success: function(data) { | ||
56 | - $('#createLinksModal').modal('hide'); | ||
57 | - $('#list-topic{{ topic.id }}-links').append(data); | ||
58 | - $('#list-topic{{ topic.id }}-links-edit').append(data); | ||
59 | - }, | ||
60 | - error: function(data){ | ||
61 | - $('.erro').html(data.responseText); | ||
62 | - $('.modal-backdrop').remove(); | ||
63 | - $('#createLinksModal').modal(); | ||
64 | - } | ||
65 | - }); | ||
66 | - event.preventDefault(); | ||
67 | - }); | ||
68 | -</script> | 43 | +{% block script_link %} |
44 | + {# // <script src="{% static '/links.js' %}"></script> #} | ||
45 | + <script type="text/javascript"> | ||
46 | + $("#form-link").submit(function(event) { | ||
47 | + var data = new FormData($('#form-link').get(0)); | ||
48 | + $.ajax({ | ||
49 | + url: "{% url 'course:links:create_link' topic.slug %}", | ||
50 | + type: $("#form-link").attr('method'), | ||
51 | + data: data, | ||
52 | + cache: false, | ||
53 | + processData: false, | ||
54 | + contentType: false, | ||
55 | + success: function(data) { | ||
56 | + $('#createLinksModal').modal('hide'); | ||
57 | + $('#list-topic{{ topic.id }}-links').append(data); | ||
58 | + $('#list-topic{{ topic.id }}-links-edit').append(data); | ||
59 | + alertify.alert('Link successfully created!') | ||
60 | + }, | ||
61 | + error: function(data){ | ||
62 | + $('.erro').html(data.responseText); | ||
63 | + $('.modal-backdrop').remove(); | ||
64 | + $('#createLinksModal').modal(); | ||
65 | + alertify.alert('Invalid link, insert a valid one!'); | ||
66 | + } | ||
67 | + }); | ||
68 | + event.preventDefault(); | ||
69 | + }); | ||
70 | + </script> | ||
71 | +{% endblock script_link %} |