Skip to content

Commit 0cca0fe

Browse files
committed
fix: classhelper should work when property is not set Issue#35
1 parent 91bfaf7 commit 0cca0fe

File tree

2 files changed

+40
-24
lines changed

2 files changed

+40
-24
lines changed

html/classhelper.css

Lines changed: 6 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -8,6 +8,10 @@
88
font-size: .9em;
99
}
1010

11+
.table-selection-none table {
12+
pointer-events: none;
13+
}
14+
1115
table th {
1216
font-weight: normal;
1317
text-align: left;
@@ -110,4 +114,5 @@ table tr:hover {
110114

111115
.separator {
112116
flex-grow: 1;
113-
}
117+
}
118+

html/classhelper.js

Lines changed: 34 additions & 23 deletions
Original file line numberDiff line numberDiff line change
@@ -28,6 +28,8 @@ const CLASSHELPER_POPUP_FEATURES = (width, height) => `popup=yes,width=${width},
2828
const CLASSHELPER_POPUP_URL = "about:blank";
2929
const CLASSHELPER_POPUP_TARGET = "_blank";
3030

31+
const CLASSHELPER_TABLE_SELECTION_NONE = "table-selection-none";
32+
3133
const ALTERNATIVE_DROPDOWN_PATHNAMES = {
3234
"roles": "/rest/roles"
3335
}
@@ -738,7 +740,9 @@ class ClassHelper extends HTMLElement {
738740
* @param {Object.<string, any>[]} data
739741
* @returns
740742
*/
741-
getTableFragment(headers, data, preSelectedValues, includeCheckbox = true) {
743+
getTableFragment(headers, data, preSelectedValues) {
744+
let includeCheckbox = !this.popupRef.document.body.classList.contains(CLASSHELPER_TABLE_SELECTION_NONE);
745+
742746
const fragment = document.createDocumentFragment();
743747

744748
const container = document.createElement('div');
@@ -794,26 +798,29 @@ class ClassHelper extends HTMLElement {
794798
tbody.appendChild(row);
795799
});
796800

797-
tbody.addEventListener("click", (e) => {
798-
let id, tr;
799-
if (e.target.tagName === "INPUT" || e.target.tagName === "TD") {
800-
id = e.target.parentElement.dataset.id;
801-
tr = e.target.parentElement;
802-
} else if (e.target.tagName === "TR") {
803-
id = e.target.dataset.id;
804-
tr = e.target;
805-
}
806-
807-
if (e.target.tagName !== "INPUT") {
808-
tr.children.item(0).checked = !tr.children.item(0).checked;
809-
}
801+
if (includeCheckbox) {
802+
tbody.addEventListener("click", (e) => {
803+
let id, tr;
804+
if (e.target.tagName === "INPUT" || e.target.tagName === "TD") {
805+
id = e.target.parentElement.dataset.id;
806+
tr = e.target.parentElement;
807+
} else if (e.target.tagName === "TR") {
808+
id = e.target.dataset.id;
809+
tr = e.target;
810+
}
810811

811-
this.dispatchEvent(new CustomEvent("selection", {
812-
detail: {
813-
value: id
812+
if (e.target.tagName !== "INPUT") {
813+
tr.children.item(0).checked = !tr.children.item(0).checked;
814814
}
815-
}));
816-
});
815+
816+
this.dispatchEvent(new CustomEvent("selection", {
817+
detail: {
818+
value: id
819+
}
820+
}));
821+
});
822+
823+
}
817824

818825
// Create table footer with the same column values as headers
819826
const footerRow = document.createElement('tr');
@@ -920,10 +927,14 @@ class ClassHelper extends HTMLElement {
920927
const body = document.createElement("body");
921928

922929
body.classList.add("flex-container");
930+
if (!props.formProperty) {
931+
this.popupRef.document.body.classList.add(CLASSHELPER_TABLE_SELECTION_NONE);
932+
body.classList.add(CLASSHELPER_TABLE_SELECTION_NONE);
933+
}
923934

924935
const itemDesignator = window.location.pathname.split("/").at(-1);
925936
let titleText = `${itemDesignator} - Classhelper`;
926-
if (props.formName) {
937+
if (props.formProperty) {
927938
// main window lookup for the label of the form property
928939
const label = document.getElementsByName(props.formProperty).item(0).parentElement.previousElementSibling;
929940
titleText = label.textContent + " - " + titleText;
@@ -948,7 +959,7 @@ class ClassHelper extends HTMLElement {
948959
const paginationFrag = this.getPaginationFragment(prevPageURL, nextPageURL, props.pageIndex, props.pageSize, collection.length);
949960
body.appendChild(paginationFrag);
950961

951-
const tableFrag = this.getTableFragment(props.fields, collection, preSelectedValues, !!props.formProperty);
962+
const tableFrag = this.getTableFragment(props.fields, collection, preSelectedValues);
952963
body.appendChild(tableFrag);
953964

954965
const separator = document.createElement("div");
@@ -1114,7 +1125,7 @@ class ClassHelper extends HTMLElement {
11141125
popupBody.replaceChild(newPaginationFrag, oldPaginationFrag);
11151126

11161127
let oldTableFrag = popupDocument.getElementById("popup-tablediv");
1117-
let newTableFrag = this.getTableFragment(props.fields, collection, accumulatorValues, !!props.formProperty);
1128+
let newTableFrag = this.getTableFragment(props.fields, collection, accumulatorValues);
11181129
popupBody.replaceChild(newTableFrag, oldTableFrag);
11191130
}
11201131

@@ -1204,7 +1215,7 @@ class ClassHelper extends HTMLElement {
12041215

12051216

12061217
let oldTableFrag = popupDocument.getElementById("popup-tablediv");
1207-
let newTableFrag = this.getTableFragment(props.fields, collection, accumulatorValues, !!props.formProperty);
1218+
let newTableFrag = this.getTableFragment(props.fields, collection, accumulatorValues);
12081219
popupBody.replaceChild(newTableFrag, oldTableFrag);
12091220
}
12101221

0 commit comments

Comments
 (0)