Skip to content

Commit

Permalink
Implemented index.js with some ajax utilities.
Browse files Browse the repository at this point in the history
  • Loading branch information
cbdavide committed Oct 13, 2017
1 parent 3209d76 commit 4377689
Show file tree
Hide file tree
Showing 2 changed files with 35 additions and 3 deletions.
31 changes: 31 additions & 0 deletions sales/static/js/index.js
Original file line number Diff line number Diff line change
@@ -0,0 +1,31 @@
function getCookie(name) {
'use strict';
var cookieValue = null;
if (document.cookie && document.cookie !== '') {
var cookies = document.cookie.split(';');
for (var i = 0; i < cookies.length; i++) {
var cookie = jQuery.trim(cookies[i]);
if (cookie.substring(0, name.length + 1) === (name + '=')) {
cookieValue = decodeURIComponent(cookie.substring(name.length + 1));
break;
}
}
}
return cookieValue;
}

function csrfSafeMethod(method) {
'use strict';
return (/^(GET|HEAD|OPTIONS|TRACE)$/.test(method));
}

$.ajaxSetup({
beforeSend: function(xhr, settings) {
'use strict';
if (!csrfSafeMethod(settings.type) && !this.crossDomain) {
xhr.setRequestHeader('X-CSRFToken', getCookie('csrftoken'));
}
}, complete: function(xhr,status) {
'use strict';
}
});
7 changes: 4 additions & 3 deletions sales/templates/sales/create_sale.html
Original file line number Diff line number Diff line change
@@ -1,4 +1,4 @@
<!DOCTYPE html>
<!DOCTYPE html>
<html lang="es">
<head>
<meta charset="utf-8">
Expand Down Expand Up @@ -60,7 +60,7 @@ <h1>Ingreso</h1>
<input type="text" class="form-control" id="descripcion" placeholder="Descripción" required>
</div>
<div class="form-group">
<label for="bar-code">Cédula Vendedor: </label>
<label for="bar-code">Cédula Empleado: </label>
<div class="input-group">
<span class="input-group-addon">C.C.</span>
<input type="text" class="form-control" id="cedula_vendedor" placeholder="Cédula del vendedor" required>
Expand Down Expand Up @@ -109,7 +109,7 @@ <h1>Ingreso</h1>

<div class="form-group">
<div class=text-right>
<button type="submit" class="btn btn-primary pull-right">Enviar</button>
<button type="submit" id="enviar" class="btn btn-primary pull-right">Enviar</button>
</div>
</div>

Expand All @@ -121,6 +121,7 @@ <h1>Ingreso</h1>
<script src="/static/js/jquery-3.2.1.min.js"></script>
<script src="/static/js/popper.min.js"></script>
<script src="/static/js/boostrap.min.js"></script>
<script src="/static/js/index.js"></script>
<script src="/static/js/app.js"></script>
</body>
</html>

0 comments on commit 4377689

Please sign in to comment.