Fix linting errors or tables.js

This commit is contained in:
Oliver Walters 2021-08-28 22:12:41 +10:00
parent e85ddf3579
commit 0620e656a0
4 changed files with 28 additions and 70 deletions

View File

@ -7,6 +7,7 @@ env:
extends: 'eslint:recommended'
parserOptions:
ecmaVersion: 12
sourceType: module
rules:
accessor-pairs: error
array-bracket-newline: 'off'

View File

@ -1,6 +1,6 @@
{% load inventree_extras %}
function attachClipboard(selector, containerselector, textElement) {
export function attachClipboard(selector, containerselector, textElement) {
// set container
if (containerselector){
containerselector = document.getElementById(containerselector);
@ -28,7 +28,7 @@ function attachClipboard(selector, containerselector, textElement) {
}
function inventreeDocReady() {
export function inventreeDocReady() {
/* Run this function when the HTML document is loaded.
* This will be called for every page that extends "base.html"
*/
@ -132,7 +132,7 @@ function inventreeDocReady() {
});
}
function isFileTransfer(transfer) {
export function isFileTransfer(transfer) {
/* Determine if a transfer (e.g. drag-and-drop) is a file transfer
*/
@ -140,27 +140,7 @@ function isFileTransfer(transfer) {
}
function isOnlineTransfer(transfer) {
/* Determine if a drag-and-drop transfer is from another website.
* e.g. dragged from another browser window
*/
return transfer.items.length > 0;
}
function getImageUrlFromTransfer(transfer) {
/* Extract external image URL from a drag-and-dropped image
*/
var url = transfer.getData('text/html').match(/src\s*=\s*"(.+?)"/)[1];
console.log('Image URL: ' + url);
return url;
}
function makeIconBadge(icon, title) {
export function makeIconBadge(icon, title) {
// Construct an 'icon badge' which floats to the right of an object
var html = `<span class='fas ${icon} label-right' title='${title}'></span>`;
@ -168,7 +148,8 @@ function makeIconBadge(icon, title) {
return html;
}
function makeIconButton(icon, cls, pk, title, options={}) {
export function makeIconButton(icon, cls, pk, title, options={}) {
// Construct an 'icon button' using the fontawesome set
var classes = `btn btn-default btn-glyph ${cls}`;
@ -190,7 +171,7 @@ function makeIconButton(icon, cls, pk, title, options={}) {
return html;
}
function makeProgressBar(value, maximum, opts={}) {
export function makeProgressBar(value, maximum, opts={}) {
/*
* Render a progessbar!
*
@ -258,7 +239,7 @@ function makeProgressBar(value, maximum, opts={}) {
}
function enableDragAndDrop(element, url, options) {
export function enableDragAndDrop(element, url, options) {
/* Enable drag-and-drop file uploading for a given element.
Params:
@ -315,7 +296,7 @@ function enableDragAndDrop(element, url, options) {
});
}
function imageHoverIcon(url) {
export function imageHoverIcon(url) {
/* Render a small thumbnail icon for an image.
* On mouseover, display a full-size version of the image
*/
@ -334,7 +315,7 @@ function imageHoverIcon(url) {
return html;
}
function inventreeSave(name, value) {
export function inventreeSave(name, value) {
/*
* Save a key:value pair to local storage
*/
@ -343,7 +324,7 @@ function inventreeSave(name, value) {
localStorage.setItem(key, value);
}
function inventreeLoad(name, defaultValue) {
export function inventreeLoad(name, defaultValue) {
/*
* Retrieve a key:value pair from local storage
*/
@ -358,27 +339,3 @@ function inventreeLoad(name, defaultValue) {
return value;
}
}
function inventreeLoadInt(name) {
/*
* Retrieve a value from local storage, and attempt to cast to integer
*/
var data = inventreeLoad(name);
return parseInt(data, 10);
}
function inventreeLoadFloat(name) {
var data = inventreeLoad(name);
return parseFloat(data);
}
function inventreeDel(name) {
var key = 'inventree-' + name;
localStorage.removeItem(key);
}

View File

@ -3,7 +3,7 @@
{% user_settings request.user as USER_SETTINGS %}
var user_settings = {
export const user_settings = {
{% for key, value in USER_SETTINGS.items %}
{{ key }}: {% primitive_to_javascript value %},
{% endfor %}
@ -11,7 +11,7 @@ var user_settings = {
{% global_settings as GLOBAL_SETTINGS %}
var global_settings = {
export const global_settings = {
{% for key, value in GLOBAL_SETTINGS.items %}
{{ key }}: {% primitive_to_javascript value %},
{% endfor %}

View File

@ -1,30 +1,30 @@
{% load i18n %}
import { inventreeLoad, inventreeSave } from '{% url "inventree.js" %}';
function reloadtable(table) {
export function reloadtable(table) {
$(table).bootstrapTable('refresh');
}
function editButton(url, text='Edit') {
export function editButton(url, text='{% trans "Edit" %}') {
return "<button class='btn btn-success edit-button btn-sm' type='button' url='" + url + "'>" + text + "</button>";
}
function deleteButton(url, text='Delete') {
export function deleteButton(url, text='{% trans "Delete" %}') {
return "<button class='btn btn-danger delete-button btn-sm' type='button' url='" + url + "'>" + text + "</button>";
}
function renderLink(text, url, options={}) {
export function renderLink(text, url, options={}) {
if (url === null || url === undefined || url === '') {
return text;
}
var max_length = options.max_length || -1;
var remove_http = options.remove_http || false;
// Shorten the displayed length if required
if ((max_length > 0) && (text.length > max_length)) {
var slice_length = (max_length - 3) / 2;
@ -39,14 +39,14 @@ function renderLink(text, url, options={}) {
}
function enableButtons(elements, enabled) {
export function enableButtons(elements, enabled) {
for (let item of elements) {
$(item).prop('disabled', !enabled);
}
}
function linkButtonsToSelection(table, buttons) {
export function linkButtonsToSelection(table, buttons) {
/* Link a bootstrap-table object to one or more buttons.
* The buttons will only be enabled if there is at least one row selected
*/
@ -59,7 +59,7 @@ function linkButtonsToSelection(table, buttons) {
enableButtons(buttons, table.bootstrapTable('getSelections').length > 0);
// Add a callback
table.on('check.bs.table uncheck.bs.table check-some.bs.table uncheck-some.bs.table check-all.bs.table uncheck-all.bs.table', function(row) {
table.on('check.bs.table uncheck.bs.table check-some.bs.table uncheck-some.bs.table check-all.bs.table uncheck-all.bs.table', function() {
enableButtons(buttons, table.bootstrapTable('getSelections').length > 0);
});
}
@ -74,7 +74,7 @@ function isNumeric(n) {
* Reload a table which has already been made into a bootstrap table.
* New filters can be optionally provided, to change the query params.
*/
function reloadTableFilters(table, filters) {
export function reloadTableFilters(table, filters) {
// Simply perform a refresh
if (filters == null) {
@ -88,8 +88,8 @@ function reloadTableFilters(table, filters) {
// Construct a new list of filters to use for the query
var params = {};
for (var key in filters) {
params[key] = filters[key];
for (var k in filters) {
params[k] = filters[k];
}
// Original query params will override
@ -220,7 +220,7 @@ $.fn.inventreeTable = function(options) {
};
// Callback when a column is changed
options.onColumnSwitch = function(field, checked) {
options.onColumnSwitch = function() {
var columns = table.bootstrapTable('getVisibleColumns');
@ -263,7 +263,7 @@ $.fn.inventreeTable = function(options) {
}
}
function customGroupSorter(sortName, sortOrder, sortData) {
export function customGroupSorter(sortName, sortOrder, sortData) {
var order = sortOrder === 'desc' ? -1 : 1;