mirror of
https://we.phorge.it/source/phorge.git
synced 2024-11-22 23:02:42 +01:00
f2c36a934e
Summary: Ref T5187. This definitely feels a bit flimsy and I'm going to hold it until I cut the release since it changes a couple of things about Workflow in general, but it seems to work OK and most of it is fine. The intent is described in T5187#176236. In practice, most of that works like I describe, then the `phui-file-upload` behavior gets some weird glue to figure out if the input is part of the form. Not the most elegant system, but I think it'll hold until we come up with many reasons to write a lot more Javascript. Test Plan: Used both drag-and-drop and the upload dialog to upload files in Safari, Firefox and Chrome. {F1653716} Reviewers: chad Reviewed By: chad Maniphest Tasks: T5187 Differential Revision: https://secure.phabricator.com/D15953
80 lines
1.5 KiB
JavaScript
80 lines
1.5 KiB
JavaScript
/**
|
|
* @provides javelin-behavior-phui-file-upload
|
|
* @requires javelin-behavior
|
|
* javelin-stratcom
|
|
* javelin-dom
|
|
* phuix-dropdown-menu
|
|
*/
|
|
|
|
JX.behavior('phui-file-upload', function(config) {
|
|
|
|
function startUpload(workflow, input) {
|
|
var files = input.files;
|
|
|
|
if (!files || !files.length) {
|
|
return;
|
|
}
|
|
|
|
var state = {
|
|
workflow: workflow,
|
|
input: input,
|
|
waiting: 0,
|
|
phids: []
|
|
};
|
|
|
|
var callback = JX.bind(null, didUpload, state);
|
|
|
|
var dummy = input;
|
|
var uploader = new JX.PhabricatorDragAndDropFileUpload(dummy)
|
|
.setURI(config.uploadURI)
|
|
.setChunkThreshold(config.chunkThreshold);
|
|
|
|
uploader.listen('didUpload', callback);
|
|
uploader.start();
|
|
|
|
workflow.pause();
|
|
for (var ii = 0; ii < files.length; ii++) {
|
|
state.waiting++;
|
|
uploader.sendRequest(files[ii]);
|
|
}
|
|
}
|
|
|
|
function didUpload(state, file) {
|
|
state.phids.push(file.getPHID());
|
|
state.waiting--;
|
|
|
|
if (state.waiting) {
|
|
return;
|
|
}
|
|
|
|
state.workflow
|
|
.addData(config.inputName, state.phids.join(', '))
|
|
.resume();
|
|
}
|
|
|
|
JX.Workflow.listen('start', function(workflow) {
|
|
var form = workflow.getSourceForm();
|
|
if (!form) {
|
|
return;
|
|
}
|
|
|
|
var input;
|
|
try {
|
|
input = JX.$(config.fileInputID);
|
|
} catch (ex) {
|
|
return;
|
|
}
|
|
|
|
var local_form = JX.DOM.findAbove(input, 'form');
|
|
if (!local_form) {
|
|
return;
|
|
}
|
|
|
|
if (local_form !== form) {
|
|
return;
|
|
}
|
|
|
|
startUpload(workflow, input);
|
|
});
|
|
|
|
});
|