1 angular.module('egItemMissingPieces',
2 ['ngRoute', 'ui.bootstrap', 'egCoreMod','egUiMod'])
4 .controller('MissingPiecesCtrl',
5 ['$scope','$q','$window','$location','egCore','egConfirmDialog','egAlertDialog','egCirc',
6 function($scope , $q , $window , $location , egCore , egConfirmDialog , egAlertDialog , egCirc) {
8 $scope.selectMe = true; // focus text input
11 function get_copy(barcode) {
13 return egCore.net.request(
15 'open-ils.actor.get_barcodes',
16 egCore.auth.token(), egCore.auth.user().ws_ou(),
19 .then(function(resp) { // get_barcodes
21 if (evt = egCore.evt.parse(resp)) {
22 console.error(evt.toString());
26 if (!resp || !resp[0]) {
27 $scope.bcNotFound = barcode;
28 $scope.selectMe = true;
32 return egCore.pcrud.search('acp', {id : resp[0].id}, {
35 acp : ['call_number'],
37 bre : ['simple_record']
40 // avoid fleshing MARC on the bre
41 // note: don't add simple_record.. not sure why
48 function mark_missing_pieces(copy) {
51 egCore.strings.CONFIRM_MARK_MISSING_TITLE,
52 egCore.strings.CONFIRM_MARK_MISSING_BODY, {
53 barcode : copy.barcode(),
54 title : copy.call_number().record().simple_record().title()
56 }).result.then(function() {
58 // kick off mark missing
59 return egCore.net.request(
61 'open-ils.circ.mark_item_missing_pieces',
62 egCore.auth.token(), copy.id()
65 }).then(function(resp) {
66 var evt = egCore.evt.parse(resp); // should always produce event
68 if (evt.textcode == 'ACTION_CIRCULATION_NOT_FOUND') {
69 return egAlertDialog.open(
70 egCore.strings.CIRC_NOT_FOUND, {barcode : copy.barcode()});
73 var payload = evt.payload;
75 // TODO: open copy editor inline? new tab?
77 // print the missing pieces slip
78 var promise = $q.when();
80 // wait for completion, since it may spawn a confirm dialog
81 promise = egCore.print.print({
83 content_type : 'text/html',
84 content : payload.slip.template_output().data()
89 $scope.letter = payload.letter.template_output().data();
92 // apply patron penalty
94 promise.then(function() {
95 egCirc.create_penalty(payload.circ.usr())
102 $scope.print_letter = function() {
105 content_type : 'text/plain',
106 content : $scope.letter
110 // find the item by barcode, then proceed w/ missing pieces
111 $scope.submitBarcode = function(args) {
113 $scope.bcNotFound = null;
114 if (!args.barcode) return;
116 $scope.selectMe = false;
117 $scope.letter = null;
119 get_copy(args.barcode).then(mark_missing_pieces);