]> git.evergreen-ils.org Git - Evergreen.git/blob - Open-ILS/web/js/ui/default/staff/circ/services/holds.js
LP#1646210 Add CN Affixes to Grids WIP
[Evergreen.git] / Open-ILS / web / js / ui / default / staff / circ / services / holds.js
1 /**
2  * Holds, yo
3  */
4
5 angular.module('egCoreMod')
6
7 .factory('egHolds',
8
9        ['$uibModal','$q','egCore','egConfirmDialog','egAlertDialog',
10 function($uibModal , $q , egCore , egConfirmDialog , egAlertDialog) {
11
12     var service = {};
13
14     service.fetch_holds = function(hold_ids) {
15         var deferred = $q.defer();
16
17         // Fetch hold details in batches for better UI responsiveness.
18         var batch_size = 5;
19         var index = 0;
20
21         function one_batch() {
22             var ids = hold_ids.slice(index, index + batch_size)
23                 .filter(function(id) {return Boolean(id)}) // avoid nulls
24
25             console.debug('egHolds.fetch_holds => ' + ids);
26             index += batch_size;
27
28             if (!ids.length) {
29                 deferred.resolve();
30                 return;
31             }
32
33             egCore.net.request(
34                 'open-ils.circ',
35                 'open-ils.circ.hold.details.batch.retrieve.authoritative',
36                 egCore.auth.token(), ids, {
37                     include_current_copy : true,
38                     include_usr          : true,
39                     include_cancel_cause : true,
40                     include_requestor    : true
41                 }
42
43             ).then(
44                 one_batch,  // kick off the next batch
45                 null, 
46                 function(hold_data) {
47                     var hold = hold_data.hold;
48                     hold_data.id = hold.id();
49                     service.local_flesh(hold_data);
50                     deferred.notify(hold_data);
51                 }
52             );
53         }
54
55         one_batch(); // kick it off
56         return deferred.promise;
57     }
58
59
60     service.cancel_holds = function(hold_ids) {
61        
62         return $uibModal.open({
63             templateUrl : './circ/share/t_cancel_hold_dialog',
64             backdrop: 'static',
65             controller : 
66                 ['$scope', '$uibModalInstance', 'cancel_reasons',
67                 function($scope, $uibModalInstance, cancel_reasons) {
68                     $scope.args = {
69                         cancel_reason : 5,
70                         cancel_reasons : cancel_reasons,
71                         num_holds : hold_ids.length
72                     };
73                     
74                     $scope.cancel = function($event) {
75                         $uibModalInstance.dismiss();
76                         $event.preventDefault();
77                     }
78
79                     $scope.ok = function() {
80
81                         function cancel_one() {
82                             var hold_id = hold_ids.pop();
83                             if (!hold_id) {
84                                 $uibModalInstance.close();
85                                 return;
86                             }
87                             egCore.net.request(
88                                 'open-ils.circ', 'open-ils.circ.hold.cancel',
89                                 egCore.auth.token(), hold_id,
90                                 $scope.args.cancel_reason,
91                                 $scope.args.note
92                             ).then(function(resp) {
93                                 if (evt = egCore.evt.parse(resp)) {
94                                     egCore.audio.play(
95                                         'warning.hold.cancel_failed');
96                                     console.error('unable to cancel hold: ' 
97                                         + evt.toString());
98                                 }
99                                 cancel_one();
100                             });
101                         }
102
103                         cancel_one();
104                     }
105                 }
106             ],
107             resolve : {
108                 cancel_reasons : function() {
109                     return service.get_cancel_reasons();
110                 }
111             }
112         }).result;
113     }
114
115     service.uncancel_holds = function(hold_ids) {
116        
117         return $uibModal.open({
118             templateUrl : './circ/share/t_uncancel_hold_dialog',
119             backdrop: 'static',
120             controller : 
121                 ['$scope', '$uibModalInstance',
122                 function($scope, $uibModalInstance) {
123                     $scope.args = {
124                         num_holds : hold_ids.length
125                     };
126                     
127                     $scope.cancel = function($event) {
128                         $uibModalInstance.dismiss();
129                         $event.preventDefault();
130                     }
131
132                     $scope.ok = function() {
133
134                         function uncancel_one() {
135                             var hold_id = hold_ids.pop();
136                             if (!hold_id) {
137                                 $uibModalInstance.close();
138                                 return;
139                             }
140                             egCore.net.request(
141                                 'open-ils.circ', 'open-ils.circ.hold.uncancel',
142                                 egCore.auth.token(), hold_id
143                             ).then(function(resp) {
144                                 if (evt = egCore.evt.parse(resp)) {
145                                     egCore.audio.play(
146                                         'warning.hold.uncancel_failed');
147                                     console.error('unable to uncancel hold: ' 
148                                         + evt.toString());
149                                 }
150                                 uncancel_one();
151                             });
152                         }
153
154                         uncancel_one();
155                     }
156                 }
157             ]
158         }).result;
159     }
160
161     service.get_cancel_reasons = function() {
162         if (egCore.env.ahrcc) return $q.when(egCore.env.ahrcc.list);
163         return egCore.pcrud.retrieveAll('ahrcc', {}, {atomic : true})
164         .then(function(list) { return egCore.env.absorbList(list, 'ahrcc').list });
165     }
166
167     // Updates a batch of holds, notifies on each response.
168     // new_values = array of hashes describing values to change,
169     // including the id of the hold to change.
170     // e.g. {id : 1, mint_condition : true}
171     service.update_holds = function(new_values) {
172         return egCore.net.request(
173             'open-ils.circ',
174             'open-ils.circ.hold.update.batch',
175             egCore.auth.token(), null, new_values).then(
176             function(resp) {
177                 if (evt = egCore.evt.parse(resp)) {
178                     egCore.audio.play(
179                         'warning.hold.batch_update');
180                     console.error('unable to batch update holds: '
181                         + evt.toString());
182                 } else {
183                     egCore.audio.play(
184                         'success.hold.batch_update');
185                 }
186             }
187         );
188     }
189
190     service.set_copy_quality = function(hold_ids) {
191         if (!hold_ids.length) return $q.when();
192         return $uibModal.open({
193             templateUrl : './circ/share/t_hold_copy_quality_dialog',
194             backdrop: 'static',
195             controller : 
196                 ['$scope', '$uibModalInstance',
197                 function($scope, $uibModalInstance) {
198
199                     function update(val) {
200                         var vals = hold_ids.map(function(hold_id) {
201                             return {id : hold_id, mint_condition : val}})
202                         service.update_holds(vals).finally(function() {
203                             $uibModalInstance.close();
204                         });
205                     }
206                     $scope.good = function() { update(true) }
207                     $scope.any = function() { update(false) }
208                     $scope.cancel = function() { $uibModalInstance.dismiss() }
209                 }
210             ]
211         }).result;
212     }
213
214     service.edit_pickup_lib = function(hold_ids) {
215         if (!hold_ids.length) return $q.when();
216         return $uibModal.open({
217             templateUrl : './circ/share/t_hold_edit_pickup_lib',
218             backdrop: 'static',
219             controller : 
220                 ['$scope', '$uibModalInstance',
221                 function($scope, $uibModalInstance) {
222                     $scope.cant_be_pickup = function (id) { return !egCore.org.CanHaveUsers(id); };
223                     $scope.args = {};
224                     $scope.ok = function() { 
225                         var vals = hold_ids.map(function(hold_id) {
226                             return {
227                                 id : hold_id, 
228                                 pickup_lib : $scope.args.org_unit.id()
229                             }
230                         });
231                         service.update_holds(vals).finally(function() {
232                             $uibModalInstance.close();
233                         });
234                     }
235                     $scope.cancel = function() { $uibModalInstance.dismiss() }
236                 }
237             ]
238         }).result;
239     }
240
241     service.get_sms_carriers = function() {
242         if (egCore.env.csc) return $q.when(egCore.env.csc.list);
243         return egCore.pcrud.retrieveAll('csc', {}, {atomic : true})
244         .then(function(list) { return egCore.env.absorbList(list, 'csc').list });
245     }
246
247     service.edit_notify_prefs = function(hold_ids) {
248         if (!hold_ids.length) return $q.when();
249         return $uibModal.open({
250             templateUrl : './circ/share/t_hold_notification_prefs',
251             backdrop: 'static',
252             controller : 
253                 ['$scope', '$uibModalInstance', 'sms_carriers',
254                 function($scope, $uibModalInstance, sms_carriers) {
255                     $scope.args = {}
256                     $scope.sms_carriers = sms_carriers;
257                     $scope.num_holds = hold_ids.length;
258                     $scope.ok = function() { 
259
260                         var vals = hold_ids.map(function(hold_id) {
261                             var val = {id : hold_id};
262                             angular.forEach(
263                                 ['email', 'phone', 'sms'],
264                                 function(type) {
265                                     var key = type + '_notify';
266                                     if ($scope.args['update_' + key]) 
267                                         val[key] = $scope.args[key];
268                                 }
269                             );
270                             if ($scope.args.update_sms_carrier)
271                                 val.sms_carrier = $scope.args.sms_carrier.id();
272                             return val;
273                         });
274
275                         service.update_holds(vals).finally(function() {
276                             $uibModalInstance.close();
277                         });
278                     }
279                     $scope.cancel = function() { $uibModalInstance.dismiss() }
280                 }
281             ],
282             resolve : {
283                 sms_carriers : service.get_sms_carriers
284             }
285         }).result;
286     }
287
288     service.edit_dates = function(hold_ids) {
289         if (!hold_ids.length) return $q.when();
290
291         // collects the fields from the dialog the user wishes to modify
292         function relay_to_update(modal_scope) {
293             var vals = hold_ids.map(function(hold_id) {
294                 var val = {id : hold_id};
295                 angular.forEach(
296                     ['thaw_date', 'request_time', 'expire_time', 'shelf_expire_time'], 
297                     function(field) {
298                         if (modal_scope.args['modify_' + field]) 
299                             val[field] = modal_scope.args[field].toISOString();
300                     }
301                 );
302
303                 return val;
304             });
305
306             console.log(JSON.stringify(vals,null,2));
307             return service.update_holds(vals);
308         }
309
310         return $uibModal.open({
311             templateUrl : './circ/share/t_hold_dates',
312             backdrop: 'static',
313             controller : 
314                 ['$scope', '$uibModalInstance',
315                 function($scope, $uibModalInstance) {
316                     var today = new Date();
317                     $scope.args = {
318                         thaw_date : today,
319                         request_time : today,
320                         expire_time : today,
321                         shelf_expire_time : today
322                     }
323                     $scope.num_holds = hold_ids.length;
324                     $scope.ok = function() { 
325                         relay_to_update($scope).then($uibModalInstance.close);
326                     }
327                     $scope.cancel = function() { $uibModalInstance.dismiss() }
328                 }
329             ],
330         }).result;
331     }
332
333     service.update_field_with_confirm = function(hold_ids, msg_key, field, value) {
334         if (!hold_ids.length) return $q.when();
335
336         return egConfirmDialog.open(
337             egCore.strings[msg_key], '', {num_holds : hold_ids.length})
338         .result.then(function() {
339
340             var vals = hold_ids.map(function(hold_id) {
341                 val = {id : hold_id};
342                 val[field] = value;
343                 return val;
344             });
345             return service.update_holds(vals);
346         });
347     }
348
349     service.suspend_holds = function(hold_ids) {
350         return service.update_field_with_confirm(
351             hold_ids, 'SUSPEND_HOLDS', 'frozen', true);
352     }
353
354     service.activate_holds = function(hold_ids) {
355         return service.update_field_with_confirm(
356             hold_ids, 'ACTIVATE_HOLDS', 'frozen', false);
357     }
358
359     service.set_top_of_queue = function(hold_ids) {
360         return service.update_field_with_confirm(
361             hold_ids, 'SET_TOP_OF_QUEUE', 'cut_in_line', true);
362     }
363
364     service.clear_top_of_queue = function(hold_ids) {
365         return service.update_field_with_confirm(
366             hold_ids, 'CLEAR_TOP_OF_QUEUE', 'cut_in_line', null);
367     }
368
369     service.transfer_to_marked_title = function(hold_ids) {
370         if (!hold_ids.length) return $q.when();
371
372         var bib_id = egCore.hatch.getLocalItem(
373             'eg.circ.hold.title_transfer_target');
374
375         if (!bib_id) {
376             // no target marked
377             return egAlertDialog.open(
378                 egCore.strings.NO_HOLD_TRANSFER_TITLE_MARKED).result;
379         }
380
381         return egConfirmDialog.open(
382             egCore.strings.TRANSFER_HOLD_TO_TITLE, '', {
383                 num_holds : hold_ids.length,
384                 bib_id : bib_id
385             }
386         ).result.then(function() {
387             return egCore.net.request(
388                 'open-ils.circ',
389                 'open-ils.circ.hold.change_title.specific_holds',
390                 egCore.auth.token(), bib_id, hold_ids);
391         });
392     }
393
394     service.transfer_all_bib_holds_to_marked_title = function(bib_ids) {
395         if (!bib_ids.length) return $q.when();
396
397         var target_bib_id = egCore.hatch.getLocalItem(
398             'eg.circ.hold.title_transfer_target');
399
400         if (!target_bib_id) {
401             // no target marked
402             return egAlertDialog.open(
403                 egCore.strings.NO_HOLD_TRANSFER_TITLE_MARKED).result;
404         }
405
406         return egConfirmDialog.open(
407             egCore.strings.TRANSFER_ALL_BIB_HOLDS_TO_TITLE, '', {
408                 num_bibs : bib_ids.length,
409                 bib_id : target_bib_id
410             }
411         ).result.then(function() {
412             return egCore.net.request(
413                 'open-ils.circ',
414                 'open-ils.circ.hold.change_title',
415                 egCore.auth.token(), target_bib_id, bib_ids);
416         });
417     }
418
419     // serially retargets each hold
420     service.retarget = function(hold_ids) {
421         if (!hold_ids.length) return $q.when();
422         var deferred = $q.defer();
423
424         egConfirmDialog.open(
425             egCore.strings.RETARGET_HOLDS, '', 
426             {hold_ids : hold_ids.join(',')}
427
428         ).result.then(function() {
429
430             function do_one() {
431                 var hold_id = hold_ids.pop();
432                 if (!hold_id) {
433                     deferred.resolve();
434                     return;
435                 }
436
437                 egCore.net.request(
438                     'open-ils.circ',
439                     'open-ils.circ.hold.reset',
440                     egCore.auth.token(), hold_id).finally(do_one);
441             }
442
443             do_one(); // kick it off
444         });
445
446         return deferred.promise;
447     }
448
449     // fleshes orgs, etc. for hold data blobs retrieved from
450     // open-ils.circ.hold.details[.batch].retrieve
451     service.local_flesh = function(hold_data) {
452
453         hold_data.status_string = 
454             egCore.strings['HOLD_STATUS_' + hold_data.status] 
455             || hold_data.status;
456
457         var hold = hold_data.hold;
458         var volume = hold_data.volume;
459         hold.pickup_lib(egCore.org.get(hold.pickup_lib()));
460         hold.current_shelf_lib(egCore.org.get(hold.current_shelf_lib()));
461         hold_data.id = hold.id();
462
463         // TODO: LP#1697954 fleshing calls below are deprecated in favor
464         // of API fleshing.
465
466         if (hold.requestor() && typeof hold.requestor() != 'object') {
467             console.debug('fetching hold requestor');
468             egCore.pcrud.retrieve('au',hold.requestor()).then(function(u) { hold.requestor(u) });
469         }
470
471         if (hold.cancel_cause() && typeof hold.cancel_cause() != 'object') {
472             console.debug('fetching hold cancel cause');
473             egCore.pcrud.retrieve('ahrcc',hold.cancel_cause()).then(function(c) { hold.cancel_cause(c) });
474         }
475
476         if (hold.usr() && typeof hold.usr() != 'object') {
477             console.debug('fetching hold user');
478             egCore.pcrud.retrieve('au',hold.usr()).then(function(u) { hold.usr(u) });
479         }
480
481         // current_copy is not always fleshed in the API
482         if (hold.current_copy() && typeof hold.current_copy() != 'object') {
483             hold.current_copy(hold_data.copy);
484             
485             // likewise, current_copy's status isn't fleshed in the API
486             if(hold.current_copy().status() !== null &&
487                typeof hold.current_copy().status() != 'object')
488                 egCore.pcrud.retrieve('ccs',hold.current_copy().status()
489                     ).then(function(c) { hold.current_copy().status(c) });
490         }
491
492         //Call number affixes are not always fleshed in the API
493         if (volume.prefix() && typeof volume.prefix() != 'object') {
494             console.debug('fetching call number prefix');
495             egCore.pcrud.retrieve('acnp',volume.prefix()).then(function(p) {volume.prefix(p)});
496         }
497         if (volume.suffix() && typeof volume.suffix() != 'object') {
498             console.debug('fetching call number prefix');
499             egCore.pcrud.retrieve('acns',volume.suffix()).then(function(s) {volume.suffix(s)});
500         }
501     }
502
503     return service;
504 }])
505
506 /**  
507  * Action handlers for the common Hold grid UI.
508  * These generally scrub the data for valid input then pass the
509  * holds / copies / etc. off to the relevant action in egHolds or egCirc.
510  *
511  * Caller must apply a reset_page function, which is called after 
512  * most actionis are performed.
513  */
514 .factory('egHoldGridActions', 
515        ['$window','$location','$timeout','egCore','egHolds','egCirc',
516 function($window , $location , $timeout , egCore , egHolds , egCirc) {
517     
518     var service = {};
519
520     service.refresh = function() {
521         console.error('egHoldGridActions.refresh not defined!');
522     }
523
524     service.cancel_hold = function(items) {
525         var hold_ids = items.filter(function(item) {
526             return !item.hold.cancel_time();
527         }).map(function(item) {return item.hold.id()});
528
529         return egHolds.cancel_holds(hold_ids).then(service.refresh);
530     }
531
532     service.uncancel_hold = function(items) {
533         var hold_ids = items.filter(function(item) {
534             return item.hold.cancel_time();
535         }).map(function(item) {return item.hold.id()});
536
537         return egHolds.uncancel_holds(hold_ids).then(service.refresh);
538     }
539
540     // jump to circ list for either 1) the targeted copy or
541     // 2) the hold target copy for copy-level holds
542     service.show_recent_circs = function(items) {
543         var focus = items.length == 1;
544         angular.forEach(items, function(item) {
545             if (item.copy) {
546                 var url = egCore.env.basePath +
547                           '/cat/item/' +
548                           item.copy.id() +
549                           '/circ_list';
550                 $timeout(function() { var x = $window.open(url, '_blank'); if (focus) x.focus() });
551             }
552         });
553     }
554
555     service.show_patrons = function(items) {
556         var focus = items.length == 1;
557         angular.forEach(items, function(item) {
558             var url = egCore.env.basePath +
559                       'circ/patron/' +
560                       item.hold.usr().id() +
561                       '/holds';
562             $timeout(function() { var x = $window.open(url, '_blank'); if (focus) x.focus() });
563         });
564     }
565
566     service.show_holds_for_title = function(items) {
567         var focus = items.length == 1;
568         angular.forEach(items, function(item) {
569             var url = egCore.env.basePath +
570                       'cat/catalog/record/' +
571                       item.mvr.doc_id() +
572                       '/holds';
573             $timeout(function() { var x = $window.open(url, '_blank'); if (focus) x.focus() });
574         });
575     }
576
577
578     function generic_update(items, action) {
579         if (!items.length) return $q.when();
580         var hold_ids = items.map(function(item) {return item.hold.id()});
581         return egHolds[action](hold_ids).then(service.refresh);
582     }
583
584     service.set_copy_quality = function(items) {
585         generic_update(items, 'set_copy_quality'); }
586     service.edit_pickup_lib = function(items) {
587         generic_update(items, 'edit_pickup_lib'); }
588     service.edit_notify_prefs = function(items) {
589         generic_update(items, 'edit_notify_prefs'); }
590     service.edit_dates = function(items) {
591         generic_update(items, 'edit_dates'); }
592     service.suspend = function(items) {
593         generic_update(items, 'suspend_holds'); }
594     service.activate = function(items) {
595         generic_update(items, 'activate_holds'); }
596     service.set_top_of_queue = function(items) {
597         generic_update(items, 'set_top_of_queue'); }
598     service.clear_top_of_queue = function(items) {
599         generic_update(items, 'clear_top_of_queue'); }
600     service.transfer_to_marked_title = function(items) {
601         generic_update(items, 'transfer_to_marked_title'); }
602
603     service.mark_damaged = function(items) {
604         angular.forEach(items, function(item) {
605             if (item.copy) {
606                 egCirc.mark_damaged({
607                     id: item.copy.id(),
608                     barcode: item.copy.barcode()
609                 }).then(service.refresh);
610             }
611         });
612     }
613
614     service.mark_missing = function(items) {
615         var copy_ids = items
616             .filter(function(item) { return Boolean(item.copy) })
617             .map(function(item) { return item.copy.id() });
618         if (copy_ids.length) 
619             egCirc.mark_missing(copy_ids).then(service.refresh);
620     }
621
622     service.retarget = function(items) {
623         var hold_ids = items.map(function(item) { return item.hold.id() });
624         egHolds.retarget(hold_ids).then(service.refresh);
625     }
626
627     return service;
628 }])
629
630 /**
631  * Hold details interface 
632  */
633 .directive('egHoldDetails', function() {
634     return {
635         restrict : 'AE',
636         templateUrl : './circ/share/t_hold_details',
637         scope : {
638             holdId : '=',
639             // if set, called whenever hold details are retrieved.  The
640             // argument is the hold blob returned from hold.details.retrieve
641             holdRetrieved : '=',
642             showPatron : '='
643         },
644         controller : [
645                     '$scope','$uibModal','egCore','egHolds','egCirc',
646             function($scope , $uibModal , egCore , egHolds , egCirc) {
647
648                 function draw() {
649                     if (!$scope.holdId) return;
650
651                     egCore.net.request(
652                         'open-ils.circ',
653                         'open-ils.circ.hold.details.retrieve.authoritative',
654                         egCore.auth.token(), $scope.holdId, {
655                             include_current_copy : true,
656                             include_usr          : true,
657                             include_cancel_cause : true,
658                             include_requestor    : true
659                         }
660                     ).then(function(hold_data) { 
661                         egHolds.local_flesh(hold_data);
662     
663                         angular.forEach(hold_data, 
664                             function(val, key) { $scope[key] = val });
665
666                         // fetch + flesh the cancel_cause if needed
667                         if ($scope.hold.cancel_time()) {
668                             egHolds.get_cancel_reasons().then(function() {
669                                 // egHolds caches the causes in egEnv
670                                 $scope.hold.cancel_cause(
671                                     egCore.env.ahrcc.map[$scope.hold.cancel_cause()]);
672                             })
673                         }
674
675                         if ($scope.hold.current_copy()) {
676                             egCirc.flesh_copy_location($scope.hold.current_copy());
677                         }
678
679                         if ($scope.holdRetrieved)
680                             $scope.holdRetrieved(hold_data);
681
682                     });
683                 }
684
685                 $scope.show_notify_tab = function() {
686                     $scope.detail_tab = 'notify';
687                     egCore.pcrud.search('ahn',
688                         {hold : $scope.hold.id()}, 
689                         {flesh : 1, flesh_fields : {ahn : ['notify_staff']}}, 
690                         {atomic : true}
691                     ).then(function(nots) {
692                         $scope.hold.notifications(nots);
693                     });
694                 }
695
696                 $scope.delete_note = function(note) {
697                     egCore.pcrud.remove(note).then(function() {
698                         // remove the deleted note from the locally fleshed notes
699                         $scope.hold.notes(
700                             $scope.hold.notes().filter(function(n) {
701                                 return n.id() != note.id()
702                             })
703                         );
704                     });
705                 }
706
707                 $scope.new_note = function() {
708                     return $uibModal.open({
709                         templateUrl : './circ/share/t_hold_note_dialog',
710                         backdrop: 'static',
711                         controller : 
712                             ['$scope', '$uibModalInstance',
713                             function($scope, $uibModalInstance) {
714                                 $scope.args = {};
715                                 $scope.ok = function() {
716                                     $uibModalInstance.close($scope.args)
717                                 },
718                                 $scope.cancel = function($event) {
719                                     $uibModalInstance.dismiss();
720                                     $event.preventDefault();
721                                 }
722                             }
723                         ]
724                     }).result.then(function(args) {
725                         var note = new egCore.idl.ahrn();
726                         note.hold($scope.hold.id());
727                         note.staff(true);
728                         note.slip(args.slip);
729                         note.pub(args.pub); 
730                         note.title(args.title);
731                         note.body(args.body);
732                         return egCore.pcrud.create(note).then(function(n) {
733                             $scope.hold.notes().push(n);
734                         });
735                     });
736                 }
737
738                 $scope.new_notification = function() {
739                     return $uibModal.open({
740                         templateUrl : './circ/share/t_hold_notification_dialog',
741                         backdrop: 'static',
742                         controller : 
743                             ['$scope', '$uibModalInstance',
744                             function($scope, $uibModalInstance) {
745                                 $scope.args = {};
746                                 $scope.ok = function() {
747                                     $uibModalInstance.close($scope.args)
748                                 },
749                                 $scope.cancel = function($event) {
750                                     $uibModalInstance.dismiss();
751                                     $event.preventDefault();
752                                 }
753                             }
754                         ]
755                     }).result.then(function(args) {
756                         var note = new egCore.idl.ahn();
757                         note.hold($scope.hold.id());
758                         note.method(args.method);
759                         note.note(args.note);
760                         note.notify_staff(egCore.auth.user().id());
761                         note.notify_time('now');
762                         return egCore.pcrud.create(note).then(function(n) {
763                             n.notify_staff(egCore.auth.user());
764                             $scope.hold.notifications().push(n);
765                         });
766                     });
767                 }
768
769                 $scope.$watch('holdId', function(newVal, oldVal) {
770                     if (newVal != oldVal) draw();
771                 });
772
773                 draw();
774             }
775         ]
776     }
777 })
778
779