|
|
@ -95,7 +95,7 @@ define([
|
|
|
|
var id = file.id;
|
|
|
|
var id = file.id;
|
|
|
|
var dropEvent = file.dropEvent;
|
|
|
|
var dropEvent = file.dropEvent;
|
|
|
|
delete file.dropEvent;
|
|
|
|
delete file.dropEvent;
|
|
|
|
if (dropEvent.path) { file.path = dropEvent.path; }
|
|
|
|
if (dropEvent && dropEvent.path) { file.path = dropEvent.path; }
|
|
|
|
if (queue.inProgress) { return; }
|
|
|
|
if (queue.inProgress) { return; }
|
|
|
|
queue.inProgress = true;
|
|
|
|
queue.inProgress = true;
|
|
|
|
|
|
|
|
|
|
|
@ -221,12 +221,41 @@ define([
|
|
|
|
queue.next();
|
|
|
|
queue.next();
|
|
|
|
};
|
|
|
|
};
|
|
|
|
|
|
|
|
|
|
|
|
var handleFile = File.handleFile = function (file, e, thumbnail) {
|
|
|
|
var showNamePrompt = true;
|
|
|
|
|
|
|
|
var promptName = function (file, cb) {
|
|
|
|
|
|
|
|
var extIdx = file.name.lastIndexOf('.');
|
|
|
|
|
|
|
|
var name = extIdx !== -1 ? file.name.slice(0,extIdx) : file.name;
|
|
|
|
|
|
|
|
var ext = extIdx !== -1 ? file.name.slice(extIdx) : "";
|
|
|
|
|
|
|
|
var msg = Messages._getKey('upload_rename', [
|
|
|
|
|
|
|
|
Util.fixHTML(file.name),
|
|
|
|
|
|
|
|
Util.fixHTML(ext)
|
|
|
|
|
|
|
|
]);
|
|
|
|
|
|
|
|
UI.prompt(msg, name, function (newName) {
|
|
|
|
|
|
|
|
if (newName === null) {
|
|
|
|
|
|
|
|
showNamePrompt = false;
|
|
|
|
|
|
|
|
return void cb (file.name);
|
|
|
|
|
|
|
|
}
|
|
|
|
|
|
|
|
if (!newName || !newName.trim()) { return void cb (file.name); }
|
|
|
|
|
|
|
|
var newExtIdx = newName.lastIndexOf('.');
|
|
|
|
|
|
|
|
var newExt = newExtIdx !== -1 ? newName.slice(newExtIdx) : "";
|
|
|
|
|
|
|
|
if (newExt !== ext) { newName += ext; }
|
|
|
|
|
|
|
|
cb(newName);
|
|
|
|
|
|
|
|
}, null, true);
|
|
|
|
|
|
|
|
};
|
|
|
|
|
|
|
|
var handleFileState = {
|
|
|
|
|
|
|
|
queue: [],
|
|
|
|
|
|
|
|
inProgress: false
|
|
|
|
|
|
|
|
};
|
|
|
|
|
|
|
|
var handleFile = File.handleFile = function (file, e) {
|
|
|
|
|
|
|
|
//if (handleFileState.inProgress) { return void handleFileState.queue.push(file); }
|
|
|
|
|
|
|
|
handleFileState.inProgress = true;
|
|
|
|
|
|
|
|
|
|
|
|
var thumb;
|
|
|
|
var thumb;
|
|
|
|
var file_arraybuffer;
|
|
|
|
var file_arraybuffer;
|
|
|
|
|
|
|
|
var name = file.name;
|
|
|
|
var finish = function () {
|
|
|
|
var finish = function () {
|
|
|
|
var metadata = {
|
|
|
|
var metadata = {
|
|
|
|
name: file.name,
|
|
|
|
name: name,
|
|
|
|
type: file.type,
|
|
|
|
type: file.type,
|
|
|
|
};
|
|
|
|
};
|
|
|
|
if (thumb) { metadata.thumbnail = thumb; }
|
|
|
|
if (thumb) { metadata.thumbnail = thumb; }
|
|
|
@ -235,26 +264,26 @@ define([
|
|
|
|
metadata: metadata,
|
|
|
|
metadata: metadata,
|
|
|
|
dropEvent: e
|
|
|
|
dropEvent: e
|
|
|
|
});
|
|
|
|
});
|
|
|
|
|
|
|
|
handleFileState.inProgress = false;
|
|
|
|
|
|
|
|
if (handleFileState.queue.length) { handleFile(handleFileState.queue.shift()); }
|
|
|
|
|
|
|
|
};
|
|
|
|
|
|
|
|
var getName = function () {
|
|
|
|
|
|
|
|
promptName(file, function (newName) {
|
|
|
|
|
|
|
|
name = newName;
|
|
|
|
|
|
|
|
finish();
|
|
|
|
|
|
|
|
});
|
|
|
|
};
|
|
|
|
};
|
|
|
|
|
|
|
|
|
|
|
|
blobToArrayBuffer(file, function (e, buffer) {
|
|
|
|
blobToArrayBuffer(file, function (e, buffer) {
|
|
|
|
if (e) { console.error(e); }
|
|
|
|
if (e) { console.error(e); }
|
|
|
|
file_arraybuffer = buffer;
|
|
|
|
file_arraybuffer = buffer;
|
|
|
|
if (thumbnail) { // there is already a thumbnail
|
|
|
|
if (!Thumb.isSupportedType(file.type)) { return getName(); }
|
|
|
|
return blobToArrayBuffer(thumbnail, function (e, buffer) {
|
|
|
|
|
|
|
|
if (e) { console.error(e); }
|
|
|
|
|
|
|
|
thumb = arrayBufferToString(buffer);
|
|
|
|
|
|
|
|
finish();
|
|
|
|
|
|
|
|
});
|
|
|
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
if (!Thumb.isSupportedType(file.type)) { return finish(); }
|
|
|
|
|
|
|
|
// make a resized thumbnail from the image..
|
|
|
|
// make a resized thumbnail from the image..
|
|
|
|
Thumb.fromBlob(file, function (e, thumb64) {
|
|
|
|
Thumb.fromBlob(file, function (e, thumb64) {
|
|
|
|
if (e) { console.error(e); }
|
|
|
|
if (e) { console.error(e); }
|
|
|
|
if (!thumb64) { return finish(); }
|
|
|
|
if (!thumb64) { return getName(); }
|
|
|
|
thumb = thumb64;
|
|
|
|
thumb = thumb64;
|
|
|
|
finish();
|
|
|
|
getName();
|
|
|
|
});
|
|
|
|
});
|
|
|
|
});
|
|
|
|
});
|
|
|
|
};
|
|
|
|
};
|
|
|
|