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
bc94841c
Commit
bc94841c
authored
Dec 31, 2013
by
Sven Franck
Browse files
Options
Browse Files
Download
Email Patches
Plain Diff
allow custom form fields, force portal type in POST, validate against portal_type definition
parent
db51c24b
Changes
1
Show whitespace changes
Inline
Side-by-side
Showing
1 changed file
with
140 additions
and
53 deletions
+140
-53
js/erp5_loader.js
js/erp5_loader.js
+140
-53
No files found.
js/erp5_loader.js
View file @
bc94841c
...
@@ -27,14 +27,6 @@
...
@@ -27,14 +27,6 @@
**/
**/
map
.
actions
=
{
map
.
actions
=
{
/**
* Create an installation
* @method installa
**/
"
install
"
:
function
()
{
util
.
error
({
"
error
"
:
"
install: Nothing defined
"
});
},
/**
/**
* Look up single value from dict
* Look up single value from dict
* @method translateLookup
* @method translateLookup
...
@@ -304,7 +296,20 @@
...
@@ -304,7 +296,20 @@
},
},
/**
/**
* Submit a form
* 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
);
},
/**
* Add a user to the storage
* @method submit
* @method submit
* @param {object} obj Action Object
* @param {object} obj Action Object
**/
**/
...
@@ -951,7 +956,7 @@
...
@@ -951,7 +956,7 @@
"
value
"
:
field_value
,
"
value
"
:
field_value
,
"
text
"
:
textarea_value
,
"
text
"
:
textarea_value
,
"
readonly
"
:
(
prevail
.
properties
.
editable
===
false
||
"
readonly
"
:
(
prevail
.
properties
.
editable
===
false
||
spec
.
properties
.
editable
===
false
)
?
true
:
undefined
,
spec
.
properties
.
editable
===
false
)
?
"
readonly
"
:
undefined
,
"
options
"
:
(
prevail
.
widget
.
items
||
spec
.
widget
.
items
)
?
"
options
"
:
(
prevail
.
widget
.
items
||
spec
.
widget
.
items
)
?
([
([
prevail
.
widget
.
items
||
spec
.
widget
.
items
||
null
,
prevail
.
widget
.
items
||
spec
.
widget
.
items
||
null
,
...
@@ -3631,8 +3636,8 @@
...
@@ -3631,8 +3636,8 @@
text
=
"
search
"
;
text
=
"
search
"
;
}
}
// disable IOS auto functionality
// disable IOS auto functionality
config
.
attributes
.
autocapitalize
=
"
off
"
;
config
.
attributes
.
autocapitalize
=
"
none
"
;
config
.
attributes
.
autocorrect
=
"
off
"
;
config
.
attributes
.
autocorrect
=
"
none
"
;
// update class_list
// update class_list
container_class_list
=
"
ui-input-
"
+
text
+
"
ui-body-inherit
"
;
container_class_list
=
"
ui-input-
"
+
text
+
"
ui-body-inherit
"
;
}
}
...
@@ -3955,7 +3960,7 @@
...
@@ -3955,7 +3960,7 @@
storage
.
add
=
function
(
config
)
{
storage
.
add
=
function
(
config
)
{
var
property
,
replace
,
i
,
obj
,
value
,
form_elements
,
form_element
,
pass
,
var
property
,
replace
,
i
,
obj
,
value
,
form_elements
,
form_element
,
pass
,
test_full
,
test_empty
,
test_time
,
form_to_submit
,
anti_spam
,
formData
,
test_full
,
test_empty
,
test_time
,
form_to_submit
,
anti_spam
,
formData
,
valid
,
pass_id
;
valid
,
pass_id
,
validate_portal_type_fields
;
pass
=
false
;
pass
=
false
;
form_to_submit
=
document
.
getElementById
(
config
.
id
);
form_to_submit
=
document
.
getElementById
(
config
.
id
);
...
@@ -3968,7 +3973,7 @@
...
@@ -3968,7 +3973,7 @@
// spam - thx http://nedbatchelder.com/text/stopbots.html
// spam - thx http://nedbatchelder.com/text/stopbots.html
if
(
anti_spam
)
{
if
(
anti_spam
)
{
// fill form in < 1sec = spam
mer
// fill form in < 1sec = spam
if
(
Date
.
now
()
-
parseInt
(
anti_spam
.
getAttribute
(
"
data-created
"
),
10
)
if
(
Date
.
now
()
-
parseInt
(
anti_spam
.
getAttribute
(
"
data-created
"
),
10
)
>
1000
)
{
>
1000
)
{
test_time
=
true
;
test_time
=
true
;
...
@@ -3999,28 +4004,53 @@
...
@@ -3999,28 +4004,53 @@
replace
=
form_to_submit
.
id
.
split
(
"
_
"
)[
0
]
+
"
_
"
;
replace
=
form_to_submit
.
id
.
split
(
"
_
"
)[
0
]
+
"
_
"
;
obj
=
{};
obj
=
{};
// force portal_type
if
(
config
.
gadget
.
state
.
force_type
)
{
config
.
gadget
.
state
.
type
=
config
.
gadget
.
state
.
force_type
;
validate_portal_type_fields
=
true
;
}
for
(
property
in
valid
)
{
for
(
property
in
valid
)
{
if
(
valid
.
hasOwnProperty
(
property
))
{
if
(
valid
.
hasOwnProperty
(
property
))
{
value
=
valid
[
property
];
value
=
valid
[
property
];
// prepare for storage
// prepare to store
// TODO: check for portal-type in field name and skip if missing
if
(
property
!==
"
undefined
"
)
{
if
(
property
!==
"
undefined
"
)
{
// overwrite portal_type if forced
if
(
config
.
gadget
.
state
.
force_type
&&
property
!==
"
identifier
"
)
{
obj
[
property
.
replace
(
property
.
split
(
"
_
"
)[
0
],
config
.
gadget
.
state
.
force_type
.
toLowerCase
())
]
=
value
;
}
else
{
obj
[
property
]
=
value
;
obj
[
property
]
=
value
;
}
}
}
// prepare for form submit
// prepare for form submit
// NOTE: formData can post CORS!
// NOTE: formData can post CORS!
formData
.
append
(
property
.
replace
(
replace
,
""
),
value
);
//
formData.append(property.replace(replace, ""), value);
}
}
}
}
// force new object to be created
if
(
config
.
gadget
.
state
.
create_new
)
{
delete
obj
.
identifier
;
}
util
.
loader
(
""
,
"
global_dict.status_dict.saving
"
);
util
.
loader
(
""
,
"
global_dict.status_dict.saving
"
);
// TODO: a post should always include all required fields
// TODO: a post should always include all required fields
// TODO: find a way to set default fields, like timestamp etc
// TODO: find a way to set default fields, like timestamp etc
app
.
store
({
app
.
store
({
"
response
"
:
[
obj
],
"
response
"
:
[
obj
],
"
pass
"
:
{
"
type
"
:
config
.
gadget
.
state
.
type
,
"
reply
"
:
true
}
"
pass
"
:
{
"
type
"
:
config
.
gadget
.
state
.
type
,
"
reply
"
:
true
,
"
validate_type
"
:
validate_portal_type_fields
}
})
})
.
then
(
function
(
answer
)
{
.
then
(
function
(
answer
)
{
if
(
answer
.
response
.
result
===
"
success
"
)
{
if
(
answer
.
response
.
result
===
"
success
"
)
{
...
@@ -5353,7 +5383,7 @@
...
@@ -5353,7 +5383,7 @@
*/
*/
app
.
store
=
function
(
reply
)
{
app
.
store
=
function
(
reply
)
{
var
i
,
obj
,
key
,
promises
,
record
,
items
,
store
,
pass
,
send_status
,
var
i
,
obj
,
key
,
promises
,
record
,
items
,
store
,
pass
,
send_status
,
method
;
method
,
validate
;
pass
=
reply
.
pass
;
pass
=
reply
.
pass
;
...
@@ -5362,19 +5392,68 @@
...
@@ -5362,19 +5392,68 @@
items
=
util
.
parseIfNeeded
(
reply
.
response
);
items
=
util
.
parseIfNeeded
(
reply
.
response
);
if
(
store
&&
items
.
length
>
0
)
{
if
(
store
&&
items
.
length
>
0
)
{
promises
=
[];
// show some status
// show some status
util
.
loader
(
""
,
"
global_dict.status_dict.storing
"
);
util
.
loader
(
""
,
"
global_dict.status_dict.storing
"
);
// as store will also be called directly and may require field
// definitions for validating what is being stored, we may fetch
// field definitions here again. When called in the setContent
// chain, fields are already included in pass
pass
.
items
=
items
;
// only fetch if validate_type is set!
if
(
pass
.
validate_type
===
undefined
)
{
pass
.
skip
=
pass
.
undo_skip
=
true
;
}
// TODO: bad way to set attachment value!!
return
app
.
fetchConfiguration
({
"
storage
"
:
app
.
default_dict
.
storage_dict
.
settings
,
"
file
"
:
app
.
default_dict
.
storage_dict
.
data_type
,
"
attachment
"
:
pass
.
type
.
toLowerCase
()
+
"
_fieldlist
"
,
"
pass
"
:
pass
})
.
then
(
function
(
answer
)
{
promises
=
[];
// clean skip && set field validation
if
(
answer
.
pass
&&
answer
.
pass
.
undo_skip
)
{
delete
answer
.
pass
.
skip
;
delete
answer
.
pass
.
undo_skip
;
// if we have an answer = field definitions, the record fields
// must be validated before storing, so we don't store a field
// that does not exist
}
else
{
if
(
answer
.
response
)
{
validate
=
true
;
}
else
{
util
.
error
({
"
error
"
:
"
store: field definintions not found.
"
});
}
}
// loop over item and create a JIO record
// loop over item and create a JIO record
for
(
i
=
0
;
i
<
items
.
length
;
i
+=
1
)
{
for
(
i
=
0
;
i
<
pass
.
items
.
length
;
i
+=
1
)
{
record
=
items
[
i
];
record
=
pass
.
items
[
i
];
obj
=
{};
obj
=
{};
for
(
key
in
record
)
{
for
(
key
in
record
)
{
if
(
record
.
hasOwnProperty
(
key
))
{
if
(
record
.
hasOwnProperty
(
key
))
{
if
(
validate
)
{
if
(
answer
.
response
[
key
])
{
obj
[
key
]
=
record
[
key
];
}
else
{
util
.
error
({
"
error
"
:
"
store: field
"
+
key
+
"
not defined for type =
"
+
pass
.
type
});
}
}
else
{
obj
[
key
]
=
record
[
key
];
obj
[
key
]
=
record
[
key
];
}
}
}
}
}
// add portal type
// add portal type
obj
.
portal_type
=
pass
.
type
;
obj
.
portal_type
=
pass
.
type
;
...
@@ -5385,13 +5464,17 @@
...
@@ -5385,13 +5464,17 @@
delete
obj
.
identifier
;
delete
obj
.
identifier
;
}
}
// store
promises
[
i
]
=
store
[
method
||
"
post
"
](
obj
)
promises
[
i
]
=
store
[
method
||
"
post
"
](
obj
)
.
then
(
function
(
answer
)
{
.
then
(
function
(
answer
)
{
return
answer
;
return
answer
;
});
})
.
fail
(
util
.
error
);
}
}
return
RSVP
.
all
(
promises
)
return
RSVP
.
all
(
promises
)
.
then
(
function
(
response
)
{
.
then
(
function
(
response
)
{
// for single item actions, allow to return a status message
// for single item actions, allow to return a status message
if
(
response
.
length
===
1
&&
reply
.
pass
.
reply
)
{
if
(
response
.
length
===
1
&&
reply
.
pass
.
reply
)
{
send_status
=
response
[
0
];
send_status
=
response
[
0
];
...
@@ -5402,13 +5485,17 @@
...
@@ -5402,13 +5485,17 @@
};
};
})
})
.
fail
(
util
.
error
);
.
fail
(
util
.
error
);
})
.
fail
(
util
.
error
);
}
}
//
we may have
no sample data!
// no sample data!
return
{
return
{
"
response
"
:
undefined
,
"
response
"
:
undefined
,
"
pass
"
:
pass
"
pass
"
:
pass
};
};
}
}
// nothing to do
return
{
return
{
"
pass
"
:
pass
"
pass
"
:
pass
};
};
...
...
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