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
df2c26ed
Commit
df2c26ed
authored
Feb 21, 2014
by
Sven Franck
Browse files
Options
Browse Files
Download
Email Patches
Plain Diff
new storage.save method running all hacks inside hateoasstorage
parent
d0ac9f8f
Changes
1
Hide whitespace changes
Inline
Side-by-side
Showing
1 changed file
with
205 additions
and
192 deletions
+205
-192
js/erp5_loader.js
js/erp5_loader.js
+205
-192
No files found.
js/erp5_loader.js
View file @
df2c26ed
...
...
@@ -1055,6 +1055,45 @@
**/
map
.
actions
=
{
/**
* Generate a new object
* @method install
* @param {object} obj Action Object
**/
"
new
"
:
function
(
obj
)
{
storage
.
save
(
obj
);
},
/**
* Add a server
* @method submit
* @param {object} obj Action Object
**/
"
update_configuration
"
:
function
(
obj
)
{
storage
.
add
(
obj
);
},
/**
* add a service
* @method install
* @param {object} obj Action Object
**/
"
instantiate
"
:
function
(
obj
)
{
obj
.
gadget
.
state
.
create_new
=
true
;
obj
.
gadget
.
state
.
force_formdata
=
true
;
obj
.
gadget
.
state
.
url_pointer
=
"
request
"
;
storage
.
add
(
obj
);
},
/**
* Add a user to the storage
* @method submit
* @param {object} obj Action Object
**/
"
add
"
:
function
(
obj
)
{
storage
.
add
(
obj
);
},
/**
* Start a software instance
* @method start_instance
...
...
@@ -1308,6 +1347,89 @@
});
},
/**
* Create an installation = new service object
* @method install
* @param {object} obj Action Object
**/
"
install
"
:
function
(
obj
)
{
// force new portal type and POST (create new record)
obj
.
gadget
.
state
.
force_type
=
"
Service
"
;
obj
.
gadget
.
state
.
create_new
=
true
;
storage
.
add
(
obj
);
},
/**
* Destroy an installation = service object
* @method destroy
* @param {object} obj Action Object
**/
"
destroy
"
:
function
(
obj
)
{
storage
.
remove
(
obj
);
},
/**
* Start a software instance
* @method start_instance
* @param {object} obj Action Object
**/
"
update_ticket
"
:
function
(
obj
)
{
var
element
=
obj
.
element
,
formData
,
valid
,
replace
,
property
,
value
,
id
,
decode
,
store
;
id
=
obj
.
state
.
fragment_list
[
1
];
formData
=
new
FormData
();
store
=
app
.
storage_dict
;
valid
=
storage
.
validate
(
obj
.
gadget
);
decode
=
/^
[^\/]
*%2
[^\/]
*$/
.
test
(
id
);
if
(
valid
===
undefined
)
{
util
.
loader
(
""
,
"
validation_dict.general
"
,
"
ban-circle
"
);
// form is valid and not "spam"
}
else
{
replace
=
obj
.
gadget
.
id
+
"
_
"
;
for
(
property
in
valid
)
{
if
(
valid
.
hasOwnProperty
(
property
))
{
value
=
valid
[
property
];
// prepare to store
// TODO: add id to captcha fields missing it...
if
(
property
!==
"
undefined
"
)
{
if
(
property
!==
"
identifier
"
)
{
formData
.
append
(
property
.
replace
(
replace
,
""
),
value
);
}
}
}
}
util
.
loader
(
""
,
"
status_dict.updating
"
);
store
.
items
.
get
({
"
_id
"
:
window
.
decodeURIComponent
(
obj
.
state
.
fragment_list
[
1
])},{
"
_view
"
:
"
web_view
"
})
.
then
(
function
(
response
)
{
return
jIO
.
util
.
ajax
({
"
url
"
:
util
.
parse
(
response
).
data
.
_actions
.
update
.
href
,
"
type
"
:
"
POST
"
,
"
data
"
:
formData
,
"
xhrFields
"
:
{
"
withCredentials
"
:
true
}
});
})
.
then
(
function
(
answer
)
{
util
.
loader
(
""
,
"
status_dict.success
"
,
"
check
"
);
$
.
mobile
.
changePage
(
"
#services
"
);
})
.
fail
(
function
(
error
)
{
util
.
error
(
error
);
if
(
util
.
parse
(
error
.
target
).
responseText
===
""
&&
id
&&
obj
.
state
.
callback
)
{
$
.
mobile
.
changePage
(
obj
.
state
.
callback
.
replace
(
"
__id__
"
,
decode
?
id
:
window
.
encodeURIComponent
(
id
)));
}
});
}
},
// ==============================================================
/**
* Look up single value from dict
* @method translateLookup
...
...
@@ -1572,153 +1694,6 @@
.
fail
(
util
.
error
);
},
/**
* Create an installation = new service object
* @method install
* @param {object} obj Action Object
**/
"
install
"
:
function
(
obj
)
{
// force new portal type and POST (create new record)
obj
.
gadget
.
state
.
force_type
=
"
Service
"
;
obj
.
gadget
.
state
.
create_new
=
true
;
storage
.
add
(
obj
);
},
/**
* Destroy an installation = service object
* @method destroy
* @param {object} obj Action Object
**/
"
destroy
"
:
function
(
obj
)
{
storage
.
remove
(
obj
);
},
/**
* Add a user to the storage
* @method submit
* @param {object} obj Action Object
**/
"
add
"
:
function
(
obj
)
{
storage
.
add
(
obj
);
},
/**
* Add a server
* @method submit
* @param {object} obj Action Object
**/
"
add_server
"
:
function
(
obj
)
{
obj
.
gadget
.
state
.
create_new
=
true
;
obj
.
gadget
.
state
.
force_formdata
=
true
;
obj
.
gadget
.
state
.
url_pointer
=
"
request_computer
"
;
storage
.
add
(
obj
);
},
/**
* Add a server
* @method submit
* @param {object} obj Action Object
**/
"
add_ticket
"
:
function
(
obj
)
{
obj
.
gadget
.
state
.
create_new
=
true
;
obj
.
gadget
.
state
.
force_formdata
=
true
;
obj
.
gadget
.
state
.
url_pointer
=
"
request_ticket
"
;
storage
.
add
(
obj
);
},
/**
* Start a software instance
* @method start_instance
* @param {object} obj Action Object
**/
"
update_ticket
"
:
function
(
obj
)
{
var
element
=
obj
.
element
,
formData
,
valid
,
replace
,
property
,
value
,
id
,
decode
,
store
;
id
=
obj
.
state
.
fragment_list
[
1
];
formData
=
new
FormData
();
store
=
app
.
storage_dict
;
valid
=
storage
.
validate
(
obj
.
gadget
);
decode
=
/^
[^\/]
*%2
[^\/]
*$/
.
test
(
id
);
if
(
valid
===
undefined
)
{
util
.
loader
(
""
,
"
validation_dict.general
"
,
"
ban-circle
"
);
// form is valid and not "spam"
}
else
{
replace
=
obj
.
gadget
.
id
+
"
_
"
;
for
(
property
in
valid
)
{
if
(
valid
.
hasOwnProperty
(
property
))
{
value
=
valid
[
property
];
// prepare to store
// TODO: add id to captcha fields missing it...
if
(
property
!==
"
undefined
"
)
{
if
(
property
!==
"
identifier
"
)
{
formData
.
append
(
property
.
replace
(
replace
,
""
),
value
);
}
}
}
}
util
.
loader
(
""
,
"
status_dict.updating
"
);
store
.
items
.
get
({
"
_id
"
:
window
.
decodeURIComponent
(
obj
.
state
.
fragment_list
[
1
])},{
"
_view
"
:
"
web_view
"
})
.
then
(
function
(
response
)
{
return
jIO
.
util
.
ajax
({
"
url
"
:
util
.
parse
(
response
).
data
.
_actions
.
update
.
href
,
"
type
"
:
"
POST
"
,
"
data
"
:
formData
,
"
xhrFields
"
:
{
"
withCredentials
"
:
true
}
});
})
.
then
(
function
(
answer
)
{
util
.
loader
(
""
,
"
status_dict.success
"
,
"
check
"
);
$
.
mobile
.
changePage
(
"
#services
"
);
})
.
fail
(
function
(
error
)
{
util
.
error
(
error
);
if
(
util
.
parse
(
error
.
target
).
responseText
===
""
&&
id
&&
obj
.
state
.
callback
)
{
$
.
mobile
.
changePage
(
obj
.
state
.
callback
.
replace
(
"
__id__
"
,
decode
?
id
:
window
.
encodeURIComponent
(
id
)));
}
});
}
},
/**
* Add a server
* @method submit
* @param {object} obj Action Object
**/
"
update_configuration
"
:
function
(
obj
)
{
storage
.
add
(
obj
);
},
/**
* add a service
* @method install
* @param {object} obj Action Object
**/
"
instantiate
"
:
function
(
obj
)
{
obj
.
gadget
.
state
.
create_new
=
true
;
obj
.
gadget
.
state
.
force_formdata
=
true
;
obj
.
gadget
.
state
.
url_pointer
=
"
request
"
;
storage
.
add
(
obj
);
},
/**
* Instantiate a software instance
* @method install
* @param {object} obj Action Object
**/
"
add_network
"
:
function
(
obj
)
{
obj
.
gadget
.
state
.
create_new
=
true
;
obj
.
gadget
.
state
.
force_formdata
=
true
;
obj
.
gadget
.
state
.
url_pointer
=
"
request_computer_network
"
;
storage
.
add
(
obj
);
},
/**
* Show jumps popup
* @method jump
...
...
@@ -5563,17 +5538,51 @@
// generate storage object
storage
=
{};
/**
* Generate a new object
* @method newStore
* @param {object} obj Action object
*/
storage
.
save
=
function
(
obj
)
{
var
form
,
data
,
valid
,
prefix
,
decode
,
id
,
answer
,
goto
,
type
;
form
=
document
.
getElementById
(
obj
.
id
);
type
=
obj
.
state
.
url_pointer
[
obj
.
element
.
getAttribute
(
"
data-action
"
)];
prefix
=
obj
.
id
+
"
_
"
;
valid
=
storage
.
validate
(
obj
);
data
=
storage
.
parseForm
(
valid
,
prefix
,
true
);
RSVP
.
resolve
(
app
.
storage_dict
.
items
.
post
(
data
,
{
"
call
"
:
type
})
)
.
then
(
function
(
response
)
{
if
(
obj
.
state
.
callback
)
{
answer
=
util
.
parse
(
response
);
id
=
answer
.
id
;
decode
=
/^
[^\/]
*%2
[^\/]
*$/
.
test
(
id
);
goto
=
decode
?
id
:
window
.
encodeURIComponent
(
id
);
$
.
mobile
.
changePage
(
obj
.
state
.
callback
.
replace
(
"
__id__
"
,
goto
));
}
}).
fail
(
util
.
error
);
};
/**
* Make a formData object and replace prefixes
* @method parseForm
* @param {object} obj Form to parse
* @param {string} clean id of the form
* @param {boolean} plain Whether to return formData or normal data (true)
* @return {object} FormData object
*/
storage
.
parseForm
=
function
(
obj
,
clean
)
{
var
formData
,
property
,
value
;
storage
.
parseForm
=
function
(
obj
,
clean
,
plain
)
{
var
container
,
property
,
value
;
formData
=
new
FormData
();
if
(
plain
)
{
container
=
{};
}
else
{
container
=
new
FormData
();
}
for
(
property
in
obj
)
{
if
(
obj
.
hasOwnProperty
(
property
))
{
...
...
@@ -5583,12 +5592,16 @@
case
"
identifier
"
:
break
;
default
:
formData
.
append
(
property
.
replace
(
clean
,
""
),
value
);
if
(
plain
)
{
container
[
property
.
replace
(
clean
,
""
)]
=
value
;
}
else
{
container
.
append
(
property
.
replace
(
clean
,
""
),
value
);
}
break
;
}
}
}
return
formData
;
return
container
;
};
/**
...
...
@@ -7065,9 +7078,9 @@
// (pass.state.selected) : undefined;
// if a callback is provided, set it on state
if
(
pass
.
config
.
property_dict
.
submit_to
)
{
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
;
// tuck to gadget
// WARNING: this should use data(), it is BAD practice to store like this
...
...
@@ -7366,48 +7379,48 @@
// store
promises
[
i
]
=
store
[
method
||
"
post
"
](
obj
,
hacked_view
||
{})
.
then
(
function
(
answer
)
{
console
.
log
(
"
OUT
"
)
console
.
log
(
answer
)
return
answer
;
})
.
fail
(
util
.
error
);
}
}
else
{
// do it again, Sam...
promises
[
0
]
=
jIO
.
util
.
ajax
({
"
url
"
:
app
.
storage_dict
.
items
.
dict
.
url
,
"
type
"
:
"
GET
"
,
"
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
);
console
.
log
(
"
SHOULD BE REDUNDANT
"
)
// // do it again, Sam...
// promises[0] = jIO.util.ajax({
// "url": app.storage_dict.property_dict.items.storage_list[0].url,
// "type": "GET",
// "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
)
...
...
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