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
CI / CD
CI / CD
Pipelines
Jobs
Schedules
Analytics
Analytics
CI / CD
Repository
Value Stream
Wiki
Wiki
Snippets
Snippets
Members
Members
Collapse sidebar
Close sidebar
Activity
Graph
Create a new issue
Jobs
Commits
Issue Boards
Open sidebar
Aurel
jio
Commits
d7f11f46
Commit
d7f11f46
authored
Jul 21, 2017
by
Vincent Bechu
Browse files
Options
Browse Files
Download
Email Patches
Plain Diff
mappingstorage: add attachment_list
parent
16436c04
Changes
1
Show whitespace changes
Inline
Side-by-side
Showing
1 changed file
with
58 additions
and
14 deletions
+58
-14
src/jio.storage/mappingstorage.js
src/jio.storage/mappingstorage.js
+58
-14
No files found.
src/jio.storage/mappingstorage.js
View file @
d7f11f46
/*jslint indent:2, maxlen: 80, nomen: true */
/*global jIO, RSVP, UriTemplate, SimpleQuery, ComplexQuery, QueryFactory,
Query*/
Query
, FormData
*/
(
function
(
jIO
,
RSVP
,
UriTemplate
,
SimpleQuery
,
ComplexQuery
,
QueryFactory
,
Query
)
{
Query
,
FormData
)
{
"
use strict
"
;
function
getSubIdEqualSubProperty
(
storage
,
value
,
key
)
{
...
...
@@ -207,6 +207,7 @@
}
this
.
_default_mapping
=
{};
this
.
_mapping_id_memory_dict
=
{};
this
.
_attachment_list
=
spec
.
attachment_list
||
[];
initializeQueryAndDefaultMapping
(
this
);
}
...
...
@@ -316,12 +317,20 @@
return
getSubStorageId
(
storage
,
argument_list
[
0
])
.
push
(
function
(
sub_id
)
{
argument_list
[
0
]
=
sub_id
;
var
old_id
=
argument_list
[
1
];
argument_list
[
1
]
=
getAttachmentId
(
storage
,
sub_id
,
argument_list
[
0
]
,
argument_list
[
1
],
method
);
if
(
storage
.
_attachment_list
.
length
>
0
&&
storage
.
_attachment_list
.
indexOf
(
old_id
)
<
0
)
{
if
(
method
===
"
get
"
)
{
throw
new
jIO
.
util
.
jIOError
(
"
unhautorized attachment
"
,
404
);
}
return
;
}
return
storage
.
_sub_storage
[
method
+
"
Attachment
"
].
apply
(
storage
.
_sub_storage
,
argument_list
...
...
@@ -400,17 +409,42 @@
});
};
MappingStorage
.
prototype
.
putAttachment
=
function
(
id
,
attachment_id
)
{
MappingStorage
.
prototype
.
getAttachment
=
function
()
{
return
handleAttachment
(
this
,
arguments
,
"
get
"
);
};
MappingStorage
.
prototype
.
putAttachment
=
function
(
id
,
attachment_id
,
blob
)
{
var
storage
=
this
,
mapping_dict
=
storage
.
_attachment_mapping_dict
;
// THIS IS REALLY BAD, FIND AN OTHER WAY IN FUTURE
if
(
mapping_dict
!==
undefined
&&
mapping_dict
[
attachment_id
]
!==
undefined
&&
mapping_dict
[
attachment_id
].
put
!==
undefined
&&
mapping_dict
[
attachment_id
].
put
.
erp5_put_template
!==
undefined
)
{
return
getSubStorageId
(
storage
,
id
)
.
push
(
function
(
sub_id
)
{
var
url
=
UriTemplate
.
parse
(
mapping_dict
[
attachment_id
].
put
.
erp5_put_template
).
expand
({
id
:
sub_id
}),
data
=
new
FormData
();
data
.
append
(
"
field_my_file
"
,
blob
);
data
.
append
(
"
form_id
"
,
"
File_view
"
);
return
jIO
.
util
.
ajax
({
"
type
"
:
"
POST
"
,
"
url
"
:
url
,
"
data
"
:
data
,
"
xhrFields
"
:
{
withCredentials
:
true
}
});
});
}
return
handleAttachment
(
this
,
arguments
,
"
put
"
,
id
)
.
push
(
function
()
{
return
attachment_id
;
});
};
MappingStorage
.
prototype
.
getAttachment
=
function
()
{
return
handleAttachment
(
this
,
arguments
,
"
get
"
);
};
MappingStorage
.
prototype
.
removeAttachment
=
function
(
id
,
attachment_id
)
{
return
handleAttachment
(
this
,
arguments
,
"
remove
"
,
id
)
.
push
(
function
()
{
...
...
@@ -428,7 +462,8 @@
.
push
(
function
(
result
)
{
var
attachment_id
,
attachments
=
{},
mapping_dict
=
{};
mapping_dict
=
{},
i
;
for
(
attachment_id
in
storage
.
_attachment_mapping_dict
)
{
if
(
storage
.
_attachment_mapping_dict
.
hasOwnProperty
(
attachment_id
))
{
mapping_dict
[
getAttachmentId
(
storage
,
sub_id
,
attachment_id
,
"
get
"
)]
...
...
@@ -437,6 +472,8 @@
}
for
(
attachment_id
in
result
)
{
if
(
result
.
hasOwnProperty
(
attachment_id
))
{
if
(
!
(
storage
.
_attachment_list
.
length
>
0
&&
storage
.
_attachment_list
.
indexOf
(
attachment_id
)
<
0
))
{
if
(
mapping_dict
.
hasOwnProperty
(
attachment_id
))
{
attachments
[
mapping_dict
[
attachment_id
]]
=
{};
}
else
{
...
...
@@ -444,6 +481,12 @@
}
}
}
}
for
(
i
=
0
;
i
<
storage
.
_attachment_list
.
length
;
i
+=
1
)
{
if
(
!
attachments
.
hasOwnProperty
(
storage
.
_attachment_list
[
i
]))
{
attachments
[
storage
.
_attachment_list
[
i
]]
=
{};
}
}
return
attachments
;
});
};
...
...
@@ -598,4 +641,5 @@
};
jIO
.
addStorage
(
'
mapping
'
,
MappingStorage
);
}(
jIO
,
RSVP
,
UriTemplate
,
SimpleQuery
,
ComplexQuery
,
QueryFactory
,
Query
));
\ No newline at end of file
}(
jIO
,
RSVP
,
UriTemplate
,
SimpleQuery
,
ComplexQuery
,
QueryFactory
,
Query
,
FormData
));
\ No newline at end of file
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