Skip to content
GitLab
Explore
Sign in
Primary navigation
Search or go to…
Project
D
drupal-3464530
Manage
Activity
Members
Labels
Plan
Custom issue tracker
Code
Merge requests
Repository
Branches
Commits
Tags
Repository graph
Compare revisions
Locked files
Build
Pipelines
Jobs
Pipeline schedules
Artifacts
Deploy
Model registry
Analyze
Value stream analytics
Contributor analytics
CI/CD analytics
Repository analytics
Code review analytics
Insights
Model experiments
Help
Help
Support
GitLab documentation
Compare GitLab plans
Community forum
Contribute to GitLab
Provide feedback
Terms and privacy
Keyboard shortcuts
?
Snippets
Groups
Projects
Show more breadcrumbs
Issue forks
drupal-3464530
Commits
bd326831
Unverified
Commit
bd326831
authored
8 months ago
by
Théodore Biadala
Browse files
Options
Downloads
Patches
Plain Diff
refactor
parent
9a465ffa
Branches
Branches containing commit
No related tags found
No related merge requests found
Changes
1
Hide whitespace changes
Inline
Side-by-side
Showing
1 changed file
core/modules/user/user.permissions.js
+63
-62
63 additions, 62 deletions
core/modules/user/user.permissions.js
with
63 additions
and
62 deletions
core/modules/user/user.permissions.js
+
63
−
62
View file @
bd326831
...
...
@@ -4,63 +4,6 @@
*/
(
function
(
$
,
Drupal
,
debounce
)
{
// Create fake checkboxes. We use fake checkboxes instead of reusing
// the existing checkboxes here because new checkboxes don't alter the
// submitted form. If we'd automatically check existing checkboxes, the
// permission table would be polluted with redundant entries. This is
// deliberate, but desirable when we automatically check them.
const
$fakeCheckbox
=
$
(
Drupal
.
theme
(
'
checkbox
'
))
.
removeClass
(
'
form-checkbox
'
)
.
addClass
(
'
fake-checkbox js-fake-checkbox
'
)
.
attr
({
disabled
:
'
disabled
'
,
checked
:
'
checked
'
,
title
:
Drupal
.
t
(
'
This permission is inherited from the authenticated user role.
'
,
),
});
const
$wrapper
=
$
(
'
<div></div>
'
).
append
(
$fakeCheckbox
);
const
fakeCheckboxHtml
=
$wrapper
.
html
();
/**
* Process each table row to create fake checkboxes.
*
* @param {object} object
* @param {HTMLElement} object.target
*/
function
tableRowProcessing
({
target
})
{
once
(
'
permission-checkbox
'
,
target
.
closest
(
'
tr
'
)).
forEach
(
(
unprocessedRow
)
=>
{
const
inputs
=
unprocessedRow
.
querySelectorAll
(
'
input[type="checkbox"]:not(.js-rid-anonymous, .js-rid-authenticated)
'
,
);
inputs
.
forEach
((
check
)
=>
{
check
.
classList
.
add
(
'
real-checkbox
'
,
'
js-real-checkbox
'
);
check
.
insertAdjacentHTML
(
'
beforebegin
'
,
fakeCheckboxHtml
);
});
},
);
}
// An IntersectionObserver object is associated with each of the table
// rows to activate checkboxes interactively as users scroll the page
// up or down. This should alleviate the load of processing all of the
// checkboxes upon page load at once.
const
tableRowObserver
=
new
IntersectionObserver
(
(
entries
,
thisObserver
)
=>
{
entries
.
filter
((
entry
)
=>
entry
.
isIntersecting
)
.
forEach
((
entry
)
=>
{
tableRowProcessing
(
entry
);
thisObserver
.
unobserve
(
entry
.
target
);
});
},
{
rootMargin
:
'
50%
'
,
},
);
/**
* Shows checked and disabled checkboxes for inherited permissions.
*
...
...
@@ -72,18 +15,76 @@
Drupal
.
behaviors
.
permissions
=
{
attach
()
{
once
(
'
permissions
'
,
'
table#permissions
'
).
forEach
((
table
)
=>
{
$
(
table
).
on
(
'
click.permissions
'
,
'
input[type="checkbox"].js-rid-authenticated
'
,
tableRowProcessing
,
// Create fake checkboxes. We use fake checkboxes instead of reusing
// the existing checkboxes here because new checkboxes don't alter the
// submitted form. If we'd automatically check existing checkboxes, the
// permission table would be polluted with redundant entries. This is
// deliberate, but desirable when we automatically check them.
const
$fakeCheckbox
=
$
(
Drupal
.
theme
(
'
checkbox
'
))
.
removeClass
(
'
form-checkbox
'
)
.
addClass
(
'
fake-checkbox js-fake-checkbox
'
)
.
attr
({
disabled
:
'
disabled
'
,
checked
:
'
checked
'
,
title
:
Drupal
.
t
(
'
This permission is inherited from the authenticated user role.
'
,
),
});
const
$wrapper
=
$
(
'
<div></div>
'
).
append
(
$fakeCheckbox
);
const
fakeCheckboxHtml
=
$wrapper
.
html
();
/**
* Process each table row to create fake checkboxes.
*
* @param {object} object
* @param {HTMLElement} object.target
*/
function
tableRowProcessing
({
target
})
{
once
(
'
permission-checkbox
'
,
target
).
forEach
((
checkbox
)
=>
{
checkbox
.
closest
(
'
tr
'
)
.
querySelectorAll
(
'
input[type="checkbox"]:not(.js-rid-anonymous, .js-rid-authenticated)
'
,
)
.
forEach
((
check
)
=>
{
check
.
classList
.
add
(
'
real-checkbox
'
,
'
js-real-checkbox
'
);
check
.
insertAdjacentHTML
(
'
beforebegin
'
,
fakeCheckboxHtml
);
});
});
}
// An IntersectionObserver object is associated with each of the table
// rows to activate checkboxes interactively as users scroll the page
// up or down. This prevents processing all checkboxes on page load.
const
tableRowObserver
=
new
IntersectionObserver
(
(
entries
,
thisObserver
)
=>
{
entries
.
filter
((
entry
)
=>
entry
.
isIntersecting
)
.
forEach
((
entry
)
=>
{
tableRowProcessing
(
entry
);
thisObserver
.
unobserve
(
entry
.
target
);
});
},
{
rootMargin
:
'
50%
'
,
},
);
// Select all table rows and attach an observer to each.
// Select rows with checked authenticated role and attach an observer
// to each.
table
.
querySelectorAll
(
'
tbody tr input[type="checkbox"].js-rid-authenticated:checked
'
,
)
.
forEach
((
checkbox
)
=>
tableRowObserver
.
observe
(
checkbox
));
// Create checkboxes only when necessary on click.
$
(
table
).
on
(
'
click.permissions
'
,
'
input[type="checkbox"].js-rid-authenticated
'
,
tableRowProcessing
,
);
});
},
};
...
...
This diff is collapsed.
Click to expand it.
Preview
0%
Loading
Try again
or
attach a new file
.
Cancel
You are about to add
0
people
to the discussion. Proceed with caution.
Finish editing this message first!
Save comment
Cancel
Please
register
or
sign in
to comment