Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Journalist UI change 6904 #7176

Open
wants to merge 2 commits into
base: develop
Choose a base branch
from
Open
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
10 changes: 10 additions & 0 deletions securedrop/static/css/journalist.css
Original file line number Diff line number Diff line change
Expand Up @@ -796,6 +796,16 @@ a.btn,
font-size: .8em;
}

button[disabled],
button[disabled]:hover,
a#delete-collections-link.disabled,
a#delete-collections-link.disabled:hover {
background: lightgrey;
color: darkgrey;
border:none;
cursor: default;
}

button:not([lang=ar]),
a.btn:not([lang=ar]),
.btn:not([lang=ar]) {
Expand Down
47 changes: 43 additions & 4 deletions securedrop/static/js/journalist.js
Original file line number Diff line number Diff line change
Expand Up @@ -5,6 +5,7 @@

const COLLECTION_SELECTOR_PREFIX = "table";
const ROW_SELECTOR_PREFIX = COLLECTION_SELECTOR_PREFIX + " tr"
const CHECKBOX_SELECTOR = ROW_SELECTOR_PREFIX + ':not(.hidden) input[name="cols_selected"]'

function closest(element, selector) {
let parent = element.parentNode;
Expand Down Expand Up @@ -34,6 +35,35 @@ function show(selector, displayStyle = "revert") {
});
}

function disableButtons(selector) {
let nodelist = document.querySelectorAll(selector);
Array.prototype.forEach.call(nodelist, function(element) {
element.disabled = true;
element.classList.add("disabled");
})
}

function enableButtons(selector) {
let nodelist = document.querySelectorAll(selector);
Array.prototype.forEach.call(nodelist, function(element) {
element.disabled = false;
element.classList.remove("disabled");
})
}

function disableButtonsIfNoCheckedRows() {
let buttons = 'button[name="action"]';
let deletelink = 'a#delete-collections-link'
let checkedboxes = document.querySelectorAll(CHECKBOX_SELECTOR + ":checked");
if (checkedboxes.length == 0) {
disableButtons(buttons);
disableButtons(deletelink);
} else {
enableButtons(buttons);
enableButtons(deletelink);
}
}

function enhance_ui() {
// Add the "quick filter" box for the list of sources
let filterContainer = document.getElementById("filter-container");
Expand Down Expand Up @@ -107,36 +137,38 @@ function ready(fn) {
}

ready(function() {
disableButtonsIfNoCheckedRows();
enhance_ui();

let selectAll = document.getElementById("select_all");

if (selectAll) {
selectAll.style.cursor = "pointer";
selectAll.addEventListener("click", function() {
let checkboxes = document.querySelectorAll(ROW_SELECTOR_PREFIX + ":not(.hidden) input[type=checkbox]");
let checkboxes = document.querySelectorAll(CHECKBOX_SELECTOR);
for (let i = 0; i < checkboxes.length; i++) {
checkboxes[i].checked = true;
}
disableButtonsIfNoCheckedRows();
});
}

let selectNone = document.getElementById("select_none");
if (selectNone) {
selectNone.style.cursor = "pointer";
selectNone.addEventListener("click", function() {
let checkboxes = document.querySelectorAll(ROW_SELECTOR_PREFIX + ":not(.hidden) input[type=checkbox]");
let checkboxes = document.querySelectorAll(CHECKBOX_SELECTOR);
for (let i = 0; i < checkboxes.length; i++) {
checkboxes[i].checked = false;
}
disableButtonsIfNoCheckedRows();
});
}

let selectUnread = document.getElementById("select_unread");
if (selectUnread) {
selectUnread.style.cursor = "pointer";
selectUnread.addEventListener("click", function() {
let checkboxes = document.querySelectorAll(ROW_SELECTOR_PREFIX + " input[type='checkbox']:not(.hidden)");
let checkboxes = document.querySelectorAll(CHECKBOX_SELECTOR);
for (let i = 0; i < checkboxes.length; i++) {
if (checkboxes[i].classList.contains("unread-cb")) {
checkboxes[i].checked = true;
Expand All @@ -147,6 +179,11 @@ ready(function() {
});
}

let checkboxes = document.querySelectorAll(CHECKBOX_SELECTOR);
for (let i = 0; i < checkboxes.length; i++) {
checkboxes[i].addEventListener("click", disableButtonsIfNoCheckedRows);
}

// When unread messages are downloaded from the source list, mark
// the source read.
let unreadLinks = document.querySelectorAll(".unread .unread a");
Expand Down Expand Up @@ -247,3 +284,5 @@ ready(function() {
}
}
});