5 angular.module('egVolCopy',
6 ['ngRoute', 'ui.bootstrap', 'egCoreMod', 'egUiMod', 'egGridMod'])
8 .filter('boolText', function(){
14 .config(['ngToastProvider', function(ngToastProvider) {
15 ngToastProvider.configure({
16 verticalPosition: 'bottom',
21 .config(function($routeProvider, $locationProvider, $compileProvider) {
22 $locationProvider.html5Mode(true);
23 $compileProvider.aHrefSanitizationWhitelist(/^\s*(https?|blob):/); // grid export
26 delay : ['egStartup', function(egStartup) { return egStartup.go(); }]
29 $routeProvider.when('/cat/volcopy/edit_templates', {
30 templateUrl: './cat/volcopy/t_view',
31 controller: 'EditCtrl',
35 $routeProvider.when('/cat/volcopy/:dataKey', {
36 templateUrl: './cat/volcopy/t_view',
37 controller: 'EditCtrl',
41 $routeProvider.when('/cat/volcopy/:dataKey/:mode', {
42 templateUrl: './cat/volcopy/t_view',
43 controller: 'EditCtrl',
50 function(egCore , $q) {
53 currently_generating : false,
54 auto_gen_barcode : false,
55 barcode_checkdigit : false,
58 tree : {}, // holds lib->cn->copy hash stack
59 copies : [] // raw copy list
62 service.nextBarcode = function(bc) {
63 service.currently_generating = true;
64 return egCore.net.request(
66 'open-ils.cat.item.barcode.autogen',
68 bc, 1, { checkdigit: service.barcode_checkdigit }
69 ).then(function(resp) { // get_barcodes
70 var evt = egCore.evt.parse(resp);
71 if (!evt) return resp[0];
76 service.checkBarcode = function(bc) {
77 if (!service.barcode_checkdigit) return true;
78 if (bc != Number(bc)) return false;
80 // "16.00" == Number("16.00"), but the . is bad.
81 // Throw out any barcode that isn't just digits
82 if (bc.search(/\D/) != -1) return false;
83 var last_digit = bc.substr(bc.length-1);
84 var stripped_barcode = bc.substr(0,bc.length-1);
85 return service.barcodeCheckdigit(stripped_barcode).toString() == last_digit;
88 service.barcodeCheckdigit = function(bc) {
89 var reverse_barcode = bc.toString().split('').reverse();
90 var check_sum = 0; var multiplier = 2;
91 for (var i = 0; i < reverse_barcode.length; i++) {
92 var digit = reverse_barcode[i];
93 var product = digit * multiplier; product = product.toString();
95 for (var j = 0; j < product.length; j++) {
96 temp_sum += Number( product[j] );
98 check_sum += Number( temp_sum );
99 multiplier = ( multiplier == 2 ? 1 : 2 );
101 check_sum = check_sum.toString();
102 var next_multiple_of_10 = (check_sum.match(/(\d*)\d$/)[1] * 10) + 10;
103 var check_digit = next_multiple_of_10 - Number(check_sum); if (check_digit == 10) check_digit = 0;
107 // returns a promise resolved with the list of circ mods
108 service.get_classifications = function() {
110 return $q.when(egCore.env.acnc.list);
112 return egCore.pcrud.retrieveAll('acnc', null, {atomic : true})
113 .then(function(list) {
114 egCore.env.absorbList(list, 'acnc');
119 service.get_prefixes = function(org) {
120 return egCore.pcrud.search('acnp',
121 {owning_lib : egCore.org.fullPath(org, true)},
122 {order_by : { acnp : 'label_sortkey' }}, {atomic : true}
127 service.get_statcats = function(orgs) {
128 return egCore.pcrud.search('asc',
132 asc : ['owner','entries']
139 service.get_locations = function(orgs) {
140 return egCore.pcrud.search('acpl',
142 {order_by : { acpl : 'name' }}, {atomic : true}
146 service.get_suffixes = function(org) {
147 return egCore.pcrud.search('acns',
148 {owning_lib : egCore.org.fullPath(org, true)},
149 {order_by : { acns : 'label_sortkey' }}, {atomic : true}
154 service.get_statuses = function() {
156 return $q.when(egCore.env.ccs.list);
158 return egCore.pcrud.retrieveAll('ccs', {order_by : { ccs : 'name' }}, {atomic : true}).then(
160 egCore.env.absorbList(list, 'ccs');
167 service.get_circ_mods = function() {
169 return $q.when(egCore.env.ccm.list);
171 return egCore.pcrud.retrieveAll('ccm', {}, {atomic : true}).then(
173 egCore.env.absorbList(list, 'ccm');
180 service.get_circ_types = function() {
182 return $q.when(egCore.env.citm.list);
184 return egCore.pcrud.retrieveAll('citm', {}, {atomic : true}).then(
186 egCore.env.absorbList(list, 'citm');
193 service.get_age_protects = function() {
194 if (egCore.env.crahp)
195 return $q.when(egCore.env.crahp.list);
197 return egCore.pcrud.retrieveAll('crahp', {}, {atomic : true}).then(
199 egCore.env.absorbList(list, 'crahp');
206 service.get_floating_groups = function() {
208 return $q.when(egCore.env.cfg.list);
210 return egCore.pcrud.retrieveAll('cfg', {}, {atomic : true}).then(
212 egCore.env.absorbList(list, 'cfg');
219 service.bmp_parts = {};
220 service.get_parts = function(rec) {
221 if (service.bmp_parts[rec])
222 return $q.when(service.bmp_parts[rec]);
224 return egCore.pcrud.search('bmp',
225 {record : rec, deleted : 'f'},
226 null, {atomic : true}
227 ).then(function(list) {
228 service.bmp_parts[rec] = list;
237 acp : ['call_number','parts','stat_cat_entries', 'notes'],
238 acn : ['label_class','prefix','suffix']
242 service.addCopy = function (cp) {
244 if (!cp.parts()) cp.parts([]); // just in case...
246 var lib = cp.call_number().owning_lib();
247 var cn = cp.call_number().id();
249 if (!service.tree[lib]) service.tree[lib] = {};
250 if (!service.tree[lib][cn]) service.tree[lib][cn] = [];
252 service.tree[lib][cn].push(cp);
253 service.copies.push(cp);
256 service.checkDuplicateBarcode = function(bc, id) {
258 return egCore.pcrud.search('acp', { deleted : 'f', 'barcode' : bc, id : { '!=' : id } })
260 function () { return final },
261 function () { return final },
262 function () { final = true; }
266 service.fetchIds = function(idList) {
267 service.tree = {}; // clear the tree on fetch
268 service.copies = []; // clear the copy list on fetch
269 return egCore.pcrud.search('acp', { 'id' : idList }, service.flesh).then(null,null,
271 service.addCopy(copy);
276 // create a new acp object with default values
277 // (both hard-coded and coming from OU settings)
278 service.generateNewCopy = function(callNumber, owningLib, isFastAdd, isNew) {
279 var cp = new egCore.idl.acp();
280 cp.id( --service.new_cp_id );
284 cp.circ_lib( owningLib );
285 cp.call_number( callNumber );
288 cp.deposit_amount(0);
289 cp.fine_level(2); // Normal
290 cp.loan_duration(2); // Normal
291 cp.location(1); // Stacks
294 cp.opac_visible('t');
296 cp.mint_condition('t');
297 cp.empty_barcode = true;
299 var status_setting = isFastAdd ?
300 'cat.default_copy_status_fast' :
301 'cat.default_copy_status_normal';
305 ).then(function(set) {
306 var default_ccs = parseInt(set[status_setting]);
307 if (isNaN(default_ccs))
308 default_ccs = (isFastAdd ? 0 : 5); // 0 is Available, 5 is In Process
309 cp.status(default_ccs);
318 .directive("egVolCopyEdit", function () {
324 '<div class="col-xs-5" ng-class="{'+"'has-error'"+':barcode_has_error}">'+
325 '<input id="{{callNumber.id()}}_{{copy.id()}}"'+
326 ' eg-enter="nextBarcode(copy.id())" class="form-control"'+
327 ' type="text" ng-model="barcode" ng-change="updateBarcode()"/>'+
328 '<div class="label label-danger" ng-if="duplicate_barcode">{{duplicate_barcode_string}}</div>'+
329 '<div class="label label-danger" ng-if="empty_barcode">{{empty_barcode_string}}</div>'+
331 '<div class="col-xs-3"><input class="form-control" type="number" min="1" ng-model="copy_number" ng-change="updateCopyNo()"/></div>'+
332 '<div class="col-xs-4"><eg-basic-combo-box eg-disabled="record == 0" list="parts" selected="part"></eg-basic-combo-box></div>'+
335 scope: { focusNext: "=", copy: "=", callNumber: "=", index: "@", record: "@" },
336 controller : ['$scope','itemSvc','egCore',
337 function ( $scope , itemSvc , egCore ) {
338 $scope.new_part_id = 0;
339 $scope.barcode_has_error = false;
340 $scope.duplicate_barcode = false;
341 $scope.empty_barcode = false;
342 $scope.duplicate_barcode_string = window.duplicate_barcode_string;
343 $scope.empty_barcode_string = window.empty_barcode_string;
345 if (!$scope.copy.barcode()) $scope.copy.empty_barcode = true;
347 $scope.nextBarcode = function (i) {
348 $scope.focusNext(i, $scope.barcode);
351 $scope.updateBarcode = function () {
352 if ($scope.barcode != '') {
353 $scope.copy.empty_barcode = $scope.empty_barcode = false;
354 $scope.barcode_has_error = !Boolean(itemSvc.checkBarcode($scope.barcode));
355 itemSvc.checkDuplicateBarcode($scope.barcode, $scope.copy.id())
356 .then(function (state) { $scope.copy.duplicate_barcode = $scope.duplicate_barcode = state });
358 $scope.copy.empty_barcode = $scope.empty_barcode = true;
361 $scope.copy.barcode($scope.barcode);
362 $scope.copy.ischanged(1);
363 if (itemSvc.currently_generating)
364 $scope.focusNext($scope.copy.id(), $scope.barcode);
367 $scope.updateCopyNo = function () { $scope.copy.copy_number($scope.copy_number); $scope.copy.ischanged(1); };
368 $scope.updatePart = function () {
370 var p = $scope.part_list.filter(function (x) {
371 return x.label() == $scope.part
373 if (p.length > 0) { // preexisting part
375 } else { // create one...
376 var part = new egCore.idl.bmp();
377 part.id( --$scope.new_part_id );
379 part.label( $scope.part );
380 part.record( $scope.callNumber.record() );
381 $scope.copy.parts([part]);
382 $scope.copy.ischanged(1);
385 $scope.copy.parts([]);
387 $scope.copy.ischanged(1);
389 $scope.$watch('part', $scope.updatePart);
391 $scope.barcode = $scope.copy.barcode();
392 $scope.copy_number = $scope.copy.copy_number();
394 if ($scope.copy.parts()) {
395 $scope.part = $scope.copy.parts()[0];
396 if ($scope.part) $scope.part = $scope.part.label();
400 $scope.part_list = [];
402 itemSvc.get_parts($scope.callNumber.record()).then(function(list){
403 $scope.part_list = list;
404 angular.forEach(list, function(p){ $scope.parts.push(p.label()) });
405 $scope.parts = angular.copy($scope.parts);
414 .directive("egVolRow", function () {
421 '<div class="col-xs-2">'+
422 '<select ng-disabled="record == 0" class="form-control" ng-model="classification" ng-change="updateClassification()" ng-options="cl.name() for cl in classification_list"/>'+
424 '<div class="col-xs-1">'+
425 '<select ng-disabled="record == 0" class="form-control" ng-model="prefix" ng-change="updatePrefix()" ng-options="p.label() for p in prefix_list"/>'+
427 '<div class="col-xs-2">'+
428 '<input ng-disabled="record == 0" class="form-control" type="text" ng-change="updateLabel()" ng-model="label"/>'+
429 '<div class="label label-danger" ng-if="empty_label">{{empty_label_string}}</div>'+
431 '<div class="col-xs-1">'+
432 '<select ng-disabled="record == 0" class="form-control" ng-model="suffix" ng-change="updateSuffix()" ng-options="s.label() for s in suffix_list"/>'+
434 '<div ng-hide="onlyVols" class="col-xs-1"><input ng-disabled="record == 0" class="form-control" type="number" ng-model="copy_count" min="{{orig_copy_count}}" ng-change="changeCPCount()"></div>'+
435 '<div ng-hide="onlyVols" class="col-xs-5">'+
436 '<eg-vol-copy-edit record="{{record}}" ng-repeat="cp in copies track by idTracker(cp)" focus-next="focusNextBarcode" copy="cp" call-number="callNumber"></eg-vol-copy-edit>'+
440 scope: {focusNext: "=", allcopies: "=", copies: "=", onlyVols: "=", record: "@" },
441 controller : ['$scope','itemSvc','egCore',
442 function ( $scope , itemSvc , egCore ) {
443 $scope.callNumber = $scope.copies[0].call_number();
444 if (!$scope.callNumber.label()) $scope.callNumber.emtpy_label = true;
446 $scope.empty_label = false;
447 $scope.empty_label_string = window.empty_label_string;
449 $scope.idTracker = function (x) { if (x && x.id) return x.id() };
451 // XXX $() is not working! arg
452 $scope.focusNextBarcode = function (i, prev_bc) {
455 angular.forEach($scope.copies, function (cp) {
463 if (yep) n = cp.id();
467 var next = '#' + $scope.callNumber.id() + '_' + n;
470 if (!itemSvc.currently_generating) el.focus();
471 if (prev_bc && itemSvc.auto_gen_barcode && el.val() == "") {
472 itemSvc.nextBarcode(prev_bc).then(function(bc){
475 el.trigger('change');
478 itemSvc.currently_generating = false;
482 $scope.focusNext($scope.callNumber.id(),prev_bc)
486 $scope.suffix_list = [];
487 itemSvc.get_suffixes($scope.callNumber.owning_lib()).then(function(list){
488 $scope.suffix_list = list;
489 $scope.$watch('callNumber.suffix()', function (v) {
490 if (angular.isObject(v)) v = v.id();
491 $scope.suffix = $scope.suffix_list.filter( function (s) {
497 $scope.updateSuffix = function () {
498 angular.forEach($scope.copies, function(cp) {
499 cp.call_number().suffix($scope.suffix);
500 cp.call_number().ischanged(1);
504 $scope.prefix_list = [];
505 itemSvc.get_prefixes($scope.callNumber.owning_lib()).then(function(list){
506 $scope.prefix_list = list;
507 $scope.$watch('callNumber.prefix()', function (v) {
508 if (angular.isObject(v)) v = v.id();
509 $scope.prefix = $scope.prefix_list.filter(function (p) {
515 $scope.updatePrefix = function () {
516 angular.forEach($scope.copies, function(cp) {
517 cp.call_number().prefix($scope.prefix);
518 cp.call_number().ischanged(1);
521 $scope.$watch('callNumber.owning_lib()', function(oldLib, newLib) {
522 if (oldLib == newLib) return;
523 var currentPrefix = $scope.callNumber.prefix();
524 if (angular.isObject(currentPrefix)) currentPrefix = currentPrefix.id();
525 itemSvc.get_prefixes($scope.callNumber.owning_lib()).then(function(list){
526 $scope.prefix_list = list;
527 var newPrefixId = $scope.prefix_list.filter(function (p) {
528 return p.id() == currentPrefix;
530 if (newPrefixId.id) newPrefixId = newPrefixId.id();
531 $scope.prefix = $scope.prefix_list.filter(function (p) {
532 return p.id() == newPrefixId;
534 if ($scope.newPrefixId != currentPrefix) {
535 $scope.callNumber.prefix($scope.prefix);
538 var currentSuffix = $scope.callNumber.suffix();
539 if (angular.isObject(currentSuffix)) currentSuffix = currentSuffix.id();
540 itemSvc.get_suffixes($scope.callNumber.owning_lib()).then(function(list){
541 $scope.suffix_list = list;
542 var newSuffixId = $scope.suffix_list.filter(function (s) {
543 return s.id() == currentSuffix;
545 if (newSuffixId.id) newSuffixId = newSuffixId.id();
546 $scope.suffix = $scope.suffix_list.filter(function (s) {
547 return s.id() == newSuffixId;
549 if ($scope.newSuffixId != currentSuffix) {
550 $scope.callNumber.suffix($scope.suffix);
555 $scope.classification_list = [];
556 itemSvc.get_classifications().then(function(list){
557 $scope.classification_list = list;
558 $scope.$watch('callNumber.label_class()', function (v) {
559 if (angular.isObject(v)) v = v.id();
560 $scope.classification = $scope.classification_list.filter(function (c) {
566 $scope.updateClassification = function () {
567 angular.forEach($scope.copies, function(cp) {
568 cp.call_number().label_class($scope.classification);
569 cp.call_number().ischanged(1);
573 $scope.updateLabel = function () {
574 if ($scope.label == '') {
575 $scope.callNumber.empty_label = $scope.empty_label = true;
577 $scope.callNumber.empty_label = $scope.empty_label = false;
579 angular.forEach($scope.copies, function(cp) {
580 cp.call_number().label($scope.label);
581 cp.call_number().ischanged(1);
585 $scope.$watch('callNumber.label()', function (v) {
589 $scope.prefix = $scope.callNumber.prefix();
590 $scope.suffix = $scope.callNumber.suffix();
591 $scope.classification = $scope.callNumber.label_class();
592 $scope.label = $scope.callNumber.label();
594 $scope.copy_count = $scope.copies.length;
595 $scope.orig_copy_count = $scope.copy_count;
597 $scope.changeCPCount = function () {
598 while ($scope.copy_count > $scope.copies.length) {
599 var cp = itemSvc.generateNewCopy(
601 $scope.callNumber.owning_lib(),
605 $scope.copies.push( cp );
606 $scope.allcopies.push( cp );
610 if ($scope.copy_count >= $scope.orig_copy_count) {
611 var how_many = $scope.copies.length - $scope.copy_count;
613 var dead = $scope.copies.splice($scope.copy_count,how_many);
614 $scope.callNumber.copies($scope.copies);
616 // Trimming the global list is a bit more tricky
617 angular.forEach( dead, function (d) {
618 angular.forEach( $scope.allcopies, function (l, i) {
619 if (l === d) $scope.allcopies.splice(i,1);
632 .directive("egVolEdit", function () {
638 '<div class="col-xs-1"><eg-org-selector alldisabled="{{record == 0}}" selected="owning_lib" disable-test="cant_have_vols"></eg-org-selector></div>'+
639 '<div class="col-xs-1"><input ng-disabled="record == 0" class="form-control" type="number" min="{{orig_cn_count}}" ng-model="cn_count" ng-change="changeCNCount()"/></div>'+
640 '<div class="col-xs-10">'+
641 '<eg-vol-row only-vols="onlyVols" record="{{record}}"'+
642 'ng-repeat="(cn,copies) in struct" '+
643 'focus-next="focusNextFirst" copies="copies" allcopies="allcopies">'+
648 scope: { focusNext: "=", allcopies: "=", struct: "=", lib: "@", record: "@", onlyVols: "=" },
649 controller : ['$scope','itemSvc','egCore',
650 function ( $scope , itemSvc , egCore ) {
651 $scope.first_cn = Object.keys($scope.struct)[0];
652 $scope.full_cn = $scope.struct[$scope.first_cn][0].call_number();
654 $scope.defaults = {};
655 egCore.hatch.getItem('cat.copy.defaults').then(function(t) {
661 $scope.focusNextFirst = function(prev_cn,prev_bc) {
664 angular.forEach(Object.keys($scope.struct).sort(), function (cn) {
676 var next = '#' + n + '_' + $scope.struct[n][0].id();
679 if (!itemSvc.currently_generating) el.focus();
680 if (prev_bc && itemSvc.auto_gen_barcode && el.val() == "") {
681 itemSvc.nextBarcode(prev_bc).then(function(bc){
684 el.trigger('change');
687 itemSvc.currently_generating = false;
691 $scope.focusNext($scope.lib, prev_bc);
695 $scope.cn_count = Object.keys($scope.struct).length;
696 $scope.orig_cn_count = $scope.cn_count;
698 $scope.owning_lib = egCore.org.get($scope.lib);
699 $scope.$watch('owning_lib', function (oldLib, newLib) {
700 if (oldLib == newLib) return;
701 angular.forEach( Object.keys($scope.struct), function (cn) {
702 $scope.struct[cn][0].call_number().owning_lib( $scope.owning_lib.id() );
703 $scope.struct[cn][0].call_number().ischanged(1);
707 $scope.cant_have_vols = function (id) { return !egCore.org.CanHaveVolumes(id); };
709 $scope.$watch('cn_count', function (n) {
710 var o = Object.keys($scope.struct).length;
711 if (n > o) { // adding
712 for (var i = o; o < n; o++) {
713 var cn = new egCore.idl.acn();
714 cn.id( --itemSvc.new_cn_id );
716 cn.prefix( $scope.defaults.prefix || -1 );
717 cn.suffix( $scope.defaults.suffix || -1 );
718 cn.label_class( $scope.defaults.classification || 1 );
719 cn.owning_lib( $scope.owning_lib.id() );
720 cn.record( $scope.full_cn.record() );
722 var cp = itemSvc.generateNewCopy(
724 $scope.owning_lib.id(),
729 $scope.struct[cn.id()] = [cp];
730 $scope.allcopies.push(cp);
731 if (!$scope.defaults.classification) {
733 ['cat.default_classification_scheme'],
735 ).then(function (val) {
736 cn.label_class(val['cat.default_classification_scheme']);
740 } else if (n < o && n >= $scope.orig_cn_count) { // removing
741 var how_many = o - n;
744 .sort(function(a, b){return parseInt(a)-parseInt(b)})
745 .filter(function(x){ return parseInt(x) <= 0 });
746 for (var i = 0; i < how_many; i++) {
747 // Trimming the global list is a bit more tricky
748 angular.forEach($scope.struct[list[i]], function (d) {
749 angular.forEach( $scope.allcopies, function (l, j) {
750 if (l === d) $scope.allcopies.splice(j,1);
753 delete $scope.struct[list[i]];
766 .controller('EditCtrl',
767 ['$scope','$q','$window','$routeParams','$location','$timeout','egCore','egNet','egGridDataProvider','itemSvc','$uibModal',
768 function($scope , $q , $window , $routeParams , $location , $timeout , egCore , egNet , egGridDataProvider , itemSvc , $uibModal) {
770 $scope.defaults = { // If defaults are not set at all, allow everything
771 barcode_checkdigit : false,
772 auto_gen_barcode : false,
777 loan_duration : true,
782 deposit_amount : true,
786 mint_condition : true,
789 circ_modifier : true,
798 $scope.new_lib_to_add = egCore.org.get(egCore.auth.user().ws_ou());
799 $scope.changeNewLib = function (org) {
800 $scope.new_lib_to_add = org;
802 $scope.addLibToStruct = function () {
803 var newLib = $scope.new_lib_to_add;
804 var cn = new egCore.idl.acn();
805 cn.id( --itemSvc.new_cn_id );
807 cn.prefix( $scope.defaults.prefix || -1 );
808 cn.suffix( $scope.defaults.suffix || -1 );
809 cn.label_class( $scope.defaults.classification || 1 );
810 cn.owning_lib( newLib.id() );
811 cn.record( $scope.record_id );
813 var cp = itemSvc.generateNewCopy(
820 $scope.data.addCopy(cp);
822 if (!$scope.defaults.classification) {
824 ['cat.default_classification_scheme'],
826 ).then(function (val) {
827 cn.label_class(val['cat.default_classification_scheme']);
832 $scope.embedded = ($routeParams.mode && $routeParams.mode == 'embedded') ? true : false;
833 $scope.edit_templates = ($location.path().match(/edit_template/)) ? true : false;
835 $scope.saveDefaults = function () {
836 egCore.hatch.setItem('cat.copy.defaults', $scope.defaults);
839 $scope.fetchDefaults = function () {
840 egCore.hatch.getItem('cat.copy.defaults').then(function(t) {
843 if (!$scope.batch) $scope.batch = {};
844 $scope.batch.classification = $scope.defaults.classification;
845 $scope.batch.prefix = $scope.defaults.prefix;
846 $scope.batch.suffix = $scope.defaults.suffix;
847 $scope.working.statcat_filter = $scope.defaults.statcat_filter;
849 typeof $scope.defaults.statcat_filter == 'object' &&
850 Object.keys($scope.defaults.statcat_filter).length > 0
852 // want fieldmapper object here...
853 $scope.defaults.statcat_filter =
854 egCore.idl.Clone($scope.defaults.statcat_filter);
856 $scope.working.statcat_filter = $scope.defaults.statcat_filter.id();
858 if ($scope.defaults.always_volumes) $scope.show_vols = true;
859 if ($scope.defaults.barcode_checkdigit) itemSvc.barcode_checkdigit = true;
860 if ($scope.defaults.auto_gen_barcode) itemSvc.auto_gen_barcode = true;
864 $scope.fetchDefaults();
866 $scope.$watch('defaults.statcat_filter', function() {
867 $scope.saveDefaults();
869 $scope.$watch('defaults.auto_gen_barcode', function (n,o) {
870 itemSvc.auto_gen_barcode = n
873 $scope.$watch('defaults.barcode_checkdigit', function (n,o) {
874 itemSvc.barcode_checkdigit = n
877 $scope.dirty = false;
878 $scope.$watch('dirty',
879 function(newVal, oldVal) {
880 if (newVal && newVal != oldVal) {
881 $($window).on('beforeunload.edit', function(){
882 return 'There is unsaved data!'
885 $($window).off('beforeunload.edit');
890 $scope.only_vols = false;
891 $scope.show_vols = true;
892 $scope.show_copies = true;
894 $scope.tracker = function (x,f) { if (x) return x[f]() };
895 $scope.idTracker = function (x) { if (x) return $scope.tracker(x,'id') };
896 $scope.cant_have_vols = function (id) { return !egCore.org.CanHaveVolumes(id); };
898 $scope.orgById = function (id) { return egCore.org.get(id) }
899 $scope.statusById = function (id) {
900 return $scope.status_list.filter( function (s) { return s.id() == id } )[0];
902 $scope.locationById = function (id) {
903 return $scope.location_cache[''+id];
906 $scope.workingToComplete = function () {
907 angular.forEach( $scope.workingGridControls.selectedItems(), function (c) {
908 angular.forEach( itemSvc.copies, function (w, i) {
910 $scope.completed_copies = $scope.completed_copies.concat(itemSvc.copies.splice(i,1));
917 $scope.completeToWorking = function () {
918 angular.forEach( $scope.completedGridControls.selectedItems(), function (c) {
919 angular.forEach( $scope.completed_copies, function (w, i) {
921 itemSvc.copies = itemSvc.copies.concat($scope.completed_copies.splice(i,1));
928 createSimpleUpdateWatcher = function (field) {
929 return $scope.$watch('working.' + field, function () {
930 var newval = $scope.working[field];
932 if (typeof newval != 'undefined') {
933 if (angular.isObject(newval)) { // we'll use the pkey
934 if (newval.id) newval = newval.id();
935 else if (newval.code) newval = newval.code();
938 if (""+newval == "" || newval == null) {
939 $scope.working[field] = undefined;
943 if ($scope.workingGridControls && $scope.workingGridControls.selectedItems) {
945 $scope.workingGridControls.selectedItems(),
947 if (cp[field]() !== newval) {
961 statcat_filter: undefined
964 $scope.statcatUpdate = function (id) {
965 var newval = $scope.working.statcats[id];
967 if (typeof newval != 'undefined') {
968 if (angular.isObject(newval)) { // we'll use the pkey
969 newval = newval.id();
972 if (""+newval == "" || newval == null) {
973 $scope.working.statcats[id] = undefined;
977 if (!$scope.in_item_select && $scope.workingGridControls && $scope.workingGridControls.selectedItems) {
979 $scope.workingGridControls.selectedItems(),
984 angular.forEach( cp.stat_cat_entries(), function (e) {
985 if (e.stat_cat() == id) { // mark deleted
992 var e = new egCore.idl.asce();
998 cp.stat_cat_entries() ?
999 cp.stat_cat_entries().concat([ e ]) :
1005 // trim out all deleted ones; the API used to
1006 // do the update doesn't actually consult
1007 // isdeleted for stat cat entries
1008 cp.stat_cat_entries(
1009 cp.stat_cat_entries().filter(function (e) {
1010 return !Boolean(e.isdeleted());
1021 var dataKey = $routeParams.dataKey;
1022 console.debug('dataKey: ' + dataKey);
1024 if ((dataKey && dataKey.length > 0) || $scope.edit_templates) {
1026 $scope.templates = {};
1027 $scope.template_name = '';
1028 $scope.template_name_list = [];
1030 $scope.fetchTemplates = function () {
1031 egCore.hatch.getItem('cat.copy.templates').then(function(t) {
1033 $scope.templates = t;
1034 $scope.template_name_list = Object.keys(t);
1037 egCore.hatch.getItem('cat.copy.last_template').then(function(t) {
1038 if (t) $scope.template_name = t;
1041 $scope.fetchTemplates();
1043 $scope.applyTemplate = function (n) {
1044 angular.forEach($scope.templates[n], function (v,k) {
1045 if (k == 'circ_lib') {
1046 $scope.working[k] = egCore.org.get(v);
1047 } else if (!angular.isObject(v)) {
1048 $scope.working[k] = angular.copy(v);
1050 angular.forEach(v, function (sv,sk) {
1051 if (k == 'callnumber') {
1052 angular.forEach(v, function (cnv,cnk) {
1053 $scope.batch[cnk] = cnv;
1055 $scope.applyBatchCNValues();
1057 $scope.working[k][sk] = angular.copy(sv);
1058 if (k == 'statcats') $scope.statcatUpdate(sk);
1063 egCore.hatch.setItem('cat.copy.last_template', n);
1066 $scope.copytab = 'working';
1067 $scope.tab = 'edit';
1068 $scope.summaryRecord = null;
1069 $scope.record_id = null;
1071 $scope.completed_copies = [];
1072 $scope.location_orgs = [];
1073 $scope.location_cache = {};
1074 $scope.statcats = [];
1075 if (!$scope.batch) $scope.batch = {};
1077 $scope.applyBatchCNValues = function () {
1078 if ($scope.data.tree) {
1079 angular.forEach($scope.data.tree, function(cn_hash) {
1080 angular.forEach(cn_hash, function(copies) {
1081 angular.forEach(copies, function(cp) {
1082 if (typeof $scope.batch.classification != 'undefined' && $scope.batch.classification != '') {
1083 var label_class = $scope.classification_list.filter(function(p){ return p.id() == $scope.batch.classification })[0];
1084 cp.call_number().label_class(label_class);
1085 cp.call_number().ischanged(1);
1086 $scope.dirty = true;
1088 if (typeof $scope.batch.prefix != 'undefined' && $scope.batch.prefix != '') {
1089 var prefix = $scope.prefix_list.filter(function(p){ return p.id() == $scope.batch.prefix })[0];
1090 cp.call_number().prefix(prefix);
1091 cp.call_number().ischanged(1);
1092 $scope.dirty = true;
1094 if (typeof $scope.batch.label != 'undefined' && $scope.batch.label != '') {
1095 cp.call_number().label($scope.batch.label);
1096 cp.call_number().ischanged(1);
1097 $scope.dirty = true;
1099 if (typeof $scope.batch.suffix != 'undefined' && $scope.batch.suffix != '') {
1100 var suffix = $scope.suffix_list.filter(function(p){ return p.id() == $scope.batch.suffix })[0];
1101 cp.call_number().suffix(suffix);
1102 cp.call_number().ischanged(1);
1103 $scope.dirty = true;
1111 $scope.clearWorking = function () {
1112 angular.forEach($scope.working, function (v,k,o) {
1113 if (!angular.isObject(v)) {
1114 if (typeof v != 'undefined')
1115 $scope.working[k] = undefined;
1116 } else if (k != 'circ_lib') {
1117 angular.forEach(v, function (sv,sk) {
1118 if (typeof v != 'undefined')
1119 $scope.working[k][sk] = undefined;
1123 $scope.working.circ_lib = undefined; // special
1126 $scope.completedGridDataProvider = egGridDataProvider.instance({
1127 get : function(offset, count) {
1128 //return provider.arrayNotifier(itemSvc.copies, offset, count);
1129 return this.arrayNotifier($scope.completed_copies, offset, count);
1133 $scope.completedGridControls = {};
1135 $scope.workingGridDataProvider = egGridDataProvider.instance({
1136 get : function(offset, count) {
1137 //return provider.arrayNotifier(itemSvc.copies, offset, count);
1138 return this.arrayNotifier(itemSvc.copies, offset, count);
1142 $scope.workingGridControls = {};
1143 $scope.add_vols_copies = false;
1144 $scope.is_fast_add = false;
1148 'open-ils.actor.anon_cache.get_value',
1149 dataKey, 'edit-these-copies'
1150 ).then(function (data) {
1153 if (data.hide_vols && !$scope.defaults.always_volumes) $scope.show_vols = false;
1154 if (data.hide_copies) {
1155 $scope.show_copies = false;
1156 $scope.only_vols = true;
1159 $scope.record_id = data.record_id;
1161 function fetchRaw () {
1162 if (!$scope.only_vols) $scope.dirty = true;
1163 $scope.add_vols_copies = true;
1165 /* data.raw data structure looks like this:
1167 * callnumber : $cn_id, // optional, to add a copy to a cn
1168 * owner : $org, // optional, defaults to ws_ou
1169 * label : $cn_label, // optional, to supply a label on a new cn
1170 * barcode : $cp_barcode // optional, to supply a barcode on a new cp
1171 * fast_add : boolean // optional, to specify whether this came
1175 * All can be left out and a completely empty vol/copy combo will be vivicated.
1181 if (proto.fast_add) $scope.is_fast_add = true;
1182 if (proto.callnumber) {
1183 return egCore.pcrud.retrieve('acn', proto.callnumber)
1184 .then(function(cn) {
1185 var cp = new itemSvc.generateNewCopy(
1187 proto.owner || egCore.auth.user().ws_ou(),
1189 ((!$scope.only_vols) ? true : false)
1192 if (proto.barcode) cp.barcode( proto.barcode );
1197 var cn = new egCore.idl.acn();
1198 cn.id( --itemSvc.new_cn_id );
1200 cn.prefix( $scope.defaults.prefix || -1 );
1201 cn.suffix( $scope.defaults.suffix || -1 );
1202 cn.owning_lib( proto.owner || egCore.auth.user().ws_ou() );
1203 cn.record( $scope.record_id );
1204 egCore.org.settings(
1205 ['cat.default_classification_scheme'],
1207 ).then(function (val) {
1209 $scope.defaults.classification ||
1210 val['cat.default_classification_scheme'] ||
1214 cn.label( proto.label );
1218 'open-ils.cat.biblio.record.marc_cn.retrieve',
1221 ).then(function(cn_array) {
1222 if (cn_array.length > 0) {
1223 for (var field in cn_array[0]) {
1224 cn.label( cn_array[0][field] );
1232 var cp = new itemSvc.generateNewCopy(
1234 proto.owner || egCore.auth.user().ws_ou(),
1239 if (proto.barcode) cp.barcode( proto.barcode );
1247 return itemSvc.copies;
1250 if (data.copies && data.copies.length)
1251 return itemSvc.fetchIds(data.copies).then(fetchRaw);
1257 }).then( function() {
1258 $scope.data = itemSvc;
1259 $scope.workingGridDataProvider.refresh();
1262 $scope.can_save = false;
1263 function check_saveable () {
1264 var can_save = true;
1268 if (i.duplicate_barcode || i.empty_barcode || i.call_number().empty_label)
1273 $scope.can_save = can_save;
1276 $scope.disableSave = function () {
1278 return !$scope.can_save;
1281 $scope.focusNextFirst = function(prev_lib,prev_bc) {
1284 angular.forEach(Object.keys($scope.data.tree).sort(), function (lib) {
1287 if (lib == prev_lib) {
1296 var first_cn = Object.keys($scope.data.tree[n])[0];
1297 var next = '#' + first_cn + '_' + $scope.data.tree[n][first_cn][0].id();
1300 if (!itemSvc.currently_generating) el.focus();
1301 if (prev_bc && itemSvc.auto_gen_barcode && el.val() == "") {
1302 itemSvc.nextBarcode(prev_bc).then(function(bc){
1305 el.trigger('change');
1308 itemSvc.currently_generating = false;
1314 $scope.in_item_select = false;
1315 $scope.afterItemSelect = function() { $scope.in_item_select = false };
1316 $scope.handleItemSelect = function (item_list) {
1317 if (item_list && item_list.length > 0) {
1318 $scope.in_item_select = true;
1320 angular.forEach(Object.keys($scope.defaults.attributes), function (attr) {
1322 var value_hash = {};
1323 angular.forEach(item_list, function (item) {
1325 var v = item[attr]()
1326 if (angular.isObject(v)) {
1327 if (v.id) v = v.id();
1328 else if (v.code) v = v.code();
1334 if (Object.keys(value_hash).length == 1) {
1335 if (attr == 'circ_lib') {
1336 $scope.working[attr] = egCore.org.get(item_list[0][attr]());
1338 $scope.working[attr] = item_list[0][attr]();
1341 $scope.working[attr] = undefined;
1345 angular.forEach($scope.statcats, function (sc) {
1348 var value_hash = {};
1350 angular.forEach(item_list, function (item) {
1351 if (item.stat_cat_entries()) {
1352 if (item.stat_cat_entries().length > 0) {
1353 var right_sc = item.stat_cat_entries().filter(function (e) {
1354 return e.stat_cat() == sc.id() && !Boolean(e.isdeleted());
1357 if (right_sc.length > 0) {
1358 value_hash[right_sc[0].id()] = right_sc[0].id();
1368 if (!none && Object.keys(value_hash).length == 1) {
1369 $scope.working.statcats[sc.id()] = value_hash[Object.keys(value_hash)[0]];
1371 $scope.working.statcats[sc.id()] = undefined;
1376 $scope.clearWorking();
1381 $scope.$watch('data.copies.length', function () {
1382 if ($scope.data.copies) {
1383 var base_orgs = $scope.data.copies.map(function(cp){
1384 return cp.circ_lib()
1386 $scope.data.copies.map(function(cp){
1387 return cp.call_number().owning_lib()
1390 [egCore.auth.user().ws_ou()]
1391 ).filter(function(e,i,a){
1392 return a.lastIndexOf(e) === i;
1396 angular.forEach(base_orgs, function(o) {
1397 all_orgs = all_orgs.concat( egCore.org.fullPath(o, true) );
1400 var final_orgs = all_orgs.filter(function(e,i,a){
1401 return a.lastIndexOf(e) === i;
1402 }).sort(function(a, b){return parseInt(a)-parseInt(b)});
1404 if ($scope.location_orgs.toString() != final_orgs.toString()) {
1405 $scope.location_orgs = final_orgs;
1406 if ($scope.location_orgs.length) {
1407 itemSvc.get_locations($scope.location_orgs).then(function(list){
1408 angular.forEach(list, function(l) {
1409 $scope.location_cache[ ''+l.id() ] = l;
1411 $scope.location_list = list;
1414 $scope.statcat_filter_list = [];
1415 angular.forEach($scope.location_orgs, function (o) {
1416 $scope.statcat_filter_list.push(egCore.org.get(o));
1419 itemSvc.get_statcats($scope.location_orgs).then(function(list){
1420 $scope.statcats = list;
1421 angular.forEach($scope.statcats, function (s) {
1423 if (!$scope.working)
1424 $scope.working = { statcats: {}, statcat_filter: undefined};
1425 if (!$scope.working.statcats)
1426 $scope.working.statcats = {};
1428 if (!$scope.in_item_select) {
1429 $scope.working.statcats[s.id()] = undefined;
1431 createStatcatUpdateWatcher(s.id());
1433 $scope.in_item_select = false;
1434 // do a refresh here to work around a race
1435 // condition that can result in stat cats
1436 // not being selected.
1437 $scope.workingGridDataProvider.refresh();
1443 $scope.workingGridDataProvider.refresh();
1446 $scope.statcat_visible = function (sc_owner) {
1447 var visible = typeof $scope.working.statcat_filter === 'undefined' || !$scope.working.statcat_filter;
1448 angular.forEach(egCore.org.ancestors(sc_owner), function (ancestor_org) {
1449 if ($scope.working.statcat_filter == ancestor_org.id())
1455 $scope.suffix_list = [];
1456 itemSvc.get_suffixes(egCore.auth.user().ws_ou()).then(function(list){
1457 $scope.suffix_list = list;
1460 $scope.prefix_list = [];
1461 itemSvc.get_prefixes(egCore.auth.user().ws_ou()).then(function(list){
1462 $scope.prefix_list = list;
1465 $scope.classification_list = [];
1466 itemSvc.get_classifications().then(function(list){
1467 $scope.classification_list = list;
1470 $scope.$watch('completed_copies.length', function () {
1471 $scope.completedGridDataProvider.refresh();
1474 $scope.location_list = [];
1475 itemSvc.get_locations().then(function(list){
1476 $scope.location_list = list;
1478 createSimpleUpdateWatcher('location');
1480 $scope.status_list = [];
1481 itemSvc.get_statuses().then(function(list){
1482 $scope.status_list = list;
1484 createSimpleUpdateWatcher('status');
1486 $scope.circ_modifier_list = [];
1487 itemSvc.get_circ_mods().then(function(list){
1488 $scope.circ_modifier_list = list;
1490 createSimpleUpdateWatcher('circ_modifier');
1492 $scope.circ_type_list = [];
1493 itemSvc.get_circ_types().then(function(list){
1494 $scope.circ_type_list = list;
1496 createSimpleUpdateWatcher('circ_as_type');
1498 $scope.age_protect_list = [];
1499 itemSvc.get_age_protects().then(function(list){
1500 $scope.age_protect_list = list;
1502 createSimpleUpdateWatcher('age_protect');
1504 $scope.floating_list = [];
1505 itemSvc.get_floating_groups().then(function(list){
1506 $scope.floating_list = list;
1508 createSimpleUpdateWatcher('floating');
1510 createSimpleUpdateWatcher('circ_lib');
1511 createSimpleUpdateWatcher('circulate');
1512 createSimpleUpdateWatcher('holdable');
1513 createSimpleUpdateWatcher('fine_level');
1514 createSimpleUpdateWatcher('loan_duration');
1515 createSimpleUpdateWatcher('price');
1516 createSimpleUpdateWatcher('cost');
1517 createSimpleUpdateWatcher('deposit');
1518 createSimpleUpdateWatcher('deposit_amount');
1519 createSimpleUpdateWatcher('mint_condition');
1520 createSimpleUpdateWatcher('opac_visible');
1521 createSimpleUpdateWatcher('ref');
1523 $scope.saveCompletedCopies = function (and_exit) {
1525 var perCnCopies = {};
1526 angular.forEach( $scope.completed_copies, function (cp) {
1527 var cn = cp.call_number();
1528 var cn_cps = cp.call_number().copies();
1529 cp.call_number().copies([]);
1530 var cn_id = cp.call_number().id();
1531 cp.call_number(cn_id); // prevent loops in JSON-ification
1532 if (!cnHash[cn_id]) {
1533 cnHash[cn_id] = egCore.idl.Clone(cn);
1534 perCnCopies[cn_id] = [egCore.idl.Clone(cp)];
1536 perCnCopies[cn_id].push(egCore.idl.Clone(cp));
1538 cp.call_number(cn); // put the data back
1539 cp.call_number().copies(cn_cps);
1540 if (typeof cnHash[cn_id].prefix() == 'object')
1541 cnHash[cn_id].prefix(cnHash[cn_id].prefix().id()); // un-object-ize some fields
1542 if (typeof cnHash[cn_id].suffix() == 'object')
1543 cnHash[cn_id].suffix(cnHash[cn_id].suffix().id()); // un-object-ize some fields
1546 angular.forEach(perCnCopies, function (v, k) {
1547 cnHash[k].copies(v);
1551 angular.forEach(cnHash, function (v, k) {
1557 'open-ils.cat.asset.volume.fleshed.batch.update.override',
1558 egCore.auth.token(), cnList, 1, { auto_merge_vols : 1, create_parts : 1 }
1559 ).then(function(update_count) {
1561 $scope.dirty = false;
1562 $timeout(function(){$window.close()});
1567 $scope.saveAndContinue = function () {
1568 $scope.saveCompletedCopies(false);
1571 $scope.workingSaveAndExit = function () {
1572 $scope.workingToComplete();
1573 $scope.saveAndExit();
1576 $scope.saveAndExit = function () {
1577 $scope.saveCompletedCopies(true);
1582 $scope.copy_notes_dialog = function(copy_list) {
1583 var default_pub = Boolean($scope.defaults.copy_notes_pub);
1584 if (!angular.isArray(copy_list)) copy_list = [copy_list];
1586 return $uibModal.open({
1587 templateUrl: './cat/volcopy/t_copy_notes',
1590 ['$scope','$uibModalInstance',
1591 function($scope , $uibModalInstance) {
1592 $scope.focusNote = true;
1594 creator : egCore.auth.user().id(),
1600 $scope.require_initials = false;
1601 egCore.org.settings([
1602 'ui.staff.require_initials.copy_notes'
1603 ]).then(function(set) {
1604 $scope.require_initials = Boolean(set['ui.staff.require_initials.copy_notes']);
1607 $scope.note_list = [];
1608 if (copy_list.length == 1) {
1609 $scope.note_list = copy_list[0].notes();
1612 $scope.ok = function(note) {
1614 if (note.initials) note.value += ' [' + note.initials + ']';
1615 angular.forEach(copy_list, function (cp) {
1616 if (!angular.isArray(cp.notes())) cp.notes([]);
1617 var n = new egCore.idl.acpn();
1619 n.creator(note.creator);
1621 n.title(note.title);
1622 n.value(note.value);
1623 n.owning_copy(cp.id());
1624 cp.notes().push( n );
1627 $uibModalInstance.close();
1630 $scope.cancel = function($event) {
1631 $uibModalInstance.dismiss();
1632 $event.preventDefault();
1640 .directive("egVolTemplate", function () {
1644 template: '<div ng-include="'+"'/eg/staff/cat/volcopy/t_attr_edit'"+'"></div>',
1648 controller : ['$scope','$window','itemSvc','egCore','ngToast',
1649 function ( $scope , $window , itemSvc , egCore , ngToast) {
1651 $scope.defaults = { // If defaults are not set at all, allow everything
1652 barcode_checkdigit : false,
1653 auto_gen_barcode : false,
1658 loan_duration : true,
1663 deposit_amount : true,
1664 opac_visible : true,
1667 mint_condition : true,
1670 circ_modifier : true,
1671 circ_as_type : true,
1679 $scope.fetchDefaults = function () {
1680 egCore.hatch.getItem('cat.copy.defaults').then(function(t) {
1682 $scope.defaults = t;
1683 $scope.working.statcat_filter = $scope.defaults.statcat_filter;
1685 typeof $scope.defaults.statcat_filter == 'object' &&
1686 Object.keys($scope.defaults.statcat_filter).length > 0
1688 // want fieldmapper object here...
1689 $scope.defaults.statcat_filter =
1690 egCore.idl.Clone($scope.defaults.statcat_filter);
1692 $scope.working.statcat_filter = $scope.defaults.statcat_filter.id();
1697 $scope.fetchDefaults();
1699 $scope.dirty = false;
1700 $scope.$watch('dirty',
1701 function(newVal, oldVal) {
1702 if (newVal && newVal != oldVal) {
1703 $($window).on('beforeunload.template', function(){
1704 return 'There is unsaved template data!'
1707 $($window).off('beforeunload.template');
1712 $scope.template_controls = true;
1714 $scope.fetchTemplates = function () {
1715 egCore.hatch.getItem('cat.copy.templates').then(function(t) {
1717 $scope.templates = t;
1718 $scope.template_name_list = Object.keys(t);
1722 $scope.fetchTemplates();
1724 $scope.applyTemplate = function (n) {
1725 angular.forEach($scope.templates[n], function (v,k) {
1726 if (k == 'circ_lib') {
1727 $scope.working[k] = egCore.org.get(v);
1728 } else if (!angular.isObject(v)) {
1729 $scope.working[k] = angular.copy(v);
1731 angular.forEach(v, function (sv,sk) {
1732 if (!(k in $scope.working))
1733 $scope.working[k] = {};
1734 $scope.working[k][sk] = angular.copy(sv);
1738 $scope.template_name = '';
1741 $scope.deleteTemplate = function (n) {
1743 delete $scope.templates[n]
1744 $scope.template_name_list = Object.keys($scope.templates);
1745 $scope.template_name = '';
1746 egCore.hatch.setItem('cat.copy.templates', $scope.templates);
1747 $scope.$parent.fetchTemplates();
1748 ngToast.create(egCore.strings.VOL_COPY_TEMPLATE_SUCCESS_DELETE);
1752 $scope.saveTemplate = function (n) {
1756 angular.forEach($scope.working, function (v,k) {
1757 if (angular.isObject(v)) { // we'll use the pkey
1758 if (v.id) v = v.id();
1759 else if (v.code) v = v.code();
1765 $scope.templates[n] = tmpl;
1766 $scope.template_name_list = Object.keys($scope.templates);
1768 egCore.hatch.setItem('cat.copy.templates', $scope.templates);
1769 $scope.$parent.fetchTemplates();
1771 $scope.dirty = false;
1773 // save all templates, as we might do after an import
1774 egCore.hatch.setItem('cat.copy.templates', $scope.templates);
1775 $scope.$parent.fetchTemplates();
1777 ngToast.create(egCore.strings.VOL_COPY_TEMPLATE_SUCCESS_SAVE);
1780 $scope.templates = {};
1781 $scope.imported_templates = { data : '' };
1782 $scope.template_name = '';
1783 $scope.template_name_list = [];
1785 $scope.$watch('imported_templates.data', function(newVal, oldVal) {
1786 if (newVal && newVal != oldVal) {
1788 var newTemplates = JSON.parse(newVal);
1789 if (!Object.keys(newTemplates).length) return;
1790 $scope.templates = newTemplates;
1791 $scope.template_name_list = Object.keys(newTemplates);
1792 $scope.template_name = '';
1794 console.log('tried to import an invalid copy template file');
1799 $scope.tracker = function (x,f) { if (x) return x[f]() };
1800 $scope.idTracker = function (x) { if (x) return $scope.tracker(x,'id') };
1801 $scope.cant_have_vols = function (id) { return !egCore.org.CanHaveVolumes(id); };
1803 $scope.orgById = function (id) { return egCore.org.get(id) }
1804 $scope.statusById = function (id) {
1805 return $scope.status_list.filter( function (s) { return s.id() == id } )[0];
1807 $scope.locationById = function (id) {
1808 return $scope.location_cache[''+id];
1811 createSimpleUpdateWatcher = function (field) {
1812 $scope.$watch('working.' + field, function () {
1813 var newval = $scope.working[field];
1815 if (typeof newval != 'undefined') {
1816 $scope.dirty = true;
1817 if (angular.isObject(newval)) { // we'll use the pkey
1818 if (newval.id) $scope.working[field] = newval.id();
1819 else if (newval.code) $scope.working[field] = newval.code();
1822 if (""+newval == "" || newval == null) {
1823 $scope.working[field] = undefined;
1832 statcat_filter: undefined
1835 $scope.statcat_visible = function (sc_owner) {
1836 var visible = typeof $scope.working.statcat_filter === 'undefined' || !$scope.working.statcat_filter;
1837 angular.forEach(egCore.org.ancestors(sc_owner), function (ancestor_org) {
1838 if ($scope.working.statcat_filter == ancestor_org.id())
1844 createStatcatUpdateWatcher = function (id) {
1845 return $scope.$watch('working.statcats[' + id + ']', function () {
1846 if ($scope.working.statcats) {
1847 var newval = $scope.working.statcats[id];
1849 if (typeof newval != 'undefined') {
1850 $scope.dirty = true;
1851 if (angular.isObject(newval)) { // we'll use the pkey
1852 newval = newval.id();
1855 if (""+newval == "" || newval == null) {
1856 $scope.working.statcats[id] = undefined;
1865 $scope.clearWorking = function () {
1866 angular.forEach($scope.working, function (v,k,o) {
1867 if (!angular.isObject(v)) {
1868 if (typeof v != 'undefined')
1869 $scope.working[k] = undefined;
1870 } else if (k != 'circ_lib') {
1871 angular.forEach(v, function (sv,sk) {
1872 $scope.working[k][sk] = undefined;
1876 $scope.working.circ_lib = undefined; // special
1877 $scope.dirty = false;
1880 $scope.working = {};
1881 $scope.location_orgs = [];
1882 $scope.location_cache = {};
1884 $scope.location_list = [];
1885 itemSvc.get_locations(
1886 egCore.org.fullPath( egCore.auth.user().ws_ou(), true )
1887 ).then(function(list){
1888 $scope.location_list = list;
1890 createSimpleUpdateWatcher('location');
1892 $scope.statcat_filter_list = egCore.org.fullPath( egCore.auth.user().ws_ou() );
1894 $scope.statcats = [];
1895 itemSvc.get_statcats(
1896 egCore.org.fullPath( egCore.auth.user().ws_ou(), true )
1897 ).then(function(list){
1898 $scope.statcats = list;
1899 angular.forEach($scope.statcats, function (s) {
1901 if (!$scope.working)
1902 $scope.working = { statcats: {}, statcat_filter: undefined};
1903 if (!$scope.working.statcats)
1904 $scope.working.statcats = {};
1906 $scope.working.statcats[s.id()] = undefined;
1907 createStatcatUpdateWatcher(s.id());
1911 $scope.status_list = [];
1912 itemSvc.get_statuses().then(function(list){
1913 $scope.status_list = list;
1915 createSimpleUpdateWatcher('status');
1917 $scope.circ_modifier_list = [];
1918 itemSvc.get_circ_mods().then(function(list){
1919 $scope.circ_modifier_list = list;
1921 createSimpleUpdateWatcher('circ_modifier');
1923 $scope.circ_type_list = [];
1924 itemSvc.get_circ_types().then(function(list){
1925 $scope.circ_type_list = list;
1927 createSimpleUpdateWatcher('circ_as_type');
1929 $scope.age_protect_list = [];
1930 itemSvc.get_age_protects().then(function(list){
1931 $scope.age_protect_list = list;
1933 createSimpleUpdateWatcher('age_protect');
1935 createSimpleUpdateWatcher('circulate');
1936 createSimpleUpdateWatcher('holdable');
1937 createSimpleUpdateWatcher('fine_level');
1938 createSimpleUpdateWatcher('loan_duration');
1939 createSimpleUpdateWatcher('cost');
1940 createSimpleUpdateWatcher('deposit');
1941 createSimpleUpdateWatcher('deposit_amount');
1942 createSimpleUpdateWatcher('mint_condition');
1943 createSimpleUpdateWatcher('opac_visible');
1944 createSimpleUpdateWatcher('ref');
1946 $scope.suffix_list = [];
1947 itemSvc.get_suffixes(egCore.auth.user().ws_ou()).then(function(list){
1948 $scope.suffix_list = list;
1951 $scope.prefix_list = [];
1952 itemSvc.get_prefixes(egCore.auth.user().ws_ou()).then(function(list){
1953 $scope.prefix_list = list;
1956 $scope.classification_list = [];
1957 itemSvc.get_classifications().then(function(list){
1958 $scope.classification_list = list;
1961 createSimpleUpdateWatcher('working.callnumber.classification');
1962 createSimpleUpdateWatcher('working.callnumber.prefix');
1963 createSimpleUpdateWatcher('working.callnumber.suffix');