Commit c4efdcbf authored by onny's avatar onny

try to clean up code

parent c4c90024
......@@ -13,6 +13,17 @@ function print_message(target, msg_type, msg) {
}
}
function post_data(url, data, target_class) {
axios
.post(url, data)
.then(function(response){
print_message(target_class, 'success', 'Entry successfully added');
})
.catch(error => {
print_message(target_class, 'error', 'Error while adding entry, please report');
});
}
var demo = new Vue({
el: '#app',
data: {
......@@ -20,24 +31,18 @@ var demo = new Vue({
'artist': [],
'project': [],
'entry': [],
'media': []
'media': [],
'entries': []
},
delimiters: ["[[","]]"],
methods: {
addArtist: function () {
addArtist() {
var newArtist = {
name: this.artist.name.trim()
};
axios
.post('/api/artist/', newArtist)
.then(function(response){
print_message('.artist', 'success', 'Artist successfully added');
})
.catch(error => {
print_message('.artist', 'error', 'Error while adding artist, please report');
});
post_data('/api/artist/', newArtist, '.artist');
},
addProject: function () {
addProject() {
if (this.project.city) {
var city = this.project.city.trim();
} else {
......@@ -50,16 +55,9 @@ var demo = new Vue({
datefrom: this.project.datefrom,
dateto: this.project.dateto
};
axios
.post('/api/project/', newProject)
.then(function(response){
print_message('.project', 'success', 'Project successfully added');
})
.catch(error => {
print_message('.project', 'error', 'Error while adding project, please report');
});
post_data('/api/project/', newProject, '.project');
},
addEntry: function () {
addEntry() {
if (this.entry.description) {
var description = this.entry.description.trim();
} else {
......@@ -78,16 +76,9 @@ var demo = new Vue({
visibility: this.entry.visibility,
type: this.entry.type
};
axios
.post('/api/entry/', newEntry)
.then(function(response){
print_message('.entry', 'success', 'Entry successfully added');
})
.catch(error => {
print_message('.entry', 'error', 'Error while adding entry, please report');
});
post_data('/api/entry/', newEntry, '.entry');
},
addMedia: function () {
addMedia() {
newMedia = {
file: document.getElementById("file"),
entry: this.entry.id
......@@ -105,26 +96,12 @@ var demo = new Vue({
print_message('.media', 'error', 'Error while uploading media, please report');
});
},
removeArtist: function (index) {
axios
.delete('/api/artist/'.concat(this.artist[index].id));
this.artist.splice(index, 1);
return true;
},
removeProject: function (index) {
removeEntry(object_type, index) {
axios
.delete('/api/project/'.concat(this.project[index].id));
this.project.splice(index, 1);
},
removeEntry: function (index) {
axios
.delete('/api/entry/'.concat(this.entry[index].id));
this.entry.splice(index, 1);
},
removeMedia: function (index) {
axios
.delete('/api/media/'.concat(this.media[index].id));
this.media.splice(index, 1);
.delete('/api/'+ object_type +'/'.concat(this.entries[index].id));
this.$delete(this.entries, index);
// FIXME then -> this.$delete
// FIXME Catch error, show message
}
},
mounted: function()
......@@ -133,23 +110,23 @@ var demo = new Vue({
case "/artists/":
axios
.get('/api/artist/')
.then(response => (this.artist = response.data));
.then(response => (this.entries = response.data));
break;
case "/projects/":
axios
.get('/api/project/')
.then(response => (this.project = response.data));
.then(response => (this.entries = response.data));
break;
case "/entries/":
axios
.get('/api/entry/')
.then(response => (this.entry = response.data));
.then(response => (this.entries = response.data));
break;
case "/media/":
axios
.get('/api/media/')
.then(response => (this.entries = response.data));
break;
case "/media/":
axios
.get('/api/media/')
.then(response => (this.media = response.data));
break;
};
}
});
......@@ -3,13 +3,14 @@
{% block jobs %}
<h2>Artists</h2>
<div class="flex-container">
<p v-if="artist.length == 0">Sorry, no jobs currently available</p>
<div v-for="(artist, index) in artist" class="artist">
<div class="col-sm-12">
<img src="https://uploads.wikiart.org/Content/images/ARTIST-480x600.jpg" width=100px>
<br><b><a :href="'/en/' + artist.slug">[[ artist.name ]]</a></b><br>
<button class="btn" v-on:click="removeArtist([[ index ]])">Delete</button>
</div>
<p v-if="entries.length == 0">Sorry, no jobs currently available</p>
<div v-for="(entry, index) in entries" class="artist">
<img src="https://uploads.wikiart.org/Content/images/ARTIST-480x600.jpg" width=100px>
<br><b><a :href="'/en/' + entry.slug">[[ entry.name ]]</a></b><br>
{% if authenticated %}
<button v-on:click="removeEntry('artist', [[ index ]])">Delete</button>
<button v-on:click="editEntry([[ index ]])">Edit</button>
{% endif %}
</div>
</div>
......
......@@ -3,14 +3,15 @@
{% block jobs %}
<h2>Entries</h2>
<div class="flex-container">
<p v-if="entry.length == 0">Sorry, no entires currently available</p>
<div v-for="(entry, index) in entry" class="artist">
<div class="col-sm-12">
<img src="https://uploads.wikiart.org/Content/images/ARTIST-480x600.jpg" width=100px>
<br><b>[[ entry.signatory ]]</b><br>
of [[ entry.project.name ]]<br>
<button class="btn" v-on:click="removeEntry([[ index ]])">Delete</button>
</div>
</div>
<p v-if="entries.length == 0">Sorry, no entires currently available</p>
<div v-for="(entry, index) in entries" class="artist">
<img src="https://uploads.wikiart.org/Content/images/ARTIST-480x600.jpg" width=100px>
<br><b>[[ entry.signatory ]]</b><br>
of [[ entry.project.name ]]<br>
{% if authenticated %}
<button v-on:click="removeEntry('entry', [[ index ]])">Delete</button>
<button v-on:click="editEntry([[ index ]])">Edit</button>
{% endif %}
</div>
</div>
{% endblock %}
......@@ -3,14 +3,15 @@
{% block jobs %}
<h2>Projects</h2>
<div class="flex-container">
<p v-if="project.length == 0">Sorry, no jobs currently available</p>
<div v-for="(project, index) in project" class="project">
<div class="col-sm-12">
<img src="https://uploads.wikiart.org/Content/images/ARTIST-480x600.jpg" width=100px>
<br><b>[[ project.name ]]</b><br>
by [[ project.artist.name ]]<br>
<button class="btn" v-on:click="removeProject([[ index ]])">Delete</button>
</div>
</div>
<p v-if="entries.length == 0">Sorry, no jobs currently available</p>
<div v-for="(entry, index) in entries" class="project">
<img src="https://uploads.wikiart.org/Content/images/ARTIST-480x600.jpg" width=100px>
<br><b>[[ entry.name ]]</b><br>
by [[ entry.artist.name ]]<br>
{% if authenticated %}
<button v-on:click="removeEntry('artist', [[ index ]])">Delete</button>
<button v-on:click="editEntry([[ index ]])">Edit</button>
{% endif %}
</div>
</div>
{% endblock %}
Markdown is supported
0% or .
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment