Skip to content
Projects
Groups
Snippets
Help
Loading...
Help
Support
Keyboard shortcuts
?
Submit feedback
Contribute to GitLab
Sign in / Register
Toggle navigation
erp5
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
1
Merge Requests
1
Analytics
Analytics
Repository
Value Stream
Wiki
Wiki
Snippets
Snippets
Members
Members
Collapse sidebar
Close sidebar
Activity
Graph
Create a new issue
Commits
Issue Boards
Open sidebar
Cédric Le Ninivin
erp5
Commits
42786fe3
Commit
42786fe3
authored
Oct 25, 2019
by
Xiaowu Zhang
Committed by
Cédric Le Ninivin
Feb 09, 2021
Browse files
Options
Browse Files
Download
Email Patches
Plain Diff
erp5_production_planning: display total line for production matrix
parent
00da8381
Changes
3
Show whitespace changes
Inline
Side-by-side
Showing
3 changed files
with
165 additions
and
1 deletion
+165
-1
bt5/erp5_production_planning/SkinTemplateItem/portal_skins/erp5_production_planning/ProductionPlanning_view/matrixbox.xml
...production_planning/ProductionPlanning_view/matrixbox.xml
+1
-1
bt5/erp5_production_planning/SkinTemplateItem/portal_skins/erp5_production_planning/matrix_dynamic_total_line_column.js.js
...roduction_planning/matrix_dynamic_total_line_column.js.js
+136
-0
bt5/erp5_production_planning/SkinTemplateItem/portal_skins/erp5_production_planning/matrix_dynamic_total_line_column.js.xml
...oduction_planning/matrix_dynamic_total_line_column.js.xml
+28
-0
No files found.
bt5/erp5_production_planning/SkinTemplateItem/portal_skins/erp5_production_planning/ProductionPlanning_view/matrixbox.xml
View file @
42786fe3
...
...
@@ -235,7 +235,7 @@
</item>
<item>
<key>
<string>
css_class
</string>
</key>
<value>
<string></string>
</value>
<value>
<string>
matrixbox_production_planning
</string>
</value>
</item>
<item>
<key>
<string>
default
</string>
</key>
...
...
bt5/erp5_production_planning/SkinTemplateItem/portal_skins/erp5_production_planning/matrix_dynamic_total_line_column.js.js
0 → 100644
View file @
42786fe3
var
matrixbox
;
var
sRegExp
=
new
RegExp
(
'
(-?[0-9]+)([0-9]{3})
'
);
function
format
(
num
)
{
// format a number to string, only 1 234 format is supported.
num
=
num
.
toString
();
while
(
sRegExp
.
test
(
num
))
{
num
=
num
.
replace
(
sRegExp
,
'
$1 $2
'
);
}
return
num
;
}
function
parse
(
str
)
{
// parse a string to a number
// \s is for opera, others are for chrome / firefox
return
parseFloat
(
str
.
replace
(
/
\s
/g
,
""
)
.
replace
(
/ /g
,
""
)
.
replace
(
/ /g
,
""
)
);
}
/* matrixbox sums */
// XXX must also add a class to the matrixbox, not to apply on all mb
function
addTotalLineToMatrixBox
()
{
var
nb_columns
=
matrixbox
.
find
(
"
tr:first td
"
).
length
;
matrixbox
.
find
(
"
td.footer
"
).
attr
(
'
colspan
'
,
nb_columns
);
// add tr for summary line (only if having more than one line)
if
(
matrixbox
.
find
(
"
tr.DataA, tr.DataB
"
).
length
>
1
)
{
var
last_line
=
matrixbox
.
find
(
'
tr:last
'
);
var
sumline
=
$
(
'
<tr class="MatrixBoxSumLine" style="border-top: 1px solid #3D6474"/>
'
).
insertBefore
(
last_line
);
// add as many td in the summary line
$
(
'
<td class="Data footer"/>
'
).
appendTo
(
sumline
);
// ( + 1 for the title column )
// once again, if we only have one column, we do not add a summary
// column
for
(
i
=
1
;
i
<
(
nb_columns
==
2
?
1
:
nb_columns
);
i
++
)
{
$
(
'
<td class="Data footer" style="text-align: right"><span class="input figure"></span></td>
'
).
appendTo
(
sumline
);
}
}
}
function
recalculateSumLine
(
idx
,
element
)
{
// recalculates the sum line. `element` must be the tr with class
// .MatrixBoxSumLine
jQuery
(
element
).
find
(
'
span.input
'
).
each
(
function
(
idx
,
element
){
var
sum
=
0
,
inputs
=
matrixbox
.
find
(
'
tr
'
).
find
(
'
td:eq(
'
+
(
idx
+
1
)
+
'
)
'
);
for
(
i
=
1
;
i
<
inputs
.
length
-
1
;
i
++
)
{
var
input
=
inputs
[
i
];
var
tmp
=
input
.
querySelector
(
'
input
'
);
if
(
tmp
)
{
v
=
parse
(
tmp
.
value
);
}
else
{
v
=
parse
(
input
.
innerText
);
}
if
(
v
)
{
sum
+=
v
;
}
}
jQuery
(
element
).
text
(
format
(
sum
));
});
}
function
recalculateSumColumn
(
idx
,
element
)
{
// recalculates the value of a sum column. `element` must be the td with class
// .MatrixBoxSumColumn
var
me
=
jQuery
(
element
);
var
sum
=
0
;
inputs
=
me
.
parent
().
siblings
();
for
(
i
=
1
;
i
<
inputs
.
length
;
i
++
)
{
var
input
=
inputs
[
i
];
var
tmp
=
input
.
querySelector
(
'
input
'
);
if
(
tmp
)
{
v
=
parse
(
tmp
.
value
);
}
else
{
v
=
parse
(
input
.
innerText
);
}
if
(
v
)
{
sum
+=
v
;
}
}
me
.
text
(
format
(
sum
));
}
function
addTotalColumnToMatrixBox
()
{
// initialise:
nb_columns
=
matrixbox
.
find
(
"
tr:first td
"
).
length
;
// add td for summary column (only if having more than one column)
if
(
nb_columns
>
2
)
{
$
(
'
<td style="text-align: right"><span class="MatrixBoxSumColumn input figure" disabled="disabled"/></td>
'
).
appendTo
(
matrixbox
.
find
(
'
tr.DataA, tr.DataB
'
)
);
$
(
'
<td/>
'
).
appendTo
(
matrixbox
.
find
(
'
tr.matrixbox_label_line
'
));
}
}
function
addTotalLineColumnToMatrixBox
(
matrixbox_container
)
{
matrixbox
=
$
(
matrixbox_container
.
querySelector
(
'
.MatrixContent
'
));
addTotalLineToMatrixBox
();
//addTotalColumnToMatrixBox();
//matrixbox.find('.MatrixBoxSumColumn').each(recalculateSumColumn);
matrixbox
.
find
(
'
.MatrixBoxSumLine
'
).
each
(
recalculateSumLine
);
}
var
config
=
{
childList
:
true
,
subtree
:
true
,
attributes
:
false
,
characterData
:
false
};
function
observe
(
mutationsList
)
{
mutationsList
.
forEach
(
function
observerMutation
(
mutation
)
{
if
(
mutation
.
type
===
'
childList
'
)
{
len
=
mutation
.
addedNodes
.
length
;
for
(
i
=
0
;
i
<
len
;
i
+=
1
)
{
node
=
mutation
.
addedNodes
[
i
];
if
(
node
.
nodeType
===
Node
.
ELEMENT_NODE
)
{
// Make sure matrixbox is fully displayed
if
(
node
.
getAttribute
(
'
class
'
)
==
'
Data footer
'
)
{
var
matrixbox
=
document
.
querySelector
(
'
.matrixbox_production_planning
'
);
addTotalLineColumnToMatrixBox
(
matrixbox
);
observer
.
disconnect
();
}
}
}
}
});
}
// Create an observer instance linked to the callback function
var
observer
=
new
MutationObserver
(
observe
);
// Start observing the target node for configured mutations
observer
.
observe
(
document
,
config
);
bt5/erp5_production_planning/SkinTemplateItem/portal_skins/erp5_production_planning/matrix_dynamic_total_line_column.js.xml
0 → 100644
View file @
42786fe3
<?xml version="1.0"?>
<ZopeData>
<record
id=
"1"
aka=
"AAAAAAAAAAE="
>
<pickle>
<global
name=
"File"
module=
"OFS.Image"
/>
</pickle>
<pickle>
<dictionary>
<item>
<key>
<string>
__name__
</string>
</key>
<value>
<string>
matrix_dynamic_total_line_column.js
</string>
</value>
</item>
<item>
<key>
<string>
content_type
</string>
</key>
<value>
<string>
application/javascript
</string>
</value>
</item>
<item>
<key>
<string>
precondition
</string>
</key>
<value>
<string></string>
</value>
</item>
<item>
<key>
<string>
title
</string>
</key>
<value>
<string></string>
</value>
</item>
</dictionary>
</pickle>
</record>
</ZopeData>
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