mirror of
https://github.com/Esri/offline-editor-js.git
synced 2026-02-07 14:26:22 +00:00
noticed a potential problem if we have multiple input nodes or multiple files
This commit is contained in:
parent
989de0688d
commit
3f8273be9e
@ -41,7 +41,7 @@ define([], function()
|
||||
contentType: attachmentFile.type,
|
||||
name: attachmentFile.name,
|
||||
size: attachmentFile.size,
|
||||
url: 'javascript:alert("show local attached file ' + attachmentFile.name + '");',
|
||||
url: 'javascript:alert("show local attached file ' + attachmentFile.name + '");', // TODO -> download the local file
|
||||
content: attachmentFile.content
|
||||
});
|
||||
request.onsuccess = function(event)
|
||||
|
||||
@ -150,7 +150,6 @@ define([
|
||||
}
|
||||
else
|
||||
{
|
||||
// NEEDS TESTING
|
||||
var deferred = new Deferred();
|
||||
this.attachmentsStore.getAttachmentsByFeatureId(objectId, function(attachments)
|
||||
{
|
||||
@ -179,27 +178,16 @@ define([
|
||||
else
|
||||
{
|
||||
var deferred = new Deferred();
|
||||
// TODO: we need to:
|
||||
// 1. extract the file from formNode
|
||||
// 2. store the file in a format that can be later sent to the server using REST API
|
||||
// concerns:
|
||||
// a) the mechanism to convert a file path into binary data to be sent over POST
|
||||
// is normally handled by the API/Browser... how can we reuse as much of that mechanism as
|
||||
// possible? There is a big leap between parameters we receive here (objectId and formNode) and
|
||||
// the data that gets sent via REST to the server (use chrome devtools network tab to see that)
|
||||
// b) what fields should be in our attachment object stored in the db?
|
||||
// c) what should be the key in the db? objectid? attachmentid? problem is that when we are offline
|
||||
// we don't know about attachmentids and other attachments that can be attached to the same feature
|
||||
// we could use negative attachmentids, as we do with feature objectids
|
||||
console.assert(objectId);
|
||||
|
||||
// get input node(s)
|
||||
// read file from input into variable
|
||||
this._readFilesFromForm(formNode, function(files)
|
||||
{
|
||||
// callback called once for each input[type=file] node in formNode
|
||||
// callback is called once for each input[type=file] node in formNode
|
||||
// and each input node might contain several files
|
||||
console.log(files);
|
||||
console.assert(files.length == 1, "we don't support multiple files (yet?)");
|
||||
files.forEach(function(file)
|
||||
{
|
||||
// store the attachment
|
||||
@ -212,6 +200,10 @@ define([
|
||||
self.emit(self.events.ATTACHMENT_ENQUEUED,returnValue);
|
||||
callback && callback(returnValue);
|
||||
deferred.resolve(returnValue);
|
||||
// PROBLEM HERE: theoretically, the form can have multiple input[file] controls
|
||||
// and each input can contain multiple files BUT here we call the callback and
|
||||
// resolve the deferred with the FIRST of the files
|
||||
// In practice, popups only have one input, and it doesn't allow multiple files
|
||||
}
|
||||
else
|
||||
{
|
||||
@ -226,10 +218,10 @@ define([
|
||||
}
|
||||
}
|
||||
|
||||
// callback called once for each input[type=file] node in formNode
|
||||
layer._readFilesFromForm = function(formNode, callback)
|
||||
{
|
||||
var inputNodes = array.filter(formNode.elements, function(node) { return node.type == "file"});
|
||||
console.assert(inputNodes.length <= 1, "we don't support multiple input nodes in one form (yet?)");
|
||||
inputNodes.forEach(function(inputNode)
|
||||
{
|
||||
var files = [];
|
||||
|
||||
@ -30,7 +30,6 @@ describe("attachments store module", function()
|
||||
g_attachmentsStore.getUsage(function(usage)
|
||||
{
|
||||
expect(usage).not.toBeNull();
|
||||
// expect(usage.sizeBytes).toBe(0);
|
||||
expect(usage.attachmentCount).toBe(0);
|
||||
done();
|
||||
})
|
||||
@ -46,7 +45,6 @@ describe("attachments store module", function()
|
||||
g_attachmentsStore.getUsage(function(usage)
|
||||
{
|
||||
expect(usage).not.toBeNull();
|
||||
// expect(usage.sizeBytes).toBe(159);
|
||||
expect(usage.attachmentCount).toBe(1);
|
||||
done();
|
||||
})
|
||||
@ -64,7 +62,6 @@ describe("attachments store module", function()
|
||||
g_attachmentsStore.getUsage(function(usage)
|
||||
{
|
||||
expect(usage).not.toBeNull();
|
||||
// expect(usage.sizeBytes).toBe(159 * i);
|
||||
expect(usage.attachmentCount).toBe(i);
|
||||
if( i == n)
|
||||
done();
|
||||
@ -108,7 +105,6 @@ describe("attachments store module", function()
|
||||
g_attachmentsStore.getUsage(function(usage)
|
||||
{
|
||||
expect(usage).not.toBeNull();
|
||||
// expect(usage.sizeBytes).toBe(0);
|
||||
expect(usage.attachmentCount).toBe(0);
|
||||
done();
|
||||
})
|
||||
|
||||
Loading…
x
Reference in New Issue
Block a user