Commit c5a97fa8 authored by Xiaowu Zhang's avatar Xiaowu Zhang

erp5_production_planning: improve production planning

1. add copy button
2. show notification
parent b7c24aeb
......@@ -38,4 +38,43 @@
.matrixbox_production_planning table tbody td.select{
background-color: #aec2f1;
}
\ No newline at end of file
}
.matrixbox_production_planning table .copy{
width: 100%;
}
.matrixbox_production_planning div.notification {
position: fixed;
left:50%;
opacity:0;
top:50%;
text-align: left;
padding: 12pt;
color: #f8fff3;
border-radius: 0.325em;
transform: translate(-50%, -50%);
animation: notification 4s ease-out;
}
.matrixbox_production_planning div.successfully{
background: #37A419;
}
.matrixbox_production_planning div.failed{
background-color: #FF6600;
}
@keyframes notification {
0% {
opacity: 0
}
50% {
opacity: 1;
}
100% {
opacity: 0;
}
}
......@@ -168,8 +168,10 @@ function listenToInputCopy(matrixbox_container) {
index = $(element.parentElement).index();
// not space, tabulation
separator = '\t';
line = line || index;
if (line && line != index) {
if (line === undefined) {
line = index;
}
if (line != index) {
separator = '\n';
line = index;
}
......@@ -186,6 +188,7 @@ function listenToInputCopy(matrixbox_container) {
}
});
e.originalEvent.clipboardData.setData('text/plain', copy_data);
notify('Copy Successfully','successfully');
});
$('html').bind('mousedown', null, function (e) {
if (e.buttons == 1) {
......@@ -211,9 +214,9 @@ function listenToInputCopy(matrixbox_container) {
initial_tr_index = current_tr_index;
e.stopPropagation();
// for click twice problem
if (e.target.nodeName !== "INPUT") {
//e.preventDefault();
}
//if (e.target.nodeName !== "INPUT") {
// e.preventDefault();
// }
} else {
var min_tr = initial_tr_index,
max_tr = current_tr_index,
......@@ -239,6 +242,66 @@ function listenToInputCopy(matrixbox_container) {
}
});
}
function notify(message, css_class) {
var tmp;
tmp = matrixbox[0].querySelector('div.notification');
if (tmp) {
matrixbox[0].removeChild(tmp);
}
tmp = document.createElement('div');
matrixbox[0].appendChild(tmp);
tmp.className = 'notification ' + css_class;
tmp.innerHTML = message;
}
function addCopyButton(matrixbox_container) {
var td = matrixbox.find("tr:first td:first"),
copy = document.createElement('button');
copy.innerHTML = "Copy Production Planning";
copy.className = 'copy';
td.append(copy);
$(copy).bind('click', null, function (e) {
var element_list,
copy_data = "",
separator,
value,
tmp,
index,
line = undefined;
e.stopPropagation();
e.preventDefault();
matrixbox.find('tr td').each(function( index, element) {
index = $(element.parentElement).index();
// not space, tabulation
separator = '\t';
if (line === undefined) {
line = index;
}
if (line != index) {
separator = '\n';
line = index;
}
tmp = element.querySelector('input');
if (tmp) {
value = tmp.value;
} else {
value = element.innerText.split('\n')[0];
}
if (copy_data) {
copy_data = copy_data + separator + value;
} else {
copy_data = document.querySelector('input[name="field_my_title"]').value;
}
});
navigator.clipboard.writeText(copy_data).then(
function () {
notify('Copy Successfully','successfully');
},
function () {
notify('Copy Failed', 'failed');
});
});
}
var config = {
......@@ -263,6 +326,7 @@ function observe(mutationsList) {
listenToInputPaste(matrixbox_container);
listenToInputChange(matrixbox_container);
listenToInputCopy(matrixbox_container);
addCopyButton(matrixbox_container);
observer.disconnect();
}
}
......
Markdown is supported
0%
or
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment