diff --git a/.pre-commit-config.yaml b/.pre-commit-config.yaml
index c844b4f8..73369760 100644
--- a/.pre-commit-config.yaml
+++ b/.pre-commit-config.yaml
@@ -8,6 +8,10 @@ repos:
args: ["--fix", "--silent"]
# Run the formatter.
- id: ruff-format
+ - repo: https://github.com/standard/standard
+ rev: v17.1.2
+ hooks:
+ - id: standard
- repo: https://github.com/rtts/djhtml
rev: 3.0.6
hooks:
diff --git a/README.md b/README.md
index 15840f07..544e473f 100644
--- a/README.md
+++ b/README.md
@@ -5,6 +5,7 @@
[![CI status](https://github.com/ae-utbm/sith/actions/workflows/ci.yml/badge.svg)](#)
[![Docs status](https://github.com/ae-utbm/sith/actions/workflows/deploy_docs.yml/badge.svg)](https://ae-utbm.github.io/sith)
[![Built with Material for MkDocs](https://img.shields.io/badge/Material_for_MkDocs-526CFE?style=default&logo=MaterialForMkDocs&logoColor=white)](https://squidfunk.github.io/mkdocs-material/)
+[![JavaScript Style Guide](https://img.shields.io/badge/code_style-standard-brightgreen.svg)](https://standardjs.com)
[![discord](https://img.shields.io/discord/971448179075731476?label=discord&logo=discord&style=default)](https://discord.gg/xk9wfpsufm)
### This is the source code of the UTBM's student association available at [https://ae.utbm.fr/](https://ae.utbm.fr/).
diff --git a/com/static/com/js/poster_list.js b/com/static/com/js/poster_list.js
index 9d4090e9..31c2c510 100644
--- a/com/static/com/js/poster_list.js
+++ b/com/static/com/js/poster_list.js
@@ -1,24 +1,20 @@
-$(document).ready(function(){
+$(document).ready(function () {
+ $('#poster_list #view').click(function (e) {
+ $('#view').removeClass('active')
+ })
- $("#poster_list #view").click(function(e){
- $("#view").removeClass("active");
- });
+ $('#poster_list .poster .image').click(function (e) {
+ let el = $(e.target)
+ if (el.hasClass('image')) { el = el.find('img') }
+ $('#poster_list #view #placeholder').html(el.clone())
- $("#poster_list .poster .image").click(function(e){
+ $('#view').addClass('active')
+ })
- el = $(e.target);
- if(el.hasClass("image"))
- el = el.find("img")
- $("#poster_list #view #placeholder").html(el.clone());
-
- $("#view").addClass("active");
- });
-
- $(document).keyup(function(e) {
- if (e.keyCode == 27) { // escape key maps to keycode `27`
- e.preventDefault();
- $("#view").removeClass("active");
- }
- });
-
-});
+ $(document).keyup(function (e) {
+ if (e.keyCode === 27) { // escape key maps to keycode `27`
+ e.preventDefault()
+ $('#view').removeClass('active')
+ }
+ })
+})
diff --git a/com/static/com/js/slideshow.js b/com/static/com/js/slideshow.js
index 74ac9765..db6681dd 100644
--- a/com/static/com/js/slideshow.js
+++ b/com/static/com/js/slideshow.js
@@ -1,118 +1,104 @@
-$(document).ready(function(){
+// TODO: remove disable
+/* eslint-disable no-undef, camelcase */
+$(document).ready(function () {
+ transition_time = 1000
- transition_time = 1000;
+ i = 0
+ max = $('#slideshow .slide').length
- i = 0;
- max = $("#slideshow .slide").length;
+ next_trigger = 0
- next_trigger = 0
-
- function enterFullscreen() {
- element = document.getElementById("slideshow");
- $(element).addClass("fullscreen");
- if(element.requestFullscreen) {
- element.requestFullscreen();
- } else if(element.mozRequestFullScreen) {
- element.mozRequestFullScreen();
- } else if(element.webkitRequestFullscreen) {
- element.webkitRequestFullscreen();
- } else if(element.msRequestFullscreen) {
- element.msRequestFullscreen();
- }
+ function enterFullscreen () {
+ element = document.getElementById('slideshow')
+ $(element).addClass('fullscreen')
+ if (element.requestFullscreen) {
+ element.requestFullscreen()
+ } else if (element.mozRequestFullScreen) {
+ element.mozRequestFullScreen()
+ } else if (element.webkitRequestFullscreen) {
+ element.webkitRequestFullscreen()
+ } else if (element.msRequestFullscreen) {
+ element.msRequestFullscreen()
}
+ }
- function exitFullscreen() {
- element = document.getElementById("slideshow");
- $(element).removeClass("fullscreen");
- if (document.exitFullscreen) {
- document.exitFullscreen();
- } else if (document.webkitExitFullscreen) {
- document.webkitExitFullscreen();
- } else if (document.mozCancelFullScreen) {
- document.mozCancelFullScreen();
- } else if (document.msExitFullscreen) {
- document.msExitFullscreen();
- }
+ function exitFullscreen () {
+ element = document.getElementById('slideshow')
+ $(element).removeClass('fullscreen')
+ if (document.exitFullscreen) {
+ document.exitFullscreen()
+ } else if (document.webkitExitFullscreen) {
+ document.webkitExitFullscreen()
+ } else if (document.mozCancelFullScreen) {
+ document.mozCancelFullScreen()
+ } else if (document.msExitFullscreen) {
+ document.msExitFullscreen()
}
+ }
- function init_progress_bar()
- {
+ function init_progress_bar () {
+ $('#slideshow #progress_bar').css('transition', 'none')
+ $('#slideshow #progress_bar').removeClass('progress')
+ $('#slideshow #progress_bar').addClass('init')
+ }
- $("#slideshow #progress_bar").css("transition", "none");
- $("#slideshow #progress_bar").removeClass("progress");
- $("#slideshow #progress_bar").addClass("init");
+ function start_progress_bar (display_time) {
+ $('#slideshow #progress_bar').removeClass('init')
+ $('#slideshow #progress_bar').addClass('progress')
+ $('#slideshow #progress_bar').css('transition', 'width ' + display_time + 's linear')
+ }
+ function next () {
+ init_progress_bar()
+ slide = $($('#slideshow .slide').get(i % max))
+ slide.removeClass('center')
+ slide.addClass('left')
+
+ next_slide = $($('#slideshow .slide').get((i + 1) % max))
+ next_slide.removeClass('right')
+ next_slide.addClass('center')
+ display_time = next_slide.attr('display_time') || 2
+
+ $('#slideshow .bullet').removeClass('active')
+ bullet = $('#slideshow .bullet')[(i + 1) % max]
+ $(bullet).addClass('active')
+
+ i = (i + 1) % max
+
+ setTimeout(function () {
+ others_left = $('#slideshow .slide.left')
+ others_left.removeClass('left')
+ others_left.addClass('right')
+
+ start_progress_bar(display_time)
+ next_trigger = setTimeout(next, display_time * 1000)
+ }, transition_time)
+ }
+
+ display_time = $('#slideshow .center').attr('display_time')
+ init_progress_bar()
+ setTimeout(function () {
+ if (max > 1) {
+ start_progress_bar(display_time)
+ setTimeout(next, display_time * 1000)
}
+ }, 10)
- function start_progress_bar(display_time)
- {
-
- $("#slideshow #progress_bar").removeClass("init");
- $("#slideshow #progress_bar").addClass("progress");
- $("#slideshow #progress_bar").css("transition", "width " + display_time + "s linear")
-
+ $('#slideshow').click(function (e) {
+ if (!$('#slideshow').hasClass('fullscreen')) {
+ console.log('Entering fullscreen ...')
+ enterFullscreen()
+ } else {
+ console.log('Exiting fullscreen ...')
+ exitFullscreen()
}
+ })
- function next()
- {
-
- init_progress_bar();
- slide = $($("#slideshow .slide").get(i % max));
- slide.removeClass("center");
- slide.addClass("left");
-
- next_slide = $($("#slideshow .slide").get((i + 1) % max));
- next_slide.removeClass("right");
- next_slide.addClass("center");
- display_time = next_slide.attr("display_time") || 2;
-
- $("#slideshow .bullet").removeClass("active");
- bullet = $("#slideshow .bullet")[(i + 1) % max];
- $(bullet).addClass("active");
-
- i = (i + 1) % max;
-
- setTimeout(function(){
-
- others_left = $("#slideshow .slide.left");
- others_left.removeClass("left");
- others_left.addClass("right");
-
- start_progress_bar(display_time);
- next_trigger = setTimeout(next, display_time * 1000);
-
- }, transition_time);
-
+ $(document).keyup(function (e) {
+ if (e.keyCode === 27) { // escape key maps to keycode `27`
+ e.preventDefault()
+ console.log('Exiting fullscreen ...')
+ exitFullscreen()
}
-
-
- display_time = $("#slideshow .center").attr("display_time");
- init_progress_bar();
- setTimeout(function(){
- if(max > 1){
- start_progress_bar(display_time);
- setTimeout(next, display_time * 1000);
- }
- }, 10);
-
-
- $("#slideshow").click(function(e){
- if(!$("#slideshow").hasClass("fullscreen"))
- {
- console.log("Entering fullscreen ...");
- enterFullscreen();
- }else{
- console.log("Exiting fullscreen ...");
- exitFullscreen();
- }
- });
-
- $(document).keyup(function(e) {
- if (e.keyCode == 27) { // escape key maps to keycode `27`
- e.preventDefault();
- console.log("Exiting fullscreen ...");
- exitFullscreen();
- }
- });
-
-});
+ })
+})
diff --git a/core/static/core/js/script.js b/core/static/core/js/script.js
index c3319c00..501a801a 100644
--- a/core/static/core/js/script.js
+++ b/core/static/core/js/script.js
@@ -1,59 +1,60 @@
-$( function() {
- buttons = $(".choose_file_button");
- popups = $(".choose_file_widget");
- popups.dialog({
- autoOpen: false,
- modal: true,
- width: "90%",
- create: function (event) {
- target = $(event.target);
- target.parent().css({
- 'position': 'fixed',
- 'top': '5%',
- 'bottom': '5%',
- });
- target.css("height", "300px");
- console.log(target);
+/* eslint-disable camelcase */
+$(function () {
+ // const buttons = $('.choose_file_button')
+ const popups = $('.choose_file_widget')
+ popups.dialog({
+ autoOpen: false,
+ modal: true,
+ width: '90%',
+ create: function (event) {
+ const target = $(event.target)
+ target.parent().css({
+ position: 'fixed',
+ top: '5%',
+ bottom: '5%'
+ })
+ target.css('height', '300px')
+ console.log(target)
+ },
+ buttons: [
+ {
+ text: 'Choose',
+ click: function () {
+ console.log($('#file_id'))
+ $('input[name=' + $(this).attr('name') + ']').attr('value', $('#file_id').attr('value'))
+ $(this).dialog('close')
},
- buttons: [
- {
- text: "Choose",
- click: function() {
- console.log($("#file_id"));
- $("input[name="+$(this).attr('name')+"]").attr('value', $("#file_id").attr('value'));
- $( this ).dialog( "close" );
- },
- disabled: true,
- }
- ],
- });
- $( ".choose_file_button" ).button().on( "click", function() {
- popup = popups.filter("[name="+$(this).attr('name')+"]");
- console.log(popup);
- popup.html('
');
- popup.dialog({title: $(this).text()}).dialog( "open" );
- });
- $("#quick_notif li").click(function () {
- $(this).hide();
- })
-});
+ disabled: true
+ }
+ ]
+ })
+ $('.choose_file_button').button().on('click', function () {
+ const popup = popups.filter('[name=' + $(this).attr('name') + ']')
+ console.log(popup)
+ popup.html('')
+ popup.dialog({ title: $(this).text() }).dialog('open')
+ })
+ $('#quick_notif li').click(function () {
+ $(this).hide()
+ })
+})
-function createQuickNotif(msg) {
- const el = document.createElement('li')
- el.textContent = msg
- el.addEventListener('click', () => el.parentNode.removeChild(el))
- document.getElementById('quick_notif').appendChild(el)
+function createQuickNotif (msg) { // eslint-disable-line no-unused-vars
+ const el = document.createElement('li')
+ el.textContent = msg
+ el.addEventListener('click', () => el.parentNode.removeChild(el))
+ document.getElementById('quick_notif').appendChild(el)
}
-function deleteQuickNotifs() {
- const el = document.getElementById('quick_notif')
- while (el.firstChild) {
- el.removeChild(el.firstChild)
- }
+function deleteQuickNotifs () { // eslint-disable-line no-unused-vars
+ const el = document.getElementById('quick_notif')
+ while (el.firstChild) {
+ el.removeChild(el.firstChild)
+ }
}
-function display_notif() {
- $('#header_notif').toggle().parent().toggleClass("white");
+function display_notif () { // eslint-disable-line no-unused-vars
+ $('#header_notif').toggle().parent().toggleClass('white')
}
// You can't get the csrf token from the template in a widget
@@ -62,22 +63,21 @@ function display_notif() {
// Sadly, getting the cookie is not possible with CSRF_COOKIE_HTTPONLY or CSRF_USE_SESSIONS is True
// So, the true workaround is to get the token from the dom
// https://docs.djangoproject.com/en/2.0/ref/csrf/#acquiring-the-token-if-csrf-use-sessions-is-true
-function getCSRFToken() {
- return $("[name=csrfmiddlewaretoken]").val();
+function getCSRFToken () { // eslint-disable-line no-unused-vars
+ return $('[name=csrfmiddlewaretoken]').val()
}
-
-const initialUrlParams = new URLSearchParams(window.location.search);
+const initialUrlParams = new URLSearchParams(window.location.search) // eslint-disable-line no-unused-vars
/**
* @readonly
* @enum {number}
*/
const History = {
- NONE: 0,
- PUSH: 1,
- REPLACE: 2,
-};
+ NONE: 0,
+ PUSH: 1,
+ REPLACE: 2
+}
/**
* @param {string} key
@@ -85,27 +85,27 @@ const History = {
* @param {History} action
* @param {URL | null} url
*/
-function update_query_string(key, value, action = History.REPLACE, url = null) {
- if (!url){
- url = new URL(window.location.href);
- }
- if (value === undefined || value === null || value === "") {
- // If the value is null, undefined or empty => delete it
- url.searchParams.delete(key)
- } else if (Array.isArray(value)) {
- url.searchParams.delete(key)
- value.forEach((v) => url.searchParams.append(key, v))
- } else {
- url.searchParams.set(key, value);
- }
+function update_query_string (key, value, action = History.REPLACE, url = null) { // eslint-disable-line no-unused-vars
+ if (!url) {
+ url = new URL(window.location.href)
+ }
+ if (value === undefined || value === null || value === '') {
+ // If the value is null, undefined or empty => delete it
+ url.searchParams.delete(key)
+ } else if (Array.isArray(value)) {
+ url.searchParams.delete(key)
+ value.forEach((v) => url.searchParams.append(key, v))
+ } else {
+ url.searchParams.set(key, value)
+ }
- if (action === History.PUSH) {
- history.pushState(null, "", url.toString());
- } else if (action === History.REPLACE) {
- history.replaceState(null, "", url.toString());
- }
+ if (action === History.PUSH) {
+ window.history.pushState(null, '', url.toString())
+ } else if (action === History.REPLACE) {
+ window.history.replaceState(null, '', url.toString())
+ }
- return url;
+ return url
}
// TODO : If one day a test workflow is made for JS in this project
@@ -116,27 +116,27 @@ function update_query_string(key, value, action = History.REPLACE, url = null) {
* @param {string} url The paginated endpoint to fetch
* @return {Promise