-
-
Save clint74/bfe44f74523a3e643508733971f82010 to your computer and use it in GitHub Desktop.
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
{% load staticfiles %} | |
<script type="text/javascript" src="{% static 'js/jquery-3.3.1.slim.min.js' %}"></script> | |
<script type="text/javascript" src="{% static 'js/popper.min.js' %}"></script> | |
<script type="text/javascript" src="{% static 'js/bootstrap.min.js' %}"></script> | |
<script src="https://cdn.jsdelivr.net/npm/[email protected]/dist/vue.js"></script> | |
<script src="https://cdn.jsdelivr.net/npm/[email protected]"></script> | |
<script src="https://unpkg.com/axios/dist/axios.min.js"></script> | |
<script type="text/javascript" src="{% static 'js/jquery-cookie.js' %}"></script> | |
<script type="text/javascript"> | |
axios.defaults.xsrfCookieName = 'csrftoken'; | |
axios.defaults.xsrfHeaderName = 'X-CSRFToken'; | |
Vue.config.delimiters = ["${","}"]; | |
Vue.prototype.$http = axios; | |
var agendas_view = new Vue({ | |
el: '#starting', | |
delimiters: ['${','}'], | |
data: { | |
agendas: [], | |
loading: true, | |
currentAgenda: {}, | |
message: null, | |
newAgenda: { 'nome': null, 'telefone': null, 'publicado': false}, | |
search_term: '', | |
}, | |
beforeSend: function(xhr, settings) { | |
if (!csrfSafeMethod(settings.type) && !this.crossDomain) { | |
xhr.setRequestHeader("X-CSRFToken", csrftoken); | |
} | |
}, | |
mounted: function() { | |
this.getAgendas(); | |
}, | |
methods: { | |
getAgendas: function() { | |
let api_url = '/api/agenda/'; | |
if(this.search_term!==''||this.search_term!==null) { | |
api_url = `/api/agenda/?search=${this.search_term}` | |
} | |
this.loading = true; | |
this.$http.get(api_url) | |
.then((response) => { | |
this.agendas = response.data; | |
this.loading = false; | |
}) | |
.catch((err) => { | |
this.loading = false; | |
console.log(err); | |
}) | |
}, | |
getAgenda: function(id) { | |
this.loading = true; | |
this.$http.get(`/api/agenda/${id}/`) | |
.then((response) => { | |
this.currentAgenda = response.data; | |
$("#editAgendaModal").modal('show'); | |
this.loading = false; | |
}) | |
.catch((err) => { | |
this.loading = false; | |
console.log(err); | |
}) | |
}, | |
addAgenda: function() { | |
this.loading = true; | |
this.$http.post('/api/agenda/',this.newAgenda) | |
.then((response) => { | |
this.loading = true; | |
this.getAgendas(); | |
}) | |
.catch((err) => { | |
this.loading = true; | |
console.log(err); | |
}) | |
}, | |
updateAgenda: function() { | |
this.loading = true; | |
this.$http.put(`/api/agenda/${this.currentAgenda.agenda_id}/`, this.currentAgenda) | |
.then((response) => { | |
this.loading = false; | |
this.currentAgenda = response.data; | |
this.getAgendas(); | |
}) | |
.catch((err) => { | |
this.loading = false; | |
console.log(err); | |
}) | |
}, | |
deleteAgenda: function(id) { | |
this.loading = true; | |
this.$http.delete(`/api/agenda/${id}/`) | |
.then((response) => { | |
this.loading = false; | |
this.getAgendas(); | |
}) | |
.catch((err) => { | |
this.loading = false; | |
console.log(err); | |
}) | |
} | |
} | |
}); | |
</script> |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment