218 lines
5.7 KiB
JavaScript
218 lines
5.7 KiB
JavaScript
ItemView = {
|
|
template: "#ItemView",
|
|
router_path: "/ItemView",
|
|
delimiters: ["[[", "]]"],
|
|
props: [],
|
|
|
|
data: function() {
|
|
return {
|
|
items: [],
|
|
items_headers: [],
|
|
types: [],
|
|
types_headers: [],
|
|
}
|
|
},
|
|
|
|
mounted: function() {
|
|
this.reload()
|
|
},
|
|
|
|
computed: {
|
|
items_efields: function() {
|
|
return this.items_headers.filter(e => e.encrypted).map(e => e.value)
|
|
},
|
|
|
|
types_efields: function() {
|
|
return this.types_headers.filter(e => e.encrypted).map(e => e.value)
|
|
},
|
|
},
|
|
|
|
methods: {
|
|
|
|
async reload () {
|
|
|
|
try {
|
|
const response = await this.$http.get(Urls["items:list"]())
|
|
|
|
this.items_headers = response.data.result.items_headers
|
|
this.types_headers = response.data.result.types_headers
|
|
|
|
// Decrypt all item the push
|
|
response.data.result.items.forEach(async item => {
|
|
const new_item = await this.decryptObject(this.items_efields, item)
|
|
|
|
this.items.push(new_item)
|
|
})
|
|
|
|
// Decrypt all type the push
|
|
response.data.result.types.forEach(async type => {
|
|
const new_type = await this.decryptObject(this.types_efields, type)
|
|
|
|
this.types.push(new_type)
|
|
})
|
|
|
|
} catch (err) {
|
|
|
|
Swal.fire({title: "{{_('Error during loading of items') | escapejs}}", icon: "error", position:"top-end", showConfirmButton: false, toast: true, timer: 1000})
|
|
|
|
}
|
|
|
|
},
|
|
|
|
async object_edit(url_edit, url_create, encrypted_fields, method, obj) {
|
|
|
|
let url = null
|
|
|
|
if (obj.id == undefined || obj.id == null) {
|
|
url = Urls[url_create]()
|
|
} else {
|
|
url = Urls[url_edit](obj.id)
|
|
}
|
|
|
|
try {
|
|
|
|
const newobj = await this.encryptObject(encrypted_fields, obj)
|
|
const response = await this.$http[method](url, newobj)
|
|
|
|
if (method != "delete") {
|
|
return await this.decryptObject(encrypted_fields, response.data.object)
|
|
}
|
|
|
|
} catch (err) {
|
|
|
|
let msg = "{{_('Error during edition') | escapejs}}"
|
|
if (method == "delete") {
|
|
msg = "{{_('Error during deletion') | escapejs}}"
|
|
}
|
|
|
|
Swal.fire({title: msg, icon: "error", position:"top-end", showConfirmButton: false, toast: true, timer: 1000})
|
|
|
|
throw err
|
|
|
|
}
|
|
|
|
},
|
|
|
|
item_edition (method, item) {
|
|
return this.object_edit("items:edit", "items:create", this.items_efields, method, item)
|
|
},
|
|
|
|
type_edition (method, item) {
|
|
return this.object_edit("items:type.edit", "items:type.create", this.types_efields, method, item)
|
|
},
|
|
|
|
async createItem (item) {
|
|
|
|
try {
|
|
|
|
const new_item = await this.item_edition("post", item)
|
|
this.items.push(new_item)
|
|
|
|
Swal.fire({title: "{{_('Item successfully created!') | escapejs}}", icon: "success", position:"top-end", showConfirmButton: false, toast: true, timer: 1000})
|
|
|
|
} catch (err) {
|
|
|
|
}
|
|
|
|
},
|
|
|
|
async editItem (index, item) {
|
|
|
|
try {
|
|
|
|
// Remove the item
|
|
this.items.splice(index, 1)
|
|
|
|
const new_item = await this.item_edition("post", item)
|
|
|
|
// Add the new item
|
|
this.items.push(new_item)
|
|
|
|
Swal.fire({title: "{{_('Item successfully edited') | escapejs}}", icon: "success", position:"top-end", showConfirmButton: false, toast: true, timer: 1000})
|
|
|
|
} catch (err) {
|
|
|
|
this.items.push(item)
|
|
|
|
}
|
|
|
|
},
|
|
|
|
async deleteItem (index) {
|
|
|
|
var item = this.items[index]
|
|
|
|
try {
|
|
|
|
// Remove the item
|
|
this.items.splice(index, 1)
|
|
await this.item_edition("delete", item)
|
|
|
|
Swal.fire({title: "{{_('Item successfully deleted!') | escapejs}}", icon: "success", position:"top-end", showConfirmButton: false, toast: true, timer: 1000})
|
|
|
|
} catch (err) {
|
|
|
|
this.items.push(item)
|
|
|
|
}
|
|
|
|
},
|
|
|
|
async createType (type) {
|
|
|
|
try {
|
|
|
|
const new_type = await this.type_edition("post", type)
|
|
this.types.push(new_type)
|
|
|
|
Swal.fire({title: "{{_('Type successfully created!') | escapejs}}", icon: "success", position:"top-end", showConfirmButton: false, toast: true, timer: 1000})
|
|
|
|
} catch (err) {
|
|
|
|
}
|
|
|
|
},
|
|
|
|
async editType (index, type) {
|
|
|
|
try {
|
|
|
|
this.types.splice(index, 1)
|
|
|
|
const new_type = await this.type_edition("post", type)
|
|
|
|
this.types.push(new_type)
|
|
|
|
Swal.fire({title: "{{_('Type successfully edited') | escapejs}}", icon: "success", position:"top-end", showConfirmButton: false, toast: true, timer: 1000})
|
|
|
|
} catch (err) {
|
|
|
|
this.types.push(type)
|
|
|
|
}
|
|
|
|
},
|
|
|
|
async deleteType (index) {
|
|
|
|
var type = this.types[index]
|
|
|
|
try {
|
|
|
|
// Remove the type
|
|
this.types.splice(index, 1)
|
|
|
|
await this.type_edition("delete", type)
|
|
|
|
Swal.fire({title: "{{_('Type successfully deleted!') | escapejs}}", icon: "success", position:"top-end", showConfirmButton: false, toast: true, timer: 1000})
|
|
|
|
} catch (err) {
|
|
|
|
this.types.push(type)
|
|
|
|
}
|
|
},
|
|
|
|
},
|
|
}
|