Skip to content

Commit

Permalink
Binder 176 (#177)
Browse files Browse the repository at this point in the history
* button to dearchive

* fix typo

* Revert "button to dearchive"

This reverts commit f3218e7.

* enable binder dearchive
  • Loading branch information
dongliu authored Apr 9, 2024
1 parent f30cff1 commit ad2366f
Show file tree
Hide file tree
Showing 4 changed files with 40 additions and 4 deletions.
12 changes: 12 additions & 0 deletions public/javascripts/binders.js
Original file line number Diff line number Diff line change
Expand Up @@ -333,6 +333,18 @@ $(function() {
Modal.archive('binder', 3, activeTable, archivedBinderTable);
});

$('button#dearchive').click(function() {
const activeTable = $('.tab-pane.active table').dataTable();
// dearchived binder always starts from a new status
Modal.dearchive(
'binder',
0,
activeTable,
binderTable,
transferredBinderTable
);
});

$('#add-to-binder').click(function() {
var activeTable = $('.tab-pane.active table').dataTable();
AddBinder.addModal(activeTable, 'binder');
Expand Down
28 changes: 26 additions & 2 deletions public/javascripts/lib/modal.js
Original file line number Diff line number Diff line change
Expand Up @@ -60,7 +60,7 @@ export function updateStatusFromModal(type, status, ...tables) {
});
}

export function archive(type, status, fromTable, updateTable) {
export function archive(type, status, fromTable, ...updateTables) {
const selected = fnGetSelected(fromTable, 'row-selected');
modalScroll(false);
if (selected.length === 0) {
Expand All @@ -79,7 +79,31 @@ export function archive(type, status, fromTable, updateTable) {
);
$('#modal').modal('show');
$('#submit').click(function() {
updateStatusFromModal(type, status, fromTable, updateTable);
updateStatusFromModal(type, status, fromTable, ...updateTables);
});
}
}

export function dearchive(type, status, fromTable, ...updateTables) {
const selected = fnGetSelected(fromTable, 'row-selected');
modalScroll(false);
if (selected.length === 0) {
noneSelectedModal();
} else {
$('#modalLabel').html(
`De-archive the following ${selected.length} ${type}(s)? `
);
$('#modal .modal-body').empty();
selected.forEach(function(row) {
const data = fromTable.fnGetData(row);
$('#modal .modal-body').append(formatItemUpdate(data));
});
$('#modal .modal-footer').html(
'<button id="submit" class="btn btn-primary">Confirm</button><button id="return" data-dismiss="modal" aria-hidden="true" class="btn">Return</button>'
);
$('#modal').modal('show');
$('#submit').click(function() {
updateStatusFromModal(type, status, fromTable, ...updateTables);
});
}
}
2 changes: 1 addition & 1 deletion routes/binder.js
Original file line number Diff line number Diff line change
Expand Up @@ -565,7 +565,7 @@ module.exports = function(app) {
const p = req[req.params.id];
const s = req.body.status;

if ([1, 2, 3].indexOf(s) === -1) {
if ([0, 1, 2, 3].indexOf(s) === -1) {
return res.status(400).send('invalid status');
}

Expand Down
2 changes: 1 addition & 1 deletion routes/traveler.js
Original file line number Diff line number Diff line change
Expand Up @@ -1030,7 +1030,7 @@ module.exports = function(app) {
.send('You are not authorized to change the status. ');
}

// admin and manager can request more work or archive a complted traveler
// admin and manager can request more work or archive a completed traveler
if (
doc.status === 2 &&
(req.body.status === 4 || req.body.status === 1) &&
Expand Down

0 comments on commit ad2366f

Please sign in to comment.