Skip to content
Projects
Groups
Snippets
Help
Loading...
Help
Support
Keyboard shortcuts
?
Submit feedback
Contribute to GitLab
Sign in / Register
Toggle navigation
E
ecommerce-ui
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
Members
Members
Collapse sidebar
Close sidebar
Activity
Graph
Create a new issue
Commits
Issue Boards
Open sidebar
nexedi
ecommerce-ui
Commits
37ff22d0
Commit
37ff22d0
authored
Feb 21, 2014
by
Sven Franck
Browse files
Options
Browse Files
Download
Email Patches
Plain Diff
merged put/post into storage.write method, cleanup old methods
parent
ea43ce63
Changes
1
Hide whitespace changes
Inline
Side-by-side
Showing
1 changed file
with
53 additions
and
92 deletions
+53
-92
js/erp5_loader.js
js/erp5_loader.js
+53
-92
No files found.
js/erp5_loader.js
View file @
37ff22d0
...
@@ -1061,25 +1061,16 @@
...
@@ -1061,25 +1061,16 @@
* @param {object} obj Action Object
* @param {object} obj Action Object
**/
**/
"
new
"
:
function
(
obj
)
{
"
new
"
:
function
(
obj
)
{
storage
.
save
(
obj
);
storage
.
write
(
obj
);
},
/**
* Add a server
* @method submit
* @param {object} obj Action Object
**/
"
update_configuration
"
:
function
(
obj
)
{
storage
.
add
(
obj
);
},
},
/**
/**
*
Add a user to the storage
*
Update an object
* @method submit
* @method submit
* @param {object} obj Action Object
* @param {object} obj Action Object
**/
**/
"
add
"
:
function
(
obj
)
{
"
update
"
:
function
(
obj
)
{
storage
.
add
(
obj
);
storage
.
write
(
obj
);
},
},
/**
/**
...
@@ -5528,23 +5519,36 @@
...
@@ -5528,23 +5519,36 @@
storage
=
{};
storage
=
{};
/**
/**
*
Generate a new object
*
Write to storage = POST or PUT
* @method
newStor
e
* @method
writ
e
* @param {object} obj Action object
* @param {object} obj Action object
*/
*/
storage
.
sav
e
=
function
(
obj
)
{
storage
.
writ
e
=
function
(
obj
)
{
var
form
,
data
,
valid
,
prefix
,
decode
,
id
,
answer
,
goto
,
type
;
var
form
,
data
,
valid
,
prefix
,
decode
,
id
,
answer
,
goto
,
config
,
method
;
form
=
document
.
getElementById
(
obj
.
id
);
form
=
document
.
getElementById
(
obj
.
id
);
type
=
obj
.
state
.
url_pointer
[
obj
.
element
.
getAttribute
(
"
data-action
"
)];
prefix
=
obj
.
id
+
"
_
"
;
prefix
=
obj
.
id
+
"
_
"
;
valid
=
storage
.
validate
(
obj
);
valid
=
storage
.
validate
(
obj
);
data
=
storage
.
parseForm
(
valid
,
prefix
,
true
);
data
=
storage
.
parseForm
(
valid
,
prefix
,
true
);
// post or put
if
(
form
.
identifier
)
{
method
=
"
put
"
;
config
=
{
"
_view
"
:
obj
.
state
.
view
};
data
.
_id
=
form
.
identifier
.
value
;
}
else
{
config
=
{
"
call
"
:
obj
.
state
.
url_pointer
[
obj
.
element
.
getAttribute
(
"
data-action
"
)]
};
}
RSVP
.
resolve
(
RSVP
.
resolve
(
app
.
storage_dict
.
items
.
post
(
data
,
{
"
call
"
:
type
}
)
app
.
storage_dict
.
items
[
method
||
"
post
"
](
data
,
config
)
)
)
.
then
(
function
(
response
)
{
.
then
(
function
(
response
)
{
util
.
loader
(
""
,
"
status_dict.saved
"
,
"
check
"
);
if
(
obj
.
state
.
callback
)
{
if
(
obj
.
state
.
callback
)
{
answer
=
util
.
parse
(
response
);
answer
=
util
.
parse
(
response
);
id
=
answer
.
id
;
id
=
answer
.
id
;
...
@@ -5845,7 +5849,6 @@
...
@@ -5845,7 +5849,6 @@
}
else
{
}
else
{
replace
=
form_to_submit
.
id
+
"
_
"
;
replace
=
form_to_submit
.
id
+
"
_
"
;
obj
=
{};
obj
=
{};
// force portal_type
// force portal_type
if
(
config
.
gadget
.
state
.
force_type
)
{
if
(
config
.
gadget
.
state
.
force_type
)
{
config
.
gadget
.
state
.
type
=
config
.
gadget
.
state
.
force_type
;
config
.
gadget
.
state
.
type
=
config
.
gadget
.
state
.
force_type
;
...
@@ -7068,7 +7071,7 @@
...
@@ -7068,7 +7071,7 @@
// set callback and pointer on state
// set callback and pointer on state
pass
.
state
.
callback
=
pass
.
config
.
property_dict
.
submit_to
;
pass
.
state
.
callback
=
pass
.
config
.
property_dict
.
submit_to
;
pass
.
state
.
url_pointer
=
pass
.
config
.
property_dict
.
url_pointer
;
pass
.
state
.
url_pointer
=
pass
.
config
.
property_dict
.
url_pointer
||
{}
;
// tuck to gadget
// tuck to gadget
...
@@ -7332,84 +7335,42 @@
...
@@ -7332,84 +7335,42 @@
}
}
}
}
// if we have form_data we continue
// loop over item and create a JIO record
if
(
pass
.
form_data
===
undefined
)
{
for
(
i
=
0
;
i
<
pass
.
items
.
length
;
i
+=
1
)
{
// loop over item and create a JIO record
record
=
pass
.
items
[
i
];
for
(
i
=
0
;
i
<
pass
.
items
.
length
;
i
+=
1
)
{
obj
=
{};
record
=
pass
.
items
[
i
];
for
(
key
in
record
)
{
obj
=
{};
if
(
record
.
hasOwnProperty
(
key
))
{
for
(
key
in
record
)
{
if
(
validate
)
{
if
(
record
.
hasOwnProperty
(
key
))
{
if
(
answer
.
response
[
key
])
{
if
(
validate
)
{
if
(
answer
.
response
[
key
])
{
obj
[
key
]
=
record
[
key
];
}
else
{
util
.
error
(
"
store: field
"
+
key
+
"
not defined for type =
"
+
pass
.
type
);
}
}
else
{
obj
[
key
]
=
record
[
key
];
obj
[
key
]
=
record
[
key
];
}
else
{
util
.
error
(
"
store: field
"
+
key
+
"
not defined for type =
"
+
pass
.
type
);
}
}
}
else
{
obj
[
key
]
=
record
[
key
];
}
}
}
}
}
// add portal type
// add portal type
// obj.portal_type = pass.type;
// obj.portal_type = pass.type;
// if an object identifier was set in the form, we PUT, else POST
if
(
obj
.
identifier
)
{
method
=
"
put
"
;
hacked_view
=
{
"
_view
"
:
pass
.
view
};
obj
.
_id
=
obj
.
identifier
;
delete
obj
.
identifier
;
}
// store
// if an object identifier was set in the form, we PUT, else POST
promises
[
i
]
=
store
[
method
||
"
post
"
](
obj
,
hacked_view
||
{})
if
(
obj
.
identifier
)
{
.
then
(
function
(
answer
)
{
method
=
"
put
"
;
return
answer
;
hacked_view
=
{
"
_view
"
:
pass
.
view
}
;
})
obj
.
_id
=
obj
.
identifier
;
.
fail
(
util
.
error
)
;
delete
obj
.
identifier
;
}
}
}
else
{
console
.
log
(
"
SHOULD BE REDUNDANT
"
)
// store
promises
[
i
]
=
store
[
method
||
"
post
"
](
obj
,
hacked_view
||
{})
// // do it again, Sam...
.
then
(
function
(
answer
)
{
// promises[0] = jIO.util.ajax({
return
answer
;
// "url": app.storage_dict.property_dict.items.storage_list[0].url,
})
// "type": "GET",
.
fail
(
util
.
error
);
// "xhrFields": {
// "withCredentials": true
// }
// })
// .then(function(response) {
// return jIO.util.ajax({
// "url": util.parse(response.target.responseText)._links.me.href,
// "xhrFields": {
// "withCredentials": true
// }
// });
// })
// .then(function (answer) {
// return jIO.util.ajax({
// "url": util.parse(answer.target.responseText)._actions[pass.fetch].href,
// "type": "POST",
// "data": pass.form_data,
// "xhrFields": {
// "withCredentials": true
// }
// });
// })
// .then(function (erp5_response) {
// header = erp5_response.target.getResponseHeader("Location");
// return RSVP.resolve({
// "status": 200,
// "foo": "bar",
// "location": header
// });
// })
// .fail(util.error);
}
}
return
RSVP
.
all
(
promises
)
return
RSVP
.
all
(
promises
)
...
...
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