mirror of
https://github.com/inventree/InvenTree
synced 2024-08-30 18:33:04 +00:00
More js fixes
This commit is contained in:
parent
50b54f0966
commit
e0e7788af6
@ -1,5 +1,14 @@
|
|||||||
{% load i18n %}
|
{% load i18n %}
|
||||||
|
|
||||||
|
/* globals
|
||||||
|
*/
|
||||||
|
|
||||||
|
/* exported
|
||||||
|
clearEvents,
|
||||||
|
endDate,
|
||||||
|
startDate,
|
||||||
|
*/
|
||||||
|
|
||||||
/**
|
/**
|
||||||
* Helper functions for calendar display
|
* Helper functions for calendar display
|
||||||
*/
|
*/
|
||||||
|
@ -1,7 +1,17 @@
|
|||||||
{% load i18n %}
|
{% load i18n %}
|
||||||
{% load inventree_extras %}
|
{% load inventree_extras %}
|
||||||
|
|
||||||
var jQuery = window.$;
|
/* globals
|
||||||
|
renderErrorMessage,
|
||||||
|
showAlertDialog,
|
||||||
|
*/
|
||||||
|
|
||||||
|
/* exported
|
||||||
|
inventreeGet,
|
||||||
|
inventreeDelete,
|
||||||
|
inventreeFormDataUpload,
|
||||||
|
showApiError,
|
||||||
|
*/
|
||||||
|
|
||||||
$.urlParam = function(name){
|
$.urlParam = function(name){
|
||||||
var results = new RegExp('[\?&]' + name + '=([^&#]*)').exec(window.location.href);
|
var results = new RegExp('[\?&]' + name + '=([^&#]*)').exec(window.location.href);
|
||||||
@ -35,7 +45,7 @@ function inventreeGet(url, filters={}, options={}) {
|
|||||||
var csrftoken = getCookie('csrftoken');
|
var csrftoken = getCookie('csrftoken');
|
||||||
|
|
||||||
return $.ajax({
|
return $.ajax({
|
||||||
beforeSend: function(xhr, settings) {
|
beforeSend: function(xhr) {
|
||||||
xhr.setRequestHeader('X-CSRFToken', csrftoken);
|
xhr.setRequestHeader('X-CSRFToken', csrftoken);
|
||||||
},
|
},
|
||||||
url: url,
|
url: url,
|
||||||
@ -73,7 +83,7 @@ function inventreeFormDataUpload(url, data, options={}) {
|
|||||||
var csrftoken = getCookie('csrftoken');
|
var csrftoken = getCookie('csrftoken');
|
||||||
|
|
||||||
return $.ajax({
|
return $.ajax({
|
||||||
beforeSend: function(xhr, settings) {
|
beforeSend: function(xhr) {
|
||||||
xhr.setRequestHeader('X-CSRFToken', csrftoken);
|
xhr.setRequestHeader('X-CSRFToken', csrftoken);
|
||||||
},
|
},
|
||||||
url: url,
|
url: url,
|
||||||
@ -105,7 +115,7 @@ function inventreePut(url, data={}, options={}) {
|
|||||||
var csrftoken = getCookie('csrftoken');
|
var csrftoken = getCookie('csrftoken');
|
||||||
|
|
||||||
return $.ajax({
|
return $.ajax({
|
||||||
beforeSend: function(xhr, settings) {
|
beforeSend: function(xhr) {
|
||||||
xhr.setRequestHeader('X-CSRFToken', csrftoken);
|
xhr.setRequestHeader('X-CSRFToken', csrftoken);
|
||||||
},
|
},
|
||||||
url: url,
|
url: url,
|
||||||
|
@ -1,5 +1,15 @@
|
|||||||
{% load i18n %}
|
{% load i18n %}
|
||||||
|
|
||||||
|
/* globals
|
||||||
|
makeIconButton,
|
||||||
|
renderLink,
|
||||||
|
*/
|
||||||
|
|
||||||
|
/* exported
|
||||||
|
loadAttachmentTable,
|
||||||
|
reloadAttachmentTable,
|
||||||
|
*/
|
||||||
|
|
||||||
function reloadAttachmentTable() {
|
function reloadAttachmentTable() {
|
||||||
|
|
||||||
$('#attachment-table').bootstrapTable("refresh");
|
$('#attachment-table').bootstrapTable("refresh");
|
||||||
|
@ -1,5 +1,16 @@
|
|||||||
{% load i18n %}
|
{% load i18n %}
|
||||||
|
|
||||||
|
/* globals
|
||||||
|
getAvailableTableFilters,
|
||||||
|
inventreeLoad,
|
||||||
|
inventreeSave,
|
||||||
|
reloadTableFilters,
|
||||||
|
*/
|
||||||
|
|
||||||
|
/* exported
|
||||||
|
setupFilterList,
|
||||||
|
*/
|
||||||
|
|
||||||
/**
|
/**
|
||||||
* Code for managing query filters / table options.
|
* Code for managing query filters / table options.
|
||||||
*
|
*
|
||||||
@ -42,7 +53,7 @@ function loadTableFilters(tableKey) {
|
|||||||
|
|
||||||
var filters = {};
|
var filters = {};
|
||||||
|
|
||||||
filterstring.split("&").forEach(function(item, index) {
|
filterstring.split("&").forEach(function(item) {
|
||||||
item = item.trim();
|
item = item.trim();
|
||||||
|
|
||||||
if (item.length > 0) {
|
if (item.length > 0) {
|
||||||
@ -227,7 +238,7 @@ function generateFilterInput(tableKey, filterKey) {
|
|||||||
html = `<select class='form-control filter-input' id='${id}' name='value'>`;
|
html = `<select class='form-control filter-input' id='${id}' name='value'>`;
|
||||||
|
|
||||||
for (var key in options) {
|
for (var key in options) {
|
||||||
option = options[key];
|
var option = options[key];
|
||||||
html += `<option value='${key}'>${option.value}</option>`;
|
html += `<option value='${key}'>${option.value}</option>`;
|
||||||
}
|
}
|
||||||
|
|
||||||
@ -346,7 +357,7 @@ function setupFilterList(tableKey, table, target) {
|
|||||||
});
|
});
|
||||||
|
|
||||||
// Add callback for deleting each filter
|
// Add callback for deleting each filter
|
||||||
element.find(".close").click(function(event) {
|
element.find(".close").click(function() {
|
||||||
var me = $(this);
|
var me = $(this);
|
||||||
|
|
||||||
var filter = me.attr(`filter-tag-${tableKey}`);
|
var filter = me.attr(`filter-tag-${tableKey}`);
|
||||||
@ -372,15 +383,6 @@ function getFilterTitle(tableKey, filterKey) {
|
|||||||
}
|
}
|
||||||
|
|
||||||
|
|
||||||
/**
|
|
||||||
* Return the pretty description for the given table and filter selection
|
|
||||||
*/
|
|
||||||
function getFilterDescription(tableKey, filterKey) {
|
|
||||||
var settings = getFilterSettings(tableKey, filterKey);
|
|
||||||
|
|
||||||
return settings.title;
|
|
||||||
}
|
|
||||||
|
|
||||||
/*
|
/*
|
||||||
* Return a description for the given table and filter selection.
|
* Return a description for the given table and filter selection.
|
||||||
*/
|
*/
|
||||||
|
@ -1,5 +1,22 @@
|
|||||||
{% load i18n %}
|
{% load i18n %}
|
||||||
|
|
||||||
|
/* globals
|
||||||
|
inventreeGet,
|
||||||
|
showAlertOrCache,
|
||||||
|
*/
|
||||||
|
|
||||||
|
/* exported
|
||||||
|
attachSecondaryModal,
|
||||||
|
clearField,
|
||||||
|
clearFieldOptions,
|
||||||
|
closeModal,
|
||||||
|
enableField,
|
||||||
|
getFieldValue,
|
||||||
|
reloadFieldOptions,
|
||||||
|
showModalImage,
|
||||||
|
removeRowFromModalForm,
|
||||||
|
showQuestionDialog,
|
||||||
|
*/
|
||||||
|
|
||||||
/*
|
/*
|
||||||
* Create and display a new modal dialog
|
* Create and display a new modal dialog
|
||||||
@ -77,7 +94,7 @@ function createNewModal(options={}) {
|
|||||||
});
|
});
|
||||||
|
|
||||||
// Automatically remove the modal when it is deleted!
|
// Automatically remove the modal when it is deleted!
|
||||||
$(modal_name).on('hidden.bs.modal', function(e) {
|
$(modal_name).on('hidden.bs.modal', function() {
|
||||||
$(modal_name).remove();
|
$(modal_name).remove();
|
||||||
});
|
});
|
||||||
|
|
||||||
@ -253,7 +270,7 @@ function reloadFieldOptions(fieldName, options) {
|
|||||||
// Update the target field with the new options
|
// Update the target field with the new options
|
||||||
setFieldOptions(fieldName, opts);
|
setFieldOptions(fieldName, opts);
|
||||||
},
|
},
|
||||||
error: function(response) {
|
error: function() {
|
||||||
console.log("Error GETting field options");
|
console.log("Error GETting field options");
|
||||||
}
|
}
|
||||||
});
|
});
|
||||||
@ -344,7 +361,7 @@ function attachToggle(modal) {
|
|||||||
* and also larger toggle style buttons are easier to press!
|
* and also larger toggle style buttons are easier to press!
|
||||||
*/
|
*/
|
||||||
|
|
||||||
$(modal).find("input[type='checkbox']").each(function(x) {
|
$(modal).find("input[type='checkbox']").each(function() {
|
||||||
$(this).bootstrapToggle({
|
$(this).bootstrapToggle({
|
||||||
size: 'small',
|
size: 'small',
|
||||||
onstyle: 'success',
|
onstyle: 'success',
|
||||||
@ -554,7 +571,7 @@ function renderErrorMessage(xhr) {
|
|||||||
}
|
}
|
||||||
|
|
||||||
|
|
||||||
function showAlertDialog(title, content, options={}) {
|
function showAlertDialog(title, content) {
|
||||||
/* Display a modal dialog message box.
|
/* Display a modal dialog message box.
|
||||||
*
|
*
|
||||||
* title - Title text
|
* title - Title text
|
||||||
@ -762,15 +779,15 @@ function attachSecondaryModal(modal, options) {
|
|||||||
}
|
}
|
||||||
|
|
||||||
|
|
||||||
|
// eslint-disable-next-line no-unused-vars
|
||||||
function attachSecondaries(modal, secondaries) {
|
function attachSecondaries(modal, secondaries) {
|
||||||
/* Attach a provided list of secondary modals */
|
/* Attach a provided list of secondary modals */
|
||||||
|
|
||||||
// 2021-07-18 - Secondary modals will be disabled for now, until they are re-implemented in the "API forms" architecture
|
// 2021-07-18 - Secondary modals will be disabled for now, until they are re-implemented in the "API forms" architecture
|
||||||
return;
|
|
||||||
|
|
||||||
for (var i = 0; i < secondaries.length; i++) {
|
// for (var i = 0; i < secondaries.length; i++) {
|
||||||
attachSecondaryModal(modal, secondaries[i]);
|
// attachSecondaryModal(modal, secondaries[i]);
|
||||||
}
|
// }
|
||||||
}
|
}
|
||||||
|
|
||||||
function insertActionButton(modal, options) {
|
function insertActionButton(modal, options) {
|
||||||
@ -838,8 +855,6 @@ function handleModalForm(url, options) {
|
|||||||
|
|
||||||
var form = $(modal).find('.js-modal-form');
|
var form = $(modal).find('.js-modal-form');
|
||||||
|
|
||||||
var _form = $(modal).find(".js-modal-form");
|
|
||||||
|
|
||||||
form.ajaxForm({
|
form.ajaxForm({
|
||||||
url: url,
|
url: url,
|
||||||
dataType: 'json',
|
dataType: 'json',
|
||||||
@ -860,7 +875,7 @@ function handleModalForm(url, options) {
|
|||||||
modalEnable(modal, false);
|
modalEnable(modal, false);
|
||||||
},
|
},
|
||||||
// POST was successful
|
// POST was successful
|
||||||
success: function(response, status, xhr, f) {
|
success: function(response) {
|
||||||
// Re-enable the modal
|
// Re-enable the modal
|
||||||
modalEnable(modal, true);
|
modalEnable(modal, true);
|
||||||
if ('form_valid' in response) {
|
if ('form_valid' in response) {
|
||||||
@ -913,13 +928,13 @@ function handleModalForm(url, options) {
|
|||||||
afterForm(response, options);
|
afterForm(response, options);
|
||||||
}
|
}
|
||||||
},
|
},
|
||||||
error: function(xhr, ajaxOptions, thrownError) {
|
error: function(xhr) {
|
||||||
// There was an error submitting form data via POST
|
// There was an error submitting form data via POST
|
||||||
|
|
||||||
$(modal).modal('hide');
|
$(modal).modal('hide');
|
||||||
showAlertDialog('{% trans "Error posting form data" %}', renderErrorMessage(xhr));
|
showAlertDialog('{% trans "Error posting form data" %}', renderErrorMessage(xhr));
|
||||||
},
|
},
|
||||||
complete: function(xhr) {
|
complete: function() {
|
||||||
//TODO
|
//TODO
|
||||||
}
|
}
|
||||||
});
|
});
|
||||||
@ -960,7 +975,7 @@ function launchModalForm(url, options = {}) {
|
|||||||
$(modal).find('#modal-footer-buttons').html('');
|
$(modal).find('#modal-footer-buttons').html('');
|
||||||
|
|
||||||
// Form the ajax request to retrieve the django form data
|
// Form the ajax request to retrieve the django form data
|
||||||
ajax_data = {
|
var ajax_data = {
|
||||||
url: url,
|
url: url,
|
||||||
type: 'get',
|
type: 'get',
|
||||||
dataType: 'json',
|
dataType: 'json',
|
||||||
@ -1017,7 +1032,7 @@ function launchModalForm(url, options = {}) {
|
|||||||
showAlertDialog('{% trans "Invalid server response" %}', '{% trans "JSON response missing form data" %}');
|
showAlertDialog('{% trans "Invalid server response" %}', '{% trans "JSON response missing form data" %}');
|
||||||
}
|
}
|
||||||
},
|
},
|
||||||
error: function (xhr, ajaxOptions, thrownError) {
|
error: function (xhr) {
|
||||||
|
|
||||||
$(modal).modal('hide');
|
$(modal).modal('hide');
|
||||||
|
|
||||||
|
@ -1,18 +1,19 @@
|
|||||||
{% load i18n %}
|
{% load i18n %}
|
||||||
|
|
||||||
|
/* globals
|
||||||
|
blankImage,
|
||||||
|
select2Thumbnail
|
||||||
|
*/
|
||||||
|
|
||||||
function blankImage() {
|
/* exported
|
||||||
return `/static/img/blank_image.png`;
|
renderBuild,
|
||||||
}
|
renderCompany,
|
||||||
|
renderManufacturerPart,
|
||||||
// Render a select2 thumbnail image
|
renderOwner,
|
||||||
function select2Thumbnail(image) {
|
renderPartCategory,
|
||||||
if (!image) {
|
renderStockLocation,
|
||||||
image = blankImage();
|
renderSupplierPart,
|
||||||
}
|
*/
|
||||||
|
|
||||||
return `<img src='${image}' class='select2-thumbnail'>`;
|
|
||||||
}
|
|
||||||
|
|
||||||
|
|
||||||
/*
|
/*
|
||||||
@ -29,6 +30,7 @@ function select2Thumbnail(image) {
|
|||||||
|
|
||||||
|
|
||||||
// Renderer for "Company" model
|
// Renderer for "Company" model
|
||||||
|
// eslint-disable-next-line no-unused-vars
|
||||||
function renderCompany(name, data, parameters, options) {
|
function renderCompany(name, data, parameters, options) {
|
||||||
|
|
||||||
var html = select2Thumbnail(data.image);
|
var html = select2Thumbnail(data.image);
|
||||||
@ -42,6 +44,7 @@ function renderCompany(name, data, parameters, options) {
|
|||||||
|
|
||||||
|
|
||||||
// Renderer for "StockItem" model
|
// Renderer for "StockItem" model
|
||||||
|
// eslint-disable-next-line no-unused-vars
|
||||||
function renderStockItem(name, data, parameters, options) {
|
function renderStockItem(name, data, parameters, options) {
|
||||||
|
|
||||||
var image = data.part_detail.thumbnail || data.part_detail.image || blankImage();
|
var image = data.part_detail.thumbnail || data.part_detail.image || blankImage();
|
||||||
@ -65,6 +68,7 @@ function renderStockItem(name, data, parameters, options) {
|
|||||||
|
|
||||||
|
|
||||||
// Renderer for "StockLocation" model
|
// Renderer for "StockLocation" model
|
||||||
|
// eslint-disable-next-line no-unused-vars
|
||||||
function renderStockLocation(name, data, parameters, options) {
|
function renderStockLocation(name, data, parameters, options) {
|
||||||
|
|
||||||
var level = '- '.repeat(data.level);
|
var level = '- '.repeat(data.level);
|
||||||
@ -80,7 +84,7 @@ function renderStockLocation(name, data, parameters, options) {
|
|||||||
return html;
|
return html;
|
||||||
}
|
}
|
||||||
|
|
||||||
|
// eslint-disable-next-line no-unused-vars
|
||||||
function renderBuild(name, data, parameters, options) {
|
function renderBuild(name, data, parameters, options) {
|
||||||
|
|
||||||
var image = null;
|
var image = null;
|
||||||
@ -101,6 +105,7 @@ function renderBuild(name, data, parameters, options) {
|
|||||||
|
|
||||||
|
|
||||||
// Renderer for "Part" model
|
// Renderer for "Part" model
|
||||||
|
// eslint-disable-next-line no-unused-vars
|
||||||
function renderPart(name, data, parameters, options) {
|
function renderPart(name, data, parameters, options) {
|
||||||
|
|
||||||
var html = select2Thumbnail(data.image);
|
var html = select2Thumbnail(data.image);
|
||||||
@ -117,6 +122,7 @@ function renderPart(name, data, parameters, options) {
|
|||||||
}
|
}
|
||||||
|
|
||||||
// Renderer for "User" model
|
// Renderer for "User" model
|
||||||
|
// eslint-disable-next-line no-unused-vars
|
||||||
function renderUser(name, data, parameters, options) {
|
function renderUser(name, data, parameters, options) {
|
||||||
|
|
||||||
var html = `<span>${data.username}</span>`;
|
var html = `<span>${data.username}</span>`;
|
||||||
@ -130,6 +136,7 @@ function renderUser(name, data, parameters, options) {
|
|||||||
|
|
||||||
|
|
||||||
// Renderer for "Owner" model
|
// Renderer for "Owner" model
|
||||||
|
// eslint-disable-next-line no-unused-vars
|
||||||
function renderOwner(name, data, parameters, options) {
|
function renderOwner(name, data, parameters, options) {
|
||||||
|
|
||||||
var html = `<span>${data.name}</span>`;
|
var html = `<span>${data.name}</span>`;
|
||||||
@ -150,6 +157,7 @@ function renderOwner(name, data, parameters, options) {
|
|||||||
|
|
||||||
|
|
||||||
// Renderer for "PartCategory" model
|
// Renderer for "PartCategory" model
|
||||||
|
// eslint-disable-next-line no-unused-vars
|
||||||
function renderPartCategory(name, data, parameters, options) {
|
function renderPartCategory(name, data, parameters, options) {
|
||||||
|
|
||||||
var level = '- '.repeat(data.level);
|
var level = '- '.repeat(data.level);
|
||||||
@ -165,7 +173,7 @@ function renderPartCategory(name, data, parameters, options) {
|
|||||||
return html;
|
return html;
|
||||||
}
|
}
|
||||||
|
|
||||||
|
// eslint-disable-next-line no-unused-vars
|
||||||
function renderPartParameterTemplate(name, data, parameters, options) {
|
function renderPartParameterTemplate(name, data, parameters, options) {
|
||||||
|
|
||||||
var html = `<span>${data.name} - [${data.units}]</span>`;
|
var html = `<span>${data.name} - [${data.units}]</span>`;
|
||||||
@ -175,6 +183,7 @@ function renderPartParameterTemplate(name, data, parameters, options) {
|
|||||||
|
|
||||||
|
|
||||||
// Renderer for "ManufacturerPart" model
|
// Renderer for "ManufacturerPart" model
|
||||||
|
// eslint-disable-next-line no-unused-vars
|
||||||
function renderManufacturerPart(name, data, parameters, options) {
|
function renderManufacturerPart(name, data, parameters, options) {
|
||||||
|
|
||||||
var manufacturer_image = null;
|
var manufacturer_image = null;
|
||||||
@ -203,6 +212,7 @@ function renderManufacturerPart(name, data, parameters, options) {
|
|||||||
|
|
||||||
|
|
||||||
// Renderer for "SupplierPart" model
|
// Renderer for "SupplierPart" model
|
||||||
|
// eslint-disable-next-line no-unused-vars
|
||||||
function renderSupplierPart(name, data, parameters, options) {
|
function renderSupplierPart(name, data, parameters, options) {
|
||||||
|
|
||||||
var supplier_image = null;
|
var supplier_image = null;
|
||||||
|
Loading…
Reference in New Issue
Block a user