mirror of
https://github.com/ArenMg/aren.git
synced 2025-01-11 00:30:20 +00:00
Image upload carto
This commit is contained in:
parent
35738311e3
commit
86613d0312
2 changed files with 36 additions and 31 deletions
|
@ -857,6 +857,18 @@ const ApiService = function (anUrl, locale) {
|
||||||
params.path = "/" + params.id + "/duplicate";
|
params.path = "/" + params.id + "/duplicate";
|
||||||
this.call(params);
|
this.call(params);
|
||||||
};
|
};
|
||||||
|
this.uploadMap = ({ data, onSuccess, onError, onProgress, loading } = {}) => {
|
||||||
|
ajaxCall({
|
||||||
|
method: "POST",
|
||||||
|
path: "documents/map",
|
||||||
|
data: data,
|
||||||
|
onProgress,
|
||||||
|
onSuccess,
|
||||||
|
onError: onError,
|
||||||
|
json: false,
|
||||||
|
loading: loading,
|
||||||
|
});
|
||||||
|
};
|
||||||
this.Debates.addComment = function (params = {}) {
|
this.Debates.addComment = function (params = {}) {
|
||||||
params.method = "POST";
|
params.method = "POST";
|
||||||
params.path = "/" + params.id + "/comments";
|
params.path = "/" + params.id + "/comments";
|
||||||
|
|
|
@ -26,7 +26,7 @@
|
||||||
|
|
||||||
<template v-slot:right>
|
<template v-slot:right>
|
||||||
<span
|
<span
|
||||||
:disabled="document.mapLink.length<=0"
|
:disabled="!imgUrl"
|
||||||
v-if="editionMode"
|
v-if="editionMode"
|
||||||
class="waves-effect waves-light btn"
|
class="waves-effect waves-light btn"
|
||||||
@click="saveDocument()"
|
@click="saveDocument()"
|
||||||
|
@ -59,6 +59,7 @@
|
||||||
style="visibility: hidden;"
|
style="visibility: hidden;"
|
||||||
type="file"
|
type="file"
|
||||||
@change="onCartoSelected"
|
@change="onCartoSelected"
|
||||||
|
accept=".jpg"
|
||||||
/>
|
/>
|
||||||
</div>
|
</div>
|
||||||
<div class="cartoInformation-bloc">
|
<div class="cartoInformation-bloc">
|
||||||
|
@ -185,7 +186,11 @@ module.exports = {
|
||||||
},
|
},
|
||||||
saveDocument() {
|
saveDocument() {
|
||||||
this.editionMode = false;
|
this.editionMode = false;
|
||||||
//this.document.mapLink = this.getBase64Image();
|
ArenService.uploadMap({
|
||||||
|
data: this.selectedCarto,
|
||||||
|
onSuccess: ({name}) => {
|
||||||
|
//console.log(name);
|
||||||
|
this.document.mapLink = name;
|
||||||
ArenService.Documents.createOrUpdate({
|
ArenService.Documents.createOrUpdate({
|
||||||
data: this.document,
|
data: this.document,
|
||||||
onSuccess: (document) => {
|
onSuccess: (document) => {
|
||||||
|
@ -195,6 +200,11 @@ module.exports = {
|
||||||
},
|
},
|
||||||
});
|
});
|
||||||
},
|
},
|
||||||
|
onError: (err) => {
|
||||||
|
console.log(err);
|
||||||
|
}
|
||||||
|
})
|
||||||
|
},
|
||||||
copyDocument(from, to) {
|
copyDocument(from, to) {
|
||||||
to.name = from.name;
|
to.name = from.name;
|
||||||
to.author = from.author;
|
to.author = from.author;
|
||||||
|
@ -202,30 +212,13 @@ module.exports = {
|
||||||
},
|
},
|
||||||
onCartoSelected(event) {
|
onCartoSelected(event) {
|
||||||
const file = event.target.files[0];
|
const file = event.target.files[0];
|
||||||
this.selectedCarto = file;
|
|
||||||
|
let formData = new FormData();
|
||||||
|
formData.append("file", file, file.name);
|
||||||
|
this.selectedCarto = formData;
|
||||||
|
|
||||||
this.imgUrl = URL.createObjectURL(file);
|
this.imgUrl = URL.createObjectURL(file);
|
||||||
this.document.mapLink = this.getBase64Image();
|
|
||||||
},
|
},
|
||||||
getBase64Image() {
|
|
||||||
// Create an empty canvas element
|
|
||||||
let img = document.getElementById("mapImg");
|
|
||||||
var canvas = document.createElement("canvas");
|
|
||||||
canvas.width = img.width;
|
|
||||||
canvas.height = img.height;
|
|
||||||
|
|
||||||
// Copy the image contents to the canvas
|
|
||||||
var ctx = canvas.getContext("2d");
|
|
||||||
ctx.drawImage(img, 0, 0);
|
|
||||||
|
|
||||||
// Get the data-URL formatted image
|
|
||||||
// Firefox supports PNG and JPEG. You could check img.src to
|
|
||||||
// guess the original format, but be aware the using "image/jpg"
|
|
||||||
// will re-encode the image.
|
|
||||||
var dataURL = canvas.toDataURL("image/png");
|
|
||||||
//let dt = dataURL.replace(/^data:image\/(png|jpg);base64,/, "");
|
|
||||||
console.log(dataURL);
|
|
||||||
return dataURL;
|
|
||||||
}
|
|
||||||
},
|
},
|
||||||
components: {
|
components: {
|
||||||
"wysiwyg-editor": vueLoader("components/widgets/wysiwygEditor"),
|
"wysiwyg-editor": vueLoader("components/widgets/wysiwygEditor"),
|
||||||
|
|
Loading…
Reference in a new issue