mirror of
https://github.com/inventree/InvenTree.git
synced 2025-04-29 20:16:44 +00:00
Fix linting errors or tables.js
This commit is contained in:
parent
e85ddf3579
commit
0620e656a0
@ -7,6 +7,7 @@ env:
|
|||||||
extends: 'eslint:recommended'
|
extends: 'eslint:recommended'
|
||||||
parserOptions:
|
parserOptions:
|
||||||
ecmaVersion: 12
|
ecmaVersion: 12
|
||||||
|
sourceType: module
|
||||||
rules:
|
rules:
|
||||||
accessor-pairs: error
|
accessor-pairs: error
|
||||||
array-bracket-newline: 'off'
|
array-bracket-newline: 'off'
|
||||||
|
@ -1,6 +1,6 @@
|
|||||||
{% load inventree_extras %}
|
{% load inventree_extras %}
|
||||||
|
|
||||||
function attachClipboard(selector, containerselector, textElement) {
|
export function attachClipboard(selector, containerselector, textElement) {
|
||||||
// set container
|
// set container
|
||||||
if (containerselector){
|
if (containerselector){
|
||||||
containerselector = document.getElementById(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.
|
/* Run this function when the HTML document is loaded.
|
||||||
* This will be called for every page that extends "base.html"
|
* 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
|
/* Determine if a transfer (e.g. drag-and-drop) is a file transfer
|
||||||
*/
|
*/
|
||||||
|
|
||||||
@ -140,27 +140,7 @@ function isFileTransfer(transfer) {
|
|||||||
}
|
}
|
||||||
|
|
||||||
|
|
||||||
function isOnlineTransfer(transfer) {
|
export function makeIconBadge(icon, title) {
|
||||||
/* 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) {
|
|
||||||
// Construct an 'icon badge' which floats to the right of an object
|
// Construct an 'icon badge' which floats to the right of an object
|
||||||
|
|
||||||
var html = `<span class='fas ${icon} label-right' title='${title}'></span>`;
|
var html = `<span class='fas ${icon} label-right' title='${title}'></span>`;
|
||||||
@ -168,7 +148,8 @@ function makeIconBadge(icon, title) {
|
|||||||
return html;
|
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
|
// Construct an 'icon button' using the fontawesome set
|
||||||
|
|
||||||
var classes = `btn btn-default btn-glyph ${cls}`;
|
var classes = `btn btn-default btn-glyph ${cls}`;
|
||||||
@ -190,7 +171,7 @@ function makeIconButton(icon, cls, pk, title, options={}) {
|
|||||||
return html;
|
return html;
|
||||||
}
|
}
|
||||||
|
|
||||||
function makeProgressBar(value, maximum, opts={}) {
|
export function makeProgressBar(value, maximum, opts={}) {
|
||||||
/*
|
/*
|
||||||
* Render a progessbar!
|
* 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.
|
/* Enable drag-and-drop file uploading for a given element.
|
||||||
|
|
||||||
Params:
|
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.
|
/* Render a small thumbnail icon for an image.
|
||||||
* On mouseover, display a full-size version of the image
|
* On mouseover, display a full-size version of the image
|
||||||
*/
|
*/
|
||||||
@ -334,7 +315,7 @@ function imageHoverIcon(url) {
|
|||||||
return html;
|
return html;
|
||||||
}
|
}
|
||||||
|
|
||||||
function inventreeSave(name, value) {
|
export function inventreeSave(name, value) {
|
||||||
/*
|
/*
|
||||||
* Save a key:value pair to local storage
|
* Save a key:value pair to local storage
|
||||||
*/
|
*/
|
||||||
@ -343,7 +324,7 @@ function inventreeSave(name, value) {
|
|||||||
localStorage.setItem(key, value);
|
localStorage.setItem(key, value);
|
||||||
}
|
}
|
||||||
|
|
||||||
function inventreeLoad(name, defaultValue) {
|
export function inventreeLoad(name, defaultValue) {
|
||||||
/*
|
/*
|
||||||
* Retrieve a key:value pair from local storage
|
* Retrieve a key:value pair from local storage
|
||||||
*/
|
*/
|
||||||
@ -358,27 +339,3 @@ function inventreeLoad(name, defaultValue) {
|
|||||||
return value;
|
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);
|
|
||||||
}
|
|
@ -3,7 +3,7 @@
|
|||||||
|
|
||||||
{% user_settings request.user as USER_SETTINGS %}
|
{% user_settings request.user as USER_SETTINGS %}
|
||||||
|
|
||||||
var user_settings = {
|
export const user_settings = {
|
||||||
{% for key, value in USER_SETTINGS.items %}
|
{% for key, value in USER_SETTINGS.items %}
|
||||||
{{ key }}: {% primitive_to_javascript value %},
|
{{ key }}: {% primitive_to_javascript value %},
|
||||||
{% endfor %}
|
{% endfor %}
|
||||||
@ -11,7 +11,7 @@ var user_settings = {
|
|||||||
|
|
||||||
{% global_settings as GLOBAL_SETTINGS %}
|
{% global_settings as GLOBAL_SETTINGS %}
|
||||||
|
|
||||||
var global_settings = {
|
export const global_settings = {
|
||||||
{% for key, value in GLOBAL_SETTINGS.items %}
|
{% for key, value in GLOBAL_SETTINGS.items %}
|
||||||
{{ key }}: {% primitive_to_javascript value %},
|
{{ key }}: {% primitive_to_javascript value %},
|
||||||
{% endfor %}
|
{% endfor %}
|
||||||
|
@ -1,30 +1,30 @@
|
|||||||
{% load i18n %}
|
{% load i18n %}
|
||||||
|
|
||||||
|
import { inventreeLoad, inventreeSave } from '{% url "inventree.js" %}';
|
||||||
|
|
||||||
function reloadtable(table) {
|
|
||||||
|
export function reloadtable(table) {
|
||||||
$(table).bootstrapTable('refresh');
|
$(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>";
|
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>";
|
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 === '') {
|
if (url === null || url === undefined || url === '') {
|
||||||
return text;
|
return text;
|
||||||
}
|
}
|
||||||
|
|
||||||
var max_length = options.max_length || -1;
|
var max_length = options.max_length || -1;
|
||||||
|
|
||||||
var remove_http = options.remove_http || false;
|
|
||||||
|
|
||||||
// Shorten the displayed length if required
|
// Shorten the displayed length if required
|
||||||
if ((max_length > 0) && (text.length > max_length)) {
|
if ((max_length > 0) && (text.length > max_length)) {
|
||||||
var slice_length = (max_length - 3) / 2;
|
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) {
|
for (let item of elements) {
|
||||||
$(item).prop('disabled', !enabled);
|
$(item).prop('disabled', !enabled);
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|
||||||
function linkButtonsToSelection(table, buttons) {
|
export function linkButtonsToSelection(table, buttons) {
|
||||||
/* Link a bootstrap-table object to one or more 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
|
* 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);
|
enableButtons(buttons, table.bootstrapTable('getSelections').length > 0);
|
||||||
|
|
||||||
// Add a callback
|
// 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);
|
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.
|
* Reload a table which has already been made into a bootstrap table.
|
||||||
* New filters can be optionally provided, to change the query params.
|
* New filters can be optionally provided, to change the query params.
|
||||||
*/
|
*/
|
||||||
function reloadTableFilters(table, filters) {
|
export function reloadTableFilters(table, filters) {
|
||||||
|
|
||||||
// Simply perform a refresh
|
// Simply perform a refresh
|
||||||
if (filters == null) {
|
if (filters == null) {
|
||||||
@ -88,8 +88,8 @@ function reloadTableFilters(table, filters) {
|
|||||||
// Construct a new list of filters to use for the query
|
// Construct a new list of filters to use for the query
|
||||||
var params = {};
|
var params = {};
|
||||||
|
|
||||||
for (var key in filters) {
|
for (var k in filters) {
|
||||||
params[key] = filters[key];
|
params[k] = filters[k];
|
||||||
}
|
}
|
||||||
|
|
||||||
// Original query params will override
|
// Original query params will override
|
||||||
@ -220,7 +220,7 @@ $.fn.inventreeTable = function(options) {
|
|||||||
};
|
};
|
||||||
|
|
||||||
// Callback when a column is changed
|
// Callback when a column is changed
|
||||||
options.onColumnSwitch = function(field, checked) {
|
options.onColumnSwitch = function() {
|
||||||
|
|
||||||
var columns = table.bootstrapTable('getVisibleColumns');
|
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;
|
var order = sortOrder === 'desc' ? -1 : 1;
|
||||||
|
|
||||||
|
Loading…
x
Reference in New Issue
Block a user