Handle multiple file uploaders on the same page
This commit is contained in:
@@ -32,6 +32,7 @@ define([
|
|||||||
module.create = function (common, config) {
|
module.create = function (common, config) {
|
||||||
var File = {};
|
var File = {};
|
||||||
var origin = common.getMetadataMgr().getPrivateData().origin;
|
var origin = common.getMetadataMgr().getPrivateData().origin;
|
||||||
|
var response = Util.response();
|
||||||
|
|
||||||
var teamId = config.teamId; // XXX Teams file upload as a team
|
var teamId = config.teamId; // XXX Teams file upload as a team
|
||||||
|
|
||||||
@@ -75,21 +76,25 @@ define([
|
|||||||
|
|
||||||
var sframeChan = common.getSframeChannel();
|
var sframeChan = common.getSframeChannel();
|
||||||
var onError = $.noop,
|
var onError = $.noop,
|
||||||
onComplete = $.noop,
|
|
||||||
updateProgress = $.noop,
|
updateProgress = $.noop,
|
||||||
onPending = $.noop;
|
onPending = $.noop;
|
||||||
sframeChan.on('EV_FILE_UPLOAD_STATE', function (data) {
|
sframeChan.on('EV_FILE_UPLOAD_STATE', function (data) {
|
||||||
if (data.error) {
|
if (data.error && response.expected(data.uid)) {
|
||||||
|
response.clear(data.uid);
|
||||||
return void onError(data.error);
|
return void onError(data.error);
|
||||||
}
|
}
|
||||||
if (data.complete && data.href) {
|
if (data.complete && data.href && data.uid) {
|
||||||
return void onComplete(data.href);
|
if (response.expected(data.uid)) {
|
||||||
|
response.handle(data.uid, [data.href]);
|
||||||
|
}
|
||||||
|
return;
|
||||||
}
|
}
|
||||||
if (typeof data.progress !== "undefined") {
|
if (typeof data.progress !== "undefined" && response.expected(data.uid)) {
|
||||||
return void updateProgress(data.progress);
|
return void updateProgress(data.progress);
|
||||||
}
|
}
|
||||||
});
|
});
|
||||||
sframeChan.on('Q_CANCEL_PENDING_FILE_UPLOAD', function (data, cb) {
|
sframeChan.on('Q_CANCEL_PENDING_FILE_UPLOAD', function (data, cb) {
|
||||||
|
if (!response.expected(data.uid)) { return; }
|
||||||
onPending(cb);
|
onPending(cb);
|
||||||
});
|
});
|
||||||
var upload = function (file) {
|
var upload = function (file) {
|
||||||
@@ -121,7 +126,8 @@ define([
|
|||||||
});
|
});
|
||||||
};
|
};
|
||||||
|
|
||||||
onComplete = function (href) {
|
file.uid = Util.uid();
|
||||||
|
response.expect(file.uid, function (href) {
|
||||||
var mdMgr = common.getMetadataMgr();
|
var mdMgr = common.getMetadataMgr();
|
||||||
var origin = mdMgr.getPrivateData().origin;
|
var origin = mdMgr.getPrivateData().origin;
|
||||||
$link.prepend($('<span>', {'class': 'fa fa-external-link'}));
|
$link.prepend($('<span>', {'class': 'fa fa-external-link'}));
|
||||||
@@ -143,7 +149,7 @@ define([
|
|||||||
|
|
||||||
queue.inProgress = false;
|
queue.inProgress = false;
|
||||||
queue.next();
|
queue.next();
|
||||||
};
|
});
|
||||||
|
|
||||||
onError = function (e) {
|
onError = function (e) {
|
||||||
queue.inProgress = false;
|
queue.inProgress = false;
|
||||||
|
|||||||
@@ -723,22 +723,27 @@ define([
|
|||||||
};
|
};
|
||||||
var updateProgress = function (progressValue) {
|
var updateProgress = function (progressValue) {
|
||||||
sendEvent({
|
sendEvent({
|
||||||
|
uid: data.uid,
|
||||||
progress: progressValue
|
progress: progressValue
|
||||||
});
|
});
|
||||||
};
|
};
|
||||||
var onComplete = function (href) {
|
var onComplete = function (href) {
|
||||||
sendEvent({
|
sendEvent({
|
||||||
complete: true,
|
complete: true,
|
||||||
|
uid: data.uid,
|
||||||
href: href
|
href: href
|
||||||
});
|
});
|
||||||
};
|
};
|
||||||
var onError = function (e) {
|
var onError = function (e) {
|
||||||
sendEvent({
|
sendEvent({
|
||||||
|
uid: data.uid,
|
||||||
error: e
|
error: e
|
||||||
});
|
});
|
||||||
};
|
};
|
||||||
var onPending = function (cb) {
|
var onPending = function (cb) {
|
||||||
sframeChan.query('Q_CANCEL_PENDING_FILE_UPLOAD', null, function (err, data) {
|
sframeChan.query('Q_CANCEL_PENDING_FILE_UPLOAD', {
|
||||||
|
uid: data.uid
|
||||||
|
}, function (err, data) {
|
||||||
if (data) {
|
if (data) {
|
||||||
cb();
|
cb();
|
||||||
}
|
}
|
||||||
|
|||||||
Reference in New Issue
Block a user