Skip to content
Projects
Groups
Snippets
Help
Loading...
Help
Support
Keyboard shortcuts
?
Submit feedback
Contribute to GitLab
Sign in / Register
Toggle navigation
J
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
Boris Kocherov
jio
Commits
7b68148a
Commit
7b68148a
authored
Aug 30, 2016
by
Boris Kocherov
Browse files
Options
Browse Files
Download
Email Patches
Plain Diff
attachaspropertystorage: allow using content_type for attachment and
fix bug
parent
b7c65ab7
Changes
1
Hide whitespace changes
Inline
Side-by-side
Showing
1 changed file
with
46 additions
and
21 deletions
+46
-21
src/jio.storage/attachaspropertystorage.js
src/jio.storage/attachaspropertystorage.js
+46
-21
No files found.
src/jio.storage/attachaspropertystorage.js
View file @
7b68148a
/*jslint nomen: true*/
/*jslint nomen: true*/
/*global RSVP, FileReader*/
/*global RSVP, FileReader, Blob*/
// JIO AttachAsProperty Storage Description :
//JIO AttachAsProperty Storage Description :
// {
//description = {
// type: "attachasproperty",
// type: "attachasproperty",
// map: {
// map: {
// attach_id: 'property_ud',
// attach_id: {
// attach1_id: 'property1_ud',
// // name of property containing body of attachment
// },
// body_name: 'property_id',
// sub_storage: {
// // name of property containing content_type of attachment
// }
// content_type_name: 'content_type'
// }
// },
// attach1_id: {
// body_name: 'property1_id',
// content_type_name: 'content_type'
// }
// },
// sub_storage: {}
//};
(
function
(
jIO
,
RSVP
)
{
(
function
(
jIO
,
RSVP
)
{
"
use strict
"
;
"
use strict
"
;
...
@@ -36,21 +43,24 @@
...
@@ -36,21 +43,24 @@
sub_storage
=
this
.
_sub_storage
;
sub_storage
=
this
.
_sub_storage
;
return
this
.
_sub_storage
.
get
.
apply
(
this
.
_sub_storage
,
arguments
)
return
this
.
_sub_storage
.
get
.
apply
(
this
.
_sub_storage
,
arguments
)
.
push
(
function
(
result
)
{
.
push
(
function
(
result
)
{
var
property_name
,
var
arg_list
=
[],
arg_list
=
[],
attach_name
;
attach_name
;
for
(
attach_name
in
map
)
{
for
(
attach_name
in
map
)
{
if
(
map
.
hasOwnProperty
(
attach_name
))
{
if
(
map
.
hasOwnProperty
(
attach_name
))
{
property_name
=
map
[
attach_name
]
||
attach_name
;
arg_list
.
push
(
attach_name
);
arg_list
.
push
(
attach_name
);
}
}
}
}
return
RSVP
.
all
(
arg_list
.
map
(
function
(
attach_name
)
{
return
RSVP
.
all
(
arg_list
.
map
(
function
(
attach_name
)
{
var
body_name
=
map
[
attach_name
].
body_name
||
attach_name
,
content_type_name
=
map
[
attach_name
].
content_type_name
;
return
sub_storage
.
getAttachment
(
key
,
attach_name
)
return
sub_storage
.
getAttachment
(
key
,
attach_name
)
.
push
(
function
(
value
)
{
.
push
(
function
(
value
)
{
if
(
content_type_name
)
{
result
[
content_type_name
]
=
value
.
type
;
}
return
jIO
.
util
.
readBlobAsText
(
value
)
return
jIO
.
util
.
readBlobAsText
(
value
)
.
then
(
function
(
r
)
{
.
then
(
function
(
r
)
{
result
[
propert
y_name
]
=
r
.
target
.
result
;
result
[
bod
y_name
]
=
r
.
target
.
result
;
});
});
})
})
.
push
(
undefined
,
function
(
error
)
{
.
push
(
undefined
,
function
(
error
)
{
...
@@ -67,23 +77,38 @@
...
@@ -67,23 +77,38 @@
AttachAsProperty
.
prototype
.
put
=
function
(
key
,
value_to_save
)
{
AttachAsProperty
.
prototype
.
put
=
function
(
key
,
value_to_save
)
{
var
attach_name
,
var
attach_name
,
args_list
=
[],
args_list
=
[],
property_name
,
body_name
,
content_type_name
,
content_type
,
value
,
value
,
sub_storage
=
this
.
_sub_storage
;
sub_storage
=
this
.
_sub_storage
;
for
(
attach_name
in
this
.
map
)
{
for
(
attach_name
in
this
.
map
)
{
if
(
this
.
map
.
hasOwnProperty
(
attach_name
))
{
if
(
this
.
map
.
hasOwnProperty
(
attach_name
))
{
property_name
=
this
.
map
[
attach_name
]
||
attach_name
;
body_name
=
this
.
map
[
attach_name
].
body_name
||
attach_name
;
value
=
value_to_save
[
propert
y_name
];
value
=
value_to_save
[
bod
y_name
];
if
(
value
!==
undefined
)
{
if
(
value
!==
undefined
)
{
delete
value_to_save
[
property_name
];
content_type_name
=
this
.
map
[
attach_name
].
content_type_name
;
args_list
.
push
([
attach_name
,
value
]);
if
(
content_type_name
)
{
content_type
=
value_to_save
[
content_type_name
];
}
else
{
content_type
=
null
;
}
delete
value_to_save
[
body_name
];
args_list
.
push
([
attach_name
,
value
,
content_type
]);
}
}
}
}
}
}
return
sub_storage
.
put
.
apply
(
sub_storage
,
arguments
)
return
sub_storage
.
put
.
apply
(
sub_storage
,
arguments
)
.
push
(
function
()
{
.
push
(
function
()
{
return
RSVP
.
all
(
args_list
.
map
(
function
(
a
)
{
return
RSVP
.
all
(
args_list
.
map
(
function
(
a
)
{
return
sub_storage
.
putAttachment
(
key
,
a
[
0
],
a
[
1
]);
var
content_type
=
a
[
2
],
body
;
if
(
content_type
)
{
body
=
new
Blob
([
a
[
1
]],
{
type
:
content_type
});
}
else
{
body
=
a
[
1
];
}
return
sub_storage
.
putAttachment
(
key
,
a
[
0
],
body
);
}));
}));
});
});
};
};
...
...
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