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

lint all the JavaScript files #1462

Merged
merged 1 commit into from
Dec 17, 2024
Merged
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
71 changes: 33 additions & 38 deletions src/ims/element/static/admin_events.js
Original file line number Diff line number Diff line change
Expand Up @@ -28,19 +28,19 @@ function initPage() {
}


var accessControlList = null
let accessControlList = null

function loadAccessControlList(success) {
function ok(data, status, xhr) {
accessControlList = data;

if (success != undefined) {
if (success) {
success();
}
}

function fail(error, status, xhr) {
var message = "Failed to load access control list:\n" + error
const message = "Failed to load access control list:\n" + error
console.error(message);
window.alert(message);
}
Expand All @@ -49,13 +49,13 @@ function loadAccessControlList(success) {
}


var _accessTemplate = null;
var _entryTemplate = null;
let _accessTemplate = null;
let _entryTemplate = null;

var accessModes = ["readers", "writers", "reporters"];
let accessModes = ["readers", "writers", "reporters"];

function drawAccess() {
var container = $("#event_access_container");
const container = $("#event_access_container");

if (_accessTemplate == null) {
_accessTemplate = container.children(".event_access:first");
Expand All @@ -68,13 +68,9 @@ function drawAccess() {

container.empty();

for (var i in events) {
var event = events[i];

for (var i in accessModes) {
var mode = accessModes[i];

var eventAccess = $(_accessTemplate).clone();
for (const event of events) {
for (const mode of accessModes) {
const eventAccess = $(_accessTemplate).clone();

// Add an id to the element for future reference
eventAccess.attr("id", "event_access_" + event + "_" + mode);
Expand All @@ -89,25 +85,24 @@ function drawAccess() {


function updateEventAccess(event, mode) {
var eventACL = accessControlList[event];
const eventACL = accessControlList[event];

if (eventACL == undefined) {
if (eventACL == null) {
return;
}

var eventAccess = $("#event_access_" + event + "_" + mode);
const eventAccess = $("#event_access_" + event + "_" + mode);

// Set displayed event name and mode
eventAccess.find(".event_name").text(event);
eventAccess.find(".access_mode").text(mode);

var entryContainer = eventAccess.find(".list-group:first");
const entryContainer = eventAccess.find(".list-group:first");

entryContainer.empty();

for (var i in eventACL[mode]) {
var expression = eventACL[mode][i];
var entryItem = _entryTemplate.clone();
for (const expression of eventACL[mode]) {
const entryItem = _entryTemplate.clone();

entryItem.append(expression);
entryItem.attr("value", expression);
Expand All @@ -118,7 +113,7 @@ function updateEventAccess(event, mode) {


function addEvent(sender) {
var event = sender.value.trim();
const event = sender.value.trim();

function refresh() {
loadAccessControlList(drawAccess);
Expand All @@ -130,7 +125,7 @@ function addEvent(sender) {
}

function fail(requestError, status, xhr) {
var message = "Failed to add event:\n" + requestError
const message = "Failed to add event:\n" + requestError
console.log(message);
refresh();
controlHasError($(sender));
Expand All @@ -142,22 +137,22 @@ function addEvent(sender) {


function addAccess(sender) {
var container = $(sender).parents(".event_access:first");
var event = container.find(".event_name:first").text();
var mode = container.find(".access_mode:first").text();
var newExpression = sender.value.trim();
const container = $(sender).parents(".event_access:first");
const event = container.find(".event_name:first").text();
const mode = container.find(".access_mode:first").text();
const newExpression = sender.value.trim();

var acl = accessControlList[event][mode].slice();
const acl = accessControlList[event][mode].slice();

acl.push(newExpression);

edits = {};
const edits = {};
edits[event] = {};
edits[event][mode] = acl;

function refresh() {
for (var i in accessModes) {
updateEventAccess(event, accessModes[i]);
for (const mode of accessModes) {
updateEventAccess(event, mode);
}
}

Expand All @@ -176,12 +171,12 @@ function addAccess(sender) {


function removeAccess(sender) {
var container = $(sender).parents(".event_access:first");
var event = container.find(".event_name:first").text();
var mode = container.find(".access_mode:first").text();
var expression = $(sender).parent().attr("value").trim();
const container = $(sender).parents(".event_access:first");
const event = container.find(".event_name:first").text();
const mode = container.find(".access_mode:first").text();
const expression = $(sender).parent().attr("value").trim();

var acl = accessControlList[event][mode].slice();
const acl = accessControlList[event][mode].slice();

if (acl.indexOf(expression) < 0) {
console.error("no such ACL: " + expression);
Expand All @@ -190,7 +185,7 @@ function removeAccess(sender) {

acl.splice(acl.indexOf(expression), 1);

edits = {};
const edits = {};
edits[event] = {};
edits[event][mode] = acl;

Expand Down Expand Up @@ -218,7 +213,7 @@ function sendACL(edits, success, error) {
}

function fail(requestError, status, xhr) {
var message = "Failed to edit ACL:\n" + requestError
const message = "Failed to edit ACL:\n" + requestError;
console.log(message);
error();
window.alert(message);
Expand Down
36 changes: 17 additions & 19 deletions src/ims/element/static/admin_streets.js
Original file line number Diff line number Diff line change
Expand Up @@ -28,21 +28,21 @@ function initPage() {
}


var streets = null;
let streets = null;

function loadStreets(success) {
var url = url_streets;
const url = url_streets;

function ok(data, status, xhr) {
streets = data;

if (success != undefined) {
if (success) {
success();
}
}

function fail(error, status, xhr) {
var message = "Failed to load streets:\n" + error
const message = "Failed to load streets:\n" + error;
console.error(message);
window.alert(message);
}
Expand All @@ -51,11 +51,11 @@ function loadStreets(success) {
}


var _streetsTemplate = null;
var _entryTemplate = null;
let _streetsTemplate = null;
let _entryTemplate = null;

function drawStreets() {
var container = $("#event_streets_container");
const container = $("#event_streets_container");

if (_streetsTemplate == null) {
_streetsTemplate = container.children(".event_streets:first");
Expand All @@ -68,10 +68,8 @@ function drawStreets() {

container.empty();

for (var i in events) {
var event = events[i];

var eventStreets = $(_streetsTemplate).clone();
for (const event of events) {
const eventStreets = $(_streetsTemplate).clone();

// Add an id to the element for future reference
eventStreets.attr("id", "event_streets_" + event);
Expand All @@ -85,24 +83,24 @@ function drawStreets() {


function updateEventStreets(event) {
var eventStreets = streets[event];
const eventStreets = streets[event];

if (eventStreets == undefined) {
if (eventStreets == null) {
return;
}

var eventStreetsElement = $("#event_streets_" + event);
const eventStreetsElement = $("#event_streets_" + event);

// Set displayed event name
eventStreetsElement.find(".event_name").text(event);

var entryContainer = eventStreetsElement.find(".list-group:first");
const entryContainer = eventStreetsElement.find(".list-group:first");

entryContainer.empty();

for (var streetID in eventStreets) {
var streetName = eventStreets[streetID];
var entryItem = _entryTemplate.clone();
for (const streetID in eventStreets) {
const streetName = eventStreets[streetID];
const entryItem = _entryTemplate.clone();

entryItem.append(streetID + ": " + streetName);
entryItem.attr("value", streetID);
Expand All @@ -128,7 +126,7 @@ function sendStreets(edits, success, error) {
}

function fail(requestError, status, xhr) {
var message = "Failed to edit streets:\n" + requestError
const message = "Failed to edit streets:\n" + requestError;
console.log(message);
error();
window.alert(message);
Expand Down
31 changes: 15 additions & 16 deletions src/ims/element/static/admin_types.js
Original file line number Diff line number Diff line change
Expand Up @@ -33,16 +33,16 @@ function loadAndDrawIncidentTypes() {
}


var incidentTypes = null;
var incidentTypesVisible = null;
let incidentTypes = null;
let incidentTypesVisible = null;

function loadIncidentTypes(success) {
var gotAll = false;
var gotVisible = false;
let gotAll = false;
let gotVisible = false;

function ok() {
if (gotAll && gotVisible) {
if (success != undefined) {
if (success) {
success();
}
}
Expand All @@ -62,7 +62,7 @@ function loadIncidentTypes(success) {
}

function fail(error, status, xhr) {
var message = "Failed to load incident types:\n" + error
const message = "Failed to load incident types:\n" + error;
console.error(message);
window.alert(message);
}
Expand All @@ -72,11 +72,11 @@ function loadIncidentTypes(success) {
}


var _incidentTypesTemplate = null;
var _entryTemplate = null;
let _incidentTypesTemplate = null;
let _entryTemplate = null;

function drawIncidentTypes() {
var container = $("#incident_types_container");
const container = $("#incident_types_container");

if (_incidentTypesTemplate == null) {
_incidentTypesTemplate = container.children(".incident_types:first");
Expand All @@ -92,17 +92,16 @@ function drawIncidentTypes() {


function updateIncidentTypes() {
var incidentTypesElement = $("#incident_types");
const incidentTypesElement = $("#incident_types");

var entryContainer = incidentTypesElement.find(".list-group:first");
const entryContainer = incidentTypesElement.find(".list-group:first");

entryContainer.empty();

for (var i in incidentTypes) {
var incidentType = incidentTypes[i];
var entryItem = _entryTemplate.clone();
for (const incidentType of incidentTypes) {
const entryItem = _entryTemplate.clone();

if (incidentTypesVisible.indexOf(incidentType) == -1) {
if (incidentTypesVisible.indexOf(incidentType) === -1) {
entryItem.addClass("item-hidden")
} else {
entryItem.addClass("item-visible")
Expand Down Expand Up @@ -157,7 +156,7 @@ function sendIncidentTypes(edits, success, error) {
}

function fail(requestError, status, xhr) {
var message = "Failed to edit incident types:\n" + requestError
const message = "Failed to edit incident types:\n" + requestError;
console.log(message);
error();
window.alert(message);
Expand Down
Loading
Loading