}
$scope.edit_due_date = function(items) {
+ if (!items.length) return;
+
$modal.open({
templateUrl : './circ/patron/t_edit_due_date_dialog',
controller : [
'$scope','$modalInstance',
function($scope , $modalInstance) {
+
+ // if there is only one circ, default to the due date
+ // of that circ. Otherwise, default to today.
+ var due_date = items.length == 1 ?
+ Date.parse(items[0].due_date()) : new Date();
+
$scope.args = {
num_circs : items.length,
- due_date : new Date()
+ due_date : due_date
}
+
+ // Fire off the due-date updater for each circ.
+ // When all is done, close the dialog
$scope.ok = function(args) {
- // TODO open-ils.circ.circulation.due_date.update (circ_id, date)
- $modalInstance.close();
+ var due = args.due_date.toISOString().replace(/T.*/,'');
+ console.debug("applying due date of " + due);
+
+ var promises = [];
+ angular.forEach(items, function(circ) {
+ promises.push(
+ egCore.net.request(
+ 'open-ils.circ',
+ 'open-ils.circ.circulation.due_date.update',
+ egCore.auth.token(), circ.id(), due
+
+ ).then(function(new_circ) {
+ // update the grid circ with the canonical
+ // date from the modified circulation.
+ circ.due_date(new_circ.due_date());
+ })
+ );
+ });
+
+ $q.all(promises).then(function() {
+ $modalInstance.close();
+ provider.refresh();
+ });
}
$scope.cancel = function($event) {
$modalInstance.dismiss();