Commit cb7a94da16ef98baaea5bc0b066e5e0708a035b5

Authored by ailsoncgt
1 parent 4b2a6ea1

template add file #133

Showing 1 changed file with 103 additions and 71 deletions   Show diff stats
files/templates/files/create_file.html
1   -{% load widget_tweaks i18n %}
  1 +{% load static widget_tweaks i18n %}
  2 +
2 3 <!-- MODAL CREATE FILE -->
3   -<div class="modal fade" id="createFileModal" tabindex="-1" role="dialog" aria-labelledby="createFileLabel" style="display: none;">
4   - <div class="modal-dialog" role="document">
5   - <div class="modal-content">
6   - <div class="modal-header">
7   - <button type="button" class="close" data-dismiss="modal" aria-label="Close"><span aria-hidden="true">×</span></button>
8   - <h4 class="modal-title" id="createFileLabel">{% trans 'Add File' %}</h4>
9   - </div>
10   - <div class="modal-body">
11   - <!-- Card -->
12   - <form class="form-horizontal">
13   - {% csrf_token %}
14   - {% if messages %}
15   - {% for message in messages %}
16   - <div class="alert alert-{{ message.tags }} alert-dismissible" role="alert">
17   - <button type="button" class="close" data-dismiss="alert" aria-label="Close">
18   - <span aria-hidden="true">&times;</span>
19   - </button>
20   - <p>{{ message }}</p>
21   - </div>
22   - {% endfor %}
23   - {% endif %}
24   - <fieldset>
25   - {% for field in form_file %}
26   - <div class="form-group is-empy{% if form.has_error %} has-error {% endif %} is-fileinput">
27   - <div class="col-md-12">
28   - {% if field.field.required %}
29   - <label for="{{ field.auto_id }}" class="control-label">{{ field.label }}<span>*</span></label>
30   - {% else %}
31   - <label for="{{ field.auto_id }}" class=" control-label">{{ field.label }}</label>
32   - {% endif %}
33   - {% if field.auto_id == 'id_file_url' %}
34   - {% render_field field class='form-control input-sm' %}
35   - <div class="input-group">
36   - <input type="text" readonly="" class="form-control" placeholder="{% trans 'Choose your file...' %}">
37   - <span class="input-group-btn input-group-sm">
38   - <button type="button" class="btn btn-fab btn-fab-mini">
39   - <i class="material-icons">attach_file</i>
40   - </button>
41   - </span>
  4 +<div class="erro">
  5 + <div class="modal fade" id="fileModal" tabindex="-1" role="dialog" aria-labelledby="createFileLabel">
  6 + <div class="modal-dialog" role="document">
  7 + <div class="modal-content">
  8 + <div class="modal-header">
  9 + <button type="button" class="close" data-dismiss="modal" aria-label="Close"><span aria-hidden="true">×</span></button>
  10 + <h4 class="modal-title" id="createFileLabel">{% trans 'Add File' %}</h4>
  11 + </div>
  12 + <div class="modal-body">
  13 + <!-- Card -->
  14 + <form class="form-horizontal" method="post" id="form-file" enctype="multipart/form-data">
  15 + {% csrf_token %}
  16 + {% if messages %}
  17 + {% for message in messages %}
  18 + <div class="alert alert-{{ message.tags }} alert-dismissible" role="alert">
  19 + <button type="button" class="close" data-dismiss="alert" aria-label="Close">
  20 + <span aria-hidden="true">&times;</span>
  21 + </button>
  22 + <p>{{ message }}</p>
  23 + </div>
  24 + {% endfor %}
  25 + {% endif %}
  26 + <fieldset>
  27 + {% for field in form %}
  28 + <div class="form-group is-empy{% if form.has_error %} has-error {% endif %} is-fileinput">
  29 + <div class="col-md-12">
  30 + {% if field.field.required %}
  31 + <label for="{{ field.auto_id }}" class="control-label">{{ field.label }}<span>*</span></label>
  32 + {% else %}
  33 + <label for="{{ field.auto_id }}" class=" control-label">{{ field.label }}</label>
  34 + {% endif %}
  35 + {% if field.auto_id == 'id_file_url' %}
  36 + {% render_field field class='form-control input-sm' %}
  37 + <div class="input-group">
  38 + <input type="text" readonly="" class="form-control" placeholder="{% trans 'Choose your file...' %}">
  39 + <span class="input-group-btn input-group-sm">
  40 + <button type="button" class="btn btn-fab btn-fab-mini">
  41 + <i class="material-icons">attach_file</i>
  42 + </button>
  43 + </span>
  44 + </div>
  45 + {% else %}
  46 + {% render_field field class='form-control input-sm' %}
  47 + <span id="helpBlock" class="help-block">{{ field.help_text }}</span>
  48 + {% endif %}
  49 + </div>
  50 +
  51 + {% if field.errors %}
  52 + <div class="alert alert-danger alert-dismissible clearfix" role="alert">
  53 + <button type="button" class="close" data-dismiss="alert" aria-label="Close">
  54 + <span aria-hidden="true">&times;</span>
  55 + </button>
  56 + <ul>
  57 + {% for error in field.errors %}
  58 + <li>{{ error }}</li>
  59 + {% endfor %}
  60 + </ul>
