Skip to content
Projects
Groups
Snippets
Help
Loading...
Help
Support
Keyboard shortcuts
?
Submit feedback
Contribute to GitLab
Sign in / Register
Toggle navigation
jio
Project overview
Project overview
Details
Activity
Releases
Repository
Repository
Files
Commits
Branches
Tags
Contributors
Graph
Compare
Issues
0
Issues
0
List
Boards
Labels
Milestones
Merge Requests
0
Merge Requests
0
Analytics
Analytics
Repository
Value Stream
Wiki
Wiki
Snippets
Snippets
Members
Members
Collapse sidebar
Close sidebar
Activity
Graph
Create a new issue
Commits
Issue Boards
Open sidebar
Guillaume Royer
jio
Commits
50944886
Commit
50944886
authored
Jan 21, 2016
by
Romain Courteaud
Browse files
Options
Browse Files
Download
Email Patches
Plain Diff
ERP5Storage: add support for FileField
parent
050d8c9d
Changes
2
Hide whitespace changes
Inline
Side-by-side
Showing
2 changed files
with
70 additions
and
5 deletions
+70
-5
src/jio.storage/erp5storage.js
src/jio.storage/erp5storage.js
+14
-5
test/jio.storage/erp5storage.tests.js
test/jio.storage/erp5storage.tests.js
+56
-0
No files found.
src/jio.storage/erp5storage.js
View file @
50944886
...
...
@@ -370,16 +370,25 @@
.
push
(
function
(
evt
)
{
var
form_data
=
JSON
.
parse
(
evt
.
target
.
result
),
data
=
new
FormData
(),
array
,
i
,
key
;
key
,
value
;
for
(
key
in
form_data
)
{
if
(
form_data
.
hasOwnProperty
(
key
))
{
if
(
Array
.
isArray
(
form_data
[
key
]))
{
for
(
i
=
0
;
i
<
form_data
[
key
].
length
;
i
+=
1
)
{
data
.
append
(
key
,
form_data
[
key
][
i
]);
}
array
=
form_data
[
key
];
}
else
{
data
.
append
(
key
,
form_data
[
key
]);
array
=
[
form_data
[
key
]];
}
for
(
i
=
0
;
i
<
array
.
length
;
i
+=
1
)
{
value
=
array
[
i
];
if
(
typeof
value
===
"
object
"
)
{
data
.
append
(
key
,
jIO
.
util
.
dataURItoBlob
(
value
.
url
),
value
.
file_name
);
}
else
{
data
.
append
(
key
,
value
);
}
}
}
}
...
...
test/jio.storage/erp5storage.tests.js
View file @
50944886
...
...
@@ -575,6 +575,62 @@
});
});
test
(
"
putAttachment convert data URL
"
,
function
()
{
var
submit_url
=
domain
+
"
/Form_view/Base_edit
"
,
id
=
"
fake
"
,
form_json
=
{
my_foo_file
:
{
url
:
'
data:text/plain;charset=utf-8;base64,Zm9v
'
,
file_name
:
'
bar.stream
'
}
},
context
=
this
,
server
=
this
.
server
;
this
.
server
.
respondWith
(
"
POST
"
,
submit_url
,
[
204
,
{
"
Content-Type
"
:
"
text/xml
"
},
""
]);
stop
();
expect
(
12
);
this
.
jio
.
putAttachment
(
id
,
submit_url
,
new
Blob
([
JSON
.
stringify
(
form_json
)])
)
.
then
(
function
()
{
equal
(
server
.
requests
.
length
,
1
);
equal
(
server
.
requests
[
0
].
method
,
"
POST
"
);
equal
(
server
.
requests
[
0
].
url
,
submit_url
);
equal
(
server
.
requests
[
0
].
status
,
204
);
ok
(
server
.
requests
[
0
].
requestBody
instanceof
FormData
);
ok
(
context
.
spy
.
calledOnce
,
"
FormData.append count
"
+
context
.
spy
.
callCount
);
equal
(
context
.
spy
.
firstCall
.
args
[
0
],
"
my_foo_file
"
,
"
First append call
"
);
ok
(
context
.
spy
.
firstCall
.
args
[
1
]
instanceof
Blob
,
"
First append call
"
);
equal
(
context
.
spy
.
firstCall
.
args
[
1
].
type
,
"
text/plain;charset=utf-8
"
,
"
First append call
"
);
equal
(
context
.
spy
.
firstCall
.
args
[
2
],
"
bar.stream
"
,
"
First append call
"
);
equal
(
server
.
requests
[
0
].
withCredentials
,
true
);
return
jIO
.
util
.
readBlobAsText
(
context
.
spy
.
firstCall
.
args
[
1
]);
})
.
then
(
function
(
evt
)
{
equal
(
evt
.
target
.
result
,
'
foo
'
);
})
.
fail
(
function
(
error
)
{
ok
(
false
,
error
);
})
.
always
(
function
()
{
start
();
});
});
/////////////////////////////////////////////////////////////////
// erp5Storage.getAttachment
/////////////////////////////////////////////////////////////////
...
...
Write
Preview
Markdown
is supported
0%
Try again
or
attach a new file
Attach a file
Cancel
You are about to add
0
people
to the discussion. Proceed with caution.
Finish editing this message first!
Cancel
Please
register
or
sign in
to comment