Refactor some code

This commit is contained in:
Oliver Walters 2019-05-16 22:19:49 +10:00
parent 0a1887477c
commit 117fd701cd
3 changed files with 37 additions and 79 deletions

View File

@ -44,43 +44,4 @@
url: "{% url 'api-stock-list' %}",
});
function selectedStock() {
return $("#stock-table").bootstrapTable('getSelections');
}
$("#multi-item-move").click(function() {
var items = selectedStock();
moveStockItems(items,
{
success: function() {
$("#stock-table").bootstrapTable('refresh');
}
});
return false;
});
$("#multi-item-stocktake").click(function() {
updateStockItems({
action: 'stocktake'
});
return false;
});
$("#multi-item-remove").click(function() {
updateStockItems({
action: 'remove',
});
return false;
});
$("#multi-item-add").click(function() {
updateStockItems({
action: 'add',
});
return false;
})
{% endblock %}

View File

@ -434,6 +434,42 @@ function loadStockTable(table, options) {
if (options.buttons) {
linkButtonsToSelection(table, options.buttons);
}
// Automatically link button callbacks
$('#multi-item-stocktake').click(function() {
updateStockItems({
action: 'stocktake',
});
return false;
});
$('#multi-item-remove').click(function() {
updateStockItems({
action: 'remove',
});
return false;
});
$('#multi-item-add').click(function() {
updateStockItems({
action: 'add',
});
return false;
});
$("#multi-item-move").click(function() {
var items = $("#stock-table").bootstrapTable('getSelections');
moveStockItems(items,
{
success: function() {
$("#stock-table").bootstrapTable('refresh');
}
});
return false;
});
}

View File

@ -133,45 +133,6 @@
return false;
});
function selectedStock() {
return $("#stock-table").bootstrapTable('getSelections');
}
$("#multi-item-move").click(function() {
var items = selectedStock();
moveStockItems(items,
{
success: function() {
$("#stock-table").bootstrapTable('refresh');
}
});
return false;
});
$('#multi-item-stocktake').click(function() {
updateStockItems({
action: 'stocktake',
});
return false;
});
$('#multi-item-remove').click(function() {
updateStockItems({
action: 'remove',
});
return false;
});
$('#multi-item-add').click(function() {
updateStockItems({
action: 'add',
});
return false;
});
loadStockTable($("#stock-table"), {
buttons: [
'#stock-options',