42 61 </div>
43   - {% else %}
44   - {% render_field field class='form-control input-sm' %}
45   - <span id="helpBlock" class="help-block">{{ field.help_text }}</span>
46 62 {% endif %}
47 63 </div>
48   -
49   - {% if field.errors %}
50   - <div class="alert alert-danger alert-dismissible" role="alert">
51   - <button type="button" class="close" data-dismiss="alert" aria-label="Close">
52   - <span aria-hidden="true">&times;</span>
53   - </button>
54   - <ul>
55   - {% for error in field.errors %}
56   - <li>{{ error }}</li>
57   - {% endfor %}
58   - </ul>
59   - </div>
60   - {% endif %}
61   - </div>
62   - {% endfor %}
  64 + {% endfor %}
63 65  
64   - <div class="form-group">
65   - <div class="col-md-12 text-center">
66   - <p><b>The file size shouldn't exceed 10MB</b></p>
  66 + <div class="form-group">
  67 + <div class="col-md-12 text-center">
  68 + <p><b>The file size shouldn't exceed 10MB</b></p>
  69 + </div>
67 70 </div>
68   - </div>
69 71  
70   - <div class="form-group">
71   - <div class="col-md-12">
72   - <a href="javascript:void(0)" class="btn btn-raised btn-default">Cancel<div class="ripple-container"></div></a>
73   - <a href="javascript:void(0)" class="btn btn-raised btn-primary">Submit</a>
  72 + <div class="form-group">
  73 + <div class="col-md-12">
  74 + <button type="button" class="btn btn-danger btn-raised" data-dismiss="modal">{% trans "Close" %}</button>
  75 + <button class="btn btn-raised btn-primary" type="submit">Submit</button>
  76 + </div>
74 77 </div>
75   - </div>
76   - </fieldset>
77   - </form>
78   - <!-- .end Card -->
79   - </div>
  78 + </fieldset>
  79 + </form>
  80 + <!-- .end Card -->
  81 + </div>
  82 + </div>
80 83 </div>
81 84 </div>
82 85 </div>
  86 +
  87 +{% block script_file %}
  88 +
  89 + {# // <script src="{% static 'js/file.js' %}"></script> #}
  90 + <script type="text/javascript">
  91 + $("#form-file").submit(function(event) {
  92 + var data = new FormData($('#form-file').get(0));
  93 + $.ajax({
  94 + url: "{% url 'course:file:create_file' topic.slug %}",
  95 + type: $("#form-file").attr('method'),
  96 + data: data,
  97 + cache: false,
  98 + processData: false,
  99 + contentType: false,
  100 + success: function(data) {
  101 + $('#fileModal').modal('hide');
  102 + alert(data);
  103 + // $('#list-topic-files').append(data);
  104 + },
  105 + error: function(data){
  106 + $('.erro').html(data.responseText);
  107 + $('.modal-backdrop').remove();
  108 + $('#fileModal').modal();
  109 + }
  110 + });
  111 + event.preventDefault();
  112 + });
  113 + </script>
  114 +{% endblock script_file %}
83 115 <!-- EndModal -->
84 116 \ No newline at end of file
... ...