mirror of
https://github.com/cisagov/manage.get.gov.git
synced 2025-08-18 07:24:10 +02:00
updated comments
This commit is contained in:
parent
3cf7d5138e
commit
8ddd5e7b1f
1 changed files with 13 additions and 8 deletions
|
@ -106,7 +106,7 @@ function initializeWidgetOnToList(toList, toListId) {
|
||||||
|
|
||||||
let deleteLink = null;
|
let deleteLink = null;
|
||||||
if (hasDeletePermission) {
|
if (hasDeletePermission) {
|
||||||
// create the delete button
|
// create the delete button if user has permission to delete
|
||||||
deleteLink = createAndCustomizeLink(
|
deleteLink = createAndCustomizeLink(
|
||||||
toList,
|
toList,
|
||||||
toListId,
|
toListId,
|
||||||
|
@ -165,11 +165,11 @@ function initializeWidgetOnToList(toList, toListId) {
|
||||||
// toList - the element in the DOM for the toList
|
// toList - the element in the DOM for the toList
|
||||||
// toListId - the ID of the element in the DOM
|
// toListId - the ID of the element in the DOM
|
||||||
// className - className to add to the created link
|
// className - className to add to the created link
|
||||||
|
// action - the action to perform on the item {change, delete, view}
|
||||||
// imgSrc - the img.src for the created link
|
// imgSrc - the img.src for the created link
|
||||||
// imgAlt - the img.alt for the created link
|
|
||||||
// dataMappings - dictionary which relates toListId to href for the created link
|
// dataMappings - dictionary which relates toListId to href for the created link
|
||||||
// dataPopup - boolean for whether the link should produce a popup window
|
// dataPopup - boolean for whether the link should produce a popup window
|
||||||
// firstPosition - boolean indicating if link should be first position in list of links, otherwise, just before last link
|
// firstPosition - boolean indicating if link should be first position in list of links, otherwise, should be last link
|
||||||
function createAndCustomizeLink(toList, toListId, className, action, imgSrc, dataMappings, dataPopup, firstPosition) {
|
function createAndCustomizeLink(toList, toListId, className, action, imgSrc, dataMappings, dataPopup, firstPosition) {
|
||||||
// Create a link element
|
// Create a link element
|
||||||
var link = document.createElement('a');
|
var link = document.createElement('a');
|
||||||
|
@ -210,15 +210,19 @@ function createAndCustomizeLink(toList, toListId, className, action, imgSrc, dat
|
||||||
link.appendChild(img);
|
link.appendChild(img);
|
||||||
|
|
||||||
let relatedWidgetWrapper = toList.closest('.related-widget-wrapper');
|
let relatedWidgetWrapper = toList.closest('.related-widget-wrapper');
|
||||||
// Insert the link at the specified position
|
// If firstPosition is true, insert link as the first child element
|
||||||
if (firstPosition) {
|
if (firstPosition) {
|
||||||
relatedWidgetWrapper.insertBefore(link, relatedWidgetWrapper.children[0]);
|
relatedWidgetWrapper.insertBefore(link, relatedWidgetWrapper.children[0]);
|
||||||
} else {
|
} else {
|
||||||
|
// otherwise, insert the link prior to the last child (which is a div)
|
||||||
|
// and also prior to any text elements immediately preceding the last
|
||||||
|
// child node
|
||||||
var lastChild = relatedWidgetWrapper.lastChild;
|
var lastChild = relatedWidgetWrapper.lastChild;
|
||||||
|
|
||||||
// Check if lastChild is an element node (not a text node, comment, etc.)
|
// Check if lastChild is an element node (not a text node, comment, etc.)
|
||||||
if (lastChild.nodeType === 1) {
|
if (lastChild.nodeType === 1) {
|
||||||
var previousSibling = lastChild.previousSibling;
|
var previousSibling = lastChild.previousSibling;
|
||||||
|
// need to work around some white space which has been inserted into the dom
|
||||||
while (previousSibling.nodeType !== 1) {
|
while (previousSibling.nodeType !== 1) {
|
||||||
previousSibling = previousSibling.previousSibling;
|
previousSibling = previousSibling.previousSibling;
|
||||||
}
|
}
|
||||||
|
@ -230,10 +234,9 @@ function createAndCustomizeLink(toList, toListId, className, action, imgSrc, dat
|
||||||
return link;
|
return link;
|
||||||
}
|
}
|
||||||
|
|
||||||
// Either enable or disable widget buttons when select is clicked. Select can be in either the from list
|
// Either enable or disable widget buttons when select is clicked. Action (enable or disable) taken depends on the count
|
||||||
// or the to list. Action (enable or disable) taken depends on the tocal count of selected items across
|
// of selected items in selectElement. If exactly one item is selected, buttons are enabled, and urls for the buttons are
|
||||||
// both lists. If exactly one item is selected, buttons are enabled, and urls for the buttons associated
|
// associated with the selected item
|
||||||
// with the selected item
|
|
||||||
function handleSelectClick(selectElement, changeLink, deleteLink, viewLink) {
|
function handleSelectClick(selectElement, changeLink, deleteLink, viewLink) {
|
||||||
|
|
||||||
// If one item is selected (across selectElement and relatedSelectElement), enable buttons; otherwise, disable them
|
// If one item is selected (across selectElement and relatedSelectElement), enable buttons; otherwise, disable them
|
||||||
|
@ -245,6 +248,8 @@ function handleSelectClick(selectElement, changeLink, deleteLink, viewLink) {
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
|
// return true if there exist elements on the page with classname of delete-related.
|
||||||
|
// presence of one or more of these elements indicates user has permission to delete
|
||||||
function hasDeletePermissionOnPage() {
|
function hasDeletePermissionOnPage() {
|
||||||
return document.querySelector('.delete-related') != null
|
return document.querySelector('.delete-related') != null
|
||||||
}
|
}
|
||||||
|
|
Loading…
Add table
Add a link
Reference in a new issue