Skip to content

Commit a66878b

Browse files
committed
List.js, print button
1 parent d34622f commit a66878b

File tree

3 files changed

+47
-0
lines changed

3 files changed

+47
-0
lines changed

Protest/Front/deviceslist.js

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -25,6 +25,7 @@ class DevicesList extends List {
2525
this.SetupFind();
2626
this.toolbar.appendChild(this.AddToolbarSeparator());
2727
this.utilitiesDropDown = this.AddToolbarDropdown("mono/hammer.svg?light");
28+
this.SetupPrint();
2829
this.sentChatButton = this.AddSendToChatButton();
2930

3031
this.utilitiesDropDown.menu.style.height = "130px";

Protest/Front/list.js

Lines changed: 45 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -484,6 +484,51 @@ class List extends Window {
484484
return findInput;
485485
}
486486

487+
SetupPrint() {
488+
if (!this.toolbar) return null;
489+
490+
const printButton = this.AddToolbarButton("Print", "mono/printer.svg?light");
491+
492+
printButton.onclick = ()=> {
493+
const newPrint = window.open();
494+
newPrint.document.title = this.header.textContent;
495+
newPrint.document.write("<html><body></body></html>");
496+
497+
const table = document.createElement("table");
498+
table.style.borderCollapse = "collapse";
499+
newPrint.document.body.appendChild(table);
500+
501+
for (let i=0; i<this.columnsElements.length; i++) {
502+
const th = document.createElement("th");
503+
th.style.textTransform = "uppercase";
504+
th.textContent = this.columnsElements[i].textContent;
505+
table.appendChild(th);
506+
}
507+
508+
for (let i=0; i<this.list.childNodes.length; i++) {
509+
const entry = this.link.data[this.list.childNodes[i].getAttribute("id")];
510+
511+
const tr = document.createElement("tr");
512+
513+
for (let j=0; j<this.columnsElements.length; j++) {
514+
const td = document.createElement("td");
515+
td.style.padding = "1px 2px";
516+
td.style.border = "1px solid #c0c0c0";
517+
const key = this.columnsElements[j].textContent;
518+
if (key in entry) {
519+
td.textContent = entry[key].v;
520+
}
521+
tr.appendChild(td);
522+
}
523+
table.appendChild(tr);
524+
}
525+
526+
newPrint.onload = ()=> newPrint.print();
527+
newPrint.document.close();
528+
setTimeout(()=> newPrint.close(), 99);
529+
};
530+
}
531+
487532
PopOut() { //overrides
488533
super.PopOut();
489534
this.UpdateViewport(true);

Protest/Front/userslist.js

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -24,6 +24,7 @@ class UsersList extends List {
2424
const filterButton = this.SetupFilter();
2525
this.SetupFind();
2626
this.toolbar.appendChild(this.AddToolbarSeparator());
27+
this.SetupPrint();
2728
this.sentChatButton = this.AddSendToChatButton();
2829

2930
if (this.args.find && this.args.find.length > 0) {

0 commit comments

Comments
 (0)