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
a439b2ae
Commit
a439b2ae
authored
Apr 09, 2014
by
Sven Franck
Browse files
Options
Browse Files
Download
Email Patches
Plain Diff
app: made text format/crop/merge generic over table/list
parent
a9679be0
Changes
1
Hide whitespace changes
Inline
Side-by-side
Showing
1 changed file
with
66 additions
and
21 deletions
+66
-21
js/erp5_loader.js
js/erp5_loader.js
+66
-21
No files found.
js/erp5_loader.js
View file @
a439b2ae
...
...
@@ -1739,11 +1739,13 @@
factory
.
element
({
"
type
"
:
block
.
type
,
"
direct
"
:
{
"
className
"
:
(
block
.
aside
?
"
ui-li-aside
"
:
"
"
)
+
(
block
.
text_i18n
?
"
translate
"
:
""
)
"
className
"
:
(
block
.
aside
?
"
ui-li-aside
"
:
"
"
)
+
(
block
.
text_i18n
?
"
translate
"
:
"
"
)
+
block
.
class_list
},
"
attributes
"
:
{
"
data-i18n
"
:
block
.
text_i18n
||
""
},
"
logic
"
:
{
"
text
"
:
block
.
text
}
"
logic
"
:
{
"
text
"
:
block
.
text
,
"
data-i18n
"
:
block
.
text_i18n
||
null
}
})
);
}
...
...
@@ -3365,21 +3367,10 @@
cell
=
util
.
mergeObject
(
core
,
util
.
cloneObject
(
segment
.
field_list
[
k
]));
// custom header (!) cells have text/i18n defined
// TODO: convert to input field here?
if
(
!
cell
.
custom
)
{
crop
=
cell
.
crop
;
// HACK: only used for price_currency crop contents
if
(
crop
)
{
re
=
new
RegExp
(
crop
,
'
g
'
);
cell
.
text
=
record
[
cell
.
field
].
replace
(
re
,
''
);
}
else
{
// TODO: not all numbers want to be rounded to 2 digits....
if
(
!
isNaN
(
parseFloat
(
record
[
cell
.
field
]))
&&
isFinite
(
record
[
cell
.
field
]))
{
cell
.
text
=
Math
.
round
(
record
[
cell
.
field
]).
toFixed
(
2
);
}
else
{
cell
.
text
=
record
[
cell
.
field
];
}
}
cell
.
text_i18n
=
null
;
cell
.
text
=
util
.
generateText
(
record
[
cell
.
field
],
cell
,
record
)
cell
.
text_i18n
=
record
.
text_i18n
||
null
;
}
row
.
push
(
cell
);
}
...
...
@@ -3460,14 +3451,16 @@
for
(
k
=
0
;
k
<
section
.
field_list
.
length
;
k
+=
1
)
{
field
=
section
.
field_list
[
k
];
// add object to text-array
if
(
new_item
[
pos
].
text
)
{
//
add object to text-array
//
TODO: so much nulllll, also how to convert to input field?
new_item
[
pos
].
text
.
push
({
"
type
"
:
field
.
type
||
"
span
"
,
"
text
"
:
record
[
field
.
field
]
,
"
text
"
:
util
.
generateText
(
record
[
field
.
field
],
field
,
record
)
,
"
aside
"
:
field
.
aside
||
null
,
"
count
"
:
field
.
count
||
null
,
"
text_i18n
"
:
record
[
field
.
field
+
"
_18n
"
]
||
null
"
text_i18n
"
:
record
.
text_i18n
||
null
,
"
class_list
"
:
field
.
class_list
||
""
});
}
else
{
// set type to record field or field value (custom fields!)
...
...
@@ -5439,6 +5432,58 @@
*/
util
=
{};
/**
* Crop a string (data field)
* @method crop
* @param {string} str String to crop
* @param {string} crop String to crop
* @return {string} cropped string
**/
util
.
crop
=
function
(
str
,
crop
)
{
var
re
=
new
RegExp
(
crop
,
'
g
'
);
return
str
.
replace
(
re
,
''
);
};
/**
* format a string (data field)
* @method format
* @param {string} str String to format
* @param {object} spec Formating options (type, etc)
* @return {string} formatted string
**/
util
.
format
=
function
(
str
,
spec
)
{
switch
(
spec
.
type
)
{
case
"
integer
"
:
if
(
!
isNaN
(
parseFloat
(
str
))
&&
isFinite
(
str
))
{
return
Math
.
round
(
str
).
toFixed
(
spec
.
digits
);
}
}
return
str
;
};
/**
* generates a text based on mapping criteria
* @method generateText
* @param {string} str String to modify
* @param {object} spec Formatting options
* @param {object} record Full record (only used for merge)
* @return {string} modified string
**/
util
.
generateText
=
function
(
str
,
spec
,
record
)
{
if
(
spec
.
crop
)
{
str
=
util
.
crop
(
str
,
spec
.
crop
);
}
if
(
spec
.
format
)
{
str
=
util
.
format
(
str
,
spec
.
format
);
}
// TODO: ? vs merge -> make generic
if
(
spec
.
mergeText
)
{
str
+=
"
"
+
record
[
spec
.
mergeText
];
}
return
str
;
};
/**
* Fetch a value from an object based on an array path
* @method fetchByArray
...
...
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