mirror of
https://github.com/inventree/InvenTree.git
synced 2025-04-29 12:06:44 +00:00
Merge pull request #135 from SchrodingersGat/select-button-enable
Disable buttons that require row selection, until a selection has been made
This commit is contained in:
commit
2191b7f719
@ -9,7 +9,7 @@
|
|||||||
<div id='button-toolbar'>
|
<div id='button-toolbar'>
|
||||||
<button class='btn btn-success' id='add-stock-item'>New Stock Item</button>
|
<button class='btn btn-success' id='add-stock-item'>New Stock Item</button>
|
||||||
<div id='opt-dropdown' class="dropdown" style='float: right;'>
|
<div id='opt-dropdown' class="dropdown" style='float: right;'>
|
||||||
<button class="btn btn-primary dropdown-toggle" type="button" data-toggle="dropdown">Options
|
<button id='stock-options' class="btn btn-primary dropdown-toggle" type="button" data-toggle="dropdown">Options
|
||||||
<span class="caret"></span></button>
|
<span class="caret"></span></button>
|
||||||
<ul class="dropdown-menu">
|
<ul class="dropdown-menu">
|
||||||
<li><a href='#' id='multi-item-take' title='Take items from stock'>Take items</a></li>
|
<li><a href='#' id='multi-item-take' title='Take items from stock'>Take items</a></li>
|
||||||
@ -49,6 +49,9 @@
|
|||||||
params: {
|
params: {
|
||||||
part: {{ part.id }},
|
part: {{ part.id }},
|
||||||
},
|
},
|
||||||
|
buttons: [
|
||||||
|
'#stock-options',
|
||||||
|
],
|
||||||
url: "{% url 'api-stock-list' %}",
|
url: "{% url 'api-stock-list' %}",
|
||||||
});
|
});
|
||||||
|
|
||||||
|
@ -319,8 +319,11 @@ function deleteStockItems(items, options) {
|
|||||||
}
|
}
|
||||||
|
|
||||||
|
|
||||||
function loadStockTable(modal, options) {
|
|
||||||
modal.bootstrapTable({
|
|
||||||
|
function loadStockTable(table, options) {
|
||||||
|
|
||||||
|
table.bootstrapTable({
|
||||||
sortable: true,
|
sortable: true,
|
||||||
search: true,
|
search: true,
|
||||||
method: 'get',
|
method: 'get',
|
||||||
@ -376,4 +379,8 @@ function loadStockTable(modal, options) {
|
|||||||
],
|
],
|
||||||
url: options.url,
|
url: options.url,
|
||||||
});
|
});
|
||||||
|
|
||||||
|
if (options.buttons) {
|
||||||
|
linkButtonsToSelection(table, options.buttons);
|
||||||
|
}
|
||||||
};
|
};
|
@ -60,3 +60,23 @@ function renderEditable(text, options) {
|
|||||||
return html;
|
return html;
|
||||||
}
|
}
|
||||||
|
|
||||||
|
function enableButtons(elements, enabled) {
|
||||||
|
for (let item of elements) {
|
||||||
|
$(item).prop('disabled', !enabled);
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
|
||||||
|
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
|
||||||
|
*/
|
||||||
|
|
||||||
|
// Initially set the enable state of the 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) {
|
||||||
|
enableButtons(buttons, table.bootstrapTable('getSelections').length > 0);
|
||||||
|
});
|
||||||
|
}
|
||||||
|
@ -43,7 +43,7 @@
|
|||||||
<div class='container-fluid' style='float: right;'>
|
<div class='container-fluid' style='float: right;'>
|
||||||
<button class="btn btn-success" id='item-create'>New Stock Item</span></button>
|
<button class="btn btn-success" id='item-create'>New Stock Item</span></button>
|
||||||
<div class="dropdown" style='float: right;'>
|
<div class="dropdown" style='float: right;'>
|
||||||
<button class="btn btn-primary dropdown-toggle" type="button" data-toggle="dropdown">Options
|
<button id='stock-options' class="btn btn-primary dropdown-toggle" type="button" data-toggle="dropdown">Options
|
||||||
<span class="caret"></span></button>
|
<span class="caret"></span></button>
|
||||||
<ul class="dropdown-menu">
|
<ul class="dropdown-menu">
|
||||||
<li><a href="#" id='multi-item-add' title='Add to selected stock items'>Add stock</a></li>
|
<li><a href="#" id='multi-item-add' title='Add to selected stock items'>Add stock</a></li>
|
||||||
@ -158,6 +158,9 @@
|
|||||||
});
|
});
|
||||||
|
|
||||||
loadStockTable($("#stock-table"), {
|
loadStockTable($("#stock-table"), {
|
||||||
|
buttons: [
|
||||||
|
'#stock-options',
|
||||||
|
],
|
||||||
params: {
|
params: {
|
||||||
{% if location %}
|
{% if location %}
|
||||||
location: {{ location.id }},
|
location: {{ location.id }},
|
||||||
|
Loading…
x
Reference in New Issue
Block a user