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) {
37 tree : {}, // holds lib->cn->copy hash stack
38 copies : [] // raw copy list
41 // returns a promise resolved with the list of circ mods
42 service.get_classifications = function() {
44 return $q.when(egCore.env.acnc.list);
46 return egCore.pcrud.retrieveAll('acnc', null, {atomic : true})
47 .then(function(list) {
48 egCore.env.absorbList(list, 'acnc');
53 service.get_prefixes = function(org) {
54 return egCore.pcrud.search('acnp',
55 {owning_lib : egCore.org.fullPath(org, true)},
61 service.get_statcats = function(orgs) {
62 return egCore.pcrud.search('asc',
66 asc : ['owner','entries']
73 service.get_locations = function(orgs) {
74 return egCore.pcrud.search('acpl',
80 service.get_suffixes = function(org) {
81 return egCore.pcrud.search('acns',
82 {owning_lib : egCore.org.fullPath(org, true)},
88 service.get_statuses = function() {
90 return $q.when(egCore.env.ccs.list);
92 return egCore.pcrud.retrieveAll('ccs', {}, {atomic : true}).then(
94 egCore.env.absorbList(list, 'ccs');
101 service.get_circ_mods = function() {
103 return $q.when(egCore.env.ccm.list);
105 return egCore.pcrud.retrieveAll('ccm', {}, {atomic : true}).then(
107 egCore.env.absorbList(list, 'ccm');
114 service.get_circ_types = function() {
116 return $q.when(egCore.env.citm.list);
118 return egCore.pcrud.retrieveAll('citm', {}, {atomic : true}).then(
120 egCore.env.absorbList(list, 'citm');
127 service.get_age_protects = function() {
128 if (egCore.env.crahp)
129 return $q.when(egCore.env.crahp.list);
131 return egCore.pcrud.retrieveAll('crahp', {}, {atomic : true}).then(
133 egCore.env.absorbList(list, 'crahp');
140 service.bmp_parts = {};
141 service.get_parts = function(rec) {
142 if (service.bmp_parts[rec])
143 return $q.when(service.bmp_parts[rec]);
145 return egCore.pcrud.search('bmp',
147 null, {atomic : true}
148 ).then(function(list) {
149 service.bmp_parts[rec] = list;
158 acp : ['call_number','parts','stat_cat_entries', 'notes'],
159 acn : ['label_class','prefix','suffix']
163 service.addCopy = function (cp) {
165 if (!cp.parts()) cp.parts([]); // just in case...
167 var lib = cp.call_number().owning_lib();
168 var cn = cp.call_number().id();
170 if (!service.tree[lib]) service.tree[lib] = {};
171 if (!service.tree[lib][cn]) service.tree[lib][cn] = [];
173 service.tree[lib][cn].push(cp);
174 service.copies.push(cp);
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,
182 service.addCopy(copy);
190 .directive("egVolCopyEdit", function () {
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()"/>'+
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>'+
205 scope: { focusNext: "=", copy: "=", callNumber: "=", index: "@" },
206 controller : ['$scope','itemSvc','egCore',
207 function ( $scope , itemSvc , egCore ) {
208 $scope.new_part_id = 0;
210 $scope.nextBarcode = function (i) {
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 () {
218 var p = $scope.part_list.filter(function (x) {
219 return x.label() == $scope.part
221 if (p.length > 0) { // preexisting part
223 } else { // create one...
224 var part = new egCore.idl.bmp();
225 part.id( --$scope.new_part_id );
227 part.label( $scope.part );
228 part.record( $scope.callNumber.owning_lib() );
229 $scope.copy.parts([part]);
230 $scope.copy.ischanged(1);
233 $scope.copy.parts([]);
236 $scope.$watch('part', $scope.updatePart);
238 $scope.barcode = $scope.copy.barcode();
239 $scope.copy_number = $scope.copy.copy_number();
241 if ($scope.copy.parts()) {
242 $scope.part = $scope.copy.parts()[0];
243 if ($scope.part) $scope.part = $scope.part.label();
247 $scope.part_list = [];
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);
261 .directive("egVolRow", function () {
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)"/>'+
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)"/>'+
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)"/>'+
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>'+
284 scope: {focusNext: "=", allcopies: "=", copies: "=" },
285 controller : ['$scope','itemSvc','egCore',
286 function ( $scope , itemSvc , egCore ) {
287 $scope.callNumber = $scope.copies[0].call_number();
289 $scope.idTracker = function (x) { if (x && x.id) return x.id() };
291 // XXX $() is not working! arg
292 $scope.focusNextBarcode = function (i) {
295 angular.forEach($scope.copies, function (cp) {
303 if (yep) n = cp.id();
307 var next = '#' + $scope.callNumber.id() + '_' + n;
311 $scope.focusNext($scope.callNumber.id())
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) {
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);
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) {
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);
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) {
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);
366 $scope.updateLabel = function () {
367 angular.forEach($scope.copies, function(cp) {
368 cp.call_number().label($scope.label);
369 cp.call_number().ischanged(1);
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( --itemSvc.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 if ($scope.copy_count >= $scope.orig_copy_count) {
397 var how_many = $scope.copies.length - $scope.copy_count;
399 var dead = $scope.copies.splice($scope.copy_count,how_many);
400 $scope.callNumber.copies($scope.copies);
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);
418 .directive("egVolEdit", function () {
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">'+
428 'ng-repeat="(cn,copies) in struct | orderBy:cn track by cn" '+
429 'focus-next="focusNextFirst" copies="copies" allcopies="allcopies">'+
434 scope: { focusNext: "=", allcopies: "=", struct: "=", lib: "@", record: "@" },
435 controller : ['$scope','itemSvc','egCore',
436 function ( $scope , itemSvc , egCore ) {
437 $scope.first_cn = Object.keys($scope.struct)[0];
438 $scope.full_cn = $scope.struct[$scope.first_cn][0].call_number();
440 $scope.defaults = {};
441 egCore.hatch.getItem('cat.copy.defaults').then(function(t) {
447 $scope.focusNextFirst = function(prev_cn) {
450 angular.forEach(Object.keys($scope.struct).sort(), function (cn) {
451 console.log('checking '+cn);
455 console.log('prev is '+cn);
459 console.log('prev is not '+cn);
464 console.log('found '+n);
466 var next = '#' + n + '_' + $scope.struct[n][0].id();
470 $scope.focusNext($scope.lib);
474 $scope.cn_count = Object.keys($scope.struct).length;
475 $scope.orig_cn_count = $scope.cn_count;
477 $scope.owning_lib = egCore.org.get($scope.lib);
478 $scope.$watch('owning_lib', function (l) {
479 angular.forEach( $scope.struct[$scope.first_cn], function (cp) {
480 cp.call_number().owning_lib( $scope.owning_lib.id() );
484 $scope.cant_have_vols = function (id) { return !egCore.org.CanHaveVolumes(id); };
486 $scope.$watch('cn_count', function (n) {
487 var o = Object.keys($scope.struct).length;
488 if (n > o) { // adding
489 for (var i = o; o < n; o++) {
490 var cn = new egCore.idl.acn();
491 cn.id( --itemSvc.new_cn_id );
493 cn.prefix( $scope.defaults.prefix || -1 );
494 cn.suffix( $scope.defaults.suffix || -1 );
495 cn.label_class( $scope.defaults.classification || 1 );
496 cn.owning_lib( $scope.owning_lib.id() );
497 cn.record( $scope.full_cn.record() );
499 var cp = new egCore.idl.acp();
500 cp.call_number( cn );
501 cp.id( --itemSvc.new_cp_id );
506 cp.deposit_amount(0);
507 cp.fine_level(2); // Normal
508 cp.loan_duration(2); // Normal
509 cp.location(1); // Stacks
512 cp.opac_visible('t');
514 cp.mint_condition('t');
516 cp.circ_lib( $scope.owning_lib.id() );
517 cp.call_number( cn );
519 $scope.struct[cn.id()] = [cp];
520 $scope.allcopies.push(cp);
522 } else if (n < o && n >= $scope.orig_cn_count) { // removing
523 var how_many = o - n;
526 .sort(function(a, b){return parseInt(a)-parseInt(b)})
527 .filter(function(x){ return parseInt(x) <= 0 });
528 for (var i = 0; i < how_many; i++) {
529 // Trimming the global list is a bit more tricky
530 console.log('trying to trim ' + i);
531 angular.forEach($scope.struct[list[i]], function (d) {
532 angular.forEach( $scope.allcopies, function (l, j) {
533 if (l === d) $scope.allcopies.splice(j,1);
536 delete $scope.struct[list[i]];
549 .controller('EditCtrl',
550 ['$scope','$q','$window','$routeParams','$location','$timeout','egCore','egNet','egGridDataProvider','itemSvc','$modal',
551 function($scope , $q , $window , $routeParams , $location , $timeout , egCore , egNet , egGridDataProvider , itemSvc , $modal) {
553 $scope.defaults = { // If defaults are not set at all, allow everything
558 loan_duration : true,
563 deposit_amount : true,
567 mint_condition : true,
570 circ_modifier : true,
578 $scope.saveDefaults = function () {
579 egCore.hatch.setItem('cat.copy.defaults', $scope.defaults);
582 $scope.fetchDefaults = function () {
583 egCore.hatch.getItem('cat.copy.defaults').then(function(t) {
586 if (!$scope.batch) $scope.batch = {};
587 $scope.batch.classification = $scope.defaults.classification;
588 $scope.batch.prefix = $scope.defaults.prefix;
589 $scope.batch.suffix = $scope.defaults.suffix;
590 $scope.working.statcat_filter = $scope.defaults.statcat_filter;
591 if ($scope.defaults.always_vols) $scope.show_vols = true;
595 $scope.fetchDefaults();
597 $scope.dirty = false;
598 $scope.$watch('dirty',
599 function(newVal, oldVal) {
600 if (newVal && newVal != oldVal) {
601 $($window).on('beforeunload.edit', function(){
602 return 'There is unsaved data!'
605 $($window).off('beforeunload.edit');
610 $scope.show_vols = true;
611 $scope.show_copies = true;
613 $scope.tracker = function (x,f) { if (x) return x[f]() };
614 $scope.idTracker = function (x) { if (x) return $scope.tracker(x,'id') };
615 $scope.cant_have_vols = function (id) { return !egCore.org.CanHaveVolumes(id); };
617 $scope.orgById = function (id) { return egCore.org.get(id) }
618 $scope.statusById = function (id) {
619 return $scope.status_list.filter( function (s) { return s.id() == id } )[0];
621 $scope.locationById = function (id) {
622 return $scope.location_cache[''+id];
625 $scope.workingToComplete = function () {
626 angular.forEach( $scope.workingGridControls.selectedItems(), function (c) {
627 angular.forEach( itemSvc.copies, function (w, i) {
629 $scope.completed_copies = $scope.completed_copies.concat(itemSvc.copies.splice(i,1));
634 $scope.completeToWorking = function () {
635 angular.forEach( $scope.completedGridControls.selectedItems(), function (c) {
636 angular.forEach( $scope.completed_copies, function (w, i) {
638 itemSvc.copies = itemSvc.copies.concat($scope.completed_copies.splice(i,1));
643 createSimpleUpdateWatcher = function (field) {
644 return $scope.$watch('working.' + field, function () {
645 var newval = $scope.working[field];
647 if (typeof newval != 'undefined') {
648 if (angular.isObject(newval)) { // we'll use the pkey
649 if (newval.id) newval = newval.id();
650 else if (newval.code) newval = newval.code();
653 if (""+newval == "" || newval == null) {
654 $scope.working[field] = undefined;
658 if ($scope.workingGridControls && $scope.workingGridControls.selectedItems) {
660 $scope.workingGridControls.selectedItems(),
662 if (cp[field]() !== newval) {
676 statcat_filter: undefined
679 $scope.statcatUpdate = function (id) {
680 var newval = $scope.working.statcats[id];
682 if (typeof newval != 'undefined') {
683 if (angular.isObject(newval)) { // we'll use the pkey
684 newval = newval.id();
687 if (""+newval == "" || newval == null) {
688 $scope.working.statcats[id] = undefined;
692 if (!$scope.in_item_select && $scope.workingGridControls && $scope.workingGridControls.selectedItems) {
694 $scope.workingGridControls.selectedItems(),
699 angular.forEach( cp.stat_cat_entries(), function (e) {
700 if (e.stat_cat() == id) { // mark deleted
707 var e = new egCore.idl.ascecm();
709 e.owning_copy( cp.id() );
711 e.stat_cat_entry( newval );
714 cp.stat_cat_entries().concat([ e ])
719 cp.stat_cat_entries( // trim out ephemeral deleted ones
720 cp.stat_cat_entries().filter(function (e) {
721 if (Boolean(e.isnew())) {
722 if (Boolean(e.isdeleted())) {
737 var dataKey = $routeParams.dataKey;
738 console.debug('dataKey: ' + dataKey);
740 if (dataKey && dataKey.length > 0) {
742 $scope.templates = {};
743 $scope.template_name = '';
744 $scope.template_name_list = [];
746 $scope.fetchTemplates = function () {
747 egCore.hatch.getItem('cat.copy.templates').then(function(t) {
749 $scope.templates = t;
750 $scope.template_name_list = Object.keys(t);
754 $scope.fetchTemplates();
756 $scope.applyTemplate = function (n) {
757 angular.forEach($scope.templates[n], function (v,k) {
758 if (!angular.isObject(v)) {
759 $scope.working[k] = angular.copy(v);
761 angular.forEach(v, function (sv,sk) {
762 if (k == 'callnumber') {
763 angular.forEach(v, function (cnv,cnk) {
764 $scope.batch[cnk] = cnv;
766 $scope.applyBatchCNValues();
768 $scope.working[k][sk] = angular.copy(sv);
769 if (k == 'statcats') $scope.statcatUpdate(sk);
774 $scope.template_name = '';
777 $scope.copytab = 'working';
779 $scope.summaryRecord = null;
780 $scope.record_id = null;
782 $scope.completed_copies = [];
783 $scope.location_orgs = [];
784 $scope.location_cache = {};
785 $scope.statcats = [];
786 if (!$scope.batch) $scope.batch = {};
788 $scope.applyBatchCNValues = function () {
789 if ($scope.data.tree) {
790 angular.forEach($scope.data.tree, function(cn_hash) {
791 angular.forEach(cn_hash, function(copies) {
792 angular.forEach(copies, function(cp) {
793 if (typeof $scope.batch.classification != 'undefined' && $scope.batch.classification != '')
794 cp.call_number().label_class($scope.batch.classification);
796 if (typeof $scope.batch.prefix != 'undefined' && $scope.batch.prefix != '')
797 cp.call_number().prefix($scope.batch.prefix);
799 if (typeof $scope.batch.label != 'undefined' && $scope.batch.label != '')
800 cp.call_number().label($scope.batch.label);
802 if (typeof $scope.batch.suffix != 'undefined' && $scope.batch.suffix != '')
803 cp.call_number().suffix($scope.batch.suffix);
811 $scope.clearWorking = function () {
812 angular.forEach($scope.working, function (v,k,o) {
813 if (!angular.isObject(v)) {
814 if (typeof v != 'undefined')
815 $scope.working[k] = undefined;
816 } else if (k != 'circ_lib') {
817 angular.forEach(v, function (sv,sk) {
818 if (typeof v != 'undefined')
819 $scope.working[k][sk] = undefined;
823 $scope.working.circ_lib = undefined; // special
826 $scope.completedGridDataProvider = egGridDataProvider.instance({
827 get : function(offset, count) {
828 //return provider.arrayNotifier(itemSvc.copies, offset, count);
829 return this.arrayNotifier($scope.completed_copies, offset, count);
833 $scope.completedGridControls = {};
835 $scope.workingGridDataProvider = egGridDataProvider.instance({
836 get : function(offset, count) {
837 //return provider.arrayNotifier(itemSvc.copies, offset, count);
838 return this.arrayNotifier(itemSvc.copies, offset, count);
842 $scope.workingGridControls = {};
843 $scope.add_vols_copies = false;
847 'open-ils.actor.anon_cache.get_value',
848 dataKey, 'edit-these-copies'
849 ).then(function (data) {
852 if (data.hide_vols && !$scope.defaults.always_vols) $scope.show_vols = false;
853 if (data.hide_copies) $scope.show_copies = false;
855 $scope.record_id = data.record_id;
857 if (data.copies && data.copies.length)
858 return itemSvc.fetchIds(data.copies);
860 if (data.raw && data.raw.length) {
862 $scope.add_vols_copies = true;
864 /* data.raw data structure looks like this:
866 * callnumber : $cn_id, // optional, to add a copy to a cn
867 * owner : $org, // optional, defaults to ws_ou
868 * label : $cn_label, // optional, to supply a label on a new cn
869 * barcode : $cp_barcode // optional, to supply a barcode on a new cp
872 * All can be left out and a completely empty vol/copy combo will be vivicated.
878 if (proto.callnumber) {
879 return egCore.pcrud.retrieve('acn', proto.callnumber)
881 var cp = new egCore.idl.acp();
882 cp.call_number( cn );
883 cp.id( --itemSvc.new_cp_id );
885 cp.circ_lib( proto.owner || egCore.auth.user().ws_ou() );
889 cp.deposit_amount(0);
890 cp.fine_level(2); // Normal
891 cp.loan_duration(2); // Normal
892 cp.location(1); // Stacks
895 cp.opac_visible('t');
897 cp.mint_condition('t');
899 if (proto.barcode) cp.barcode( proto.barcode );
904 var cn = new egCore.idl.acn();
905 cn.id( --itemSvc.new_cn_id );
907 cn.prefix( $scope.defaults.prefix || -1 );
908 cn.suffix( $scope.defaults.suffix || -1 );
909 cn.label_class( $scope.defaults.classification || 1 );
910 cn.owning_lib( proto.owner || egCore.auth.user().ws_ou() );
911 cn.record( $scope.record_id );
912 if (proto.label) cn.label( proto.label );
914 var cp = new egCore.idl.acp();
915 cp.call_number( cn );
916 cp.id( --itemSvc.new_cp_id );
921 cp.deposit_amount(0);
922 cp.fine_level(2); // Normal
923 cp.loan_duration(2); // Normal
924 cp.location(1); // Stacks
927 cp.opac_visible('t');
929 cp.mint_condition('t');
931 cp.circ_lib( proto.owner || egCore.auth.user().ws_ou() );
932 if (proto.barcode) cp.barcode( proto.barcode );
940 return itemSvc.copies;
944 }).then( function() {
945 $scope.data = itemSvc;
946 if ($scope.add_vols_copies) {
947 egCore.org.settings([
948 'cat.default_copy_status_fast'
949 ]).then(function(set) {
950 $scope.fast_ccs = set['cat.default_copy_status_fast'] || 0;
951 angular.forEach($scope.data.copies, function (cp) {
952 cp.status($scope.fast_ccs);
954 $scope.workingGridDataProvider.refresh();
959 $scope.focusNextFirst = function(prev_lib) {
962 angular.forEach(Object.keys($scope.data.tree).sort(), function (lib) {
963 console.log('checking lib '+lib);
966 if (lib == prev_lib) {
967 console.log('prev is '+lib);
971 console.log('prev is not '+lib);
976 console.log('found '+n);
978 var first_cn = Object.keys($scope.data.tree[n])[0];
979 var next = '#' + first_cn + '_' + $scope.data.tree[n][first_cn][0].id();
983 $scope.focusNext($scope.lib);
987 $scope.in_item_select = false;
988 $scope.afterItemSelect = function() { $scope.in_item_select = false };
989 $scope.handleItemSelect = function (item_list) {
990 if (item_list && item_list.length > 0) {
991 $scope.in_item_select = true;
993 angular.forEach(Object.keys($scope.defaults.attributes), function (attr) {
996 angular.forEach(item_list, function (item) {
999 if (angular.isObject(v)) {
1000 if (v.id) v = v.id();
1001 else if (v.code) v = v.code();
1007 if (Object.keys(value_hash).length == 1) {
1008 if (attr == 'circ_lib') {
1009 $scope.working[attr] = egCore.org.get(item_list[0][attr]());
1011 $scope.working[attr] = item_list[0][attr]();
1014 $scope.working[attr] = undefined;
1018 angular.forEach($scope.statcats, function (sc) {
1021 var value_hash = {};
1023 angular.forEach(item_list, function (item) {
1024 if (item.stat_cat_entries()) {
1025 if (item.stat_cat_entries().length > 0) {
1026 var right_sc = item.stat_cat_entries().filter(function (e) {
1027 return e.stat_cat() == sc.id() && !Boolean(e.isdeleted());
1030 if (right_sc.length > 0) {
1031 value_hash[right_sc[0].stat_cat_entry()] = right_sc[0].stat_cat_entry();
1041 if (!none && Object.keys(value_hash).length == 1) {
1042 $scope.working.statcats[sc.id()] = value_hash[Object.keys(value_hash)[0]];
1044 $scope.working.statcats[sc.id()] = undefined;
1049 $scope.clearWorking();
1054 $scope.$watch('data.copies.length', function () {
1055 if ($scope.data.copies) {
1056 var base_orgs = $scope.data.copies.map(function(cp){
1057 return cp.circ_lib()
1059 $scope.data.copies.map(function(cp){
1060 return cp.call_number().owning_lib()
1063 [egCore.auth.user().ws_ou()]
1064 ).filter(function(e,i,a){
1065 return a.lastIndexOf(e) === i;
1069 angular.forEach(base_orgs, function(o) {
1070 all_orgs = all_orgs.concat( egCore.org.fullPath(o, true) );
1073 var final_orgs = all_orgs.filter(function(e,i,a){
1074 return a.lastIndexOf(e) === i;
1075 }).sort(function(a, b){return parseInt(a)-parseInt(b)});
1077 if ($scope.location_orgs.toString() != final_orgs.toString()) {
1078 $scope.location_orgs = final_orgs;
1079 if ($scope.location_orgs.length) {
1080 itemSvc.get_locations($scope.location_orgs).then(function(list){
1081 angular.forEach(list, function(l) {
1082 $scope.location_cache[ ''+l.id() ] = l;
1084 $scope.location_list = list;
1087 $scope.statcat_filter_list = [];
1088 angular.forEach($scope.location_orgs, function (o) {
1089 $scope.statcat_filter_list.push(egCore.org.get(o));
1092 itemSvc.get_statcats($scope.location_orgs).then(function(list){
1093 $scope.statcats = list;
1094 angular.forEach($scope.statcats, function (s) {
1096 if (!$scope.working)
1097 $scope.working = { statcats: {}, statcat_filter: undefined};
1098 if (!$scope.working.statcats)
1099 $scope.working.statcats = {};
1101 if (!$scope.in_item_select) {
1102 $scope.working.statcats[s.id()] = undefined;
1104 createStatcatUpdateWatcher(s.id());
1106 $scope.in_item_select = false;
1112 $scope.workingGridDataProvider.refresh();
1115 $scope.suffix_list = [];
1116 itemSvc.get_suffixes(egCore.auth.user().ws_ou()).then(function(list){
1117 $scope.suffix_list = list;
1120 $scope.prefix_list = [];
1121 itemSvc.get_prefixes(egCore.auth.user().ws_ou()).then(function(list){
1122 $scope.prefix_list = list;
1125 $scope.classification_list = [];
1126 itemSvc.get_classifications().then(function(list){
1127 $scope.classification_list = list;
1130 $scope.$watch('completed_copies.length', function () {
1131 $scope.completedGridDataProvider.refresh();
1134 $scope.location_list = [];
1135 itemSvc.get_locations().then(function(list){
1136 $scope.location_list = list;
1138 createSimpleUpdateWatcher('location');
1140 $scope.status_list = [];
1141 itemSvc.get_statuses().then(function(list){
1142 $scope.status_list = list;
1144 createSimpleUpdateWatcher('status');
1146 $scope.circ_modifier_list = [];
1147 itemSvc.get_circ_mods().then(function(list){
1148 $scope.circ_modifier_list = list;
1150 createSimpleUpdateWatcher('circ_modifier');
1152 $scope.circ_type_list = [];
1153 itemSvc.get_circ_types().then(function(list){
1154 $scope.circ_type_list = list;
1156 createSimpleUpdateWatcher('circ_as_type');
1158 $scope.age_protect_list = [];
1159 itemSvc.get_age_protects().then(function(list){
1160 $scope.age_protect_list = list;
1162 createSimpleUpdateWatcher('age_protect');
1164 createSimpleUpdateWatcher('circ_lib');
1165 createSimpleUpdateWatcher('circulate');
1166 createSimpleUpdateWatcher('holdable');
1167 createSimpleUpdateWatcher('fine_level');
1168 createSimpleUpdateWatcher('loan_duration');
1169 createSimpleUpdateWatcher('cost');
1170 createSimpleUpdateWatcher('deposit');
1171 createSimpleUpdateWatcher('deposit_amount');
1172 createSimpleUpdateWatcher('mint_condition');
1173 createSimpleUpdateWatcher('opac_visible');
1174 createSimpleUpdateWatcher('ref');
1176 $scope.saveCompletedCopies = function (and_exit) {
1178 var perCnCopies = {};
1179 angular.forEach( egCore.idl.Clone($scope.completed_copies), function (cp) {
1180 var cn_id = cp.call_number().id();
1181 if (!cnHash[cn_id]) {
1182 cnHash[cn_id] = cp.call_number();
1183 perCnCopies[cn_id] = [cp];
1185 perCnCopies[cn_id].push(cp);
1187 cp.call_number(cn_id); // prevent loops in JSON-ification
1190 angular.forEach(perCnCopies, function (v, k) {
1191 cnHash[k].copies(v);
1195 angular.forEach(cnHash, function (v, k) {
1201 'open-ils.cat.asset.volume.fleshed.batch.update.override',
1202 egCore.auth.token(), cnList, 1, { auto_merge_vols : 1, create_parts : 1 }
1203 ).then(function(update_count) {
1205 $scope.dirty = false;
1206 $timeout(function(){$window.close()});
1211 $scope.saveAndContinue = function () {
1212 $scope.saveCompletedCopies(false);
1215 $scope.saveAndExit = function () {
1216 $scope.saveCompletedCopies(true);
1221 $scope.copy_notes_dialog = function(copy_list) {
1222 var default_pub = Boolean($scope.defaults.copy_notes_pub);
1223 if (!angular.isArray(copy_list)) copy_list = [copy_list];
1225 return $modal.open({
1226 templateUrl: './cat/volcopy/t_copy_notes',
1229 ['$scope','$modalInstance',
1230 function($scope , $modalInstance) {
1231 $scope.focusNote = true;
1233 creator : egCore.auth.user().id(),
1239 $scope.require_initials = false;
1240 egCore.org.settings([
1241 'ui.staff.require_initials.copy_notes'
1242 ]).then(function(set) {
1243 $scope.require_initials = Boolean(set['ui.staff.require_initials.copy_notes']);
1246 $scope.note_list = [];
1247 if (copy_list.length == 1) {
1248 $scope.note_list = copy_list[0].notes();
1251 $scope.ok = function(note) {
1253 if (note.initials) note.value += ' [' + note.initials + ']';
1254 angular.forEach(copy_list, function (cp) {
1255 var n = new egCore.idl.acpn();
1256 n.creator(note.creator);
1258 n.title(note.title);
1259 n.value(note.value);
1260 n.owning_copy(cp.id());
1261 cp.notes().push( n );
1264 $modalInstance.close();
1267 $scope.cancel = function($event) {
1268 $modalInstance.dismiss();
1269 $event.preventDefault();
1277 .directive("egVolTemplate", function () {
1281 template: '<div ng-include="'+"'/eg/staff/cat/volcopy/t_attr_edit'"+'"></div>',
1283 controller : ['$scope','$window','itemSvc','egCore',
1284 function ( $scope , $window , itemSvc , egCore ) {
1286 $scope.defaults = { // If defaults are not set at all, allow everything
1291 loan_duration : true,
1296 deposit_amount : true,
1297 opac_visible : true,
1300 mint_condition : true,
1303 circ_modifier : true,
1304 circ_as_type : true,
1311 $scope.fetchDefaults = function () {
1312 egCore.hatch.getItem('cat.copy.defaults').then(function(t) {
1314 $scope.defaults = t;
1315 $scope.working.statcat_filter = $scope.defaults.statcat_filter;
1319 $scope.fetchDefaults();
1321 $scope.dirty = false;
1322 $scope.$watch('dirty',
1323 function(newVal, oldVal) {
1324 if (newVal && newVal != oldVal) {
1325 $($window).on('beforeunload.template', function(){
1326 return 'There is unsaved template data!'
1329 $($window).off('beforeunload.template');
1334 $scope.template_controls = true;
1336 $scope.fetchTemplates = function () {
1337 egCore.hatch.getItem('cat.copy.templates').then(function(t) {
1339 $scope.templates = t;
1340 $scope.template_name_list = Object.keys(t);
1344 $scope.fetchTemplates();
1346 $scope.applyTemplate = function (n) {
1347 angular.forEach($scope.templates[n], function (v,k) {
1348 if (!angular.isObject(v)) {
1349 $scope.working[k] = angular.copy(v);
1351 angular.forEach(v, function (sv,sk) {
1352 $scope.working[k][sk] = angular.copy(sv);
1356 $scope.template_name = '';
1359 $scope.deleteTemplate = function (n) {
1361 delete $scope.templates[n]
1362 $scope.template_name_list = Object.keys($scope.templates);
1363 $scope.template_name = '';
1364 egCore.hatch.setItem('cat.copy.templates', $scope.templates);
1365 $scope.$parent.fetchTemplates();
1369 $scope.saveTemplate = function (n) {
1373 angular.forEach($scope.working, function (v,k) {
1374 if (angular.isObject(v)) { // we'll use the pkey
1375 if (v.id) v = v.id();
1376 else if (v.code) v = v.code();
1382 $scope.templates[n] = tmpl;
1383 $scope.template_name_list = Object.keys($scope.templates);
1385 egCore.hatch.setItem('cat.copy.templates', $scope.templates);
1386 $scope.$parent.fetchTemplates();
1388 $scope.dirty = false;
1392 $scope.templates = {};
1393 $scope.template_name = '';
1394 $scope.template_name_list = [];
1396 $scope.tracker = function (x,f) { if (x) return x[f]() };
1397 $scope.idTracker = function (x) { if (x) return $scope.tracker(x,'id') };
1398 $scope.cant_have_vols = function (id) { return !egCore.org.CanHaveVolumes(id); };
1400 $scope.orgById = function (id) { return egCore.org.get(id) }
1401 $scope.statusById = function (id) {
1402 return $scope.status_list.filter( function (s) { return s.id() == id } )[0];
1404 $scope.locationById = function (id) {
1405 return $scope.location_cache[''+id];
1408 createSimpleUpdateWatcher = function (field) {
1409 $scope.$watch('working.' + field, function () {
1410 var newval = $scope.working[field];
1412 if (typeof newval != 'undefined') {
1413 $scope.dirty = true;
1414 if (angular.isObject(newval)) { // we'll use the pkey
1415 if (newval.id) $scope.working[field] = newval.id();
1416 else if (newval.code) $scope.working[field] = newval.code();
1419 if (""+newval == "" || newval == null) {
1420 $scope.working[field] = undefined;
1429 statcat_filter: undefined
1432 createStatcatUpdateWatcher = function (id) {
1433 return $scope.$watch('working.statcats[' + id + ']', function () {
1434 if ($scope.working.statcats) {
1435 var newval = $scope.working.statcats[id];
1437 if (typeof newval != 'undefined') {
1438 $scope.dirty = true;
1439 if (angular.isObject(newval)) { // we'll use the pkey
1440 newval = newval.id();
1443 if (""+newval == "" || newval == null) {
1444 $scope.working.statcats[id] = undefined;
1453 $scope.clearWorking = function () {
1454 angular.forEach($scope.working, function (v,k,o) {
1455 if (!angular.isObject(v)) {
1456 if (typeof v != 'undefined')
1457 $scope.working[k] = undefined;
1458 } else if (k != 'circ_lib') {
1459 angular.forEach(v, function (sv,sk) {
1460 $scope.working[k][sk] = undefined;
1464 $scope.working.circ_lib = undefined; // special
1465 $scope.dirty = false;
1468 $scope.working = {};
1469 $scope.location_orgs = [];
1470 $scope.location_cache = {};
1472 $scope.location_list = [];
1473 itemSvc.get_locations(
1474 egCore.org.fullPath( egCore.auth.user().ws_ou(), true )
1475 ).then(function(list){
1476 $scope.location_list = list;
1478 createSimpleUpdateWatcher('location');
1480 $scope.statcat_filter_list = egCore.org.fullPath( egCore.auth.user().ws_ou() );
1482 $scope.statcats = [];
1483 itemSvc.get_statcats(
1484 egCore.org.fullPath( egCore.auth.user().ws_ou(), true )
1485 ).then(function(list){
1486 $scope.statcats = list;
1487 angular.forEach($scope.statcats, function (s) {
1489 if (!$scope.working)
1490 $scope.working = { statcats: {}, statcat_filter: undefined};
1491 if (!$scope.working.statcats)
1492 $scope.working.statcats = {};
1494 $scope.working.statcats[s.id()] = undefined;
1495 createStatcatUpdateWatcher(s.id());
1499 $scope.status_list = [];
1500 itemSvc.get_statuses().then(function(list){
1501 $scope.status_list = list;
1503 createSimpleUpdateWatcher('status');
1505 $scope.circ_modifier_list = [];
1506 itemSvc.get_circ_mods().then(function(list){
1507 $scope.circ_modifier_list = list;
1509 createSimpleUpdateWatcher('circ_modifier');
1511 $scope.circ_type_list = [];
1512 itemSvc.get_circ_types().then(function(list){
1513 $scope.circ_type_list = list;
1515 createSimpleUpdateWatcher('circ_as_type');
1517 $scope.age_protect_list = [];
1518 itemSvc.get_age_protects().then(function(list){
1519 $scope.age_protect_list = list;
1521 createSimpleUpdateWatcher('age_protect');
1523 createSimpleUpdateWatcher('circ_lib');
1524 createSimpleUpdateWatcher('circulate');
1525 createSimpleUpdateWatcher('holdable');
1526 createSimpleUpdateWatcher('fine_level');
1527 createSimpleUpdateWatcher('loan_duration');
1528 createSimpleUpdateWatcher('cost');
1529 createSimpleUpdateWatcher('deposit');
1530 createSimpleUpdateWatcher('deposit_amount');
1531 createSimpleUpdateWatcher('mint_condition');
1532 createSimpleUpdateWatcher('opac_visible');
1533 createSimpleUpdateWatcher('ref');
1535 $scope.suffix_list = [];
1536 itemSvc.get_suffixes(egCore.auth.user().ws_ou()).then(function(list){
1537 $scope.suffix_list = list;
1540 $scope.prefix_list = [];
1541 itemSvc.get_prefixes(egCore.auth.user().ws_ou()).then(function(list){
1542 $scope.prefix_list = list;
1545 $scope.classification_list = [];
1546 itemSvc.get_classifications().then(function(list){
1547 $scope.classification_list = list;
1550 createSimpleUpdateWatcher('working.callnumber.classification');
1551 createSimpleUpdateWatcher('working.callnumber.prefix');
1552 createSimpleUpdateWatcher('working.callnumber.suffix');