]> git.evergreen-ils.org Git - working/Evergreen.git/blob - Open-ILS/web/js/ui/default/staff/cat/volcopy/app.js
webstaff: Add support for the fast-add copy status org setting
[working/Evergreen.git] / Open-ILS / web / js / ui / default / staff / cat / volcopy / app.js
1 /**
2  * Vol/Copy Editor
3  */
4
5 angular.module('egVolCopy',
6     ['ngRoute', 'ui.bootstrap', 'egCoreMod', 'egUiMod', 'egGridMod'])
7
8 .filter('boolText', function(){
9     return function (v) {
10         return v == 't';
11     }
12 })
13
14 .config(function($routeProvider, $locationProvider, $compileProvider) {
15     $locationProvider.html5Mode(true);
16     $compileProvider.aHrefSanitizationWhitelist(/^\s*(https?|blob):/); // grid export
17
18     var resolver = {
19         delay : ['egStartup', function(egStartup) { return egStartup.go(); }]
20     };
21
22     $routeProvider.when('/cat/volcopy/:dataKey', {
23         templateUrl: './cat/volcopy/t_view',
24         controller: 'EditCtrl',
25         resolve : resolver
26     });
27
28 })
29
30 .factory('itemSvc', 
31        ['egCore','$q',
32 function(egCore , $q) {
33
34     var service = {
35         new_cp_id : 0,
36         new_cn_id : 0,
37         tree : {}, // holds lib->cn->copy hash stack
38         copies : [] // raw copy list
39     };
40
41     // returns a promise resolved with the list of circ mods
42     service.get_classifications = function() {
43         if (egCore.env.acnc)
44             return $q.when(egCore.env.acnc.list);
45
46         return egCore.pcrud.retrieveAll('acnc', null, {atomic : true})
47         .then(function(list) {
48             egCore.env.absorbList(list, 'acnc');
49             return list;
50         });
51     };
52
53     service.get_prefixes = function(org) {
54         return egCore.pcrud.search('acnp',
55             {owning_lib : egCore.org.fullPath(org, true)},
56             null, {atomic : true}
57         );
58
59     };
60
61     service.get_statcats = function(orgs) {
62         return egCore.pcrud.search('asc',
63             {owner : orgs},
64             { flesh : 1,
65               flesh_fields : {
66                 asc : ['owner','entries']
67               }
68             },
69             { atomic : true }
70         );
71     };
72
73     service.get_locations = function(orgs) {
74         return egCore.pcrud.search('acpl',
75             {owning_lib : orgs},
76             null, {atomic : true}
77         );
78     };
79
80     service.get_suffixes = function(org) {
81         return egCore.pcrud.search('acns',
82             {owning_lib : egCore.org.fullPath(org, true)},
83             null, {atomic : true}
84         );
85
86     };
87
88     service.get_statuses = function() {
89         if (egCore.env.ccs)
90             return $q.when(egCore.env.ccs.list);
91
92         return egCore.pcrud.retrieveAll('ccs', {}, {atomic : true}).then(
93             function(list) {
94                 egCore.env.absorbList(list, 'ccs');
95                 return list;
96             }
97         );
98
99     };
100
101     service.get_circ_mods = function() {
102         if (egCore.env.ccm)
103             return $q.when(egCore.env.ccm.list);
104
105         return egCore.pcrud.retrieveAll('ccm', {}, {atomic : true}).then(
106             function(list) {
107                 egCore.env.absorbList(list, 'ccm');
108                 return list;
109             }
110         );
111
112     };
113
114     service.get_circ_types = function() {
115         if (egCore.env.citm)
116             return $q.when(egCore.env.citm.list);
117
118         return egCore.pcrud.retrieveAll('citm', {}, {atomic : true}).then(
119             function(list) {
120                 egCore.env.absorbList(list, 'citm');
121                 return list;
122             }
123         );
124
125     };
126
127     service.get_age_protects = function() {
128         if (egCore.env.crahp)
129             return $q.when(egCore.env.crahp.list);
130
131         return egCore.pcrud.retrieveAll('crahp', {}, {atomic : true}).then(
132             function(list) {
133                 egCore.env.absorbList(list, 'crahp');
134                 return list;
135             }
136         );
137
138     };
139
140     service.bmp_parts = {};
141     service.get_parts = function(rec) {
142         if (service.bmp_parts[rec])
143             return $q.when(service.bmp_parts[rec]);
144
145         return egCore.pcrud.search('bmp',
146             {record : rec},
147             null, {atomic : true}
148         ).then(function(list) {
149             service.bmp_parts[rec] = list;
150             return list;
151         });
152
153     };
154
155     service.flesh = {   
156         flesh : 3, 
157         flesh_fields : {
158             acp : ['call_number','parts','stat_cat_entries', 'notes'],
159             acn : ['label_class','prefix','suffix']
160         }
161     }
162
163     service.addCopy = function (cp) {
164
165         if (!cp.parts()) cp.parts([]); // just in case...
166
167         var lib = cp.call_number().owning_lib();
168         var cn = cp.call_number().id();
169
170         if (!service.tree[lib]) service.tree[lib] = {};
171         if (!service.tree[lib][cn]) service.tree[lib][cn] = [];
172
173         service.tree[lib][cn].push(cp);
174         service.copies.push(cp);
175     }
176
177     service.fetchIds = function(idList) {
178         service.tree = {}; // clear the tree on fetch
179         service.copies = []; // clear the copy list on fetch
180         return egCore.pcrud.search('acp', { 'id' : idList }, service.flesh).then(null,null,
181             function(copy) {
182                 service.addCopy(copy);
183             }
184         );
185     }
186
187     return service;
188 }])
189
190 .directive("egVolCopyEdit", function () {
191     return {
192         restrict: 'E',
193         replace: true,
194         template:
195             '<div class="row">'+
196                 '<div class="col-xs-5">'+
197                     '<input id="{{callNumber.id()}}_{{copy.id()}}"'+
198                     ' eg-enter="nextBarcode(copy.id())" class="form-control"'+
199                     ' type="text" ng-model="barcode" ng-change="updateBarcode()"/>'+
200                 '</div>'+
201                 '<div class="col-xs-3"><input class="form-control" type="number" ng-model="copy_number" ng-change="updateCopyNo()"/></div>'+
202                 '<div class="col-xs-4"><eg-basic-combo-box list="parts" selected="part"></eg-basic-combo-box></div>'+
203             '</div>',
204
205         scope: { focusNext: "=", copy: "=", callNumber: "=", index: "@" },
206         controller : ['$scope','itemSvc','egCore',
207             function ( $scope , itemSvc , egCore ) {
208                 $scope.new_part_id = 0;
209
210                 $scope.nextBarcode = function (i) {
211                     $scope.focusNext(i);
212                 }
213
214                 $scope.updateBarcode = function () { $scope.copy.barcode($scope.barcode); $scope.copy.ischanged(1); };
215                 $scope.updateCopyNo = function () { $scope.copy.copy_number($scope.copy_number); $scope.copy.ischanged(1); };
216                 $scope.updatePart = function () {
217                     if ($scope.part) {
218                         var p = $scope.part_list.filter(function (x) {
219                             return x.label() == $scope.part
220                         });
221                         if (p.length > 0) { // preexisting part
222                             $scope.copy.parts(p)
223                         } else { // create one...
224                             var part = new egCore.idl.bmp();
225                             part.id( --$scope.new_part_id );
226                             part.isnew( true );
227                             part.label( $scope.part );
228                             part.record( $scope.callNumber.owning_lib() );
229                             $scope.copy.parts([part]);
230                             $scope.copy.ischanged(1);
231                         }
232                     } else {
233                         $scope.copy.parts([]);
234                     }
235                 }
236                 $scope.$watch('part', $scope.updatePart);
237
238                 $scope.barcode = $scope.copy.barcode();
239                 $scope.copy_number = $scope.copy.copy_number();
240
241                 if ($scope.copy.parts()) {
242                     $scope.part = $scope.copy.parts()[0];
243                     if ($scope.part) $scope.part = $scope.part.label();
244                 };
245
246                 $scope.parts = [];
247                 $scope.part_list = [];
248
249                 itemSvc.get_parts($scope.callNumber.record()).then(function(list){
250                     $scope.part_list = list;
251                     angular.forEach(list, function(p){ $scope.parts.push(p.label()) });
252                     $scope.parts = angular.copy($scope.parts);
253                 });
254
255             }
256         ]
257
258     }
259 })
260
261 .directive("egVolRow", function () {
262     return {
263         restrict: 'E',
264         replace: true,
265         transclude: true,
266         template:
267             '<div class="row">'+
268                 '<div class="col-xs-2">'+
269                     '<select class="form-control" ng-model="classification" ng-options="cl.name() for cl in classification_list track by idTracker(cl)"/>'+
270                 '</div>'+
271                 '<div class="col-xs-1">'+
272                     '<select class="form-control" ng-model="prefix" ng-change="updatePrefix()" ng-options="p.label() for p in prefix_list track by idTracker(p)"/>'+
273                 '</div>'+
274                 '<div class="col-xs-2"><input class="form-control" type="text" ng-change="updateLabel()" ng-model="label"/></div>'+
275                 '<div class="col-xs-1">'+
276                     '<select class="form-control" ng-model="suffix" ng-change="updateSuffix()" ng-options="s.label() for s in suffix_list track by idTracker(s)"/>'+
277                 '</div>'+
278                 '<div class="col-xs-1"><input class="form-control" type="number" ng-model="copy_count" min="{{orig_copy_count}}" ng-change="changeCPCount()"></div>'+
279                 '<div class="col-xs-5">'+
280                     '<eg-vol-copy-edit ng-repeat="cp in copies track by idTracker(cp)" focus-next="focusNextBarcode" copy="cp" call-number="callNumber"></eg-vol-copy-edit>'+
281                 '</div>'+
282             '</div>',
283
284         scope: {focusNext: "=", allcopies: "=", copies: "=" },
285         controller : ['$scope','itemSvc','egCore',
286             function ( $scope , itemSvc , egCore ) {
287                 $scope.callNumber =  $scope.copies[0].call_number();
288
289                 $scope.idTracker = function (x) { if (x && x.id) return x.id() };
290
291                 // XXX $() is not working! arg
292                 $scope.focusNextBarcode = function (i) {
293                     var n;
294                     var yep = false;
295                     angular.forEach($scope.copies, function (cp) {
296                         if (n) return;
297
298                         if (cp.id() == i) {
299                             yep = true;
300                             return;
301                         }
302
303                         if (yep) n = cp.id();
304                     });
305
306                     if (n) {
307                         var next = '#' + $scope.callNumber.id() + '_' + n;
308                         var el = $(next);
309                         if (el) el.focus()
310                     } else {
311                         $scope.focusNext($scope.callNumber.id())
312                     }
313                 }
314
315                 $scope.suffix_list = [];
316                 itemSvc.get_suffixes($scope.callNumber.owning_lib()).then(function(list){
317                     $scope.suffix_list = list;
318                     $scope.$watch('callNumber.suffix()', function (v) {
319                         $scope.suffix = $scope.suffix_list.filter( function (s) {
320                             return s.id() == v;
321                         })[0];
322                     });
323
324                 });
325                 $scope.updateSuffix = function () {
326                     angular.forEach($scope.copies, function(cp) {
327                         cp.call_number().suffix($scope.suffix.id());
328                         cp.call_number().ischanged(1);
329                     });
330                 }
331
332                 $scope.prefix_list = [];
333                 itemSvc.get_prefixes($scope.callNumber.owning_lib()).then(function(list){
334                     $scope.prefix_list = list;
335                     $scope.$watch('callNumber.prefix()', function (v) {
336                         $scope.prefix = $scope.prefix_list.filter(function (p) {
337                             return p.id() == v;
338                         })[0];
339                     });
340
341                 });
342                 $scope.updatePrefix = function () {
343                     angular.forEach($scope.copies, function(cp) {
344                         cp.call_number().prefix($scope.prefix.id());
345                         cp.call_number().ischanged(1);
346                     });
347                 }
348
349                 $scope.classification_list = [];
350                 itemSvc.get_classifications().then(function(list){
351                     $scope.classification_list = list;
352                     $scope.$watch('callNumber.label_class()', function (v) {
353                         $scope.classification = $scope.classification_list.filter(function (c) {
354                             return c.id() == v;
355                         })[0];
356                     });
357
358                 });
359                 $scope.updateClassification = function () {
360                     angular.forEach($scope.copies, function(cp) {
361                         cp.call_number().label_class($scope.classification.id());
362                         cp.call_number().ischanged(1);
363                     });
364                 }
365
366                 $scope.updateLabel = function () {
367                     angular.forEach($scope.copies, function(cp) {
368                         cp.call_number().label($scope.label);
369                         cp.call_number().ischanged(1);
370                     });
371                 }
372
373                 $scope.$watch('callNumber.label()', function (v) {
374                     $scope.label = v;
375                 });
376
377                 $scope.prefix = $scope.callNumber.prefix();
378                 $scope.suffix = $scope.callNumber.suffix();
379                 $scope.classification = $scope.callNumber.label_class();
380                 $scope.label = $scope.callNumber.label();
381
382                 $scope.copy_count = $scope.copies.length;
383                 $scope.orig_copy_count = $scope.copy_count;
384
385                 $scope.changeCPCount = function () {
386                     while ($scope.copy_count > $scope.copies.length) {
387                         var cp = new egCore.idl.acp();
388                         cp.id( --itemSvc.new_cp_id );
389                         cp.isnew( true );
390                         cp.circ_lib( $scope.lib );
391                         cp.call_number( $scope.callNumber );
392                         $scope.copies.push( cp );
393                         $scope.allcopies.push( cp );
394                     }
395
396                     if ($scope.copy_count >= $scope.orig_copy_count) {
397                         var how_many = $scope.copies.length - $scope.copy_count;
398                         if (how_many > 0) {
399                             var dead = $scope.copies.splice($scope.copy_count,how_many);
400                             $scope.callNumber.copies($scope.copies);
401
402                             // Trimming the global list is a bit more tricky
403                             angular.forEach( dead, function (d) {
404                                 angular.forEach( $scope.allcopies, function (l, i) { 
405                                     if (l === d) $scope.allcopies.splice(i,1);
406                                 });
407                             });
408                         }
409                     }
410                 }
411
412             }
413         ]
414
415     }
416 })
417
418 .directive("egVolEdit", function () {
419     return {
420         restrict: 'E',
421         replace: true,
422         template:
423             '<div class="row">'+
424                 '<div class="col-xs-1"><eg-org-selector selected="owning_lib" disableTest="cant_have_vols"></eg-org-selector></div>'+
425                 '<div class="col-xs-1"><input class="form-control" type="number" min="{{orig_cn_count}}" ng-model="cn_count" ng-change="changeCNCount()"/></div>'+
426                 '<div class="col-xs-10">'+
427                     '<eg-vol-row ng-repeat="(cn,copies) in struct | orderBy:cn track by cn" focus-next="focusNextFirst" copies="copies" allcopies="allcopies"></eg-vol-row>'+
428                 '</div>'+
429             '</div>',
430
431         scope: { focusNext: "=", allcopies: "=", struct: "=", lib: "@", record: "@" },
432         controller : ['$scope','itemSvc','egCore',
433             function ( $scope , itemSvc , egCore ) {
434                 $scope.first_cn = Object.keys($scope.struct)[0];
435                 $scope.full_cn = $scope.struct[$scope.first_cn][0].call_number();
436
437                 $scope.defaults = {};
438                 egCore.hatch.getItem('cat.copy.defaults').then(function(t) {
439                     if (t) {
440                         $scope.defaults = t;
441                     }
442                 });
443
444                 $scope.focusNextFirst = function(prev_cn) {
445                     var n;
446                     var yep = false;
447                     angular.forEach(Object.keys($scope.struct).sort(), function (cn) {
448                         console.log('checking '+cn);
449                         if (n) return;
450
451                         if (cn == prev_cn) {
452                             console.log('prev is '+cn);
453                             yep = true;
454                             return;
455                         }
456                         console.log('prev is not '+cn);
457
458                         if (yep) n = cn;
459                     });
460
461                     console.log('found '+n);
462                     if (n) {
463                         var next = '#' + n + '_' + $scope.struct[n][0].id();
464                         var el = $(next);
465                         if (el) el.focus()
466                     } else {
467                         $scope.focusNext($scope.lib);
468                     }
469                 }
470
471                 $scope.cn_count = Object.keys($scope.struct).length;
472                 $scope.orig_cn_count = $scope.cn_count;
473
474                 $scope.owning_lib = egCore.org.get($scope.lib);
475                 $scope.$watch('owning_lib', function (l) {
476                     angular.forEach( $scope.struct[$scope.first_cn], function (cp) {
477                         cp.call_number().owning_lib( $scope.owning_lib.id() );
478                     });
479                 });
480
481                 $scope.cant_have_vols = function (id) { return !egCore.org.CanHaveVolumes(id); };
482
483                 $scope.$watch('cn_count', function (n) {
484                     var o = Object.keys($scope.struct).length;
485                     if (n > o) { // adding
486                         for (var i = o; o < n; o++) {
487                             var cn = new egCore.idl.acn();
488                             cn.id( --itemSvc.new_cn_id );
489                             cn.isnew( true );
490                             cn.prefix( $scope.defaults.prefix || -1 );
491                             cn.suffix( $scope.defaults.suffix || -1 );
492                             cn.label_class( $scope.defaults.classification || 1 );
493                             cn.owning_lib( $scope.owning_lib.id() );
494                             cn.record( $scope.full_cn.record() );
495
496                             var cp = new egCore.idl.acp();
497                             cp.id( --itemSvc.new_cp_id );
498                             cp.isnew( true );
499                             cp.circ_lib( $scope.owning_lib.id() );
500                             cp.call_number( cn );
501
502                             $scope.struct[cn.id()] = [cp];
503                             $scope.allcopies.push(cp);
504                         }
505                     } else if (n < o && n >= $scope.orig_cn_count) { // removing
506                         var how_many = o - n;
507                         var list = Object
508                                 .keys($scope.struct)
509                                 .sort(function(a, b){return parseInt(a)-parseInt(b)})
510                                 .filter(function(x){ return parseInt(x) <= 0 });
511                         for (var i = 0; i < how_many; i++) {
512                             // Trimming the global list is a bit more tricky
513                             console.log('trying to trim ' + i);
514                             angular.forEach($scope.struct[list[i]], function (d) {
515                                 angular.forEach( $scope.allcopies, function (l, j) { 
516                                     if (l === d) $scope.allcopies.splice(j,1);
517                                 });
518                             });
519                             delete $scope.struct[list[i]];
520                         }
521                     }
522                 });
523             }
524         ]
525
526     }
527 })
528
529 /**
530  * Edit controller!
531  */
532 .controller('EditCtrl', 
533        ['$scope','$q','$window','$routeParams','$location','$timeout','egCore','egNet','egGridDataProvider','itemSvc','$modal',
534 function($scope , $q , $window , $routeParams , $location , $timeout , egCore , egNet , egGridDataProvider , itemSvc , $modal) {
535
536     $scope.defaults = { // If defaults are not set at all, allow everything
537         statcats : true,
538         copy_notes : true,
539         attributes : {
540             status : true,
541             loan_duration : true,
542             fine_level : true,
543             cost : true,
544             alerts : true,
545             deposit : true,
546             deposit_amount : true,
547             opac_visible : true,
548             price : true,
549             circulate : true,
550             mint_condition : true,
551             circ_lib : true,
552             ref : true,
553             circ_modifier : true,
554             circ_as_type : true,
555             location : true,
556             holdable : true,
557             age_protect : true
558         }
559     };
560
561     $scope.saveDefaults = function () {
562         egCore.hatch.setItem('cat.copy.defaults', $scope.defaults);
563     }
564
565     $scope.fetchDefaults = function () {
566         egCore.hatch.getItem('cat.copy.defaults').then(function(t) {
567             if (t) {
568                 $scope.defaults = t;
569                 if (!$scope.batch) $scope.batch = {};
570                 $scope.batch.classification = $scope.defaults.classification;
571                 $scope.batch.prefix = $scope.defaults.prefix;
572                 $scope.batch.suffix = $scope.defaults.suffix;
573                 $scope.working.statcat_filter = $scope.defaults.statcat_filter;
574                 if ($scope.defaults.always_vols) $scope.show_vols = true;
575             }
576         });
577     }
578     $scope.fetchDefaults();
579
580     $scope.dirty = false;
581     $scope.$watch('dirty',
582         function(newVal, oldVal) {
583             if (newVal && newVal != oldVal) {
584                 $($window).on('beforeunload.edit', function(){
585                     return 'There is unsaved data!'
586                 });
587             } else {
588                 $($window).off('beforeunload.edit');
589             }
590         }
591     );
592
593     $scope.show_vols = true;
594     $scope.show_copies = true;
595
596     $scope.tracker = function (x,f) { if (x) return x[f]() };
597     $scope.idTracker = function (x) { if (x) return $scope.tracker(x,'id') };
598     $scope.cant_have_vols = function (id) { return !egCore.org.CanHaveVolumes(id); };
599
600     $scope.orgById = function (id) { return egCore.org.get(id) }
601     $scope.statusById = function (id) {
602         return $scope.status_list.filter( function (s) { return s.id() == id } )[0];
603     }
604     $scope.locationById = function (id) {
605         return $scope.location_cache[''+id];
606     }
607
608     $scope.workingToComplete = function () {
609         angular.forEach( $scope.workingGridControls.selectedItems(), function (c) {
610             angular.forEach( itemSvc.copies, function (w, i) {
611                 if (c === w)
612                     $scope.completed_copies = $scope.completed_copies.concat(itemSvc.copies.splice(i,1));
613             });
614         });
615     }
616
617     $scope.completeToWorking = function () {
618         angular.forEach( $scope.completedGridControls.selectedItems(), function (c) {
619             angular.forEach( $scope.completed_copies, function (w, i) {
620                 if (c === w)
621                     itemSvc.copies = itemSvc.copies.concat($scope.completed_copies.splice(i,1));
622             });
623         });
624     }
625
626     createSimpleUpdateWatcher = function (field) {
627         return $scope.$watch('working.' + field, function () {
628             var newval = $scope.working[field];
629
630             if (typeof newval != 'undefined') {
631                 if (angular.isObject(newval)) { // we'll use the pkey
632                     if (newval.id) newval = newval.id();
633                     else if (newval.code) newval = newval.code();
634                 }
635
636                 if (""+newval == "" || newval == null) {
637                     $scope.working[field] = undefined;
638                     newval = null;
639                 }
640
641                 if ($scope.workingGridControls && $scope.workingGridControls.selectedItems) {
642                     angular.forEach(
643                         $scope.workingGridControls.selectedItems(),
644                         function (cp) {
645                             if (cp[field]() !== newval) {
646                                 cp[field](newval);
647                                 cp.ischanged(1);
648                                 $scope.dirty = true;
649                             }
650                         }
651                     );
652                 }
653             }
654         });
655     }
656
657     $scope.working = {
658         statcats: {},
659         statcat_filter: undefined
660     };
661
662     $scope.statcatUpdate = function (id) {
663         var newval = $scope.working.statcats[id];
664
665         if (typeof newval != 'undefined') {
666             if (angular.isObject(newval)) { // we'll use the pkey
667                 newval = newval.id();
668             }
669     
670             if (""+newval == "" || newval == null) {
671                 $scope.working.statcats[id] = undefined;
672                 newval = null;
673             }
674     
675             if (!$scope.in_item_select && $scope.workingGridControls && $scope.workingGridControls.selectedItems) {
676                 angular.forEach(
677                     $scope.workingGridControls.selectedItems(),
678                     function (cp) {
679                         $scope.dirty = true;
680
681                         cp.stat_cat_entries(
682                             angular.forEach( cp.stat_cat_entries(), function (e) {
683                                 if (e.stat_cat() == id) { // mark deleted
684                                     e.isdeleted(1);
685                                 }
686                             })
687                         );
688     
689                         if (newval) {
690                             var e = new egCore.idl.ascecm();
691                             e.isnew( 1 );
692                             e.owning_copy( cp.id() );
693                             e.stat_cat( id );
694                             e.stat_cat_entry( newval );
695
696                             cp.stat_cat_entries(
697                                 cp.stat_cat_entries().concat([ e ])
698                             );
699
700                         }
701
702                         cp.stat_cat_entries( // trim out ephemeral deleted ones
703                             cp.stat_cat_entries().filter(function (e) {
704                                 if (Boolean(e.isnew())) {
705                                     if (Boolean(e.isdeleted())) {
706                                         return false;
707                                     }
708                                 }
709                                 return true;
710                             })
711                         );
712    
713                         cp.ischanged(1);
714                     }
715                 );
716             }
717         }
718     }
719
720     var dataKey = $routeParams.dataKey;
721     console.debug('dataKey: ' + dataKey);
722
723     if (dataKey && dataKey.length > 0) {
724
725         $scope.templates = {};
726         $scope.template_name = '';
727         $scope.template_name_list = [];
728
729         $scope.fetchTemplates = function () {
730             egCore.hatch.getItem('cat.copy.templates').then(function(t) {
731                 if (t) {
732                     $scope.templates = t;
733                     $scope.template_name_list = Object.keys(t);
734                 }
735             });
736         }
737         $scope.fetchTemplates();
738
739          $scope.applyTemplate = function (n) {
740             angular.forEach($scope.templates[n], function (v,k) {
741                 if (!angular.isObject(v)) {
742                     $scope.working[k] = angular.copy(v);
743                 } else {
744                     angular.forEach(v, function (sv,sk) {
745                         if (k == 'callnumber') {
746                             angular.forEach(v, function (cnv,cnk) {
747                                 $scope.batch[cnk] = cnv;
748                             });
749                             $scope.applyBatchCNValues();
750                         } else {
751                             $scope.working[k][sk] = angular.copy(sv);
752                             if (k == 'statcats') $scope.statcatUpdate(sk);
753                         }
754                     });
755                 }
756             });
757             $scope.template_name = '';
758         }
759
760         $scope.copytab = 'working';
761         $scope.tab = 'edit';
762         $scope.summaryRecord = null;
763         $scope.record_id = null;
764         $scope.data = {};
765         $scope.completed_copies = [];
766         $scope.location_orgs = [];
767         $scope.location_cache = {};
768         $scope.statcats = [];
769         if (!$scope.batch) $scope.batch = {};
770
771         $scope.applyBatchCNValues = function () {
772             if ($scope.data.tree) {
773                 angular.forEach($scope.data.tree, function(cn_hash) {
774                     angular.forEach(cn_hash, function(copies) {
775                         angular.forEach(copies, function(cp) {
776                             if (typeof $scope.batch.classification != 'undefined' && $scope.batch.classification != '')
777                                 cp.call_number().label_class($scope.batch.classification);
778                                 $scope.dirty = true;
779                             if (typeof $scope.batch.prefix != 'undefined' && $scope.batch.prefix != '')
780                                 cp.call_number().prefix($scope.batch.prefix);
781                                 $scope.dirty = true;
782                             if (typeof $scope.batch.label != 'undefined' && $scope.batch.label != '')
783                                 cp.call_number().label($scope.batch.label);
784                                 $scope.dirty = true;
785                             if (typeof $scope.batch.suffix != 'undefined' && $scope.batch.suffix != '')
786                                 cp.call_number().suffix($scope.batch.suffix);
787                                 $scope.dirty = true;
788                         });
789                     });
790                 });
791             }
792         }
793
794         $scope.clearWorking = function () {
795             angular.forEach($scope.working, function (v,k,o) {
796                 if (!angular.isObject(v)) {
797                     if (typeof v != 'undefined')
798                         $scope.working[k] = undefined;
799                 } else if (k != 'circ_lib') {
800                     angular.forEach(v, function (sv,sk) {
801                         if (typeof v != 'undefined')
802                             $scope.working[k][sk] = undefined;
803                     });
804                 }
805             });
806             $scope.working.circ_lib = undefined; // special
807         }
808
809         $scope.completedGridDataProvider = egGridDataProvider.instance({
810             get : function(offset, count) {
811                 //return provider.arrayNotifier(itemSvc.copies, offset, count);
812                 return this.arrayNotifier($scope.completed_copies, offset, count);
813             }
814         });
815
816         $scope.completedGridControls = {};
817
818         $scope.workingGridDataProvider = egGridDataProvider.instance({
819             get : function(offset, count) {
820                 //return provider.arrayNotifier(itemSvc.copies, offset, count);
821                 return this.arrayNotifier(itemSvc.copies, offset, count);
822             }
823         });
824
825         $scope.workingGridControls = {};
826         $scope.add_vols_copies = false;
827
828         egNet.request(
829             'open-ils.actor',
830             'open-ils.actor.anon_cache.get_value',
831             dataKey, 'edit-these-copies'
832         ).then(function (data) {
833
834             if (data) {
835                 if (data.hide_vols && !$scope.defaults.always_vols) $scope.show_vols = false;
836                 if (data.hide_copies) $scope.show_copies = false;
837
838                 $scope.record_id = data.record_id;
839
840                 if (data.copies && data.copies.length)
841                     return itemSvc.fetchIds(data.copies);
842
843                 if (data.raw && data.raw.length) {
844                     $scope.dirty = true;
845                     $scope.add_vols_copies = true;
846
847                     /* data.raw data structure looks like this:
848                      * [{
849                      *      callnumber : $cn_id, // optional, to add a copy to a cn
850                      *      owner      : $org, // optional, defaults to ws_ou
851                      *      label      : $cn_label, // optional, to supply a label on a new cn
852                      *      barcode    : $cp_barcode // optional, to supply a barcode on a new cp
853                      * },...]
854                      * 
855                      * All can be left out and a completely empty vol/copy combo will be vivicated.
856                      */
857
858                     angular.forEach(
859                         data.raw,
860                         function (proto) {
861                             if (proto.callnumber) {
862                                 return egCore.pcrud.retrieve('acn', proto.callnumber)
863                                 .then(function(cn) {
864                                     var cp = new egCore.idl.acp();
865                                     cp.call_number( cn );
866                                     cp.id( --itemSvc.new_cp_id );
867                                     cp.isnew( true );
868                                     cp.circ_lib( $scope.record_id );
869                                     if (proto.barcode) cp.barcode( proto.barcode );
870
871                                     itemSvc.addCopy(cp)
872                                 });
873                             } else {
874                                 var cn = new egCore.idl.acn();
875                                 cn.id( --itemSvc.new_cn_id );
876                                 cn.isnew( true );
877                                 cn.prefix( $scope.defaults.prefix || -1 );
878                                 cn.suffix( $scope.defaults.suffix || -1 );
879                                 cn.label_class( $scope.defaults.classification || 1 );
880                                 cn.owning_lib( proto.owner || egCore.auth.user().ws_ou() );
881                                 cn.record( $scope.record_id );
882                                 if (proto.label) cn.label( proto.label );
883
884                                 var cp = new egCore.idl.acp();
885                                 cp.call_number( cn );
886                                 cp.id( --itemSvc.new_cp_id );
887                                 cp.isnew( true );
888                                 cp.circ_lib( $scope.record_id );
889                                 if (proto.barcode) cp.barcode( proto.barcode );
890
891                                 itemSvc.addCopy(cp)
892                             }
893     
894                         }
895                     );
896
897                     return itemSvc.copies;
898                 }
899             }
900
901         }).then( function() {
902             if ($scope.add_vols_copies) {
903                 egCore.org.settings([
904                     'cat.default_copy_status_fast'
905                 ]).then(function(set) {
906                     $scope.fast_ccs = set['cat.default_copy_status_fast'] || 0;
907                     $scope.data = itemSvc;
908                     angular.forEach($scope.data.copies, function (cp) {
909                         cp.status($scope.fast_ccs);
910                     });
911                     $scope.workingGridDataProvider.refresh();
912                 });
913             }
914         });
915
916         $scope.focusNextFirst = function(prev_lib) {
917             var n;
918             var yep = false;
919             angular.forEach(Object.keys($scope.data.tree).sort(), function (lib) {
920                 console.log('checking lib '+lib);
921                 if (n) return;
922
923                 if (lib == prev_lib) {
924                     console.log('prev is '+lib);
925                     yep = true;
926                     return;
927                 }
928                 console.log('prev is not '+lib);
929
930                 if (yep) n = lib;
931             });
932
933             console.log('found '+n);
934             if (n) {
935                 var first_cn = Object.keys($scope.data.tree[n])[0];
936                 var next = '#' + first_cn + '_' + $scope.data.tree[n][first_cn][0].id();
937                 var el = $(next);
938                 if (el) el.focus()
939             } else {
940                 $scope.focusNext($scope.lib);
941             }
942         }
943
944         $scope.in_item_select = false;
945         $scope.afterItemSelect = function() { $scope.in_item_select = false };
946         $scope.handleItemSelect = function (item_list) {
947             if (item_list && item_list.length > 0) {
948                 $scope.in_item_select = true;
949
950                 angular.forEach(Object.keys($scope.defaults.attributes), function (attr) {
951
952                     var value_hash = {};
953                     angular.forEach(item_list, function (item) {
954                         if (item[attr]) {
955                             var v = item[attr]()
956                             if (angular.isObject(v)) {
957                                 if (v.id) v = v.id();
958                                 else if (v.code) v = v.code();
959                             }
960                             value_hash[v] = 1;
961                         }
962                     });
963
964                     if (Object.keys(value_hash).length == 1) {
965                         if (attr == 'circ_lib') {
966                             $scope.working[attr] = egCore.org.get(item_list[0][attr]());
967                         } else {
968                             $scope.working[attr] = item_list[0][attr]();
969                         }
970                     } else {
971                         $scope.working[attr] = undefined;
972                     }
973                 });
974
975                 angular.forEach($scope.statcats, function (sc) {
976
977                     var counter = -1;
978                     var value_hash = {};
979                     var none = false;
980                     angular.forEach(item_list, function (item) {
981                         if (item.stat_cat_entries()) {
982                             if (item.stat_cat_entries().length > 0) {
983                                 var right_sc = item.stat_cat_entries().filter(function (e) {
984                                     return e.stat_cat() == sc.id() && !Boolean(e.isdeleted());
985                                 });
986
987                                 if (right_sc.length > 0) {
988                                     value_hash[right_sc[0].stat_cat_entry()] = right_sc[0].stat_cat_entry();
989                                 } else {
990                                     none = true;
991                                 }
992                             }
993                         } else {
994                             none = true;
995                         }
996                     });
997
998                     if (!none && Object.keys(value_hash).length == 1) {
999                         $scope.working.statcats[sc.id()] = value_hash[Object.keys(value_hash)[0]];
1000                     } else {
1001                         $scope.working.statcats[sc.id()] = undefined;
1002                     }
1003                 });
1004
1005             } else {
1006                 $scope.clearWorking();
1007             }
1008
1009         }
1010
1011         $scope.$watch('data.copies.length', function () {
1012             if ($scope.data.copies) {
1013                 var base_orgs = $scope.data.copies.map(function(cp){
1014                     return cp.circ_lib()
1015                 }).concat(
1016                     $scope.data.copies.map(function(cp){
1017                         return cp.call_number().owning_lib()
1018                     })
1019                 ).concat(
1020                     [egCore.auth.user().ws_ou()]
1021                 ).filter(function(e,i,a){
1022                     return a.lastIndexOf(e) === i;
1023                 });
1024
1025                 var all_orgs = [];
1026                 angular.forEach(base_orgs, function(o) {
1027                     all_orgs = all_orgs.concat( egCore.org.fullPath(o, true) );
1028                 });
1029
1030                 var final_orgs = all_orgs.filter(function(e,i,a){
1031                     return a.lastIndexOf(e) === i;
1032                 }).sort(function(a, b){return parseInt(a)-parseInt(b)});
1033
1034                 if ($scope.location_orgs.toString() != final_orgs.toString()) {
1035                     $scope.location_orgs = final_orgs;
1036                     if ($scope.location_orgs.length) {
1037                         itemSvc.get_locations($scope.location_orgs).then(function(list){
1038                             angular.forEach(list, function(l) {
1039                                 $scope.location_cache[ ''+l.id() ] = l;
1040                             });
1041                             $scope.location_list = list;
1042                         });
1043
1044                         $scope.statcat_filter_list = [];
1045                         angular.forEach($scope.location_orgs, function (o) {
1046                             $scope.statcat_filter_list.push(egCore.org.get(o));
1047                         });
1048
1049                         itemSvc.get_statcats($scope.location_orgs).then(function(list){
1050                             $scope.statcats = list;
1051                             angular.forEach($scope.statcats, function (s) {
1052
1053                                 if (!$scope.working)
1054                                     $scope.working = { statcats: {}, statcat_filter: undefined};
1055                                 if (!$scope.working.statcats)
1056                                     $scope.working.statcats = {};
1057
1058                                 if (!$scope.in_item_select) {
1059                                     $scope.working.statcats[s.id()] = undefined;
1060                                 }
1061                                 createStatcatUpdateWatcher(s.id());
1062                             });
1063                             $scope.in_item_select = false;
1064                         });
1065                     }
1066                 }
1067             }
1068
1069             $scope.workingGridDataProvider.refresh();
1070         });
1071
1072         $scope.suffix_list = [];
1073         itemSvc.get_suffixes(egCore.auth.user().ws_ou()).then(function(list){
1074             $scope.suffix_list = list;
1075         });
1076
1077         $scope.prefix_list = [];
1078         itemSvc.get_prefixes(egCore.auth.user().ws_ou()).then(function(list){
1079             $scope.prefix_list = list;
1080         });
1081
1082         $scope.classification_list = [];
1083         itemSvc.get_classifications().then(function(list){
1084             $scope.classification_list = list;
1085         });
1086
1087         $scope.$watch('completed_copies.length', function () {
1088             $scope.completedGridDataProvider.refresh();
1089         });
1090
1091         $scope.location_list = [];
1092         itemSvc.get_locations().then(function(list){
1093             $scope.location_list = list;
1094         });
1095         createSimpleUpdateWatcher('location');
1096
1097         $scope.status_list = [];
1098         itemSvc.get_statuses().then(function(list){
1099             $scope.status_list = list;
1100         });
1101         createSimpleUpdateWatcher('status');
1102
1103         $scope.circ_modifier_list = [];
1104         itemSvc.get_circ_mods().then(function(list){
1105             $scope.circ_modifier_list = list;
1106         });
1107         createSimpleUpdateWatcher('circ_modifier');
1108
1109         $scope.circ_type_list = [];
1110         itemSvc.get_circ_types().then(function(list){
1111             $scope.circ_type_list = list;
1112         });
1113         createSimpleUpdateWatcher('circ_as_type');
1114
1115         $scope.age_protect_list = [];
1116         itemSvc.get_age_protects().then(function(list){
1117             $scope.age_protect_list = list;
1118         });
1119         createSimpleUpdateWatcher('age_protect');
1120
1121         createSimpleUpdateWatcher('circ_lib');
1122         createSimpleUpdateWatcher('circulate');
1123         createSimpleUpdateWatcher('holdable');
1124         createSimpleUpdateWatcher('fine_level');
1125         createSimpleUpdateWatcher('loan_duration');
1126         createSimpleUpdateWatcher('cost');
1127         createSimpleUpdateWatcher('deposit');
1128         createSimpleUpdateWatcher('deposit_amount');
1129         createSimpleUpdateWatcher('mint_condition');
1130         createSimpleUpdateWatcher('opac_visible');
1131         createSimpleUpdateWatcher('ref');
1132
1133         $scope.saveCompletedCopies = function (and_exit) {
1134             var cnHash = {};
1135             var perCnCopies = {};
1136             angular.forEach( egCore.idl.Clone($scope.completed_copies), function (cp) {
1137                 var cn_id = cp.call_number().id();
1138                 if (!cnHash[cn_id]) {
1139                     cnHash[cn_id] = cp.call_number();
1140                     perCnCopies[cn_id] = [cp];
1141                 } else {
1142                     perCnCopies[cn_id].push(cp);
1143                 }
1144                 cp.call_number(cn_id); // prevent loops in JSON-ification
1145             });
1146
1147             angular.forEach(perCnCopies, function (v, k) {
1148                 cnHash[k].copies(v);
1149             });
1150
1151             cnList = [];
1152             angular.forEach(cnHash, function (v, k) {
1153                 cnList.push(v);
1154             });
1155
1156             egNet.request(
1157                 'open-ils.cat',
1158                 'open-ils.cat.asset.volume.fleshed.batch.update.override',
1159                 egCore.auth.token(), cnList, 1, { auto_merge_vols : 1, create_parts : 1 }
1160             ).then(function(update_count) {
1161                 if (and_exit) {
1162                     $scope.dirty = false;
1163                     $timeout(function(){$window.close()});
1164                 }
1165             });
1166         }
1167
1168         $scope.saveAndContinue = function () {
1169             $scope.saveCompletedCopies(false);
1170         }
1171
1172         $scope.saveAndExit = function () {
1173             $scope.saveCompletedCopies(true);
1174         }
1175
1176     }
1177
1178     $scope.copy_notes_dialog = function(copy_list) {
1179         var default_pub = Boolean($scope.defaults.copy_notes_pub);
1180         if (!angular.isArray(copy_list)) copy_list = [copy_list];
1181
1182         return $modal.open({
1183             templateUrl: './cat/volcopy/t_copy_notes',
1184             animation: true,
1185             controller:
1186                    ['$scope','$modalInstance',
1187             function($scope , $modalInstance) {
1188                 $scope.focusNote = true;
1189                 $scope.note = {
1190                     creator : egCore.auth.user().id(),
1191                     title   : '',
1192                     value   : '',
1193                     pub     : default_pub,
1194                 };
1195
1196                 $scope.require_initials = false;
1197                 egCore.org.settings([
1198                     'ui.staff.require_initials.copy_notes'
1199                 ]).then(function(set) {
1200                     $scope.require_initials = Boolean(set['ui.staff.require_initials.copy_notes']);
1201                 });
1202
1203                 $scope.note_list = [];
1204                 if (copy_list.length == 1) {
1205                     $scope.note_list = copy_list[0].notes();
1206                 }
1207
1208                 $scope.ok = function(note) {
1209
1210                     if (note.initials) note.value += ' [' + note.initials + ']';
1211                     angular.forEach(copy_list, function (cp) {
1212                         var n = new egCore.idl.acpn();
1213                         n.creator(note.creator);
1214                         n.pub(note.pub);
1215                         n.title(note.title);
1216                         n.value(note.value);
1217                         n.owning_copy(cp.id());
1218                         cp.notes().push( n );
1219                     });
1220
1221                     $modalInstance.close();
1222                 }
1223
1224                 $scope.cancel = function($event) {
1225                     $modalInstance.dismiss();
1226                     $event.preventDefault();
1227                 }
1228             }]
1229         });
1230     }
1231
1232 }])
1233
1234 .directive("egVolTemplate", function () {
1235     return {
1236         restrict: 'E',
1237         replace: true,
1238         template: '<div ng-include="'+"'/eg/staff/cat/volcopy/t_attr_edit'"+'"></div>',
1239         scope: { },
1240         controller : ['$scope','$window','itemSvc','egCore',
1241             function ( $scope , $window , itemSvc , egCore ) {
1242
1243                 $scope.defaults = { // If defaults are not set at all, allow everything
1244                     statcats : true,
1245                     copy_notes : true,
1246                     attributes : {
1247                         status : true,
1248                         loan_duration : true,
1249                         fine_level : true,
1250                         cost : true,
1251                         alerts : true,
1252                         deposit : true,
1253                         deposit_amount : true,
1254                         opac_visible : true,
1255                         price : true,
1256                         circulate : true,
1257                         mint_condition : true,
1258                         circ_lib : true,
1259                         ref : true,
1260                         circ_modifier : true,
1261                         circ_as_type : true,
1262                         location : true,
1263                         holdable : true,
1264                         age_protect : true
1265                     }
1266                 };
1267
1268                 $scope.fetchDefaults = function () {
1269                     egCore.hatch.getItem('cat.copy.defaults').then(function(t) {
1270                         if (t) {
1271                             $scope.defaults = t;
1272                             $scope.working.statcat_filter = $scope.defaults.statcat_filter;
1273                         }
1274                     });
1275                 }
1276                 $scope.fetchDefaults();
1277
1278                 $scope.dirty = false;
1279                 $scope.$watch('dirty',
1280                     function(newVal, oldVal) {
1281                         if (newVal && newVal != oldVal) {
1282                             $($window).on('beforeunload.template', function(){
1283                                 return 'There is unsaved template data!'
1284                             });
1285                         } else {
1286                             $($window).off('beforeunload.template');
1287                         }
1288                     }
1289                 );
1290
1291                 $scope.template_controls = true;
1292
1293                 $scope.fetchTemplates = function () {
1294                     egCore.hatch.getItem('cat.copy.templates').then(function(t) {
1295                         if (t) {
1296                             $scope.templates = t;
1297                             $scope.template_name_list = Object.keys(t);
1298                         }
1299                     });
1300                 }
1301                 $scope.fetchTemplates();
1302             
1303                 $scope.applyTemplate = function (n) {
1304                     angular.forEach($scope.templates[n], function (v,k) {
1305                         if (!angular.isObject(v)) {
1306                             $scope.working[k] = angular.copy(v);
1307                         } else {
1308                             angular.forEach(v, function (sv,sk) {
1309                                 $scope.working[k][sk] = angular.copy(sv);
1310                             });
1311                         }
1312                     });
1313                     $scope.template_name = '';
1314                 }
1315
1316                 $scope.deleteTemplate = function (n) {
1317                     if (n) {
1318                         delete $scope.templates[n]
1319                         $scope.template_name_list = Object.keys($scope.templates);
1320                         $scope.template_name = '';
1321                         egCore.hatch.setItem('cat.copy.templates', $scope.templates);
1322                         $scope.$parent.fetchTemplates();
1323                     }
1324                 }
1325
1326                 $scope.saveTemplate = function (n) {
1327                     if (n) {
1328                         var tmpl = {};
1329             
1330                         angular.forEach($scope.working, function (v,k) {
1331                             if (angular.isObject(v)) { // we'll use the pkey
1332                                 if (v.id) v = v.id();
1333                                 else if (v.code) v = v.code();
1334                             }
1335             
1336                             tmpl[k] = v;
1337                         });
1338             
1339                         $scope.templates[n] = tmpl;
1340                         $scope.template_name_list = Object.keys($scope.templates);
1341             
1342                         egCore.hatch.setItem('cat.copy.templates', $scope.templates);
1343                         $scope.$parent.fetchTemplates();
1344
1345                         $scope.dirty = false;
1346                     }
1347                 }
1348             
1349                 $scope.templates = {};
1350                 $scope.template_name = '';
1351                 $scope.template_name_list = [];
1352             
1353                 $scope.tracker = function (x,f) { if (x) return x[f]() };
1354                 $scope.idTracker = function (x) { if (x) return $scope.tracker(x,'id') };
1355                 $scope.cant_have_vols = function (id) { return !egCore.org.CanHaveVolumes(id); };
1356             
1357                 $scope.orgById = function (id) { return egCore.org.get(id) }
1358                 $scope.statusById = function (id) {
1359                     return $scope.status_list.filter( function (s) { return s.id() == id } )[0];
1360                 }
1361                 $scope.locationById = function (id) {
1362                     return $scope.location_cache[''+id];
1363                 }
1364             
1365                 createSimpleUpdateWatcher = function (field) {
1366                     $scope.$watch('working.' + field, function () {
1367                         var newval = $scope.working[field];
1368             
1369                         if (typeof newval != 'undefined') {
1370                             $scope.dirty = true;
1371                             if (angular.isObject(newval)) { // we'll use the pkey
1372                                 if (newval.id) $scope.working[field] = newval.id();
1373                                 else if (newval.code) $scope.working[field] = newval.code();
1374                             }
1375             
1376                             if (""+newval == "" || newval == null) {
1377                                 $scope.working[field] = undefined;
1378                             }
1379             
1380                         }
1381                     });
1382                 }
1383             
1384                 $scope.working = {
1385                     statcats: {},
1386                     statcat_filter: undefined
1387                 };
1388             
1389                 createStatcatUpdateWatcher = function (id) {
1390                     return $scope.$watch('working.statcats[' + id + ']', function () {
1391                         if ($scope.working.statcats) {
1392                             var newval = $scope.working.statcats[id];
1393                 
1394                             if (typeof newval != 'undefined') {
1395                                 $scope.dirty = true;
1396                                 if (angular.isObject(newval)) { // we'll use the pkey
1397                                     newval = newval.id();
1398                                 }
1399                 
1400                                 if (""+newval == "" || newval == null) {
1401                                     $scope.working.statcats[id] = undefined;
1402                                     newval = null;
1403                                 }
1404                 
1405                             }
1406                         }
1407                     });
1408                 }
1409
1410                 $scope.clearWorking = function () {
1411                     angular.forEach($scope.working, function (v,k,o) {
1412                         if (!angular.isObject(v)) {
1413                             if (typeof v != 'undefined')
1414                                 $scope.working[k] = undefined;
1415                         } else if (k != 'circ_lib') {
1416                             angular.forEach(v, function (sv,sk) {
1417                                 $scope.working[k][sk] = undefined;
1418                             });
1419                         }
1420                     });
1421                     $scope.working.circ_lib = undefined; // special
1422                     $scope.dirty = false;
1423                 }
1424
1425                 $scope.working = {};
1426                 $scope.location_orgs = [];
1427                 $scope.location_cache = {};
1428             
1429                 $scope.location_list = [];
1430                 itemSvc.get_locations(
1431                     egCore.org.fullPath( egCore.auth.user().ws_ou(), true )
1432                 ).then(function(list){
1433                     $scope.location_list = list;
1434                 });
1435                 createSimpleUpdateWatcher('location');
1436
1437                 $scope.statcat_filter_list = egCore.org.fullPath( egCore.auth.user().ws_ou() );
1438
1439                 $scope.statcats = [];
1440                 itemSvc.get_statcats(
1441                     egCore.org.fullPath( egCore.auth.user().ws_ou(), true )
1442                 ).then(function(list){
1443                     $scope.statcats = list;
1444                     angular.forEach($scope.statcats, function (s) {
1445
1446                         if (!$scope.working)
1447                             $scope.working = { statcats: {}, statcat_filter: undefined};
1448                         if (!$scope.working.statcats)
1449                             $scope.working.statcats = {};
1450
1451                         $scope.working.statcats[s.id()] = undefined;
1452                         createStatcatUpdateWatcher(s.id());
1453                     });
1454                 });
1455             
1456                 $scope.status_list = [];
1457                 itemSvc.get_statuses().then(function(list){
1458                     $scope.status_list = list;
1459                 });
1460                 createSimpleUpdateWatcher('status');
1461             
1462                 $scope.circ_modifier_list = [];
1463                 itemSvc.get_circ_mods().then(function(list){
1464                     $scope.circ_modifier_list = list;
1465                 });
1466                 createSimpleUpdateWatcher('circ_modifier');
1467             
1468                 $scope.circ_type_list = [];
1469                 itemSvc.get_circ_types().then(function(list){
1470                     $scope.circ_type_list = list;
1471                 });
1472                 createSimpleUpdateWatcher('circ_as_type');
1473             
1474                 $scope.age_protect_list = [];
1475                 itemSvc.get_age_protects().then(function(list){
1476                     $scope.age_protect_list = list;
1477                 });
1478                 createSimpleUpdateWatcher('age_protect');
1479             
1480                 createSimpleUpdateWatcher('circ_lib');
1481                 createSimpleUpdateWatcher('circulate');
1482                 createSimpleUpdateWatcher('holdable');
1483                 createSimpleUpdateWatcher('fine_level');
1484                 createSimpleUpdateWatcher('loan_duration');
1485                 createSimpleUpdateWatcher('cost');
1486                 createSimpleUpdateWatcher('deposit');
1487                 createSimpleUpdateWatcher('deposit_amount');
1488                 createSimpleUpdateWatcher('mint_condition');
1489                 createSimpleUpdateWatcher('opac_visible');
1490                 createSimpleUpdateWatcher('ref');
1491
1492                 $scope.suffix_list = [];
1493                 itemSvc.get_suffixes(egCore.auth.user().ws_ou()).then(function(list){
1494                     $scope.suffix_list = list;
1495                 });
1496
1497                 $scope.prefix_list = [];
1498                 itemSvc.get_prefixes(egCore.auth.user().ws_ou()).then(function(list){
1499                     $scope.prefix_list = list;
1500                 });
1501
1502                 $scope.classification_list = [];
1503                 itemSvc.get_classifications().then(function(list){
1504                     $scope.classification_list = list;
1505                 });
1506
1507                 createSimpleUpdateWatcher('working.callnumber.classification');
1508                 createSimpleUpdateWatcher('working.callnumber.prefix');
1509                 createSimpleUpdateWatcher('working.callnumber.suffix');
1510             }
1511         ]
1512     }
1513 })
1514
1515