5 angular.module('egVolCopy',
6 ['ngRoute', 'ui.bootstrap', 'egCoreMod', 'egUiMod', 'egGridMod'])
8 .filter('boolText', function(){
14 .config(function($routeProvider, $locationProvider, $compileProvider) {
15 $locationProvider.html5Mode(true);
16 $compileProvider.aHrefSanitizationWhitelist(/^\s*(https?|blob):/); // grid export
19 delay : ['egStartup', function(egStartup) { return egStartup.go(); }]
22 $routeProvider.when('/cat/volcopy/:dataKey', {
23 templateUrl: './cat/volcopy/t_view',
24 controller: 'EditCtrl',
32 function(egCore , $q) {
35 tree : {}, // holds lib->cn->copy hash stack
36 copies : [] // raw copy list
39 // returns a promise resolved with the list of circ mods
40 service.get_classifications = function() {
42 return $q.when(egCore.env.acnc.list);
44 return egCore.pcrud.retrieveAll('acnc', null, {atomic : true})
45 .then(function(list) {
46 egCore.env.absorbList(list, 'acnc');
51 service.get_prefixes = function(org) {
52 return egCore.pcrud.search('acnp',
53 {owning_lib : egCore.org.fullPath(org, true)},
59 service.get_statcats = function(orgs) {
60 return egCore.pcrud.search('asc',
64 asc : ['owner','entries']
71 service.get_locations = function(orgs) {
72 return egCore.pcrud.search('acpl',
78 service.get_suffixes = function(org) {
79 return egCore.pcrud.search('acns',
80 {owning_lib : egCore.org.fullPath(org, true)},
86 service.get_statuses = function() {
88 return $q.when(egCore.env.ccs.list);
90 return egCore.pcrud.retrieveAll('ccs', {}, {atomic : true}).then(
92 egCore.env.absorbList(list, 'ccs');
99 service.get_circ_mods = function() {
101 return $q.when(egCore.env.ccm.list);
103 return egCore.pcrud.retrieveAll('ccm', {}, {atomic : true}).then(
105 egCore.env.absorbList(list, 'ccm');
112 service.get_circ_types = function() {
114 return $q.when(egCore.env.citm.list);
116 return egCore.pcrud.retrieveAll('citm', {}, {atomic : true}).then(
118 egCore.env.absorbList(list, 'citm');
125 service.get_age_protects = function() {
126 if (egCore.env.crahp)
127 return $q.when(egCore.env.crahp.list);
129 return egCore.pcrud.retrieveAll('crahp', {}, {atomic : true}).then(
131 egCore.env.absorbList(list, 'crahp');
138 service.bmp_parts = {};
139 service.get_parts = function(rec) {
140 if (service.bmp_parts[rec])
141 return $q.when(service.bmp_parts[rec]);
143 return egCore.pcrud.search('bmp',
145 null, {atomic : true}
146 ).then(function(list) {
147 service.bmp_parts[rec] = list;
156 acp : ['call_number','parts','stat_cat_entries'],
157 acn : ['label_class','prefix','suffix']
161 service.addCopy = function (cp) {
163 if (!cp.parts()) cp.parts([]); // just in case...
165 var lib = cp.call_number().owning_lib();
166 var cn = cp.call_number().id();
168 if (!service.tree[lib]) service.tree[lib] = {};
169 if (!service.tree[lib][cn]) service.tree[lib][cn] = [];
171 service.tree[lib][cn].push(cp);
172 service.copies.push(cp);
175 service.fetchIds = function(idList) {
176 service.tree = {}; // clear the tree on fetch
177 service.copies = []; // clear the copy list on fetch
178 return egCore.pcrud.search('acp', { 'id' : idList }, service.flesh).then(null,null,
180 service.addCopy(copy);
188 .directive("egVolCopyEdit", function () {
194 '<div class="col-xs-5">'+
195 '<input id="{{callNumber.id()}}.{{copy.id()}}"'+
196 ' eg-enter="nextBarcode()" class="form-control"'+
197 ' type="text" ng-model="barcode" ng-change="updateBarcode()"/>'+
199 '<div class="col-xs-3"><input class="form-control" type="number" ng-model="copy_number" ng-change="updateCopyNo()"/></div>'+
200 '<div class="col-xs-4"><eg-basic-combo-box list="parts" selected="part"></eg-basic-combo-box></div>'+
203 scope: { copy: "=", callNumber: "=", index: "@" },
204 controller : ['$scope','itemSvc',
205 function ( $scope , itemSvc ) {
206 $scope.new_part_id = 0;
208 $scope.nextBarcode = function (i) {
209 $scope.$parent.focusNextBarcode($scope.copy.id());
212 $scope.updateBarcode = function () { $scope.copy.barcode($scope.barcode); $scope.copy.ischanged(1); };
213 $scope.updateCopyNo = function () { $scope.copy.copy_number($scope.copy_number); $scope.copy.ischanged(1); };
214 $scope.updatePart = function () {
215 var p = $scope.part_list.filter(function (x) {
216 return x.label() == $scope.part
218 if (p.length > 0) { // preexisting part
220 } else { // create one...
221 var part = new egCore.idl.bmp();
222 part.id( --$scope.new_part_id );
224 part.label( $scope.part );
225 part.record( $scope.callNumber.owning_lib() );
226 $scope.copy.parts([part]);
227 $scope.copy.ischanged(1);
231 $scope.barcode = $scope.copy.barcode();
232 $scope.copy_number = $scope.copy.copy_number();
234 if ($scope.copy.parts()) {
235 $scope.part = $scope.copy.parts()[0];
236 if ($scope.part) $scope.part = $scope.part.label();
240 $scope.part_list = [];
242 itemSvc.get_parts($scope.callNumber.record()).then(function(list){
243 $scope.part_list = list;
244 angular.forEach(list, function(p){ $scope.parts.push(p.label()) });
253 .directive("egVolRow", function () {
260 '<div class="col-xs-2">'+
261 '<select class="form-control" ng-model="classification" ng-options="cl.name() for cl in classification_list track by idTracker(cl)"/>'+
263 '<div class="col-xs-1">'+
264 '<select class="form-control" ng-model="prefix" ng-change="updatePrefix()" ng-options="p.label() for p in prefix_list track by idTracker(p)"/>'+
266 '<div class="col-xs-2"><input class="form-control" type="text" ng-change="updateLabel()" ng-model="label"/></div>'+
267 '<div class="col-xs-1">'+
268 '<select class="form-control" ng-model="suffix" ng-change="updateSuffix()" ng-options="s.label() for s in suffix_list track by idTracker(s)"/>'+
270 '<div class="col-xs-1"><input class="form-control" type="number" ng-model="copy_count" min="{{orig_copy_count}}" ng-change="changeCPCount()"></div>'+
271 '<div class="col-xs-5">'+
272 '<eg-vol-copy-edit ng-repeat="cp in copies track by idTracker(cp)" copy="cp" call-number="callNumber"></eg-vol-copy-edit>'+
276 scope: {allcopies: "=", copies: "=" },
277 controller : ['$scope','itemSvc','egCore',
278 function ( $scope , itemSvc , egCore ) {
279 $scope.new_cp_id = 0;
280 $scope.callNumber = $scope.copies[0].call_number();
282 $scope.idTracker = function (x) { if (x) return x.id() };
284 // XXX $() is not working! arg
285 $scope.focusNextBarcode = function (i) {
288 angular.forEach($scope.copies, function (cp) {
296 if (yep) n = cp.id();
300 var next = '#' + $scope.callNumber.id() + '.' + n;
301 var el = $(next).get(0);
306 $scope.suffix_list = [];
307 itemSvc.get_suffixes($scope.callNumber.owning_lib()).then(function(list){
308 $scope.suffix_list = list;
310 $scope.updateSuffix = function () {
311 angular.forEach($scope.copies, function(cp) {
312 cp.call_number().suffix($scope.suffix);
313 cp.call_number().ischanged(1);
317 $scope.prefix_list = [];
318 itemSvc.get_prefixes($scope.callNumber.owning_lib()).then(function(list){
319 $scope.prefix_list = list;
321 $scope.updatePrefix = function () {
322 angular.forEach($scope.copies, function(cp) {
323 cp.call_number().prefix($scope.prefix);
324 cp.call_number().ischanged(1);
328 $scope.classification_list = [];
329 itemSvc.get_classifications().then(function(list){
330 $scope.classification_list = list;
332 $scope.updateClassification = function () {
333 angular.forEach($scope.copies, function(cp) {
334 cp.call_number().label_class($scope.classification);
335 cp.call_number().ischanged(1);
339 $scope.updateLabel = function () {
340 angular.forEach($scope.copies, function(cp) {
341 cp.call_number().label($scope.label);
342 cp.call_number().ischanged(1);
346 $scope.$watch('callNumber.prefix()', function (v) {
347 if (typeof v != 'object') {
348 $scope.prefix = $scope.prefix_list.filter(function (p) {
351 $scope.callNumber.prefix($scope.prefix);
355 $scope.$watch('callNumber.suffix()', function (v) {
356 if (typeof v != 'object') {
357 $scope.suffix = $scope.suffix_list.filter( function (s) {
360 $scope.callNumber.suffix($scope.suffix);
364 $scope.$watch('callNumber.label_class()', function (v) {
365 if (typeof v != 'object') {
366 $scope.classification = $scope.classification_list.filter(function (c) {
369 $scope.callNumber.label_class($scope.classification);
373 $scope.$watch('callNumber.label()', function (v) {
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();
382 $scope.copy_count = $scope.copies.length;
383 $scope.orig_copy_count = $scope.copy_count;
385 $scope.changeCPCount = function () {
386 while ($scope.copy_count > $scope.copies.length) {
387 var cp = new egCore.idl.acp();
388 cp.id( --$scope.new_cp_id );
390 cp.circ_lib( $scope.lib );
391 cp.call_number( $scope.callNumber );
392 $scope.copies.push( cp );
393 $scope.allcopies.push( cp );
396 var how_many = $scope.copies.length - $scope.copy_count;
398 var dead = $scope.copies.splice($scope.copy_count,how_many);
399 $scope.callNumber.copies($scope.copies);
401 // Trimming the global list is a bit more tricky
402 angular.forEach( dead, function (d) {
403 angular.forEach( $scope.allcopies, function (l, i) {
404 if (l === d) $scope.allcopies.splice(i,1);
416 .directive("egVolEdit", function () {
422 '<div class="col-xs-1"><eg-org-selector selected="owning_lib" disableTest="cant_have_vols"></eg-org-selector></div>'+
423 '<div class="col-xs-1"><input class="form-control" type="number" min="{{orig_cn_count}}" ng-model="cn_count" ng-change="changeCNCount()"/></div>'+
424 '<div class="col-xs-10">'+
425 '<eg-vol-row ng-repeat="(cn,copies) in struct track by cn" copies="copies" allcopies="allcopies"></eg-vol-row>'+
429 scope: { allcopies: "=", struct: "=", lib: "@", record: "@" },
430 controller : ['$scope','itemSvc','egCore',
431 function ( $scope , itemSvc , egCore ) {
432 $scope.new_cn_id = 0;
433 $scope.first_cn = Object.keys($scope.struct)[0];
434 $scope.full_cn = $scope.struct[$scope.first_cn][0].call_number();
436 $scope.cn_count = Object.keys($scope.struct).length;
437 $scope.orig_cn_count = $scope.cn_count;
439 $scope.owning_lib = egCore.org.get($scope.lib);
440 $scope.$watch('owning_lib', function (l) {
441 angular.forEach( $scope.struct[$scope.first_cn], function (cp) {
442 cp.call_number().owning_lib( $scope.owning_lib.id() );
446 $scope.cant_have_vols = function (id) { return !egCore.org.CanHaveVolumes(id); };
448 $scope.$watch('cn_count', function (n) {
449 var o = Object.keys($scope.struct).length;
450 if (n > o) { // adding
451 for (var i = o; o < n; o++) {
452 var cn = new egCore.idl.acn();
453 cn.id( --$scope.new_cn_id );
455 cn.owning_lib( $scope.owning_lib.id() );
456 cn.record( $scope.full_cn.record() );
458 var cp = new egCore.idl.acp();
459 cp.id( --$scope.new_cp_id );
461 cp.circ_lib( $scope.owning_lib.id() );
462 cp.call_number( cn );
464 $scope.struct[cn.id()] = [cp];
465 $scope.allcopies.push(cp);
467 } else if (n < o) { // removing
468 var how_many = o - n;
471 .sort(function(a, b){return a-b})
473 for (var i = how_many; i > 0; i--) {
474 // Trimming the global list is a bit more tricky
475 angular.forEach($scope.struct[list[i]], function (d) {
476 angular.forEach( $scope.allcopies, function (l, j) {
477 if (l === d) $scope.allcopies.splice(j,1);
480 delete $scope.struct[list[i]];
493 .controller('EditCtrl',
494 ['$scope','$q','$routeParams','$location','$timeout','egCore','egNet','egGridDataProvider','itemSvc',
495 function($scope , $q , $routeParams , $location , $timeout , egCore , egNet , egGridDataProvider , itemSvc) {
497 $scope.defaults = { // If defaults are not set at all, allow everything
501 loan_duration : true,
506 deposit_amount : true,
510 mint_condition : true,
513 circ_modifier : true,
521 $scope.saveDefaults = function () {
522 egCore.hatch.setItem('cat.copy.defaults', $scope.defaults);
525 $scope.fetchDefaults = function () {
526 egCore.hatch.getItem('cat.copy.defaults').then(function(t) {
529 if (!$scope.batch) $scope.batch = {};
530 $scope.batch.classification = $scope.defaults.classification;
531 $scope.batch.prefix = $scope.defaults.prefix;
532 $scope.batch.suffix = $scope.defaults.suffix;
533 $scope.working.statcat_filter = $scope.defaults.statcat_filter;
534 if ($scope.defaults.always_vols) $scope.show_vols = true;
538 $scope.fetchDefaults();
540 $scope.dirty = false;
542 $scope.show_vols = true;
543 $scope.show_copies = true;
545 $scope.tracker = function (x,f) { if (x) return x[f]() };
546 $scope.idTracker = function (x) { if (x) return $scope.tracker(x,'id') };
547 $scope.cant_have_vols = function (id) { return !egCore.org.CanHaveVolumes(id); };
549 $scope.orgById = function (id) { return egCore.org.get(id) }
550 $scope.statusById = function (id) {
551 return $scope.status_list.filter( function (s) { return s.id() == id } )[0];
553 $scope.locationById = function (id) {
554 return $scope.location_cache[''+id];
557 $scope.workingToComplete = function () {
558 angular.forEach( $scope.workingGridControls.selectedItems(), function (c) {
559 angular.forEach( itemSvc.copies, function (w, i) {
561 $scope.completed_copies = $scope.completed_copies.concat(itemSvc.copies.splice(i,1));
566 $scope.completeToWorking = function () {
567 angular.forEach( $scope.completedGridControls.selectedItems(), function (c) {
568 angular.forEach( $scope.completed_copies, function (w, i) {
570 itemSvc.copies = itemSvc.copies.concat($scope.completed_copies.splice(i,1));
575 createSimpleUpdateWatcher = function (field) {
576 return $scope.$watch('working.' + field, function () {
577 var newval = $scope.working[field];
579 if (typeof newval != 'undefined') {
580 if (angular.isObject(newval)) { // we'll use the pkey
581 if (newval.id) newval = newval.id();
582 else if (newval.code) newval = newval.code();
585 if (""+newval == "" || newval == null) {
586 $scope.working[field] = undefined;
590 if ($scope.workingGridControls && $scope.workingGridControls.selectedItems) {
592 $scope.workingGridControls.selectedItems(),
593 function (cp) { cp[field](newval); cp.ischanged(1); }
602 statcat_filter: undefined
605 $scope.statcatUpdate = function (id) {
606 var newval = $scope.working.statcats[id];
608 if (typeof newval != 'undefined') {
609 if (angular.isObject(newval)) { // we'll use the pkey
610 newval = newval.id();
613 if (""+newval == "" || newval == null) {
614 $scope.working.statcats[id] = undefined;
618 if (!$scope.in_item_select && $scope.workingGridControls && $scope.workingGridControls.selectedItems) {
620 $scope.workingGridControls.selectedItems(),
623 angular.forEach( cp.stat_cat_entries(), function (e) {
624 if (e.stat_cat() == id) { // mark deleted
631 var e = new egCore.idl.ascecm();
633 e.owning_copy( cp.id() );
635 e.stat_cat_entry( newval );
638 cp.stat_cat_entries().concat([ e ])
643 cp.stat_cat_entries( // trim out ephemeral deleted ones
644 cp.stat_cat_entries().filter(function (e) {
645 if (Boolean(e.isnew())) {
646 if (Boolean(e.isdeleted())) {
661 $scope.applyTemplate = function (n) {
662 angular.forEach($scope.templates[n], function (v,k) {
663 if (!angular.isObject(v)) {
664 $scope.working[k] = angular.copy(v);
666 angular.forEach(v, function (sv,sk) {
667 $scope.working[k][sk] = angular.copy(sv);
668 if (k == 'statcats') $scope.statcatUpdate(sk);
674 var dataKey = $routeParams.dataKey;
675 console.debug('dataKey: ' + dataKey);
677 if (dataKey && dataKey.length > 0) {
679 $scope.templates = {};
680 $scope.template_name = '';
681 $scope.template_name_list = [];
683 $scope.fetchTemplates = function () {
684 egCore.hatch.getItem('cat.copy.templates').then(function(t) {
686 $scope.templates = t;
687 $scope.template_name_list = Object.keys(t);
691 $scope.fetchTemplates();
693 $scope.copytab = 'working';
695 $scope.summaryRecord = null;
696 $scope.record_id = null;
698 $scope.completed_copies = [];
699 $scope.location_orgs = [];
700 $scope.location_cache = {};
701 $scope.statcats = [];
702 if (!$scope.batch) $scope.batch = {};
704 $scope.applyBatchCNValues = function () {
705 if ($scope.data.tree) {
706 angular.forEach($scope.data.tree, function(cn_hash) {
707 angular.forEach(cn_hash, function(copies) {
708 angular.forEach(copies, function(cp) {
709 if (typeof $scope.batch.classification != 'undefined' && $scope.batch.classification != '')
710 cp.call_number().label_class($scope.batch.classification);
711 if (typeof $scope.batch.prefix != 'undefined' && $scope.batch.prefix != '')
712 cp.call_number().prefix($scope.batch.prefix);
713 if (typeof $scope.batch.label != 'undefined' && $scope.batch.label != '')
714 cp.call_number().label($scope.batch.label);
715 if (typeof $scope.batch.suffix != 'undefined' && $scope.batch.suffix != '')
716 cp.call_number().suffix($scope.batch.suffix);
723 $scope.clearWorking = function () {
724 angular.forEach($scope.working, function (v,k,o) {
725 if (!angular.isObject(v)) {
726 if (typeof v != 'undefined')
727 $scope.working[k] = undefined;
728 } else if (k != 'circ_lib') {
729 angular.forEach(v, function (sv,sk) {
730 if (typeof v != 'undefined')
731 $scope.working[k][sk] = undefined;
735 $scope.working.circ_lib = undefined; // special
738 $scope.completedGridDataProvider = egGridDataProvider.instance({
739 get : function(offset, count) {
740 //return provider.arrayNotifier(itemSvc.copies, offset, count);
741 return this.arrayNotifier($scope.completed_copies, offset, count);
745 $scope.completedGridControls = {};
747 $scope.workingGridDataProvider = egGridDataProvider.instance({
748 get : function(offset, count) {
749 //return provider.arrayNotifier(itemSvc.copies, offset, count);
750 return this.arrayNotifier(itemSvc.copies, offset, count);
754 $scope.workingGridControls = {};
758 'open-ils.actor.anon_cache.get_value',
759 dataKey, 'edit-these-copies'
760 ).then(function (data) {
763 if (data.hide_vols && !$scope.defaults.always_vols) $scope.show_vols = false;
764 if (data.hide_copies) $scope.show_copies = false;
766 $scope.record_id = data.record_id;
768 if (data.copies && data.copies.length)
769 return itemSvc.fetchIds(data.copies);
771 if (data.raw && data.raw.length) {
773 /* data.raw must be an array of copies with (at least)
774 * the call number fleshed on each. For new copies
775 * create from whole cloth, the id for each should
776 * probably be negative and isnew() should return true.
777 * Each /distinct/ call number must have a distinct id
778 * as well, probably negative also if they're new. Clear?
783 function (cp) { itemSvc.addCopy(cp) }
786 return itemSvc.copies;
790 }).then( function() {
791 $scope.data = itemSvc;
792 $scope.workingGridDataProvider.refresh();
795 $scope.in_item_select = false;
796 $scope.afterItemSelect = function() { $scope.in_item_select = false };
797 $scope.handleItemSelect = function (item_list) {
798 if (item_list && item_list.length > 0) {
799 $scope.in_item_select = true;
801 angular.forEach(Object.keys($scope.defaults.attributes), function (attr) {
804 angular.forEach(item_list, function (item) {
807 if (angular.isObject(v)) {
808 if (v.id) v = v.id();
809 else if (v.code) v = v.code();
815 if (Object.keys(value_hash).length == 1) {
816 if (attr == 'circ_lib') {
817 $scope.working[attr] = egCore.org.get(item_list[0][attr]());
819 $scope.working[attr] = item_list[0][attr]();
822 $scope.working[attr] = undefined;
826 angular.forEach($scope.statcats, function (sc) {
831 angular.forEach(item_list, function (item) {
832 if (item.stat_cat_entries().length > 0) {
833 var right_sc = item.stat_cat_entries().filter(function (e) {
834 return e.stat_cat() == sc.id() && !Boolean(e.isdeleted());
837 if (right_sc.length > 0) {
838 value_hash[right_sc[0].stat_cat_entry()] = right_sc[0].stat_cat_entry();
847 if (!none && Object.keys(value_hash).length == 1) {
848 $scope.working.statcats[sc.id()] = value_hash[Object.keys(value_hash)[0]];
850 $scope.working.statcats[sc.id()] = undefined;
855 $scope.clearWorking();
860 $scope.$watch('data.copies.length', function () {
861 if ($scope.data.copies) {
862 var base_orgs = $scope.data.copies.map(function(cp){
865 $scope.data.copies.map(function(cp){
866 return cp.call_number().owning_lib()
869 [egCore.auth.user().ws_ou()]
870 ).filter(function(e,i,a){
871 return a.lastIndexOf(e) === i;
875 angular.forEach(base_orgs, function(o) {
876 all_orgs = all_orgs.concat( egCore.org.fullPath(o, true) );
879 var final_orgs = all_orgs.filter(function(e,i,a){
880 return a.lastIndexOf(e) === i;
881 }).sort(function(a,b){return b-a});
883 if ($scope.location_orgs.toString() != final_orgs.toString()) {
884 $scope.location_orgs = final_orgs;
885 if ($scope.location_orgs.length) {
886 itemSvc.get_locations($scope.location_orgs).then(function(list){
887 angular.forEach(list, function(l) {
888 $scope.location_cache[ ''+l.id() ] = l;
890 $scope.location_list = list;
893 $scope.statcat_filter_list = [];
894 angular.forEach($scope.location_orgs, function (o) {
895 $scope.statcat_filter_list.push(egCore.org.get(o));
898 itemSvc.get_statcats($scope.location_orgs).then(function(list){
899 $scope.statcats = list;
900 angular.forEach($scope.statcats, function (s) {
903 $scope.working = { statcats: {}, statcat_filter: undefined};
904 if (!$scope.working.statcats)
905 $scope.working.statcats = {};
907 if (!$scope.in_item_select) {
908 $scope.working.statcats[s.id()] = undefined;
910 createStatcatUpdateWatcher(s.id());
912 $scope.in_item_select = false;
918 $scope.workingGridDataProvider.refresh();
921 $scope.suffix_list = [];
922 itemSvc.get_suffixes(egCore.auth.user().ws_ou()).then(function(list){
923 $scope.suffix_list = list;
926 $scope.prefix_list = [];
927 itemSvc.get_prefixes(egCore.auth.user().ws_ou()).then(function(list){
928 $scope.prefix_list = list;
931 $scope.classification_list = [];
932 itemSvc.get_classifications().then(function(list){
933 $scope.classification_list = list;
936 $scope.$watch('completed_copies.length', function () {
937 $scope.completedGridDataProvider.refresh();
940 $scope.location_list = [];
941 itemSvc.get_locations().then(function(list){
942 $scope.location_list = list;
944 createSimpleUpdateWatcher('location');
946 $scope.status_list = [];
947 itemSvc.get_statuses().then(function(list){
948 $scope.status_list = list;
950 createSimpleUpdateWatcher('status');
952 $scope.circ_modifier_list = [];
953 itemSvc.get_circ_mods().then(function(list){
954 $scope.circ_modifier_list = list;
956 createSimpleUpdateWatcher('circ_modifier');
958 $scope.circ_type_list = [];
959 itemSvc.get_circ_types().then(function(list){
960 $scope.circ_type_list = list;
962 createSimpleUpdateWatcher('circ_as_type');
964 $scope.age_protect_list = [];
965 itemSvc.get_age_protects().then(function(list){
966 $scope.age_protect_list = list;
968 createSimpleUpdateWatcher('age_protect');
970 createSimpleUpdateWatcher('circ_lib');
971 createSimpleUpdateWatcher('circulate');
972 createSimpleUpdateWatcher('holdable');
973 createSimpleUpdateWatcher('fine_level');
974 createSimpleUpdateWatcher('loan_duration');
975 createSimpleUpdateWatcher('cost');
976 createSimpleUpdateWatcher('deposit');
977 createSimpleUpdateWatcher('deposit_amount');
978 createSimpleUpdateWatcher('mint_condition');
979 createSimpleUpdateWatcher('opac_visible');
980 createSimpleUpdateWatcher('ref');
986 .directive("egVolTemplate", function () {
990 template: '<div ng-include="'+"'/eg/staff/cat/volcopy/t_attr_edit'"+'"></div>',
992 controller : ['$scope','itemSvc','egCore',
993 function ( $scope , itemSvc , egCore ) {
995 $scope.defaults = { // If defaults are not set at all, allow everything
999 loan_duration : true,
1004 deposit_amount : true,
1005 opac_visible : true,
1008 mint_condition : true,
1011 circ_modifier : true,
1012 circ_as_type : true,
1019 $scope.fetchDefaults = function () {
1020 egCore.hatch.getItem('cat.copy.defaults').then(function(t) {
1022 $scope.defaults = t;
1023 $scope.working.statcat_filter = $scope.defaults.statcat_filter;
1027 $scope.fetchDefaults();
1029 $scope.dirty = false;
1030 $scope.template_controls = true;
1032 $scope.fetchTemplates = function () {
1033 egCore.hatch.getItem('cat.copy.templates').then(function(t) {
1035 $scope.templates = t;
1036 $scope.template_name_list = Object.keys(t);
1040 $scope.fetchTemplates();
1042 $scope.applyTemplate = function (n) {
1043 angular.forEach($scope.templates[n], function (v,k) {
1044 if (!angular.isObject(v)) {
1045 $scope.working[k] = angular.copy(v);
1047 angular.forEach(v, function (sv,sk) {
1048 $scope.working[k][sk] = angular.copy(sv);
1054 $scope.deleteTemplate = function (n) {
1056 delete $scope.templates[n]
1057 $scope.template_name_list = Object.keys($scope.templates);
1058 $scope.template_name = '';
1059 egCore.hatch.setItem('cat.copy.templates', $scope.templates);
1060 $scope.$parent.fetchTemplates();
1064 $scope.saveTemplate = function (n) {
1068 angular.forEach($scope.working, function (v,k) {
1069 if (angular.isObject(v)) { // we'll use the pkey
1070 if (v.id) v = v.id();
1071 else if (v.code) v = v.code();
1077 $scope.templates[n] = tmpl;
1078 $scope.template_name_list = Object.keys($scope.templates);
1080 egCore.hatch.setItem('cat.copy.templates', $scope.templates);
1081 $scope.$parent.fetchTemplates();
1085 $scope.templates = {};
1086 $scope.template_name = '';
1087 $scope.template_name_list = [];
1089 $scope.tracker = function (x,f) { if (x) return x[f]() };
1090 $scope.idTracker = function (x) { if (x) return $scope.tracker(x,'id') };
1091 $scope.cant_have_vols = function (id) { return !egCore.org.CanHaveVolumes(id); };
1093 $scope.orgById = function (id) { return egCore.org.get(id) }
1094 $scope.statusById = function (id) {
1095 return $scope.status_list.filter( function (s) { return s.id() == id } )[0];
1097 $scope.locationById = function (id) {
1098 return $scope.location_cache[''+id];
1101 createSimpleUpdateWatcher = function (field) {
1102 $scope.$watch('working.' + field, function () {
1103 var newval = $scope.working[field];
1105 if (typeof newval != 'undefined') {
1106 $scope.dirty = true;
1107 if (angular.isObject(newval)) { // we'll use the pkey
1108 if (newval.id) $scope.working[field] = newval.id();
1109 else if (newval.code) $scope.working[field] = newval.code();
1112 if (""+newval == "" || newval == null) {
1113 $scope.working[field] = undefined;
1122 statcat_filter: undefined
1125 createStatcatUpdateWatcher = function (id) {
1126 return $scope.$watch('working.statcats[' + id + ']', function () {
1127 if ($scope.working.statcats) {
1128 var newval = $scope.working.statcats[id];
1130 if (typeof newval != 'undefined') {
1131 if (angular.isObject(newval)) { // we'll use the pkey
1132 newval = newval.id();
1135 if (""+newval == "" || newval == null) {
1136 $scope.working.statcats[id] = undefined;
1145 $scope.clearWorking = function () {
1146 angular.forEach($scope.working, function (v,k,o) {
1147 if (!angular.isObject(v)) {
1148 if (typeof v != 'undefined')
1149 $scope.working[k] = undefined;
1150 } else if (k != 'circ_lib') {
1151 angular.forEach(v, function (sv,sk) {
1152 $scope.working[k][sk] = undefined;
1156 $scope.working.circ_lib = undefined; // special
1159 $scope.working = {};
1160 $scope.location_orgs = [];
1161 $scope.location_cache = {};
1163 $scope.location_list = [];
1164 itemSvc.get_locations(
1165 egCore.org.fullPath( egCore.auth.user().ws_ou(), true )
1166 ).then(function(list){
1167 $scope.location_list = list;
1169 createSimpleUpdateWatcher('location');
1171 $scope.statcat_filter_list = egCore.org.fullPath( egCore.auth.user().ws_ou() );
1173 $scope.statcats = [];
1174 itemSvc.get_statcats(
1175 egCore.org.fullPath( egCore.auth.user().ws_ou(), true )
1176 ).then(function(list){
1177 $scope.statcats = list;
1178 angular.forEach($scope.statcats, function (s) {
1180 if (!$scope.working)
1181 $scope.working = { statcats: {}, statcat_filter: undefined};
1182 if (!$scope.working.statcats)
1183 $scope.working.statcats = {};
1185 $scope.working.statcats[s.id()] = undefined;
1186 createStatcatUpdateWatcher(s.id());
1190 $scope.status_list = [];
1191 itemSvc.get_statuses().then(function(list){
1192 $scope.status_list = list;
1194 createSimpleUpdateWatcher('status');
1196 $scope.circ_modifier_list = [];
1197 itemSvc.get_circ_mods().then(function(list){
1198 $scope.circ_modifier_list = list;
1200 createSimpleUpdateWatcher('circ_modifier');
1202 $scope.circ_type_list = [];
1203 itemSvc.get_circ_types().then(function(list){
1204 $scope.circ_type_list = list;
1206 createSimpleUpdateWatcher('circ_as_type');
1208 $scope.age_protect_list = [];
1209 itemSvc.get_age_protects().then(function(list){
1210 $scope.age_protect_list = list;
1212 createSimpleUpdateWatcher('age_protect');
1214 createSimpleUpdateWatcher('circ_lib');
1215 createSimpleUpdateWatcher('circulate');
1216 createSimpleUpdateWatcher('holdable');
1217 createSimpleUpdateWatcher('fine_level');
1218 createSimpleUpdateWatcher('loan_duration');
1219 createSimpleUpdateWatcher('cost');
1220 createSimpleUpdateWatcher('deposit');
1221 createSimpleUpdateWatcher('deposit_amount');
1222 createSimpleUpdateWatcher('mint_condition');
1223 createSimpleUpdateWatcher('opac_visible');
1224 createSimpleUpdateWatcher('ref');