Consolidated function to adjust stock

- Add / remove / stocktake
- Handle forms and tables properly
This commit is contained in:
Oliver Walters 2019-04-17 23:17:04 +10:00
parent ba1b8d9181
commit 963883acd6
3 changed files with 57 additions and 26 deletions

View File

@ -70,28 +70,24 @@
return false;
});
function _stock(action) {
adjustStock({
action: action,
items: selectedStock(),
success: function() {
$('#stock-table').bootstrapTable('refresh');
}
});
}
$("#multi-item-stocktake").click(function() {
_stock('stocktake');
updateStockItems({
action: 'stocktake'
});
return false;
});
$("#multi-item-take").click(function() {
_stock('remove');
updateStockItems({
action: 'remove',
});
return false;
});
$("#multi-item-give").click(function() {
_stock('add');
updateStockItems({
action: 'add',
});
return false;
})

View File

@ -153,6 +153,19 @@ function updateStock(items, options={}) {
});
}
function selectStockItems(options) {
/* Return list of selections from stock table
* If options.table not provided, assumed to be '#stock-table'
*/
var table_name = options.table || '#stock-table';
// Return list of selected items from the bootstrap table
return $(table_name).bootstrapTable('getSelections');
}
function adjustStock(options) {
if (options.items) {
updateStock(options.items, options);
@ -172,6 +185,32 @@ function adjustStock(options) {
}
}
function updateStockItems(options) {
/* Update one or more stock items selected from a stock-table
* Options available:
* 'action' - Action to perform - 'add' / 'remove' / 'stocktake'
* 'table' - ID of the stock table (default = '#stock-table'
*/
var table = options.table || '#stock-table';
var items = selectStockItems({
table: table,
});
// Pass items through
options.items = items;
options.table = table;
// On success, reload the table
options.success = function() {
$(table).bootstrapTable('refresh');
};
adjustStock(options);
}
function moveStockItems(items, options) {
var modal = options.modal || '#modal-form';

View File

@ -136,28 +136,24 @@
return false;
});
function _stock(action) {
adjustStock({
action: action,
items: selectedStock(),
success: function() {
$('#stock-table').bootstrapTable('refresh');
}
})
}
$('#multi-item-stocktake').click(function() {
_stock('stocktake');
updateStockItems({
action: 'stocktake',
});
return false;
});
$('#multi-item-remove').click(function() {
_stock('remove');
updateStockItems({
action: 'remove',
});
return false;
});
$('#multi-item-add').click(function() {
_stock('add');
updateStockItems({
action: 'add',
});
return false;
});