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
c01edfeb
Commit
c01edfeb
authored
Jan 03, 2014
by
Sven Franck
Browse files
Options
Browse Files
Download
Email Patches
Plain Diff
change prefix from portal_type to id of form
parent
05113df3
Changes
1
Hide whitespace changes
Inline
Side-by-side
Showing
1 changed file
with
50 additions
and
28 deletions
+50
-28
js/erp5_loader.js
js/erp5_loader.js
+50
-28
No files found.
js/erp5_loader.js
View file @
c01edfeb
...
...
@@ -15,10 +15,6 @@
* Mapping data structure to factory (actions, gadgets, buttons, utilities)
* @object map
**/
// NOTE: to use the UI generator with your own data structure, write your
// own map object, which contains all actions, all gadgets and mapping
// methods to convert your data into the JSON configuration needed by
// the factory.
map
=
{};
/**
...
...
@@ -700,8 +696,7 @@
// should only be possible if links will be external, but how to set?
if
(
spec
.
property_dict
.
link
)
{
obj
.
href
=
"
#
"
+
core
+
"
::
"
+
item
[
spec
.
portal_type_title
+
"
_
"
+
(
spec
.
property_dict
.
link_identifier
||
"
id
"
)];
item
[
spec
.
property_dict
.
link_identifier
||
"
id
"
];
}
// TODO: don't do this based on hardcoded filenames!!!
...
...
@@ -778,6 +773,7 @@
/**
* Map field definition to factory form element
* @method mapFormField
* @param {string} form_id ID of form to prefix all form fields
* @param {object} spec Form field definition
* @param {object} overrides Overrides for this field
* @param {string} value Value to set this field to
...
...
@@ -785,9 +781,9 @@
**/
// NOTE: select options must be fetched here, because we are setting
// the mapping from (ERP5) custom API to internal API here
"
mapFormField
"
:
function
(
spec
,
overrides
,
passed_value
)
{
"
mapFormField
"
:
function
(
form_id
,
spec
,
overrides
,
passed_value
)
{
var
validation_list
,
class_list
,
element
,
type
,
prevail
,
clear
,
config
,
field_value
,
skip
,
use_type
,
textarea_value
;
field_value
,
skip
,
use_type
,
textarea_value
,
alternate_name
;
// build config object
config
=
{};
...
...
@@ -820,6 +816,7 @@
}
// easy way out if not enabled
// TODO: should a span still have full structure (label/container)?
if
(
prevail
.
properties
.
enabled
===
false
||
spec
.
properties
.
enabled
===
false
)
{
config
=
{
...
...
@@ -943,12 +940,16 @@
validation_list
=
undefined
;
}
// define alternate name here
alternate_name
=
prevail
.
widget
.
alternate_name
||
spec
.
widget
.
alternate_name
;
// construct config
// NOTE: type (checkbox, radio...) set in attributes, because can be
// null on select/textarea
config
.
type
=
element
;
config
.
direct
=
{
"
id
"
:
(
prevail
.
widget
.
id
||
spec
.
widget
.
id
),
"
id
"
:
form_id
+
"
_
"
+
(
prevail
.
widget
.
id
||
spec
.
widget
.
id
),
"
className
"
:
class_list
+
"
"
+
(
prevail
.
widget
.
css_class
||
spec
.
widget
.
css_class
||
""
)
};
...
...
@@ -960,8 +961,7 @@
config
.
logic
=
{
"
data-vv-validations
"
:
validation_list
||
undefined
,
"
extra
"
:
prevail
.
widget
.
extra
||
spec
.
widget
.
extra
||
undefined
,
"
name
"
:
prevail
.
widget
.
alternate_name
||
spec
.
widget
.
alternate_name
||
null
,
"
name
"
:
alternate_name
?
form_id
+
"
_
"
+
alternate_name
:
null
,
"
size
"
:
prevail
.
widget
.
display_width
||
spec
.
widget
.
display_width
||
prevail
.
widget
.
size
||
spec
.
widget
.
size
||
undefined
,
"
rows
"
:
prevail
.
widget
.
width
||
spec
.
widget
.
width
||
undefined
,
...
...
@@ -1515,7 +1515,7 @@
element
.
reset
=
reset_state
;
element
.
form
=
spec
.
form
;
element
.
fields
=
field_dict
;
element
.
id
=
spec
.
id
;
element
.
reference
=
spec
.
id
;
}
target
.
appendChild
(
app
.
setContent
(
element
));
}
...
...
@@ -1762,12 +1762,15 @@
*/
factory
.
util
.
wrapInForm
=
function
(
spec
)
{
if
(
spec
.
form
)
{
if
(
spec
.
reference
===
undefined
&&
spec
.
id
===
undefined
)
{
util
.
error
({
"
error
"
:
"
wrapInForm: Missing form id.
"
});
}
return
factory
.
element
(
"
form
"
,
{
"
method
"
:
"
POST
"
,
"
action
"
:
"
#
"
,
"
id
"
:
spec
.
id
,
"
id
"
:
spec
.
reference
||
spec
.
id
,
"
className
"
:
(
spec
.
class_list
||
""
)
},
{
"
data-ajax
"
:
false
,
"
autocomplete
"
:
"
off
"
},
...
...
@@ -2217,9 +2220,10 @@
factory
.
form
=
function
(
spec
)
{
var
i
,
j
,
k
,
layout
,
element
,
container
,
area
,
field
,
overrides
,
position
,
doc
,
config
,
value
,
stamp
,
sauce
,
encode
,
secure
,
safety_box
,
fragment
,
wrap
,
item_id
,
input_config
;
safety_box
,
fragment
,
wrap
,
item_id
,
input_config
,
form_id
;
fragment
=
factory
.
util
.
wrapInForm
(
spec
);
form_id
=
spec
.
reference
;
secure
=
spec
.
property_dict
.
secure
;
item_id
=
spec
.
data
?
(
spec
.
data
.
_id
||
undefined
)
:
undefined
;
...
...
@@ -2228,7 +2232,7 @@
// set optional captcha config
if
(
captcha
)
{
keys
.
id
=
spec
.
id
+
"
_captcha
"
;
keys
.
id
=
form_
id
+
"
_captcha
"
;
keys
[
"
data-key
"
]
=
spec
.
property_dict
.
public_key
;
}
...
...
@@ -2281,7 +2285,7 @@
{
"
type
"
:
"
hidden
"
,
"
value
"
:
spec
.
property_dict
.
secret_hash
,
"
id
"
:
spec
.
id
+
"
_not_a_secret
"
"
id
"
:
form_
id
+
"
_not_a_secret
"
},
{
"
data-created
"
:
stamp
...
...
@@ -2343,7 +2347,12 @@
value
=
doc
?
(
doc
[
field
.
title
])
:
undefined
;
// map config to what we need
input_config
=
map
.
utils
.
mapFormField
(
config
,
overrides
,
value
);
input_config
=
map
.
utils
.
mapFormField
(
form_id
,
config
,
overrides
,
value
);
}
...
...
@@ -2397,7 +2406,7 @@
// pass reference
element
=
spec
.
children
[
k
];
if
(
spec
.
form
)
{
element
.
reference
=
spec
.
id
;
element
.
reference
=
form_
id
;
element
.
item_identifier
=
item_id
;
}
...
...
@@ -3991,7 +4000,6 @@
// spam - thx http://nedbatchelder.com/text/stopbots.html
if
(
anti_spam
)
{
// fill form in < 1sec = spam
if
(
Date
.
now
()
-
parseInt
(
anti_spam
.
getAttribute
(
"
data-created
"
),
10
)
>
1000
)
{
...
...
@@ -4016,7 +4024,13 @@
if
(
test_empty
&&
test_full
&&
test_time
)
{
pass
=
true
;
}
// skip spam testing
}
else
{
pass
=
true
;
}
// DONE and ...?
if
(
pass
===
true
)
{
return
valid
;
}
...
...
@@ -4079,9 +4093,9 @@
if
(
valid
===
undefined
)
{
util
.
loader
(
""
,
"
validation_dict.general
"
,
"
ban-circle
"
);
//
valid form and no spam
//
form is valid and not "spam"
}
else
{
replace
=
form_to_submit
.
id
.
split
(
"
_
"
)[
0
]
+
"
_
"
;
replace
=
form_to_submit
.
id
+
"
_
"
;
obj
=
{};
// force portal_type
...
...
@@ -4095,18 +4109,25 @@
value
=
valid
[
property
];
// prepare to store
// TODO: add id to captcha fields missing it...
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
;
if
(
property
!==
"
identifier
"
)
{
obj
[
property
.
replace
(
replace
,
""
)]
=
value
;
}
else
{
obj
[
property
]
=
value
;
}
// 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;
// }
}
// prepare for form submit
...
...
@@ -5472,12 +5493,13 @@
pass
=
reply
.
pass
;
if
(
reply
.
response
)
{
// TODO: remove once no need for sample data
if
(
pass
.
needs_fields
)
{
delete
pass
.
needs_fields
;
pass
.
fields
=
util
.
parseIfNeeded
(
reply
.
response
);
}
store
=
storage
.
items
;
items
=
util
.
parseIfNeeded
(
reply
.
response
);
...
...
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