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 currently_generating : false,
36 auto_gen_barcode : false,
37 barcode_checkdigit : false,
40 tree : {}, // holds lib->cn->copy hash stack
41 copies : [] // raw copy list
44 service.nextBarcode = function(bc) {
45 service.currently_generating = true;
46 return egCore.net.request(
48 'open-ils.cat.item.barcode.autogen',
50 bc, 1, { checkdigit: service.barcode_checkdigit }
51 ).then(function(resp) { // get_barcodes
52 var evt = egCore.evt.parse(resp);
53 if (!evt) return resp[0];
58 service.checkBarcode = function(bc) {
59 if (!service.barcode_checkdigit) return true;
60 if (bc != Number(bc)) return false;
62 // "16.00" == Number("16.00"), but the . is bad.
63 // Throw out any barcode that isn't just digits
64 if (bc.search(/\D/) != -1) return false;
65 var last_digit = bc.substr(bc.length-1);
66 var stripped_barcode = bc.substr(0,bc.length-1);
67 return service.barcodeCheckdigit(stripped_barcode).toString() == last_digit;
70 service.barcodeCheckdigit = function(bc) {
71 var reverse_barcode = bc.toString().split('').reverse();
72 var check_sum = 0; var multiplier = 2;
73 for (var i = 0; i < reverse_barcode.length; i++) {
74 var digit = reverse_barcode[i];
75 var product = digit * multiplier; product = product.toString();
77 for (var j = 0; j < product.length; j++) {
78 temp_sum += Number( product[j] );
80 check_sum += Number( temp_sum );
81 multiplier = ( multiplier == 2 ? 1 : 2 );
83 check_sum = check_sum.toString();
84 var next_multiple_of_10 = (check_sum.match(/(\d*)\d$/)[1] * 10) + 10;
85 var check_digit = next_multiple_of_10 - Number(check_sum); if (check_digit == 10) check_digit = 0;
89 // returns a promise resolved with the list of circ mods
90 service.get_classifications = function() {
92 return $q.when(egCore.env.acnc.list);
94 return egCore.pcrud.retrieveAll('acnc', null, {atomic : true})
95 .then(function(list) {
96 egCore.env.absorbList(list, 'acnc');
101 service.get_prefixes = function(org) {
102 return egCore.pcrud.search('acnp',
103 {owning_lib : egCore.org.fullPath(org, true)},
104 null, {atomic : true}
109 service.get_statcats = function(orgs) {
110 return egCore.pcrud.search('asc',
114 asc : ['owner','entries']
121 service.get_locations = function(orgs) {
122 return egCore.pcrud.search('acpl',
124 null, {atomic : true}
128 service.get_suffixes = function(org) {
129 return egCore.pcrud.search('acns',
130 {owning_lib : egCore.org.fullPath(org, true)},
131 null, {atomic : true}
136 service.get_statuses = function() {
138 return $q.when(egCore.env.ccs.list);
140 return egCore.pcrud.retrieveAll('ccs', {}, {atomic : true}).then(
142 egCore.env.absorbList(list, 'ccs');
149 service.get_circ_mods = function() {
151 return $q.when(egCore.env.ccm.list);
153 return egCore.pcrud.retrieveAll('ccm', {}, {atomic : true}).then(
155 egCore.env.absorbList(list, 'ccm');
162 service.get_circ_types = function() {
164 return $q.when(egCore.env.citm.list);
166 return egCore.pcrud.retrieveAll('citm', {}, {atomic : true}).then(
168 egCore.env.absorbList(list, 'citm');
175 service.get_age_protects = function() {
176 if (egCore.env.crahp)
177 return $q.when(egCore.env.crahp.list);
179 return egCore.pcrud.retrieveAll('crahp', {}, {atomic : true}).then(
181 egCore.env.absorbList(list, 'crahp');
188 service.bmp_parts = {};
189 service.get_parts = function(rec) {
190 if (service.bmp_parts[rec])
191 return $q.when(service.bmp_parts[rec]);
193 return egCore.pcrud.search('bmp',
194 {record : rec, deleted : 'f'},
195 null, {atomic : true}
196 ).then(function(list) {
197 service.bmp_parts[rec] = list;
206 acp : ['call_number','parts','stat_cat_entries', 'notes'],
207 acn : ['label_class','prefix','suffix']
211 service.addCopy = function (cp) {
213 if (!cp.parts()) cp.parts([]); // just in case...
215 var lib = cp.call_number().owning_lib();
216 var cn = cp.call_number().id();
218 if (!service.tree[lib]) service.tree[lib] = {};
219 if (!service.tree[lib][cn]) service.tree[lib][cn] = [];
221 service.tree[lib][cn].push(cp);
222 service.copies.push(cp);
225 service.fetchIds = function(idList) {
226 service.tree = {}; // clear the tree on fetch
227 service.copies = []; // clear the copy list on fetch
228 return egCore.pcrud.search('acp', { 'id' : idList }, service.flesh).then(null,null,
230 service.addCopy(copy);
238 .directive("egVolCopyEdit", function () {
244 '<div class="col-xs-5" ng-class="{'+"'has-error'"+':barcode_has_error}">'+
245 '<input id="{{callNumber.id()}}_{{copy.id()}}"'+
246 ' eg-enter="nextBarcode(copy.id())" class="form-control"'+
247 ' type="text" ng-model="barcode" ng-change="updateBarcode()"/>'+
249 '<div class="col-xs-3"><input class="form-control" type="number" ng-model="copy_number" ng-change="updateCopyNo()"/></div>'+
250 '<div class="col-xs-4"><eg-basic-combo-box list="parts" selected="part"></eg-basic-combo-box></div>'+
253 scope: { focusNext: "=", copy: "=", callNumber: "=", index: "@" },
254 controller : ['$scope','itemSvc','egCore',
255 function ( $scope , itemSvc , egCore ) {
256 $scope.new_part_id = 0;
257 $scope.barcode_has_error = false;
259 $scope.nextBarcode = function (i) {
260 $scope.focusNext(i, $scope.barcode);
263 $scope.updateBarcode = function () {
264 if ($scope.barcode != '')
265 $scope.barcode_has_error = !Boolean(itemSvc.checkBarcode($scope.barcode));
266 $scope.copy.barcode($scope.barcode);
267 $scope.copy.ischanged(1);
268 if (itemSvc.currently_generating)
269 $scope.focusNext($scope.copy.id(), $scope.barcode);
272 $scope.updateCopyNo = function () { $scope.copy.copy_number($scope.copy_number); $scope.copy.ischanged(1); };
273 $scope.updatePart = function () {
275 var p = $scope.part_list.filter(function (x) {
276 return x.label() == $scope.part
278 if (p.length > 0) { // preexisting part
280 } else { // create one...
281 var part = new egCore.idl.bmp();
282 part.id( --$scope.new_part_id );
284 part.label( $scope.part );
285 part.record( $scope.callNumber.owning_lib() );
286 $scope.copy.parts([part]);
287 $scope.copy.ischanged(1);
290 $scope.copy.parts([]);
293 $scope.$watch('part', $scope.updatePart);
295 $scope.barcode = $scope.copy.barcode();
296 $scope.copy_number = $scope.copy.copy_number();
298 if ($scope.copy.parts()) {
299 $scope.part = $scope.copy.parts()[0];
300 if ($scope.part) $scope.part = $scope.part.label();
304 $scope.part_list = [];
306 itemSvc.get_parts($scope.callNumber.record()).then(function(list){
307 $scope.part_list = list;
308 angular.forEach(list, function(p){ $scope.parts.push(p.label()) });
309 $scope.parts = angular.copy($scope.parts);
318 .directive("egVolRow", function () {
325 '<div class="col-xs-2">'+
326 '<select class="form-control" ng-model="classification" ng-options="cl.name() for cl in classification_list track by idTracker(cl)"/>'+
328 '<div class="col-xs-1">'+
329 '<select class="form-control" ng-model="prefix" ng-change="updatePrefix()" ng-options="p.label() for p in prefix_list track by idTracker(p)"/>'+
331 '<div class="col-xs-2"><input class="form-control" type="text" ng-change="updateLabel()" ng-model="label"/></div>'+
332 '<div class="col-xs-1">'+
333 '<select class="form-control" ng-model="suffix" ng-change="updateSuffix()" ng-options="s.label() for s in suffix_list track by idTracker(s)"/>'+
335 '<div ng-hide="onlyVols" class="col-xs-1"><input class="form-control" type="number" ng-model="copy_count" min="{{orig_copy_count}}" ng-change="changeCPCount()"></div>'+
336 '<div ng-hide="onlyVols" class="col-xs-5">'+
337 '<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>'+
341 scope: {focusNext: "=", allcopies: "=", copies: "=", onlyVols: "=" },
342 controller : ['$scope','itemSvc','egCore',
343 function ( $scope , itemSvc , egCore ) {
344 $scope.callNumber = $scope.copies[0].call_number();
346 $scope.idTracker = function (x) { if (x && x.id) return x.id() };
348 // XXX $() is not working! arg
349 $scope.focusNextBarcode = function (i, prev_bc) {
352 angular.forEach($scope.copies, function (cp) {
360 if (yep) n = cp.id();
364 var next = '#' + $scope.callNumber.id() + '_' + n;
367 if (!itemSvc.currently_generating) el.focus();
368 if (prev_bc && itemSvc.auto_gen_barcode && el.val() == "") {
369 itemSvc.nextBarcode(prev_bc).then(function(bc){
372 el.trigger('change');
375 itemSvc.currently_generating = false;
379 $scope.focusNext($scope.callNumber.id(),prev_bc)
383 $scope.suffix_list = [];
384 itemSvc.get_suffixes($scope.callNumber.owning_lib()).then(function(list){
385 $scope.suffix_list = list;
386 $scope.$watch('callNumber.suffix()', function (v) {
387 $scope.suffix = $scope.suffix_list.filter( function (s) {
393 $scope.updateSuffix = function () {
394 angular.forEach($scope.copies, function(cp) {
395 cp.call_number().suffix($scope.suffix.id());
396 cp.call_number().ischanged(1);
400 $scope.prefix_list = [];
401 itemSvc.get_prefixes($scope.callNumber.owning_lib()).then(function(list){
402 $scope.prefix_list = list;
403 $scope.$watch('callNumber.prefix()', function (v) {
404 $scope.prefix = $scope.prefix_list.filter(function (p) {
410 $scope.updatePrefix = function () {
411 angular.forEach($scope.copies, function(cp) {
412 cp.call_number().prefix($scope.prefix.id());
413 cp.call_number().ischanged(1);
417 $scope.classification_list = [];
418 itemSvc.get_classifications().then(function(list){
419 $scope.classification_list = list;
420 $scope.$watch('callNumber.label_class()', function (v) {
421 $scope.classification = $scope.classification_list.filter(function (c) {
427 $scope.updateClassification = function () {
428 angular.forEach($scope.copies, function(cp) {
429 cp.call_number().label_class($scope.classification.id());
430 cp.call_number().ischanged(1);
434 $scope.updateLabel = function () {
435 angular.forEach($scope.copies, function(cp) {
436 cp.call_number().label($scope.label);
437 cp.call_number().ischanged(1);
441 $scope.$watch('callNumber.label()', function (v) {
445 $scope.prefix = $scope.callNumber.prefix();
446 $scope.suffix = $scope.callNumber.suffix();
447 $scope.classification = $scope.callNumber.label_class();
448 $scope.label = $scope.callNumber.label();
450 $scope.copy_count = $scope.copies.length;
451 $scope.orig_copy_count = $scope.copy_count;
453 $scope.changeCPCount = function () {
454 while ($scope.copy_count > $scope.copies.length) {
455 var cp = new egCore.idl.acp();
456 cp.id( --itemSvc.new_cp_id );
458 cp.circ_lib( $scope.lib );
459 cp.call_number( $scope.callNumber );
460 $scope.copies.push( cp );
461 $scope.allcopies.push( cp );
464 if ($scope.copy_count >= $scope.orig_copy_count) {
465 var how_many = $scope.copies.length - $scope.copy_count;
467 var dead = $scope.copies.splice($scope.copy_count,how_many);
468 $scope.callNumber.copies($scope.copies);
470 // Trimming the global list is a bit more tricky
471 angular.forEach( dead, function (d) {
472 angular.forEach( $scope.allcopies, function (l, i) {
473 if (l === d) $scope.allcopies.splice(i,1);
486 .directive("egVolEdit", function () {
492 '<div class="col-xs-1"><eg-org-selector selected="owning_lib" disableTest="cant_have_vols"></eg-org-selector></div>'+
493 '<div class="col-xs-1"><input class="form-control" type="number" min="{{orig_cn_count}}" ng-model="cn_count" ng-change="changeCNCount()"/></div>'+
494 '<div class="col-xs-10">'+
495 '<eg-vol-row only-vols="onlyVols"'+
496 'ng-repeat="(cn,copies) in struct | orderBy:cn track by cn" '+
497 'focus-next="focusNextFirst" copies="copies" allcopies="allcopies">'+
502 scope: { focusNext: "=", allcopies: "=", struct: "=", lib: "@", record: "@", onlyVols: "=" },
503 controller : ['$scope','itemSvc','egCore',
504 function ( $scope , itemSvc , egCore ) {
505 $scope.first_cn = Object.keys($scope.struct)[0];
506 $scope.full_cn = $scope.struct[$scope.first_cn][0].call_number();
508 $scope.defaults = {};
509 egCore.hatch.getItem('cat.copy.defaults').then(function(t) {
515 $scope.focusNextFirst = function(prev_cn,prev_bc) {
518 angular.forEach(Object.keys($scope.struct).sort(), function (cn) {
530 var next = '#' + n + '_' + $scope.struct[n][0].id();
533 if (!itemSvc.currently_generating) el.focus();
534 if (prev_bc && itemSvc.auto_gen_barcode && el.val() == "") {
535 itemSvc.nextBarcode(prev_bc).then(function(bc){
538 el.trigger('change');
541 itemSvc.currently_generating = false;
545 $scope.focusNext($scope.lib, prev_bc);
549 $scope.cn_count = Object.keys($scope.struct).length;
550 $scope.orig_cn_count = $scope.cn_count;
552 $scope.owning_lib = egCore.org.get($scope.lib);
553 $scope.$watch('owning_lib', function (l) {
554 angular.forEach( $scope.struct[$scope.first_cn], function (cp) {
555 cp.call_number().owning_lib( $scope.owning_lib.id() );
559 $scope.cant_have_vols = function (id) { return !egCore.org.CanHaveVolumes(id); };
561 $scope.$watch('cn_count', function (n) {
562 var o = Object.keys($scope.struct).length;
563 if (n > o) { // adding
564 for (var i = o; o < n; o++) {
565 var cn = new egCore.idl.acn();
566 cn.id( --itemSvc.new_cn_id );
568 cn.prefix( $scope.defaults.prefix || -1 );
569 cn.suffix( $scope.defaults.suffix || -1 );
570 cn.label_class( $scope.defaults.classification || 1 );
571 cn.owning_lib( $scope.owning_lib.id() );
572 cn.record( $scope.full_cn.record() );
574 var cp = new egCore.idl.acp();
575 cp.call_number( cn );
576 cp.id( --itemSvc.new_cp_id );
581 cp.deposit_amount(0);
582 cp.fine_level(2); // Normal
583 cp.loan_duration(2); // Normal
584 cp.location(1); // Stacks
587 cp.opac_visible('t');
589 cp.mint_condition('t');
591 cp.circ_lib( $scope.owning_lib.id() );
592 cp.call_number( cn );
594 $scope.struct[cn.id()] = [cp];
595 $scope.allcopies.push(cp);
597 } else if (n < o && n >= $scope.orig_cn_count) { // removing
598 var how_many = o - n;
601 .sort(function(a, b){return parseInt(a)-parseInt(b)})
602 .filter(function(x){ return parseInt(x) <= 0 });
603 for (var i = 0; i < how_many; i++) {
604 // Trimming the global list is a bit more tricky
605 angular.forEach($scope.struct[list[i]], function (d) {
606 angular.forEach( $scope.allcopies, function (l, j) {
607 if (l === d) $scope.allcopies.splice(j,1);
610 delete $scope.struct[list[i]];
623 .controller('EditCtrl',
624 ['$scope','$q','$window','$routeParams','$location','$timeout','egCore','egNet','egGridDataProvider','itemSvc','$modal',
625 function($scope , $q , $window , $routeParams , $location , $timeout , egCore , egNet , egGridDataProvider , itemSvc , $modal) {
627 $scope.defaults = { // If defaults are not set at all, allow everything
628 barcode_checkdigit : false,
629 auto_gen_barcode : false,
634 loan_duration : true,
639 deposit_amount : true,
643 mint_condition : true,
646 circ_modifier : true,
654 $scope.saveDefaults = function () {
655 egCore.hatch.setItem('cat.copy.defaults', $scope.defaults);
658 $scope.fetchDefaults = function () {
659 egCore.hatch.getItem('cat.copy.defaults').then(function(t) {
662 if (!$scope.batch) $scope.batch = {};
663 $scope.batch.classification = $scope.defaults.classification;
664 $scope.batch.prefix = $scope.defaults.prefix;
665 $scope.batch.suffix = $scope.defaults.suffix;
666 $scope.working.statcat_filter = $scope.defaults.statcat_filter;
667 if ($scope.defaults.always_vols) $scope.show_vols = true;
668 if ($scope.defaults.barcode_checkdigit) itemSvc.barcode_checkdigit = true;
669 if ($scope.defaults.auto_gen_barcode) itemSvc.auto_gen_barcode = true;
673 $scope.fetchDefaults();
675 $scope.$watch('defaults.auto_gen_barcode', function (n,o) {
676 itemSvc.auto_gen_barcode = n
679 $scope.$watch('defaults.barcode_checkdigit', function (n,o) {
680 itemSvc.barcode_checkdigit = n
683 $scope.dirty = false;
684 $scope.$watch('dirty',
685 function(newVal, oldVal) {
686 if (newVal && newVal != oldVal) {
687 $($window).on('beforeunload.edit', function(){
688 return 'There is unsaved data!'
691 $($window).off('beforeunload.edit');
696 $scope.only_vols = false;
697 $scope.show_vols = true;
698 $scope.show_copies = true;
700 $scope.tracker = function (x,f) { if (x) return x[f]() };
701 $scope.idTracker = function (x) { if (x) return $scope.tracker(x,'id') };
702 $scope.cant_have_vols = function (id) { return !egCore.org.CanHaveVolumes(id); };
704 $scope.orgById = function (id) { return egCore.org.get(id) }
705 $scope.statusById = function (id) {
706 return $scope.status_list.filter( function (s) { return s.id() == id } )[0];
708 $scope.locationById = function (id) {
709 return $scope.location_cache[''+id];
712 $scope.workingToComplete = function () {
713 angular.forEach( $scope.workingGridControls.selectedItems(), function (c) {
714 angular.forEach( itemSvc.copies, function (w, i) {
716 $scope.completed_copies = $scope.completed_copies.concat(itemSvc.copies.splice(i,1));
723 $scope.completeToWorking = function () {
724 angular.forEach( $scope.completedGridControls.selectedItems(), function (c) {
725 angular.forEach( $scope.completed_copies, function (w, i) {
727 itemSvc.copies = itemSvc.copies.concat($scope.completed_copies.splice(i,1));
734 createSimpleUpdateWatcher = function (field) {
735 return $scope.$watch('working.' + field, function () {
736 var newval = $scope.working[field];
738 if (typeof newval != 'undefined') {
739 if (angular.isObject(newval)) { // we'll use the pkey
740 if (newval.id) newval = newval.id();
741 else if (newval.code) newval = newval.code();
744 if (""+newval == "" || newval == null) {
745 $scope.working[field] = undefined;
749 if ($scope.workingGridControls && $scope.workingGridControls.selectedItems) {
751 $scope.workingGridControls.selectedItems(),
753 if (cp[field]() !== newval) {
767 statcat_filter: undefined
770 $scope.statcatUpdate = function (id) {
771 var newval = $scope.working.statcats[id];
773 if (typeof newval != 'undefined') {
774 if (angular.isObject(newval)) { // we'll use the pkey
775 newval = newval.id();
778 if (""+newval == "" || newval == null) {
779 $scope.working.statcats[id] = undefined;
783 if (!$scope.in_item_select && $scope.workingGridControls && $scope.workingGridControls.selectedItems) {
785 $scope.workingGridControls.selectedItems(),
790 angular.forEach( cp.stat_cat_entries(), function (e) {
791 if (e.stat_cat() == id) { // mark deleted
798 var e = new egCore.idl.ascecm();
800 e.owning_copy( cp.id() );
802 e.stat_cat_entry( newval );
805 cp.stat_cat_entries().concat([ e ])
810 cp.stat_cat_entries( // trim out ephemeral deleted ones
811 cp.stat_cat_entries().filter(function (e) {
812 if (Boolean(e.isnew())) {
813 if (Boolean(e.isdeleted())) {
828 var dataKey = $routeParams.dataKey;
829 console.debug('dataKey: ' + dataKey);
831 if (dataKey && dataKey.length > 0) {
833 $scope.templates = {};
834 $scope.template_name = '';
835 $scope.template_name_list = [];
837 $scope.fetchTemplates = function () {
838 egCore.hatch.getItem('cat.copy.templates').then(function(t) {
840 $scope.templates = t;
841 $scope.template_name_list = Object.keys(t);
845 $scope.fetchTemplates();
847 $scope.applyTemplate = function (n) {
848 angular.forEach($scope.templates[n], function (v,k) {
849 if (k == 'circ_lib') {
850 $scope.working[k] = egCore.org.get(v);
851 } else if (!angular.isObject(v)) {
852 $scope.working[k] = angular.copy(v);
854 angular.forEach(v, function (sv,sk) {
855 if (k == 'callnumber') {
856 angular.forEach(v, function (cnv,cnk) {
857 $scope.batch[cnk] = cnv;
859 $scope.applyBatchCNValues();
861 $scope.working[k][sk] = angular.copy(sv);
862 if (k == 'statcats') $scope.statcatUpdate(sk);
867 $scope.template_name = '';
870 $scope.copytab = 'working';
872 $scope.summaryRecord = null;
873 $scope.record_id = null;
875 $scope.completed_copies = [];
876 $scope.location_orgs = [];
877 $scope.location_cache = {};
878 $scope.statcats = [];
879 if (!$scope.batch) $scope.batch = {};
881 $scope.applyBatchCNValues = function () {
882 if ($scope.data.tree) {
883 angular.forEach($scope.data.tree, function(cn_hash) {
884 angular.forEach(cn_hash, function(copies) {
885 angular.forEach(copies, function(cp) {
886 if (typeof $scope.batch.classification != 'undefined' && $scope.batch.classification != '')
887 cp.call_number().label_class($scope.batch.classification);
889 if (typeof $scope.batch.prefix != 'undefined' && $scope.batch.prefix != '')
890 cp.call_number().prefix($scope.batch.prefix);
892 if (typeof $scope.batch.label != 'undefined' && $scope.batch.label != '')
893 cp.call_number().label($scope.batch.label);
895 if (typeof $scope.batch.suffix != 'undefined' && $scope.batch.suffix != '')
896 cp.call_number().suffix($scope.batch.suffix);
904 $scope.clearWorking = function () {
905 angular.forEach($scope.working, function (v,k,o) {
906 if (!angular.isObject(v)) {
907 if (typeof v != 'undefined')
908 $scope.working[k] = undefined;
909 } else if (k != 'circ_lib') {
910 angular.forEach(v, function (sv,sk) {
911 if (typeof v != 'undefined')
912 $scope.working[k][sk] = undefined;
916 $scope.working.circ_lib = undefined; // special
919 $scope.completedGridDataProvider = egGridDataProvider.instance({
920 get : function(offset, count) {
921 //return provider.arrayNotifier(itemSvc.copies, offset, count);
922 return this.arrayNotifier($scope.completed_copies, offset, count);
926 $scope.completedGridControls = {};
928 $scope.workingGridDataProvider = egGridDataProvider.instance({
929 get : function(offset, count) {
930 //return provider.arrayNotifier(itemSvc.copies, offset, count);
931 return this.arrayNotifier(itemSvc.copies, offset, count);
935 $scope.workingGridControls = {};
936 $scope.add_vols_copies = false;
940 'open-ils.actor.anon_cache.get_value',
941 dataKey, 'edit-these-copies'
942 ).then(function (data) {
945 if (data.hide_vols && !$scope.defaults.always_vols) $scope.show_vols = false;
946 if (data.hide_copies) {
947 $scope.show_copies = false;
948 $scope.only_vols = true;
951 $scope.record_id = data.record_id;
953 if (data.copies && data.copies.length)
954 return itemSvc.fetchIds(data.copies);
956 if (data.raw && data.raw.length) {
958 $scope.add_vols_copies = true;
960 /* data.raw data structure looks like this:
962 * callnumber : $cn_id, // optional, to add a copy to a cn
963 * owner : $org, // optional, defaults to ws_ou
964 * label : $cn_label, // optional, to supply a label on a new cn
965 * barcode : $cp_barcode // optional, to supply a barcode on a new cp
968 * All can be left out and a completely empty vol/copy combo will be vivicated.
974 if (proto.callnumber) {
975 return egCore.pcrud.retrieve('acn', proto.callnumber)
977 var cp = new egCore.idl.acp();
978 cp.call_number( cn );
979 cp.id( --itemSvc.new_cp_id );
981 cp.circ_lib( proto.owner || egCore.auth.user().ws_ou() );
985 cp.deposit_amount(0);
986 cp.fine_level(2); // Normal
987 cp.loan_duration(2); // Normal
988 cp.location(1); // Stacks
991 cp.opac_visible('t');
993 cp.mint_condition('t');
995 if (proto.barcode) cp.barcode( proto.barcode );
1000 var cn = new egCore.idl.acn();
1001 cn.id( --itemSvc.new_cn_id );
1003 cn.prefix( $scope.defaults.prefix || -1 );
1004 cn.suffix( $scope.defaults.suffix || -1 );
1005 cn.label_class( $scope.defaults.classification || 1 );
1006 cn.owning_lib( proto.owner || egCore.auth.user().ws_ou() );
1007 cn.record( $scope.record_id );
1008 if (proto.label) cn.label( proto.label );
1010 var cp = new egCore.idl.acp();
1011 cp.call_number( cn );
1012 cp.id( --itemSvc.new_cp_id );
1017 cp.deposit_amount(0);
1018 cp.fine_level(2); // Normal
1019 cp.loan_duration(2); // Normal
1020 cp.location(1); // Stacks
1023 cp.opac_visible('t');
1025 cp.mint_condition('t');
1027 cp.circ_lib( proto.owner || egCore.auth.user().ws_ou() );
1028 if (proto.barcode) cp.barcode( proto.barcode );
1036 return itemSvc.copies;
1040 }).then( function() {
1041 $scope.data = itemSvc;
1042 if ($scope.add_vols_copies) {
1043 egCore.org.settings([
1044 'cat.default_copy_status_fast'
1045 ]).then(function(set) {
1046 $scope.fast_ccs = set['cat.default_copy_status_fast'] || 0;
1047 angular.forEach($scope.data.copies, function (cp) {
1048 cp.status($scope.fast_ccs);
1050 $scope.workingGridDataProvider.refresh();
1055 $scope.focusNextFirst = function(prev_lib,prev_bc) {
1058 angular.forEach(Object.keys($scope.data.tree).sort(), function (lib) {
1061 if (lib == prev_lib) {
1070 var first_cn = Object.keys($scope.data.tree[n])[0];
1071 var next = '#' + first_cn + '_' + $scope.data.tree[n][first_cn][0].id();
1074 if (!itemSvc.currently_generating) el.focus();
1075 if (prev_bc && itemSvc.auto_gen_barcode && el.val() == "") {
1076 itemSvc.nextBarcode(prev_bc).then(function(bc){
1079 el.trigger('change');
1082 itemSvc.currently_generating = false;
1088 $scope.in_item_select = false;
1089 $scope.afterItemSelect = function() { $scope.in_item_select = false };
1090 $scope.handleItemSelect = function (item_list) {
1091 if (item_list && item_list.length > 0) {
1092 $scope.in_item_select = true;
1094 angular.forEach(Object.keys($scope.defaults.attributes), function (attr) {
1096 var value_hash = {};
1097 angular.forEach(item_list, function (item) {
1099 var v = item[attr]()
1100 if (angular.isObject(v)) {
1101 if (v.id) v = v.id();
1102 else if (v.code) v = v.code();
1108 if (Object.keys(value_hash).length == 1) {
1109 if (attr == 'circ_lib') {
1110 $scope.working[attr] = egCore.org.get(item_list[0][attr]());
1112 $scope.working[attr] = item_list[0][attr]();
1115 $scope.working[attr] = undefined;
1119 angular.forEach($scope.statcats, function (sc) {
1122 var value_hash = {};
1124 angular.forEach(item_list, function (item) {
1125 if (item.stat_cat_entries()) {
1126 if (item.stat_cat_entries().length > 0) {
1127 var right_sc = item.stat_cat_entries().filter(function (e) {
1128 return e.stat_cat() == sc.id() && !Boolean(e.isdeleted());
1131 if (right_sc.length > 0) {
1132 value_hash[right_sc[0].stat_cat_entry()] = right_sc[0].stat_cat_entry();
1142 if (!none && Object.keys(value_hash).length == 1) {
1143 $scope.working.statcats[sc.id()] = value_hash[Object.keys(value_hash)[0]];
1145 $scope.working.statcats[sc.id()] = undefined;
1150 $scope.clearWorking();
1155 $scope.$watch('data.copies.length', function () {
1156 if ($scope.data.copies) {
1157 var base_orgs = $scope.data.copies.map(function(cp){
1158 return cp.circ_lib()
1160 $scope.data.copies.map(function(cp){
1161 return cp.call_number().owning_lib()
1164 [egCore.auth.user().ws_ou()]
1165 ).filter(function(e,i,a){
1166 return a.lastIndexOf(e) === i;
1170 angular.forEach(base_orgs, function(o) {
1171 all_orgs = all_orgs.concat( egCore.org.fullPath(o, true) );
1174 var final_orgs = all_orgs.filter(function(e,i,a){
1175 return a.lastIndexOf(e) === i;
1176 }).sort(function(a, b){return parseInt(a)-parseInt(b)});
1178 if ($scope.location_orgs.toString() != final_orgs.toString()) {
1179 $scope.location_orgs = final_orgs;
1180 if ($scope.location_orgs.length) {
1181 itemSvc.get_locations($scope.location_orgs).then(function(list){
1182 angular.forEach(list, function(l) {
1183 $scope.location_cache[ ''+l.id() ] = l;
1185 $scope.location_list = list;
1188 $scope.statcat_filter_list = [];
1189 angular.forEach($scope.location_orgs, function (o) {
1190 $scope.statcat_filter_list.push(egCore.org.get(o));
1193 itemSvc.get_statcats($scope.location_orgs).then(function(list){
1194 $scope.statcats = list;
1195 angular.forEach($scope.statcats, function (s) {
1197 if (!$scope.working)
1198 $scope.working = { statcats: {}, statcat_filter: undefined};
1199 if (!$scope.working.statcats)
1200 $scope.working.statcats = {};
1202 if (!$scope.in_item_select) {
1203 $scope.working.statcats[s.id()] = undefined;
1205 createStatcatUpdateWatcher(s.id());
1207 $scope.in_item_select = false;
1213 $scope.workingGridDataProvider.refresh();
1216 $scope.suffix_list = [];
1217 itemSvc.get_suffixes(egCore.auth.user().ws_ou()).then(function(list){
1218 $scope.suffix_list = list;
1221 $scope.prefix_list = [];
1222 itemSvc.get_prefixes(egCore.auth.user().ws_ou()).then(function(list){
1223 $scope.prefix_list = list;
1226 $scope.classification_list = [];
1227 itemSvc.get_classifications().then(function(list){
1228 $scope.classification_list = list;
1231 $scope.$watch('completed_copies.length', function () {
1232 $scope.completedGridDataProvider.refresh();
1235 $scope.location_list = [];
1236 itemSvc.get_locations().then(function(list){
1237 $scope.location_list = list;
1239 createSimpleUpdateWatcher('location');
1241 $scope.status_list = [];
1242 itemSvc.get_statuses().then(function(list){
1243 $scope.status_list = list;
1245 createSimpleUpdateWatcher('status');
1247 $scope.circ_modifier_list = [];
1248 itemSvc.get_circ_mods().then(function(list){
1249 $scope.circ_modifier_list = list;
1251 createSimpleUpdateWatcher('circ_modifier');
1253 $scope.circ_type_list = [];
1254 itemSvc.get_circ_types().then(function(list){
1255 $scope.circ_type_list = list;
1257 createSimpleUpdateWatcher('circ_as_type');
1259 $scope.age_protect_list = [];
1260 itemSvc.get_age_protects().then(function(list){
1261 $scope.age_protect_list = list;
1263 createSimpleUpdateWatcher('age_protect');
1265 createSimpleUpdateWatcher('circ_lib');
1266 createSimpleUpdateWatcher('circulate');
1267 createSimpleUpdateWatcher('holdable');
1268 createSimpleUpdateWatcher('fine_level');
1269 createSimpleUpdateWatcher('loan_duration');
1270 createSimpleUpdateWatcher('cost');
1271 createSimpleUpdateWatcher('deposit');
1272 createSimpleUpdateWatcher('deposit_amount');
1273 createSimpleUpdateWatcher('mint_condition');
1274 createSimpleUpdateWatcher('opac_visible');
1275 createSimpleUpdateWatcher('ref');
1277 $scope.saveCompletedCopies = function (and_exit) {
1279 var perCnCopies = {};
1280 angular.forEach( egCore.idl.Clone($scope.completed_copies), function (cp) {
1281 var cn_id = cp.call_number().id();
1282 if (!cnHash[cn_id]) {
1283 cnHash[cn_id] = cp.call_number();
1284 perCnCopies[cn_id] = [cp];
1286 perCnCopies[cn_id].push(cp);
1288 cp.call_number(cn_id); // prevent loops in JSON-ification
1289 cnHash[cn_id].prefix(cnHash[cn_id].prefix().id()); // un-object-ize some fields
1290 cnHash[cn_id].suffix(cnHash[cn_id].suffix().id()); // un-object-ize some fields
1293 angular.forEach(perCnCopies, function (v, k) {
1294 cnHash[k].copies(v);
1298 angular.forEach(cnHash, function (v, k) {
1304 'open-ils.cat.asset.volume.fleshed.batch.update.override',
1305 egCore.auth.token(), cnList, 1, { auto_merge_vols : 1, create_parts : 1 }
1306 ).then(function(update_count) {
1308 $scope.dirty = false;
1309 $timeout(function(){$window.close()});
1314 $scope.saveAndContinue = function () {
1315 $scope.saveCompletedCopies(false);
1318 $scope.workingSaveAndExit = function () {
1319 $scope.workingToComplete();
1320 $scope.saveAndExit();
1323 $scope.saveAndExit = function () {
1324 $scope.saveCompletedCopies(true);
1329 $scope.copy_notes_dialog = function(copy_list) {
1330 var default_pub = Boolean($scope.defaults.copy_notes_pub);
1331 if (!angular.isArray(copy_list)) copy_list = [copy_list];
1333 return $modal.open({
1334 templateUrl: './cat/volcopy/t_copy_notes',
1337 ['$scope','$modalInstance',
1338 function($scope , $modalInstance) {
1339 $scope.focusNote = true;
1341 creator : egCore.auth.user().id(),
1347 $scope.require_initials = false;
1348 egCore.org.settings([
1349 'ui.staff.require_initials.copy_notes'
1350 ]).then(function(set) {
1351 $scope.require_initials = Boolean(set['ui.staff.require_initials.copy_notes']);
1354 $scope.note_list = [];
1355 if (copy_list.length == 1) {
1356 $scope.note_list = copy_list[0].notes();
1359 $scope.ok = function(note) {
1361 if (note.initials) note.value += ' [' + note.initials + ']';
1362 angular.forEach(copy_list, function (cp) {
1363 var n = new egCore.idl.acpn();
1364 n.creator(note.creator);
1366 n.title(note.title);
1367 n.value(note.value);
1368 n.owning_copy(cp.id());
1369 cp.notes().push( n );
1372 $modalInstance.close();
1375 $scope.cancel = function($event) {
1376 $modalInstance.dismiss();
1377 $event.preventDefault();
1385 .directive("egVolTemplate", function () {
1389 template: '<div ng-include="'+"'/eg/staff/cat/volcopy/t_attr_edit'"+'"></div>',
1391 controller : ['$scope','$window','itemSvc','egCore',
1392 function ( $scope , $window , itemSvc , egCore ) {
1394 $scope.defaults = { // If defaults are not set at all, allow everything
1395 barcode_checkdigit : false,
1396 auto_gen_barcode : false,
1401 loan_duration : true,
1406 deposit_amount : true,
1407 opac_visible : true,
1410 mint_condition : true,
1413 circ_modifier : true,
1414 circ_as_type : true,
1421 $scope.fetchDefaults = function () {
1422 egCore.hatch.getItem('cat.copy.defaults').then(function(t) {
1424 $scope.defaults = t;
1425 $scope.working.statcat_filter = $scope.defaults.statcat_filter;
1429 $scope.fetchDefaults();
1431 $scope.dirty = false;
1432 $scope.$watch('dirty',
1433 function(newVal, oldVal) {
1434 if (newVal && newVal != oldVal) {
1435 $($window).on('beforeunload.template', function(){
1436 return 'There is unsaved template data!'
1439 $($window).off('beforeunload.template');
1444 $scope.template_controls = true;
1446 $scope.fetchTemplates = function () {
1447 egCore.hatch.getItem('cat.copy.templates').then(function(t) {
1449 $scope.templates = t;
1450 $scope.template_name_list = Object.keys(t);
1454 $scope.fetchTemplates();
1456 $scope.applyTemplate = function (n) {
1457 angular.forEach($scope.templates[n], function (v,k) {
1458 if (k == 'circ_lib') {
1459 $scope.working[k] = egCore.org.get(v);
1460 } else if (!angular.isObject(v)) {
1461 $scope.working[k] = angular.copy(v);
1463 angular.forEach(v, function (sv,sk) {
1464 $scope.working[k][sk] = angular.copy(sv);
1468 $scope.template_name = '';
1471 $scope.deleteTemplate = function (n) {
1473 delete $scope.templates[n]
1474 $scope.template_name_list = Object.keys($scope.templates);
1475 $scope.template_name = '';
1476 egCore.hatch.setItem('cat.copy.templates', $scope.templates);
1477 $scope.$parent.fetchTemplates();
1481 $scope.saveTemplate = function (n) {
1485 angular.forEach($scope.working, function (v,k) {
1486 if (angular.isObject(v)) { // we'll use the pkey
1487 if (v.id) v = v.id();
1488 else if (v.code) v = v.code();
1494 $scope.templates[n] = tmpl;
1495 $scope.template_name_list = Object.keys($scope.templates);
1497 egCore.hatch.setItem('cat.copy.templates', $scope.templates);
1498 $scope.$parent.fetchTemplates();
1500 $scope.dirty = false;
1504 $scope.templates = {};
1505 $scope.template_name = '';
1506 $scope.template_name_list = [];
1508 $scope.tracker = function (x,f) { if (x) return x[f]() };
1509 $scope.idTracker = function (x) { if (x) return $scope.tracker(x,'id') };
1510 $scope.cant_have_vols = function (id) { return !egCore.org.CanHaveVolumes(id); };
1512 $scope.orgById = function (id) { return egCore.org.get(id) }
1513 $scope.statusById = function (id) {
1514 return $scope.status_list.filter( function (s) { return s.id() == id } )[0];
1516 $scope.locationById = function (id) {
1517 return $scope.location_cache[''+id];
1520 createSimpleUpdateWatcher = function (field) {
1521 $scope.$watch('working.' + field, function () {
1522 var newval = $scope.working[field];
1524 if (typeof newval != 'undefined') {
1525 $scope.dirty = true;
1526 if (angular.isObject(newval)) { // we'll use the pkey
1527 if (newval.id) $scope.working[field] = newval.id();
1528 else if (newval.code) $scope.working[field] = newval.code();
1531 if (""+newval == "" || newval == null) {
1532 $scope.working[field] = undefined;
1541 statcat_filter: undefined
1544 createStatcatUpdateWatcher = function (id) {
1545 return $scope.$watch('working.statcats[' + id + ']', function () {
1546 if ($scope.working.statcats) {
1547 var newval = $scope.working.statcats[id];
1549 if (typeof newval != 'undefined') {
1550 $scope.dirty = true;
1551 if (angular.isObject(newval)) { // we'll use the pkey
1552 newval = newval.id();
1555 if (""+newval == "" || newval == null) {
1556 $scope.working.statcats[id] = undefined;
1565 $scope.clearWorking = function () {
1566 angular.forEach($scope.working, function (v,k,o) {
1567 if (!angular.isObject(v)) {
1568 if (typeof v != 'undefined')
1569 $scope.working[k] = undefined;
1570 } else if (k != 'circ_lib') {
1571 angular.forEach(v, function (sv,sk) {
1572 $scope.working[k][sk] = undefined;
1576 $scope.working.circ_lib = undefined; // special
1577 $scope.dirty = false;
1580 $scope.working = {};
1581 $scope.location_orgs = [];
1582 $scope.location_cache = {};
1584 $scope.location_list = [];
1585 itemSvc.get_locations(
1586 egCore.org.fullPath( egCore.auth.user().ws_ou(), true )
1587 ).then(function(list){
1588 $scope.location_list = list;
1590 createSimpleUpdateWatcher('location');
1592 $scope.statcat_filter_list = egCore.org.fullPath( egCore.auth.user().ws_ou() );
1594 $scope.statcats = [];
1595 itemSvc.get_statcats(
1596 egCore.org.fullPath( egCore.auth.user().ws_ou(), true )
1597 ).then(function(list){
1598 $scope.statcats = list;
1599 angular.forEach($scope.statcats, function (s) {
1601 if (!$scope.working)
1602 $scope.working = { statcats: {}, statcat_filter: undefined};
1603 if (!$scope.working.statcats)
1604 $scope.working.statcats = {};
1606 $scope.working.statcats[s.id()] = undefined;
1607 createStatcatUpdateWatcher(s.id());
1611 $scope.status_list = [];
1612 itemSvc.get_statuses().then(function(list){
1613 $scope.status_list = list;
1615 createSimpleUpdateWatcher('status');
1617 $scope.circ_modifier_list = [];
1618 itemSvc.get_circ_mods().then(function(list){
1619 $scope.circ_modifier_list = list;
1621 createSimpleUpdateWatcher('circ_modifier');
1623 $scope.circ_type_list = [];
1624 itemSvc.get_circ_types().then(function(list){
1625 $scope.circ_type_list = list;
1627 createSimpleUpdateWatcher('circ_as_type');
1629 $scope.age_protect_list = [];
1630 itemSvc.get_age_protects().then(function(list){
1631 $scope.age_protect_list = list;
1633 createSimpleUpdateWatcher('age_protect');
1635 createSimpleUpdateWatcher('circulate');
1636 createSimpleUpdateWatcher('holdable');
1637 createSimpleUpdateWatcher('fine_level');
1638 createSimpleUpdateWatcher('loan_duration');
1639 createSimpleUpdateWatcher('cost');
1640 createSimpleUpdateWatcher('deposit');
1641 createSimpleUpdateWatcher('deposit_amount');
1642 createSimpleUpdateWatcher('mint_condition');
1643 createSimpleUpdateWatcher('opac_visible');
1644 createSimpleUpdateWatcher('ref');
1646 $scope.suffix_list = [];
1647 itemSvc.get_suffixes(egCore.auth.user().ws_ou()).then(function(list){
1648 $scope.suffix_list = list;
1651 $scope.prefix_list = [];
1652 itemSvc.get_prefixes(egCore.auth.user().ws_ou()).then(function(list){
1653 $scope.prefix_list = list;
1656 $scope.classification_list = [];
1657 itemSvc.get_classifications().then(function(list){
1658 $scope.classification_list = list;
1661 createSimpleUpdateWatcher('working.callnumber.classification');
1662 createSimpleUpdateWatcher('working.callnumber.prefix');
1663 createSimpleUpdateWatcher('working.callnumber.suffix');