allow any type of attachments; fixed cordova build in docker

This commit is contained in:
Marc Wäckerlin
2016-01-12 00:22:58 +00:00
parent a3288d4241
commit 3c87e6585b
7 changed files with 161 additions and 43 deletions

View File

@@ -330,9 +330,19 @@ function clearmessage() {
/// Display Image Attachments
function attachments(files, id) {
if (files) files.forEach(function(file) {
console.log(file);
var img = document.createElement('img');
img.src = file.content;
$(id).append(img);
img.title = file.name;
if (file.type.match('^image/')) {
img.src = file.content;
} else {
img.src = "images/Document_sans_PICOL-PIctorial-COmmunication-Language.svg";
}
var a = document.createElement('a');
a.href = file.content;
a.target = '_blank';
a.appendChild(img);
$(id).append(a);
});
}
@@ -348,39 +358,47 @@ function fileupload(evt) {
return error("your browser does not support file upload", true);
for (var i=0, f; f=evt.target.files[i]; ++i) {
var file = f;
console.log(file);
var reader = new FileReader();
reader.onload = function(evt) {
if (evt.target.error) return error("error reading file", true);
if (evt.target.readyState==0) return notice("waiting for data …");
if (evt.target.readyState==1) return notice("loading data …");
if (!file.type.match('^image/'))
return error(file.name+": not an image", true);
var img = document.createElement("img");
img.onload = function() {
var MAX = 400;
var width = img.width;
var height = img.height;
if (width > MAX) {
height *= MAX / width;
width = MAX;
}
if (height > MAX) {
width *= MAX / height;
height = MAX;
}
var canvas = document.createElement("canvas");
canvas.width = width;
canvas.height = height;
var ctx = canvas.getContext("2d");
ctx.drawImage(img, 0, 0, width, height);
if (file.type.match('^image/')) {
var img = document.createElement("img");
img.onload = function() {
filecontent.push({type: file.type, content: img.src});
$("#preview").append(img);
success('image of type '+file.type+' is ready to be sent');
var MAX = 400;
var width = img.width;
var height = img.height;
if (width > MAX) {
height *= MAX / width;
width = MAX;
}
if (height > MAX) {
width *= MAX / height;
height = MAX;
}
var canvas = document.createElement("canvas");
canvas.width = width;
canvas.height = height;
var ctx = canvas.getContext("2d");
ctx.drawImage(img, 0, 0, width, height);
img.onload = function() {
filecontent.push({name:file.name, type: file.type, content: img.src});
$("#preview").append(img);
success('image of type '+file.type+' is ready to be sent');
}
img.title = file.name;
img.src = canvas.toDataURL(file.type);
}
img.src = canvas.toDataURL(file.type);
img.src=evt.target.result;
} else {
filecontent.push({name:file.name, type: file.type, content: evt.target.result});
var img = document.createElement("img");
img.src = "images/Document_sans_PICOL-PIctorial-COmmunication-Language.svg";
img.title = file.name;
$("#preview").append(img);
}
img.src=evt.target.result;
}
reader.readAsDataURL(file);
}