Skip to content

Commit

Permalink
Run eslint --fix on all JS
Browse files Browse the repository at this point in the history
  • Loading branch information
Indico Team authored and ThiefMaster committed Apr 14, 2021
1 parent 4a7b015 commit 51b2de1
Show file tree
Hide file tree
Showing 28 changed files with 333 additions and 354 deletions.
62 changes: 30 additions & 32 deletions indico/modules/attachments/client/js/legacy.js
Original file line number Diff line number Diff line change
Expand Up @@ -6,9 +6,7 @@
// LICENSE file for more details.

(function(global) {
'use strict';

var HISTORY_API_SUPPORTED = !!history.pushState;
const HISTORY_API_SUPPORTED = !!history.pushState;

function toggleFolder(evt) {
if ($(evt.target).closest('.actions').length) {
Expand All @@ -32,20 +30,20 @@

$(document).on('click', '[data-attachment-editor]', function(evt) {
evt.preventDefault();
var $this = $(this);
const $this = $(this);
if (this.disabled || $this.hasClass('disabled')) {
return;
}
var locator = $(this).data('locator');
var title = $(this).data('title');
var reloadOnChange = $this.data('reload-on-change') !== undefined;
const locator = $(this).data('locator');
const title = $(this).data('title');
const reloadOnChange = $this.data('reload-on-change') !== undefined;
openAttachmentManager(locator, title, reloadOnChange, $this);
});
});

global.setupAttachmentPreview = function setupAttachmentPreview() {
var attachment = $('.js-preview-dialog');
var pageURL = location.href.replace(/#.*$/, '');
const attachment = $('.js-preview-dialog');
const pageURL = location.href.replace(/#.*$/, '');

// Previewer not supported on mobile browsers
if ($.mobileBrowser) {
Expand All @@ -58,12 +56,12 @@
$('.attachment-preview-dialog').trigger('ajaxDialog:close', [true]);
} else {
if (initial && HISTORY_API_SUPPORTED) {
var hash = location.hash;
const hash = location.hash;
// start with a clean state, i.e. [..., page, page+preview]
history.replaceState({}, document.title, pageURL);
history.pushState({}, document.title, location.href + hash);
}
var id = location.hash.split('#preview:')[1];
const id = location.hash.split('#preview:')[1];
previewAttachment(id);
}
})
Expand Down Expand Up @@ -94,7 +92,7 @@
}

function previewAttachment(id) {
var attachment = $('.attachment[data-previewable][data-attachment-id="{0}"]'.format(id));
const attachment = $('.attachment[data-previewable][data-attachment-id="{0}"]'.format(id));
if (!attachment.length) {
clearHash();
return;
Expand All @@ -103,7 +101,7 @@
url: build_url(attachment.attr('href'), {preview: '1'}),
title: attachment.data('title'),
dialogClasses: 'attachment-preview-dialog',
onClose: function(data) {
onClose(data) {
$('body').off('keydown.attachmentPreview');
$('html, body').removeClass('prevent-scrolling');
if (!data) {
Expand All @@ -112,17 +110,17 @@
clearHash();
}
},
onOpen: function(popup) {
var dialog = popup.canvas.closest('.ui-dialog');
onOpen(popup) {
const dialog = popup.canvas.closest('.ui-dialog');
dialog.prev('.ui-widget-overlay').addClass('attachment-preview-overlay');
popup.canvas
.find('.attachment-preview-content-wrapper, .js-close-preview')
.on('click', function() {
popup.canvas.trigger('ajaxDialog:close');
});
popup.canvas.find('.attachment-download').on('click', function() {
var $this = $(this);
var href = $this.attr('href');
const $this = $(this);
const href = $this.attr('href');
$this.attr('href', build_url(href, {from_preview: '1', download: '1'}));
_.defer(function() {
$this.attr('href', href);
Expand All @@ -147,8 +145,8 @@
dialog.show();
});
},
onLoadError: function(xhr) {
var hash = location.hash;
onLoadError(xhr) {
const hash = location.hash;
clearHash();
if (xhr.status == 404) {
alertPopup($T.gettext('This file no longer exists. Please reload the page.'));
Expand All @@ -159,7 +157,7 @@
if (Indico.User && Indico.User.id !== undefined) {
alertPopup($T('You are not authorized to access this file.'), $T('Access Denied'));
} else {
var msg = $T('This file is protected. You will be redirected to the login page.');
const msg = $T('This file is protected. You will be redirected to the login page.');
confirmPrompt(msg, $T('Access Denied')).then(function() {
location.href = build_url(Indico.Urls.Login, {next: location.href + hash});
});
Expand All @@ -175,7 +173,7 @@
};

global.setupAttachmentEditor = function setupAttachmentEditor() {
var editor = $('.attachment-editor');
const editor = $('.attachment-editor');

function flagChanged() {
editor.trigger('ajaxDialog:setData', [true]);
Expand All @@ -185,13 +183,13 @@
.on('click', '.tree .expandable', toggleFolder)
.on('click', '.js-dialog-action', function(e) {
e.preventDefault();
var $this = $(this);
const $this = $(this);
ajaxDialog({
trigger: this,
url: $this.data('href'),
title: $this.data('title'),
hidePageHeader: true,
onClose: function(data) {
onClose(data) {
if (data) {
$('#attachments-container').html(data.attachment_list);
flagChanged();
Expand All @@ -202,13 +200,13 @@
.on('indico:confirmed', '.js-delete', function(e) {
e.preventDefault();

var $this = $(this);
const $this = $(this);
$.ajax({
url: $this.data('href'),
method: $this.data('method'),
complete: IndicoUI.Dialogs.Util.progress(),
error: handleAjaxError,
success: function(data) {
success(data) {
$('#attachments-container').html(data.attachment_list);
handleFlashes(data, true, editor);
flagChanged();
Expand All @@ -225,12 +223,12 @@
) {
reloadOnChange = reloadOnChange === undefined ? true : reloadOnChange;
ajaxDialog({
trigger: trigger,
trigger,
url: build_url(Indico.Urls.AttachmentManager, itemLocator),
title: title || $T.gettext('Manage material'),
confirmCloseUnsaved: false,
hidePageHeader: true,
onClose: function(callbackData, customData) {
onClose(callbackData, customData) {
if (customData && reloadOnChange) {
location.reload();
} else if (customData && trigger) {
Expand All @@ -248,7 +246,7 @@
url: build_url(Indico.Urls.ManagementAttachmentInfoColumn, itemLocator),
method: 'GET',
error: handleAjaxError,
success: function(data) {
success(data) {
column.replaceWith(data.html);
},
});
Expand All @@ -263,7 +261,7 @@
folderProtection
) {
folderField.on('change', function() {
var selectedFolder = $(this);
const selectedFolder = $(this);
if (protectionInfo[selectedFolder.val()] && !protectionField.prop('checked')) {
selfProtection.hide();
inheritedProtection.hide();
Expand All @@ -284,7 +282,7 @@

global.setupAttachmentTooltipButtons = function setupAttachmentTooltipButtons() {
$('.attachments-tooltip-button').each(function() {
var button = $(this);
const button = $(this);
button.qtip({
content: {
text: button.next('.material_list'),
Expand All @@ -300,10 +298,10 @@
at: 'bottom left',
},
events: {
show: function() {
show() {
button.addClass('open');
},
hide: function() {
hide() {
button.removeClass('open');
},
},
Expand Down
16 changes: 7 additions & 9 deletions indico/modules/bootstrap/client/js/index.js
Original file line number Diff line number Diff line change
Expand Up @@ -7,8 +7,6 @@

// eslint-disable-next-line import/unambiguous
$(document).ready(function() {
'use strict';

// Header shrinking function
$(window).scroll(function() {
if (
Expand All @@ -24,13 +22,13 @@ $(document).ready(function() {
// Instance Tracking slider
const toggleCheckbox = $('#form-group-enable_tracking input:checkbox');
toggleCheckbox.on('change', function() {
var $this = $(this);
var enabled = $this.prop('checked');
var itEmail = $('#contact_email');
var itContact = $('#contact_name');
var firstName = $('#first_name').val();
var lastName = $('#last_name').val();
var name = !!firstName && !!lastName ? '{0} {1}'.format(firstName, lastName) : '';
const $this = $(this);
const enabled = $this.prop('checked');
const itEmail = $('#contact_email');
const itContact = $('#contact_name');
const firstName = $('#first_name').val();
const lastName = $('#last_name').val();
const name = !!firstName && !!lastName ? '{0} {1}'.format(firstName, lastName) : '';

itEmail.prop('required', enabled);
itEmail.prop('disabled', !enabled);
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -8,12 +8,14 @@
import categoryStatisticsURL from 'indico-url:categories.statistics_json';

import moment from 'moment';
import React, {useContext, useMemo} from 'react';
import PropTypes from 'prop-types';
import React, {useContext, useMemo} from 'react';
import {Chart} from 'react-charts';
import {Container, Header, Segment, Statistic, Message, Loader} from 'semantic-ui-react';
import {Param, Translate} from 'indico/react/i18n';

import {useIndicoAxios} from 'indico/react/hooks';
import {Param, Translate} from 'indico/react/i18n';

import {LocaleContext} from '../context.js';
import './CategoryStatistics.module.scss';

Expand Down
42 changes: 19 additions & 23 deletions indico/modules/categories/client/js/display.js
Original file line number Diff line number Diff line change
Expand Up @@ -6,23 +6,21 @@
// LICENSE file for more details.

(function(global) {
'use strict';

global.setupCategoryDisplaySubcatList = function setupCategoryDisplaySubcatList() {
var url = $('.category-list').data('subcat-info-url');
const url = $('.category-list').data('subcat-info-url');
if (url === undefined) {
// there's no .category-list if there are no subcategories
return;
}
$.ajax({
url: url,
url,
dataType: 'json',
success: function(data) {
success(data) {
_.each(data.event_counts, function(count, id) {
var text = !count.value
const text = !count.value
? $T.gettext('empty')
: $T.ngettext('{0} event', '{0} events', count.value).format(count.pretty);
$('#category-event-count-' + id).text(text);
$(`#category-event-count-${id}`).text(text);
});
},
});
Expand All @@ -33,9 +31,9 @@
showPastEvents,
requestParams
) {
var $eventList = $('.event-list');
var $futureEvents = $eventList.find('.future-events');
var $pastEvents = $eventList.find('.past-events');
const $eventList = $('.event-list');
const $futureEvents = $eventList.find('.future-events');
const $pastEvents = $eventList.find('.past-events');

setupToggleEventListButton($futureEvents, onToggleFutureEvents);
setupToggleEventListButton($pastEvents, onTogglePastEvents);
Expand Down Expand Up @@ -71,8 +69,8 @@
}

function setupToggleEventListButton(wrapper, callback) {
var $wrapper = $(wrapper);
var $content = $wrapper.find('.events');
const $wrapper = $(wrapper);
const $content = $wrapper.find('.events');

function updateMessage(visible) {
$wrapper.find('.js-hide-message').toggle(visible);
Expand All @@ -88,7 +86,7 @@

$wrapper.find('.js-toggle-list').on('click', function(evt, triggeredAutomatically) {
evt.preventDefault();
var visible;
let visible;
if ($content.is(':empty')) {
visible = true;
displaySpinner(true);
Expand All @@ -97,10 +95,10 @@
data: {
before: $content.data('event-list-before'),
after: $content.data('event-list-after'),
...requestParams
...requestParams,
},
error: handleAjaxError,
success: function(data) {
success(data) {
$content.html(data.html);
$content.show();
updateMessage(true);
Expand All @@ -124,21 +122,19 @@
};

global.setupCategoryDisplay = function setupCategoryDisplay() {
'use strict';

$('.fav-button')
.on('click', function() {
var $this = $(this);
var isFavorite = $this.hasClass('enabled');
const $this = $(this);
const isFavorite = $this.hasClass('enabled');
$this.prop('disabled', true);
$.ajax({
url: $this.data('href'),
method: isFavorite ? 'DELETE' : 'PUT',
error: handleAjaxError,
success: function() {
success() {
$this.toggleClass('enabled', !isFavorite);
},
complete: function() {
complete() {
$this.prop('disabled', false);
},
});
Expand All @@ -149,8 +145,8 @@
delay: 500,
},
content: {
text: function() {
var $this = $(this);
text() {
const $this = $(this);
if ($this.hasClass('enabled')) {
return $T.gettext('Remove from your favourites');
} else {
Expand Down
Loading

0 comments on commit 51b2de1

Please sign in to comment.