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 %}
|
||||
|
||||
/* globals
|
||||
*/
|
||||
|
||||
/* exported
|
||||
clearEvents,
|
||||
endDate,
|
||||
startDate,
|
||||
*/
|
||||
|
||||
/**
|
||||
* Helper functions for calendar display
|
||||
*/
|
||||
|
@ -1,7 +1,17 @@
|
||||
{% load i18n %}
|
||||
{% load inventree_extras %}
|
||||
|
||||
var jQuery = window.$;
|
||||
/* globals
|
||||
renderErrorMessage,
|
||||
showAlertDialog,
|
||||
*/
|
||||
|
||||
/* exported
|
||||
inventreeGet,
|
||||
inventreeDelete,
|
||||
inventreeFormDataUpload,
|
||||
showApiError,
|
||||
*/
|
||||
|
||||
$.urlParam = function(name){
|
||||
var results = new RegExp('[\?&]' + name + '=([^&#]*)').exec(window.location.href);
|
||||
@ -35,7 +45,7 @@ function inventreeGet(url, filters={}, options={}) {
|
||||
var csrftoken = getCookie('csrftoken');
|
||||
|
||||
return $.ajax({
|
||||
beforeSend: function(xhr, settings) {
|
||||
beforeSend: function(xhr) {
|
||||
xhr.setRequestHeader('X-CSRFToken', csrftoken);
|
||||
},
|
||||
url: url,
|
||||
@ -73,7 +83,7 @@ function inventreeFormDataUpload(url, data, options={}) {
|
||||
var csrftoken = getCookie('csrftoken');
|
||||
|
||||
return $.ajax({
|
||||
beforeSend: function(xhr, settings) {
|
||||
beforeSend: function(xhr) {
|
||||
xhr.setRequestHeader('X-CSRFToken', csrftoken);
|
||||
},
|
||||
url: url,
|
||||
@ -105,7 +115,7 @@ function inventreePut(url, data={}, options={}) {
|
||||
var csrftoken = getCookie('csrftoken');
|
||||
|
||||
return $.ajax({
|
||||
beforeSend: function(xhr, settings) {
|
||||
beforeSend: function(xhr) {
|
||||
xhr.setRequestHeader('X-CSRFToken', csrftoken);
|
||||
},
|
||||
url: url,
|
||||
|
@ -1,5 +1,15 @@
|
||||
{% load i18n %}
|
||||
|
||||
/* globals
|
||||
makeIconButton,
|
||||
renderLink,
|
||||
*/
|
||||
|
||||
/* exported
|
||||
loadAttachmentTable,
|
||||
reloadAttachmentTable,
|
||||
*/
|
||||
|
||||
function reloadAttachmentTable() {
|
||||
|
||||
$('#attachment-table').bootstrapTable("refresh");
|
||||
|
@ -1,5 +1,16 @@
|
||||
{% load i18n %}
|
||||
|
||||
/* globals
|
||||
getAvailableTableFilters,
|
||||
inventreeLoad,
|
||||
inventreeSave,
|
||||
reloadTableFilters,
|
||||
*/
|
||||
|
||||
/* exported
|
||||
setupFilterList,
|
||||
*/
|
||||
|
||||
/**
|
||||
* Code for managing query filters / table options.
|
||||
*
|
||||
@ -42,7 +53,7 @@ function loadTableFilters(tableKey) {
|
||||
|
||||
var filters = {};
|
||||
|
||||
filterstring.split("&").forEach(function(item, index) {
|
||||
filterstring.split("&").forEach(function(item) {
|
||||
item = item.trim();
|
||||
|
||||
if (item.length > 0) {
|
||||
@ -227,7 +238,7 @@ function generateFilterInput(tableKey, filterKey) {
|
||||
html = `<select class='form-control filter-input' id='${id}' name='value'>`;
|
||||
|
||||
for (var key in options) {
|
||||
option = options[key];
|
||||
var option = options[key];
|
||||
html += `<option value='${key}'>${option.value}</option>`;
|
||||
}
|
||||
|
||||
@ -346,7 +357,7 @@ function setupFilterList(tableKey, table, target) {
|
||||
});
|
||||
|
||||
// Add callback for deleting each filter
|
||||
element.find(".close").click(function(event) {
|
||||
element.find(".close").click(function() {
|
||||
var me = $(this);
|
||||
|
||||
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.
|
||||
*/
|
||||
|
@ -1,5 +1,22 @@
|
||||
{% load i18n %}
|
||||
|
||||
/* globals
|
||||
inventreeGet,
|
||||
showAlertOrCache,
|
||||
*/
|
||||
|
||||
/* exported
|
||||
attachSecondaryModal,
|
||||
clearField,
|
||||
clearFieldOptions,
|
||||
closeModal,
|
||||
enableField,
|
||||
getFieldValue,
|
||||
reloadFieldOptions,
|
||||
showModalImage,
|
||||
removeRowFromModalForm,
|
||||
showQuestionDialog,
|
||||
*/
|
||||
|
||||
/*
|
||||
* Create and display a new modal dialog
|
||||
@ -77,7 +94,7 @@ function createNewModal(options={}) {
|
||||
});
|
||||
|
||||
// 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();
|
||||
});
|
||||
|
||||
@ -253,7 +270,7 @@ function reloadFieldOptions(fieldName, options) {
|
||||
// Update the target field with the new options
|
||||
setFieldOptions(fieldName, opts);
|
||||
},
|
||||
error: function(response) {
|
||||
error: function() {
|
||||
console.log("Error GETting field options");
|
||||
}
|
||||
});
|
||||
@ -344,7 +361,7 @@ function attachToggle(modal) {
|
||||
* 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({
|
||||
size: 'small',
|
||||
onstyle: 'success',
|
||||
@ -554,7 +571,7 @@ function renderErrorMessage(xhr) {
|
||||
}
|
||||
|
||||
|
||||
function showAlertDialog(title, content, options={}) {
|
||||
function showAlertDialog(title, content) {
|
||||
/* Display a modal dialog message box.
|
||||
*
|
||||
* title - Title text
|
||||
@ -762,15 +779,15 @@ function attachSecondaryModal(modal, options) {
|
||||
}
|
||||
|
||||
|
||||
// eslint-disable-next-line no-unused-vars
|
||||
function attachSecondaries(modal, secondaries) {
|
||||
/* 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
|
||||
return;
|
||||
|
||||
for (var i = 0; i < secondaries.length; i++) {
|
||||
attachSecondaryModal(modal, secondaries[i]);
|
||||
}
|
||||
// for (var i = 0; i < secondaries.length; i++) {
|
||||
// attachSecondaryModal(modal, secondaries[i]);
|
||||
// }
|
||||
}
|
||||
|
||||
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");
|
||||
|
||||
form.ajaxForm({
|
||||
url: url,
|
||||
dataType: 'json',
|
||||
@ -860,7 +875,7 @@ function handleModalForm(url, options) {
|
||||
modalEnable(modal, false);
|
||||
},
|
||||
// POST was successful
|
||||
success: function(response, status, xhr, f) {
|
||||
success: function(response) {
|
||||
// Re-enable the modal
|
||||
modalEnable(modal, true);
|
||||
if ('form_valid' in response) {
|
||||
@ -913,13 +928,13 @@ function handleModalForm(url, options) {
|
||||
afterForm(response, options);
|
||||
}
|
||||
},
|
||||
error: function(xhr, ajaxOptions, thrownError) {
|
||||
error: function(xhr) {
|
||||
// There was an error submitting form data via POST
|
||||
|
||||
$(modal).modal('hide');
|
||||
showAlertDialog('{% trans "Error posting form data" %}', renderErrorMessage(xhr));
|
||||
},
|
||||
complete: function(xhr) {
|
||||
complete: function() {
|
||||
//TODO
|
||||
}
|
||||
});
|
||||
@ -960,7 +975,7 @@ function launchModalForm(url, options = {}) {
|
||||
$(modal).find('#modal-footer-buttons').html('');
|
||||
|
||||
// Form the ajax request to retrieve the django form data
|
||||
ajax_data = {
|
||||
var ajax_data = {
|
||||
url: url,
|
||||
type: 'get',
|
||||
dataType: 'json',
|
||||
@ -1017,7 +1032,7 @@ function launchModalForm(url, options = {}) {
|
||||
showAlertDialog('{% trans "Invalid server response" %}', '{% trans "JSON response missing form data" %}');
|
||||
}
|
||||
},
|
||||
error: function (xhr, ajaxOptions, thrownError) {
|
||||
error: function (xhr) {
|
||||
|
||||
$(modal).modal('hide');
|
||||
|
||||
|
@ -1,18 +1,19 @@
|
||||
{% load i18n %}
|
||||
|
||||
/* globals
|
||||
blankImage,
|
||||
select2Thumbnail
|
||||
*/
|
||||
|
||||
function blankImage() {
|
||||
return `/static/img/blank_image.png`;
|
||||
}
|
||||
|
||||
// Render a select2 thumbnail image
|
||||
function select2Thumbnail(image) {
|
||||
if (!image) {
|
||||
image = blankImage();
|
||||
}
|
||||
|
||||
return `<img src='${image}' class='select2-thumbnail'>`;
|
||||
}
|
||||
/* exported
|
||||
renderBuild,
|
||||
renderCompany,
|
||||
renderManufacturerPart,
|
||||
renderOwner,
|
||||
renderPartCategory,
|
||||
renderStockLocation,
|
||||
renderSupplierPart,
|
||||
*/
|
||||
|
||||
|
||||
/*
|
||||
@ -29,6 +30,7 @@ function select2Thumbnail(image) {
|
||||
|
||||
|
||||
// Renderer for "Company" model
|
||||
// eslint-disable-next-line no-unused-vars
|
||||
function renderCompany(name, data, parameters, options) {
|
||||
|
||||
var html = select2Thumbnail(data.image);
|
||||
@ -42,6 +44,7 @@ function renderCompany(name, data, parameters, options) {
|
||||
|
||||
|
||||
// Renderer for "StockItem" model
|
||||
// eslint-disable-next-line no-unused-vars
|
||||
function renderStockItem(name, data, parameters, options) {
|
||||
|
||||
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
|
||||
// eslint-disable-next-line no-unused-vars
|
||||
function renderStockLocation(name, data, parameters, options) {
|
||||
|
||||
var level = '- '.repeat(data.level);
|
||||
@ -80,7 +84,7 @@ function renderStockLocation(name, data, parameters, options) {
|
||||
return html;
|
||||
}
|
||||
|
||||
|
||||
// eslint-disable-next-line no-unused-vars
|
||||
function renderBuild(name, data, parameters, options) {
|
||||
|
||||
var image = null;
|
||||
@ -101,6 +105,7 @@ function renderBuild(name, data, parameters, options) {
|
||||
|
||||
|
||||
// Renderer for "Part" model
|
||||
// eslint-disable-next-line no-unused-vars
|
||||
function renderPart(name, data, parameters, options) {
|
||||
|
||||
var html = select2Thumbnail(data.image);
|
||||
@ -117,6 +122,7 @@ function renderPart(name, data, parameters, options) {
|
||||
}
|
||||
|
||||
// Renderer for "User" model
|
||||
// eslint-disable-next-line no-unused-vars
|
||||
function renderUser(name, data, parameters, options) {
|
||||
|
||||
var html = `<span>${data.username}</span>`;
|
||||
@ -130,6 +136,7 @@ function renderUser(name, data, parameters, options) {
|
||||
|
||||
|
||||
// Renderer for "Owner" model
|
||||
// eslint-disable-next-line no-unused-vars
|
||||
function renderOwner(name, data, parameters, options) {
|
||||
|
||||
var html = `<span>${data.name}</span>`;
|
||||
@ -150,6 +157,7 @@ function renderOwner(name, data, parameters, options) {
|
||||
|
||||
|
||||
// Renderer for "PartCategory" model
|
||||
// eslint-disable-next-line no-unused-vars
|
||||
function renderPartCategory(name, data, parameters, options) {
|
||||
|
||||
var level = '- '.repeat(data.level);
|
||||
@ -165,7 +173,7 @@ function renderPartCategory(name, data, parameters, options) {
|
||||
return html;
|
||||
}
|
||||
|
||||
|
||||
// eslint-disable-next-line no-unused-vars
|
||||
function renderPartParameterTemplate(name, data, parameters, options) {
|
||||
|
||||
var html = `<span>${data.name} - [${data.units}]</span>`;
|
||||
@ -175,6 +183,7 @@ function renderPartParameterTemplate(name, data, parameters, options) {
|
||||
|
||||
|
||||
// Renderer for "ManufacturerPart" model
|
||||
// eslint-disable-next-line no-unused-vars
|
||||
function renderManufacturerPart(name, data, parameters, options) {
|
||||
|
||||
var manufacturer_image = null;
|
||||
@ -203,6 +212,7 @@ function renderManufacturerPart(name, data, parameters, options) {
|
||||
|
||||
|
||||
// Renderer for "SupplierPart" model
|
||||
// eslint-disable-next-line no-unused-vars
|
||||
function renderSupplierPart(name, data, parameters, options) {
|
||||
|
||||
var supplier_image = null;
|
||||
|
Loading…
Reference in New Issue
Block a user