Skip to content

Commit

Permalink
Show quick add button on related lists #451
Browse files Browse the repository at this point in the history
  • Loading branch information
arnoudkooi committed Dec 3, 2023
1 parent abb51f8 commit 2ea1de1
Show file tree
Hide file tree
Showing 3 changed files with 36 additions and 29 deletions.
5 changes: 5 additions & 0 deletions CHANGELOG.md
Original file line number Diff line number Diff line change
@@ -1,4 +1,9 @@
# CHANGELOG.md

## 7.1.8.0 (2023-12-04)
Fixes / changes:
- Show the quick add button on related lists (Discussion #451)

## 7.1.7.0 (2023-12-01)
Fixes / changes:
- The random switch -r now works together with other switches and search text (Issue #450)
Expand Down
58 changes: 30 additions & 28 deletions inject.js
Original file line number Diff line number Diff line change
Expand Up @@ -2648,16 +2648,13 @@ function snuAddTechnicalNames() {
snuSearchLargeSelects();
snuCreateHyperLinkForGlideLists();


//toggle the Technical names function
if (hasRun) {
var display = (document.querySelector('.snuwrap')?.style?.display == 'none') ? '' : 'none';
document.querySelectorAll('.snuwrap').forEach(cls => {
cls.style.display = display;
});
}


}

function snuExtendedFieldInfo() {
Expand Down Expand Up @@ -4682,31 +4679,39 @@ function snuImpersonater(doc) {
return impersonatingUser;
}


function snuAddPersonaliseListHandler() {
if (typeof GlideList2 == 'undefined' || typeof g_form != 'undefined') return; //only lists for now
let tableName = document.querySelector('#sys_target')?.value;
if (!tableName) return;
let g_list = GlideList2.get(tableName);
let missingFields = snusettings.listfields.split(',').filter(x => !g_list.fields.split(',').includes(x)).join(',');
if (!missingFields || (missingFields == 'sys_scope' && !g_list.tableName.startsWith('sys_'))) return; //do not show if not needed, fields already in list (best try)

let btn = document.querySelector('i[data-type="list_mechanic2_open"]');
if (!btn) return;

let icon = document.createElement('i');
icon.className = 'snuPersonaliseList icon-endpoint btn btn-icon table-btn-lg';
icon.title = `[SN Utils] Try to quick add:\n ${missingFields}\nto the list. \nHold ctrl/cmd to keep modal open, hold shift to add sys_id to beginning of list`;
icon.role = 'button';
icon.addEventListener('click', evt => {
let autoclose = !(evt.metaKey || evt.ctrlKey);
snuPersonaliseList(autoclose, evt.shiftKey);
});
btn.parentNode.insertBefore(icon, btn.nextSibling);

if (typeof GlideList2 == 'undefined') return;

let wrapper = document.querySelector('#related_lists_wrapper'); //add buttons to async loaded related lists on moeuseenter
if (wrapper) wrapper.addEventListener("mouseenter", snuAddPersonaliseListHandler);

let relatedListsButtons = document.querySelectorAll('[data-type="list_mechanic2_open"]:not(.snuified)');

if (!relatedListsButtons) return;
relatedListsButtons.forEach(rlb => {
let tableName = rlb?.dataset?.table;
if (!tableName) return;
let g_list = GlideList2.get(rlb?.dataset?.list_id);
let missingFields = snusettings.listfields.split(',').filter(x => !g_list.fields.split(',').includes(x)).join(',');
if (!missingFields || (missingFields == 'sys_scope' && !g_list.tableName.startsWith('sys_'))) return; //do not show if not needed, fields already in list (best try)

let icon = document.createElement('i');
icon.className = 'snuPersonaliseList icon-endpoint btn btn-icon table-btn-lg';
icon.title = `[SN Utils] Try to quick add:\n ${missingFields}\nto the list. \nHold ctrl/cmd to keep modal open, hold shift to add sys_id to beginning of list`;
icon.role = 'button';
icon.addEventListener('click', evt => {
let autoclose = !(evt.metaKey || evt.ctrlKey);
snuPersonaliseList(rlb, autoclose, evt.shiftKey);
});
rlb.parentNode.insertBefore(icon, rlb.nextSibling);
rlb.classList.add('snuified');

})

}

function snuPersonaliseList(autoclose, addsysid) {
let btn = document.querySelector('i[data-type="list_mechanic2_open"]');
function snuPersonaliseList(btn, autoclose, addsysid) {
if (btn) btn.click();
else return true;

Expand Down Expand Up @@ -4758,10 +4763,7 @@ document.addEventListener('snuEvent', function (e) {
}
});


//menu handling inside


function snuGetSlashNavigatorData(){ //get JSON from loacal storage and prepare
var prtl = Object.entries(localStorage)
.filter(ent => ent[0].includes((window?.NOW?.user?.userID || window?.NOW?.user_id || '') + '.headerMenuItems'));
Expand Down
2 changes: 1 addition & 1 deletion manifest.json
Original file line number Diff line number Diff line change
Expand Up @@ -3,7 +3,7 @@
"short_name": "SN Utils",
"description": "Productivity tools for ServiceNow. (Personal work, not affiliated to ServiceNow)",
"author": "Arnoud Kooi / arnoudkooi.com",
"version": "7.1.7.0",
"version": "7.1.8.0",
"manifest_version": 3,
"permissions": [
"activeTab",
Expand Down

0 comments on commit 2ea1de1

Please sign in to comment.