create_exercise.html
4.64 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
{% load widget_tweaks i18n static %}
<!--MODAL CREATE EXERCISE-->
<div class="modal fade" id="createExercisesModal" tabindex="-1" role="dialog" aria-labelledby="createExercise">
<div class="modal-dialog" role="document">
<div class="modal-content">
<div class="modal-header">
<button type="button" class="close" data-dismiss="modal" aria-label="Close"><span aria-hidden="true">×</span></button>
<h4 class="modal-title" id="createExercise">{% trans 'Create a New Material' %}</h4>
</div>
<div class="modal-body">
<!-- Card -->
<form class="form-horizontal" method="post" id="form-exercise" enctype="multipart/form-data">
{% csrf_token %}
{% if messages %}
{% for message in messages %}
<div class="alert alert-{{ message.tags }} alert-dismissible" role="alert">
<button type="button" class="close" data-dismiss="alert" aria-label="Close">
<span aria-hidden="true">×</span>
</button>
<p>{{ message }}</p>
</div>
{% endfor %}
{% endif %}
<fieldset>
{% for field in form %}
<div class="form-group is-empy{% if form.has_error %} has-error {% endif %} is-fileinput">
<div class="col-md-12">
{% if field.field.required %}
<label for="{{ field.auto_id }}" class="control-label">{{ field.label }}<span>*</span></label>
{% else %}
<label for="{{ field.auto_id }}" class=" control-label">{{ field.label }}</label>
{% endif %}
{% if field.auto_id == 'id_file' %}
{% render_field field class='form-control input-sm' %}
<div class="input-group">
<input type="text" readonly="" class="form-control" placeholder="{% trans 'Choose your file...' %}">
<span class="input-group-btn input-group-sm">
<button type="button" class="btn btn-fab btn-fab-mini">
<i class="material-icons">attach_file</i>
</button>
</span>
</div>
{% else %}
{% render_field field class='form-control input-sm' %}
<span id="helpBlock" class="help-block">{{ field.help_text }}</span>
{% endif %}
</div>
{% if field.errors %}
<div class="alert alert-danger alert-dismissible clearfix" role="alert">
<button type="button" class="close" data-dismiss="alert" aria-label="Close">
<span aria-hidden="true">×</span>
</button>
<ul>
{% for error in field.errors %}
<li>{{ error }}</li>
{% endfor %}
</ul>
</div>
{% endif %}
</div>
{% endfor %}
<div class="form-group">
<div class="col-md-12 text-center">
<p><b>{% trans 'The file size shouldnt exceed 10MB' %}</b></p>
</div>
</div>
<div class="form-group">
<div class="col-md-12">
<button type="button" class="btn btn-default btn-raised" data-dismiss="modal">{% trans "Close" %}</button>
<button class="btn btn-raised btn-primary" type="submit">{% trans 'Submit' %}</button>
</div>
</div>
</fieldset>
</form>
<!-- .end Card -->
</div>
</div>
</div>
</div>
<!-- EndModal -->
<script type="text/javascript">
$("#form-exercise").submit(function(event) {
$("#createExercisesModal").modal("hide");
var data = new FormData($('#form-exercise').get(0));
$.ajax({
url: "{% url 'course:exercise:create_exercise' topic.slug %}",
type: $("#form-exercise").attr('method'),
data: data,
cache: false,
processData: false,
contentType: false,
success: function(data) {
$('#createExercisesModal').modal('hide');
$('#list-topic{{ topic.id }}-exercises').append(data);
$('#list-topic{{ topic.id }}-exercises-edit').append(data);
alertify.success('Exercise successfully created!')
setTimeout(function () { location.reload(1); }, 1000);
},
error: function(data){
$('#requisicoes_ajax').empty();
$('#requisicoes_ajax').append(data.responseText);
$('#createExercisesModal').modal('show');
alertify.alert('Invalid exercise, insert a valid one!');
$('div.modal-backdrop.fade.in').remove();
}
});
event.preventDefault();
});
</script>