Skip to content

Commit 6f2e038

Browse files
committed
refactor: attribute searchWith renamed to attribute data-search-with
1 parent a8af8e7 commit 6f2e038

File tree

2 files changed

+17
-15
lines changed

2 files changed

+17
-15
lines changed

html/classhelper.js

Lines changed: 14 additions & 11 deletions
Original file line numberDiff line numberDiff line change
@@ -42,38 +42,41 @@ const ALTERNATIVE_DROPDOWN_PATHNAMES = {
4242
* ------------
4343
* The helpurl must be wrapped under this web component(user named html tag).
4444
* ```html
45-
* <roundup-classhelper searchWith="title,status[],keyword[]+name">
45+
* <roundup-classhelper data-search-with="title,status[],keyword[]+name">
4646
* ( helpurl template here, this can be tal, chameleon, jinja2.
4747
* In HTML DOM this is an helpurl anchor tag.
4848
* )
4949
* </roundup-classhelper>
5050
* ```
5151
*
52-
* The searchWith attribute of the web component is optional.
52+
* The data-search-with attribute of the web component is optional.
5353
*
54-
* searchWith attribute value is a list of comma separated names of table data fields.
54+
* data-search-with attribute value is a list of comma separated names of table data fields.
5555
* (It is possible that a data field is present in search form but absent in the table).
5656
*
5757
* A square parentheses open+close ("[]") can be added to the column name eg."status[]",
5858
* this will make that search field as a dropdown in the search form in popup window,
5959
* then a user can see all the possible values that column can have.
6060
*
61-
* eg. searchWith="title,status[],keyword[]+name" where status can have values like "open",
61+
* eg. data-search-with="title,status[],keyword[]+name" where status can have values like "open",
6262
* "closed" a dropdown will be shown with null, open and closed. This is an aesthetic usage
6363
* instead of writing in a text field for options in status.
6464
*
6565
* A plus sign or minus sign with data field can be used to specify the sort order of the dropdown.
6666
* In the above example, keyword[]+name will sort the dropdown in ascending order(a-z) of name of the keyword.
6767
* A value keyword[]-name will sort the dropdown in descending order(z-a) of name of the keyword.
6868
*
69-
* searchWith="<<column name>>[]{+|-}{id|name}"
69+
* data-search-with="<<column name>>[]{+|-}{id|name}"
7070
* Here column name is required,
7171
* optionally there can be [] for a dropdown,
7272
* optionally with "[]" present to a column name there can be
7373
* [+ or -] with succeeding "id" or "name" for sorting dropdown.
7474
*
7575
*/
7676
class ClassHelper extends HTMLElement {
77+
78+
static observedAttributes = ["data-search-with"]
79+
7780
/** @type {Window} handler to popup window */
7881
popupRef = null;
7982

@@ -84,7 +87,7 @@ class ClassHelper extends HTMLElement {
8487

8588
/**
8689
* Stores the result from api calls made to rest api,
87-
* for the parameters in searchWith attribute of this web component
90+
* for the parameters in data-search-with attribute of this web component
8891
* where a parameter is defined as a dropdown in
8992
* @type {Object.<string, Map.<string, string>>} */
9093
dropdowns = null;
@@ -231,7 +234,7 @@ class ClassHelper extends HTMLElement {
231234
}
232235

233236
attributeChangedCallback(name, oldValue, _newValue) {
234-
if (name === "searchWith") {
237+
if (name === "data-search-with") {
235238
if (!oldValue || oldValue === _newValue) {
236239
return;
237240
}
@@ -289,11 +292,11 @@ class ClassHelper extends HTMLElement {
289292
}
290293
this.dropdowns = {};
291294

292-
if (this.getAttribute("searchWith") == null) {
295+
if (this.dataset.searchWith == null) {
293296
return;
294297
}
295298

296-
const params = this.getAttribute("searchWith").split(',');
299+
const params = this.dataset.searchWith.split(',');
297300

298301
for (let param of params) {
299302
if (param.includes("[]")) {
@@ -504,7 +507,7 @@ class ClassHelper extends HTMLElement {
504507
form.setAttribute("id", "popup-search");
505508
form.classList.add("popup-search"); // Add class for styling
506509

507-
const params = this.getAttribute("searchWith").split(',');
510+
const params = this.dataset.searchWith.split(',');
508511

509512
const table = document.createElement("table");
510513
table.classList.add("search-table"); // Add class for styling
@@ -875,7 +878,7 @@ class ClassHelper extends HTMLElement {
875878

876879
popupBody.classList.add("flex-container");
877880

878-
if (this.getAttribute("searchWith")) {
881+
if (this.dataset.searchWith) {
879882
const searchFrag = this.getSearchFragment(formData);
880883
popupBody.appendChild(searchFrag);
881884
}

html/issue.item.html

Lines changed: 3 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -56,10 +56,9 @@
5656
<th i18n:translate="">Superseder</th>
5757
<td>
5858
<span tal:replace="structure python:context.superseder.field(showid=1, size=20)" />
59-
<roundup-classhelper searchWith="title,status[],keyword[]-name">
60-
<span tal:condition="context/is_edit_ok" tal:replace="structure python:db.issue.classhelp('id,title', property='superseder', pagesize=10)" />
59+
<roundup-classhelper data-search-with="title,status,keyword[]-name">
60+
<span tal:condition="context/is_edit_ok" tal:replace="structure python:db.issue.classhelp('id,title', property='superseder', pagesize=100)" />
6161
</roundup-classhelper>
62-
<span tal:condition="context/is_edit_ok" tal:replace="structure python:db.issue.classhelp('id,title', property='superseder', pagesize=10)" />
6362
<span tal:condition="context/superseder">
6463
<br><span i18n:translate="">View:</span>
6564
<a tal:repeat="sup context/superseder"
@@ -70,7 +69,7 @@
7069
<th i18n:translate="">Nosy List</th>
7170
<td>
7271
<span tal:replace="structure context/nosy/field" />
73-
<roundup-classhelper searchWith="username,phone,roles[]">
72+
<roundup-classhelper data-search-with="username,roles[]">
7473
<span tal:condition="context/is_edit_ok" tal:replace="structure
7574
python:db.user.classhelp('username,realname,address', property='nosy', width='600')" />
7675
</roundup-classhelper>

0 commit comments

Comments
 (0)