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',
141 {owning_lib : orgs, deleted : 'f'},
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_magic_statuses = function() {
155 /* TODO: make these more configurable per lp1616170 */
160 ,8 /* On holds shelf */
161 ,16 /* Long overdue */
162 ,18 /* Canceled Transit */
166 service.get_statuses = function() {
168 return $q.when(egCore.env.ccs.list);
170 return egCore.pcrud.retrieveAll('ccs', {order_by : { ccs : 'name' }}, {atomic : true}).then(
172 egCore.env.absorbList(list, 'ccs');
179 service.get_circ_mods = function() {
181 return $q.when(egCore.env.ccm.list);
183 return egCore.pcrud.retrieveAll('ccm', {}, {atomic : true}).then(
185 egCore.env.absorbList(list, 'ccm');
192 service.get_circ_types = function() {
194 return $q.when(egCore.env.citm.list);
196 return egCore.pcrud.retrieveAll('citm', {}, {atomic : true}).then(
198 egCore.env.absorbList(list, 'citm');
205 service.get_age_protects = function() {
206 if (egCore.env.crahp)
207 return $q.when(egCore.env.crahp.list);
209 return egCore.pcrud.retrieveAll('crahp', {}, {atomic : true}).then(
211 egCore.env.absorbList(list, 'crahp');
218 service.get_floating_groups = function() {
220 return $q.when(egCore.env.cfg.list);
222 return egCore.pcrud.retrieveAll('cfg', {}, {atomic : true}).then(
224 egCore.env.absorbList(list, 'cfg');
231 service.bmp_parts = {};
232 service.get_parts = function(rec) {
233 if (service.bmp_parts[rec])
234 return $q.when(service.bmp_parts[rec]);
236 return egCore.pcrud.search('bmp',
237 {record : rec, deleted : 'f'},
238 null, {atomic : true}
239 ).then(function(list) {
240 service.bmp_parts[rec] = list;
249 acp : ['call_number','parts','stat_cat_entries', 'notes', 'tags'],
250 acn : ['label_class','prefix','suffix'],
255 service.addCopy = function (cp) {
257 if (!cp.parts()) cp.parts([]); // just in case...
259 var lib = cp.call_number().owning_lib();
260 var cn = cp.call_number().id();
262 if (!service.tree[lib]) service.tree[lib] = {};
263 if (!service.tree[lib][cn]) service.tree[lib][cn] = [];
265 service.tree[lib][cn].push(cp);
266 service.copies.push(cp);
269 service.checkDuplicateBarcode = function(bc, id) {
271 return egCore.pcrud.search('acp', { deleted : 'f', 'barcode' : bc, id : { '!=' : id } })
273 function () { return final },
274 function () { return final },
275 function () { final = true; }
279 service.fetchIds = function(idList) {
280 service.tree = {}; // clear the tree on fetch
281 service.copies = []; // clear the copy list on fetch
282 return egCore.pcrud.search('acp', { 'id' : idList }, service.flesh).then(null,null,
284 service.addCopy(copy);
289 // create a new acp object with default values
290 // (both hard-coded and coming from OU settings)
291 service.generateNewCopy = function(callNumber, owningLib, isFastAdd, isNew) {
292 var cp = new egCore.idl.acp();
293 cp.id( --service.new_cp_id );
297 cp.circ_lib( owningLib );
298 cp.call_number( callNumber );
301 cp.deposit_amount(0);
302 cp.fine_level(2); // Normal
303 cp.loan_duration(2); // Normal
304 cp.location(1); // Stacks
307 cp.opac_visible('t');
309 cp.mint_condition('t');
310 cp.empty_barcode = true;
312 var status_setting = isFastAdd ?
313 'cat.default_copy_status_fast' :
314 'cat.default_copy_status_normal';
318 ).then(function(set) {
319 var default_ccs = parseInt(set[status_setting]);
320 if (isNaN(default_ccs))
321 default_ccs = (isFastAdd ? 0 : 5); // 0 is Available, 5 is In Process
322 cp.status(default_ccs);
331 .directive('stringToNumber', function() {
334 link: function(scope, element, attrs, ngModel) {
335 var precision = attrs.precision || 0;
336 ngModel.$parsers.push(function(value) {
340 function updateDisplay() {
341 var value = parseFloat(ngModel.$viewValue);
342 if ( isNaN(value) ) { return; }
343 element.val(value.toFixed(precision));
346 ngModel.$formatters.push(function(value) {
347 return parseFloat(value);
350 ngModel.$viewChangeListeners.push(updateDisplay);
352 ngModel.$render = function() {
359 .directive("egVolCopyEdit", function () {
365 '<div class="col-xs-5" ng-class="{'+"'has-error'"+':barcode_has_error}">'+
366 '<input id="{{callNumber.id()}}_{{copy.id()}}"'+
367 ' eg-enter="nextBarcode(copy.id())" class="form-control"'+
368 ' type="text" ng-model="barcode" ng-change="updateBarcode()"/>'+
369 '<div class="label label-danger" ng-if="duplicate_barcode">{{duplicate_barcode_string}}</div>'+
370 '<div class="label label-danger" ng-if="empty_barcode">{{empty_barcode_string}}</div>'+
372 '<div class="col-xs-3"><input class="form-control" type="number" min="1" ng-model="copy_number" ng-change="updateCopyNo()"/></div>'+
373 '<div class="col-xs-4"><eg-basic-combo-box eg-disabled="record == 0" list="parts" selected="part"></eg-basic-combo-box></div>'+
376 scope: { focusNext: "=", copy: "=", callNumber: "=", index: "@", record: "@" },
377 controller : ['$scope','itemSvc','egCore',
378 function ( $scope , itemSvc , egCore ) {
379 $scope.new_part_id = 0;
380 $scope.barcode_has_error = false;
381 $scope.duplicate_barcode = false;
382 $scope.empty_barcode = false;
383 $scope.duplicate_barcode_string = window.duplicate_barcode_string;
384 $scope.empty_barcode_string = window.empty_barcode_string;
386 if (!$scope.copy.barcode()) $scope.copy.empty_barcode = true;
388 $scope.nextBarcode = function (i) {
389 $scope.focusNext(i, $scope.barcode);
392 $scope.updateBarcode = function () {
393 if ($scope.barcode != '') {
394 $scope.copy.empty_barcode = $scope.empty_barcode = false;
395 $scope.barcode_has_error = !Boolean(itemSvc.checkBarcode($scope.barcode));
396 itemSvc.checkDuplicateBarcode($scope.barcode, $scope.copy.id())
397 .then(function (state) { $scope.copy.duplicate_barcode = $scope.duplicate_barcode = state });
399 $scope.copy.empty_barcode = $scope.empty_barcode = true;
402 $scope.copy.barcode($scope.barcode);
403 $scope.copy.ischanged(1);
404 if (itemSvc.currently_generating)
405 $scope.focusNext($scope.copy.id(), $scope.barcode);
408 $scope.updateCopyNo = function () { $scope.copy.copy_number($scope.copy_number); $scope.copy.ischanged(1); };
409 $scope.updatePart = function () {
411 var p = $scope.part_list.filter(function (x) {
412 return x.label() == $scope.part
414 if (p.length > 0) { // preexisting part
416 } else { // create one...
417 var part = new egCore.idl.bmp();
418 part.id( --$scope.new_part_id );
420 part.label( $scope.part );
421 part.record( $scope.callNumber.record() );
422 $scope.copy.parts([part]);
423 $scope.copy.ischanged(1);
426 $scope.copy.parts([]);
428 $scope.copy.ischanged(1);
430 $scope.$watch('part', $scope.updatePart);
432 $scope.barcode = $scope.copy.barcode();
433 $scope.copy_number = $scope.copy.copy_number();
435 if ($scope.copy.parts()) {
436 $scope.part = $scope.copy.parts()[0];
437 if ($scope.part) $scope.part = $scope.part.label();
441 $scope.part_list = [];
443 itemSvc.get_parts($scope.callNumber.record()).then(function(list){
444 $scope.part_list = list;
445 angular.forEach(list, function(p){ $scope.parts.push(p.label()) });
446 $scope.parts = angular.copy($scope.parts);
455 .directive("egVolRow", function () {
462 '<div class="col-xs-2">'+
463 '<select ng-disabled="record == 0" class="form-control" ng-model="classification" ng-change="updateClassification()" ng-options="cl.name() for cl in classification_list"/>'+
465 '<div class="col-xs-1">'+
466 '<select ng-disabled="record == 0" class="form-control" ng-model="prefix" ng-change="updatePrefix()" ng-options="p.label() for p in prefix_list"/>'+
468 '<div class="col-xs-2">'+
469 '<input ng-disabled="record == 0" class="form-control" type="text" ng-change="updateLabel()" ng-model="label"/>'+
470 '<div class="label label-danger" ng-if="empty_label">{{empty_label_string}}</div>'+
472 '<div class="col-xs-1">'+
473 '<select ng-disabled="record == 0" class="form-control" ng-model="suffix" ng-change="updateSuffix()" ng-options="s.label() for s in suffix_list"/>'+
475 '<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>'+
476 '<div ng-hide="onlyVols" class="col-xs-5">'+
477 '<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>'+
481 scope: {focusNext: "=", allcopies: "=", copies: "=", onlyVols: "=", record: "@" },
482 controller : ['$scope','itemSvc','egCore',
483 function ( $scope , itemSvc , egCore ) {
484 $scope.callNumber = $scope.copies[0].call_number();
485 if (!$scope.callNumber.label()) $scope.callNumber.emtpy_label = true;
487 $scope.empty_label = false;
488 $scope.empty_label_string = window.empty_label_string;
490 $scope.idTracker = function (x) { if (x && x.id) return x.id() };
492 // XXX $() is not working! arg
493 $scope.focusNextBarcode = function (i, prev_bc) {
496 angular.forEach($scope.copies, function (cp) {
504 if (yep) n = cp.id();
508 var next = '#' + $scope.callNumber.id() + '_' + n;
511 if (!itemSvc.currently_generating) el.focus();
512 if (prev_bc && itemSvc.auto_gen_barcode && el.val() == "") {
513 itemSvc.nextBarcode(prev_bc).then(function(bc){
516 el.trigger('change');
519 itemSvc.currently_generating = false;
523 $scope.focusNext($scope.callNumber.id(),prev_bc)
527 $scope.suffix_list = [];
528 itemSvc.get_suffixes($scope.callNumber.owning_lib()).then(function(list){
529 $scope.suffix_list = list;
530 $scope.$watch('callNumber.suffix()', function (v) {
531 if (angular.isObject(v)) v = v.id();
532 $scope.suffix = $scope.suffix_list.filter( function (s) {
538 $scope.updateSuffix = function () {
539 angular.forEach($scope.copies, function(cp) {
540 cp.call_number().suffix($scope.suffix);
541 cp.call_number().ischanged(1);
545 $scope.prefix_list = [];
546 itemSvc.get_prefixes($scope.callNumber.owning_lib()).then(function(list){
547 $scope.prefix_list = list;
548 $scope.$watch('callNumber.prefix()', function (v) {
549 if (angular.isObject(v)) v = v.id();
550 $scope.prefix = $scope.prefix_list.filter(function (p) {
556 $scope.updatePrefix = function () {
557 angular.forEach($scope.copies, function(cp) {
558 cp.call_number().prefix($scope.prefix);
559 cp.call_number().ischanged(1);
562 $scope.$watch('callNumber.owning_lib()', function(oldLib, newLib) {
563 if (oldLib == newLib) return;
564 var currentPrefix = $scope.callNumber.prefix();
565 if (angular.isObject(currentPrefix)) currentPrefix = currentPrefix.id();
566 itemSvc.get_prefixes($scope.callNumber.owning_lib()).then(function(list){
567 $scope.prefix_list = list;
568 var newPrefixId = $scope.prefix_list.filter(function (p) {
569 return p.id() == currentPrefix;
571 if (newPrefixId.id) newPrefixId = newPrefixId.id();
572 $scope.prefix = $scope.prefix_list.filter(function (p) {
573 return p.id() == newPrefixId;
575 if ($scope.newPrefixId != currentPrefix) {
576 $scope.callNumber.prefix($scope.prefix);
579 var currentSuffix = $scope.callNumber.suffix();
580 if (angular.isObject(currentSuffix)) currentSuffix = currentSuffix.id();
581 itemSvc.get_suffixes($scope.callNumber.owning_lib()).then(function(list){
582 $scope.suffix_list = list;
583 var newSuffixId = $scope.suffix_list.filter(function (s) {
584 return s.id() == currentSuffix;
586 if (newSuffixId.id) newSuffixId = newSuffixId.id();
587 $scope.suffix = $scope.suffix_list.filter(function (s) {
588 return s.id() == newSuffixId;
590 if ($scope.newSuffixId != currentSuffix) {
591 $scope.callNumber.suffix($scope.suffix);
596 $scope.classification_list = [];
597 itemSvc.get_classifications().then(function(list){
598 $scope.classification_list = list;
599 $scope.$watch('callNumber.label_class()', function (v) {
600 if (angular.isObject(v)) v = v.id();
601 $scope.classification = $scope.classification_list.filter(function (c) {
607 $scope.updateClassification = function () {
608 angular.forEach($scope.copies, function(cp) {
609 cp.call_number().label_class($scope.classification);
610 cp.call_number().ischanged(1);
614 $scope.updateLabel = function () {
615 if ($scope.label == '') {
616 $scope.callNumber.empty_label = $scope.empty_label = true;
618 $scope.callNumber.empty_label = $scope.empty_label = false;
620 angular.forEach($scope.copies, function(cp) {
621 cp.call_number().label($scope.label);
622 cp.call_number().ischanged(1);
626 $scope.$watch('callNumber.label()', function (v) {
630 $scope.prefix = $scope.callNumber.prefix();
631 $scope.suffix = $scope.callNumber.suffix();
632 $scope.classification = $scope.callNumber.label_class();
633 $scope.label = $scope.callNumber.label();
635 $scope.copy_count = $scope.copies.length;
636 $scope.orig_copy_count = $scope.copy_count;
638 $scope.changeCPCount = function () {
639 while ($scope.copy_count > $scope.copies.length) {
640 var cp = itemSvc.generateNewCopy(
642 $scope.callNumber.owning_lib(),
646 $scope.copies.push( cp );
647 $scope.allcopies.push( cp );
651 if ($scope.copy_count >= $scope.orig_copy_count) {
652 var how_many = $scope.copies.length - $scope.copy_count;
654 var dead = $scope.copies.splice($scope.copy_count,how_many);
655 $scope.callNumber.copies($scope.copies);
657 // Trimming the global list is a bit more tricky
658 angular.forEach( dead, function (d) {
659 angular.forEach( $scope.allcopies, function (l, i) {
660 if (l === d) $scope.allcopies.splice(i,1);
673 .directive("egVolEdit", function () {
679 '<div class="col-xs-1"><eg-org-selector alldisabled="{{record == 0}}" selected="owning_lib" disable-test="cant_have_vols"></eg-org-selector></div>'+
680 '<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>'+
681 '<div class="col-xs-10">'+
682 '<eg-vol-row only-vols="onlyVols" record="{{record}}"'+
683 'ng-repeat="(cn,copies) in struct" '+
684 'focus-next="focusNextFirst" copies="copies" allcopies="allcopies">'+
689 scope: { focusNext: "=", allcopies: "=", struct: "=", lib: "@", record: "@", onlyVols: "=" },
690 controller : ['$scope','itemSvc','egCore',
691 function ( $scope , itemSvc , egCore ) {
692 $scope.first_cn = Object.keys($scope.struct)[0];
693 $scope.full_cn = $scope.struct[$scope.first_cn][0].call_number();
695 $scope.defaults = {};
696 egCore.hatch.getItem('cat.copy.defaults').then(function(t) {
702 $scope.focusNextFirst = function(prev_cn,prev_bc) {
705 angular.forEach(Object.keys($scope.struct).sort(), function (cn) {
717 var next = '#' + n + '_' + $scope.struct[n][0].id();
720 if (!itemSvc.currently_generating) el.focus();
721 if (prev_bc && itemSvc.auto_gen_barcode && el.val() == "") {
722 itemSvc.nextBarcode(prev_bc).then(function(bc){
725 el.trigger('change');
728 itemSvc.currently_generating = false;
732 $scope.focusNext($scope.lib, prev_bc);
736 $scope.cn_count = Object.keys($scope.struct).length;
737 $scope.orig_cn_count = $scope.cn_count;
739 $scope.owning_lib = egCore.org.get($scope.lib);
740 $scope.$watch('owning_lib', function (oldLib, newLib) {
741 if (oldLib == newLib) return;
742 angular.forEach( Object.keys($scope.struct), function (cn) {
743 $scope.struct[cn][0].call_number().owning_lib( $scope.owning_lib.id() );
744 $scope.struct[cn][0].call_number().ischanged(1);
748 $scope.cant_have_vols = function (id) { return !egCore.org.CanHaveVolumes(id); };
750 $scope.$watch('cn_count', function (n) {
751 var o = Object.keys($scope.struct).length;
752 if (n > o) { // adding
753 for (var i = o; o < n; o++) {
754 var cn = new egCore.idl.acn();
755 cn.id( --itemSvc.new_cn_id );
757 cn.prefix( $scope.defaults.prefix || -1 );
758 cn.suffix( $scope.defaults.suffix || -1 );
759 cn.label_class( $scope.defaults.classification || 1 );
760 cn.owning_lib( $scope.owning_lib.id() );
761 cn.record( $scope.full_cn.record() );
763 var cp = itemSvc.generateNewCopy(
765 $scope.owning_lib.id(),
770 $scope.struct[cn.id()] = [cp];
771 $scope.allcopies.push(cp);
772 if (!$scope.defaults.classification) {
774 ['cat.default_classification_scheme'],
776 ).then(function (val) {
777 cn.label_class(val['cat.default_classification_scheme']);
781 } else if (n < o && n >= $scope.orig_cn_count) { // removing
782 var how_many = o - n;
785 .sort(function(a, b){return parseInt(a)-parseInt(b)})
786 .filter(function(x){ return parseInt(x) <= 0 });
787 for (var i = 0; i < how_many; i++) {
788 // Trimming the global list is a bit more tricky
789 angular.forEach($scope.struct[list[i]], function (d) {
790 angular.forEach( $scope.allcopies, function (l, j) {
791 if (l === d) $scope.allcopies.splice(j,1);
794 delete $scope.struct[list[i]];
807 .controller('EditCtrl',
808 ['$scope','$q','$window','$routeParams','$location','$timeout','egCore','egNet','egGridDataProvider','itemSvc','$uibModal',
809 function($scope , $q , $window , $routeParams , $location , $timeout , egCore , egNet , egGridDataProvider , itemSvc , $uibModal) {
811 $scope.forms = {}; // Accessed by t_attr_edit.tt2
813 $scope.defaults = { // If defaults are not set at all, allow everything
814 barcode_checkdigit : false,
815 auto_gen_barcode : false,
821 loan_duration : true,
826 deposit_amount : true,
830 mint_condition : true,
833 circ_modifier : true,
842 $scope.new_lib_to_add = egCore.org.get(egCore.auth.user().ws_ou());
843 $scope.changeNewLib = function (org) {
844 $scope.new_lib_to_add = org;
846 $scope.addLibToStruct = function () {
847 var newLib = $scope.new_lib_to_add;
848 var cn = new egCore.idl.acn();
849 cn.id( --itemSvc.new_cn_id );
851 cn.prefix( $scope.defaults.prefix || -1 );
852 cn.suffix( $scope.defaults.suffix || -1 );
853 cn.label_class( $scope.defaults.classification || 1 );
854 cn.owning_lib( newLib.id() );
855 cn.record( $scope.record_id );
857 var cp = itemSvc.generateNewCopy(
864 $scope.data.addCopy(cp);
866 if (!$scope.defaults.classification) {
868 ['cat.default_classification_scheme'],
870 ).then(function (val) {
871 cn.label_class(val['cat.default_classification_scheme']);
876 $scope.embedded = ($routeParams.mode && $routeParams.mode == 'embedded') ? true : false;
877 $scope.edit_templates = ($location.path().match(/edit_template/)) ? true : false;
879 $scope.saveDefaults = function () {
880 egCore.hatch.setItem('cat.copy.defaults', $scope.defaults);
883 $scope.fetchDefaults = function () {
884 egCore.hatch.getItem('cat.copy.defaults').then(function(t) {
887 if (!$scope.batch) $scope.batch = {};
888 $scope.batch.classification = $scope.defaults.classification;
889 $scope.batch.prefix = $scope.defaults.prefix;
890 $scope.batch.suffix = $scope.defaults.suffix;
891 $scope.working.statcat_filter = $scope.defaults.statcat_filter;
893 typeof $scope.defaults.statcat_filter == 'object' &&
894 Object.keys($scope.defaults.statcat_filter).length > 0
896 // want fieldmapper object here...
897 $scope.defaults.statcat_filter =
898 egCore.idl.Clone($scope.defaults.statcat_filter);
900 $scope.working.statcat_filter = $scope.defaults.statcat_filter.id();
902 if ($scope.defaults.always_volumes) $scope.show_vols = true;
903 if ($scope.defaults.barcode_checkdigit) itemSvc.barcode_checkdigit = true;
904 if ($scope.defaults.auto_gen_barcode) itemSvc.auto_gen_barcode = true;
908 $scope.fetchDefaults();
910 $scope.$watch('defaults.statcat_filter', function() {
911 $scope.saveDefaults();
913 $scope.$watch('defaults.auto_gen_barcode', function (n,o) {
914 itemSvc.auto_gen_barcode = n
917 $scope.$watch('defaults.barcode_checkdigit', function (n,o) {
918 itemSvc.barcode_checkdigit = n
921 $scope.dirty = false;
922 $scope.$watch('dirty',
923 function(newVal, oldVal) {
924 if (newVal && newVal != oldVal) {
925 $($window).on('beforeunload.edit', function(){
926 return 'There is unsaved data!'
929 $($window).off('beforeunload.edit');
934 $scope.only_vols = false;
935 $scope.show_vols = true;
936 $scope.show_copies = true;
938 $scope.tracker = function (x,f) { if (x) return x[f]() };
939 $scope.idTracker = function (x) { if (x) return $scope.tracker(x,'id') };
940 $scope.cant_have_vols = function (id) { return !egCore.org.CanHaveVolumes(id); };
942 $scope.orgById = function (id) { return egCore.org.get(id) }
943 $scope.statusById = function (id) {
944 return $scope.status_list.filter( function (s) { return s.id() == id } )[0];
946 $scope.locationById = function (id) {
947 return $scope.location_cache[''+id];
950 $scope.workingToComplete = function () {
951 angular.forEach( $scope.workingGridControls.selectedItems(), function (c) {
952 angular.forEach( itemSvc.copies, function (w, i) {
954 $scope.completed_copies = $scope.completed_copies.concat(itemSvc.copies.splice(i,1));
961 $scope.completeToWorking = function () {
962 angular.forEach( $scope.completedGridControls.selectedItems(), function (c) {
963 angular.forEach( $scope.completed_copies, function (w, i) {
965 itemSvc.copies = itemSvc.copies.concat($scope.completed_copies.splice(i,1));
972 createSimpleUpdateWatcher = function (field,exclude_copies_with_one_of_these_values) {
973 return $scope.$watch('working.' + field, function () {
974 var newval = $scope.working[field];
976 if (typeof newval != 'undefined') {
977 if (angular.isObject(newval)) { // we'll use the pkey
978 if (newval.id) newval = newval.id();
979 else if (newval.code) newval = newval.code();
982 if (""+newval == "" || newval == null) {
983 $scope.working[field] = undefined;
987 if ($scope.workingGridControls && $scope.workingGridControls.selectedItems) {
989 $scope.workingGridControls.selectedItems(),
991 if (exclude_copies_with_one_of_these_values
992 && exclude_copies_with_one_of_these_values.indexOf(cp[field](),0) > -1) {
995 if (cp[field]() !== newval) {
1009 statcat_filter: undefined
1012 $scope.statcatUpdate = function (id) {
1013 var newval = $scope.working.statcats[id];
1015 if (typeof newval != 'undefined') {
1016 if (angular.isObject(newval)) { // we'll use the pkey
1017 newval = newval.id();
1020 if (""+newval == "" || newval == null) {
1021 $scope.working.statcats[id] = undefined;
1025 if (!$scope.in_item_select && $scope.workingGridControls && $scope.workingGridControls.selectedItems) {
1027 $scope.workingGridControls.selectedItems(),
1029 $scope.dirty = true;
1031 cp.stat_cat_entries(
1032 angular.forEach( cp.stat_cat_entries(), function (e) {
1033 if (e.stat_cat() == id) { // mark deleted
1040 var e = new egCore.idl.asce();
1045 cp.stat_cat_entries(
1046 cp.stat_cat_entries() ?
1047 cp.stat_cat_entries().concat([ e ]) :
1053 // trim out all deleted ones; the API used to
1054 // do the update doesn't actually consult
1055 // isdeleted for stat cat entries
1056 cp.stat_cat_entries(
1057 cp.stat_cat_entries().filter(function (e) {
1058 return !Boolean(e.isdeleted());
1069 var dataKey = $routeParams.dataKey;
1070 console.debug('dataKey: ' + dataKey);
1072 if ((dataKey && dataKey.length > 0) || $scope.edit_templates) {
1074 $scope.templates = {};
1075 $scope.template_name = '';
1076 $scope.template_name_list = [];
1078 $scope.fetchTemplates = function () {
1079 egCore.hatch.getItem('cat.copy.templates').then(function(t) {
1081 $scope.templates = t;
1082 $scope.template_name_list = Object.keys(t);
1085 egCore.hatch.getItem('cat.copy.last_template').then(function(t) {
1086 if (t) $scope.template_name = t;
1089 $scope.fetchTemplates();
1091 $scope.applyTemplate = function (n) {
1092 angular.forEach($scope.templates[n], function (v,k) {
1093 if (k == 'circ_lib') {
1094 $scope.working[k] = egCore.org.get(v);
1095 } else if (!angular.isObject(v)) {
1096 $scope.working[k] = angular.copy(v);
1098 angular.forEach(v, function (sv,sk) {
1099 if (k == 'callnumber') {
1100 angular.forEach(v, function (cnv,cnk) {
1101 $scope.batch[cnk] = cnv;
1103 $scope.applyBatchCNValues();
1105 $scope.working[k][sk] = angular.copy(sv);
1106 if (k == 'statcats') $scope.statcatUpdate(sk);
1111 egCore.hatch.setItem('cat.copy.last_template', n);
1114 $scope.copytab = 'working';
1115 $scope.tab = 'edit';
1116 $scope.summaryRecord = null;
1117 $scope.record_id = null;
1119 $scope.completed_copies = [];
1120 $scope.location_orgs = [];
1121 $scope.location_cache = {};
1122 $scope.statcats = [];
1123 if (!$scope.batch) $scope.batch = {};
1125 $scope.applyBatchCNValues = function () {
1126 if ($scope.data.tree) {
1127 angular.forEach($scope.data.tree, function(cn_hash) {
1128 angular.forEach(cn_hash, function(copies) {
1129 angular.forEach(copies, function(cp) {
1130 if (typeof $scope.batch.classification != 'undefined' && $scope.batch.classification != '') {
1131 var label_class = $scope.classification_list.filter(function(p){ return p.id() == $scope.batch.classification })[0];
1132 cp.call_number().label_class(label_class);
1133 cp.call_number().ischanged(1);
1134 $scope.dirty = true;
1136 if (typeof $scope.batch.prefix != 'undefined' && $scope.batch.prefix != '') {
1137 var prefix = $scope.prefix_list.filter(function(p){ return p.id() == $scope.batch.prefix })[0];
1138 cp.call_number().prefix(prefix);
1139 cp.call_number().ischanged(1);
1140 $scope.dirty = true;
1142 if (typeof $scope.batch.label != 'undefined' && $scope.batch.label != '') {
1143 cp.call_number().label($scope.batch.label);
1144 cp.call_number().ischanged(1);
1145 $scope.dirty = true;
1147 if (typeof $scope.batch.suffix != 'undefined' && $scope.batch.suffix != '') {
1148 var suffix = $scope.suffix_list.filter(function(p){ return p.id() == $scope.batch.suffix })[0];
1149 cp.call_number().suffix(suffix);
1150 cp.call_number().ischanged(1);
1151 $scope.dirty = true;
1159 $scope.clearWorking = function () {
1160 angular.forEach($scope.working, function (v,k,o) {
1161 if (!angular.isObject(v)) {
1162 if (typeof v != 'undefined')
1163 $scope.working[k] = undefined;
1164 } else if (k != 'circ_lib') {
1165 angular.forEach(v, function (sv,sk) {
1166 if (typeof v != 'undefined')
1167 $scope.working[k][sk] = undefined;
1171 $scope.working.circ_lib = undefined; // special
1174 $scope.completedGridDataProvider = egGridDataProvider.instance({
1175 get : function(offset, count) {
1176 //return provider.arrayNotifier(itemSvc.copies, offset, count);
1177 return this.arrayNotifier($scope.completed_copies, offset, count);
1181 $scope.completedGridControls = {};
1183 $scope.workingGridDataProvider = egGridDataProvider.instance({
1184 get : function(offset, count) {
1185 //return provider.arrayNotifier(itemSvc.copies, offset, count);
1186 return this.arrayNotifier(itemSvc.copies, offset, count);
1190 $scope.workingGridControls = {};
1191 $scope.add_vols_copies = false;
1192 $scope.is_fast_add = false;
1196 'open-ils.actor.anon_cache.get_value',
1197 dataKey, 'edit-these-copies'
1198 ).then(function (data) {
1201 if (data.hide_vols && !$scope.defaults.always_volumes) $scope.show_vols = false;
1202 if (data.hide_copies) {
1203 $scope.show_copies = false;
1204 $scope.only_vols = true;
1207 $scope.record_id = data.record_id;
1209 function fetchRaw () {
1210 if (!$scope.only_vols) $scope.dirty = true;
1211 $scope.add_vols_copies = true;
1213 /* data.raw data structure looks like this:
1215 * callnumber : $cn_id, // optional, to add a copy to a cn
1216 * owner : $org, // optional, defaults to ws_ou
1217 * label : $cn_label, // optional, to supply a label on a new cn
1218 * barcode : $cp_barcode // optional, to supply a barcode on a new cp
1219 * fast_add : boolean // optional, to specify whether this came
1223 * All can be left out and a completely empty vol/copy combo will be vivicated.
1229 if (proto.fast_add) $scope.is_fast_add = true;
1230 if (proto.callnumber) {
1231 return egCore.pcrud.retrieve('acn', proto.callnumber)
1232 .then(function(cn) {
1233 var cp = new itemSvc.generateNewCopy(
1235 proto.owner || egCore.auth.user().ws_ou(),
1237 ((!$scope.only_vols) ? true : false)
1240 if (proto.barcode) {
1241 cp.barcode( proto.barcode );
1242 cp.empty_barcode = false;
1248 var cn = new egCore.idl.acn();
1249 cn.id( --itemSvc.new_cn_id );
1251 cn.prefix( $scope.defaults.prefix || -1 );
1252 cn.suffix( $scope.defaults.suffix || -1 );
1253 cn.owning_lib( proto.owner || egCore.auth.user().ws_ou() );
1254 cn.record( $scope.record_id );
1255 egCore.org.settings(
1256 ['cat.default_classification_scheme'],
1258 ).then(function (val) {
1260 $scope.defaults.classification ||
1261 val['cat.default_classification_scheme'] ||
1265 cn.label( proto.label );
1269 'open-ils.cat.biblio.record.marc_cn.retrieve',
1272 ).then(function(cn_array) {
1273 if (cn_array.length > 0) {
1274 for (var field in cn_array[0]) {
1275 cn.label( cn_array[0][field] );
1283 var cp = new itemSvc.generateNewCopy(
1285 proto.owner || egCore.auth.user().ws_ou(),
1290 if (proto.barcode) {
1291 cp.barcode( proto.barcode );
1292 cp.empty_barcode = false;
1301 return itemSvc.copies;
1304 if (data.copies && data.copies.length)
1305 return itemSvc.fetchIds(data.copies).then(fetchRaw);
1311 }).then( function() {
1312 $scope.data = itemSvc;
1313 $scope.workingGridDataProvider.refresh();
1316 $scope.can_save = false;
1317 function check_saveable () {
1318 var can_save = true;
1322 if (i.duplicate_barcode || i.empty_barcode || i.call_number().empty_label)
1326 if ($scope.forms.myForm && $scope.forms.myForm.$invalid) {
1329 $scope.can_save = can_save;
1332 $scope.disableSave = function () {
1334 return !$scope.can_save;
1337 $scope.focusNextFirst = function(prev_lib,prev_bc) {
1340 angular.forEach(Object.keys($scope.data.tree).sort(), function (lib) {
1343 if (lib == prev_lib) {
1352 var first_cn = Object.keys($scope.data.tree[n])[0];
1353 var next = '#' + first_cn + '_' + $scope.data.tree[n][first_cn][0].id();
1356 if (!itemSvc.currently_generating) el.focus();
1357 if (prev_bc && itemSvc.auto_gen_barcode && el.val() == "") {
1358 itemSvc.nextBarcode(prev_bc).then(function(bc){
1361 el.trigger('change');
1364 itemSvc.currently_generating = false;
1370 $scope.in_item_select = false;
1371 $scope.afterItemSelect = function() { $scope.in_item_select = false };
1372 $scope.handleItemSelect = function (item_list) {
1373 if (item_list && item_list.length > 0) {
1374 $scope.in_item_select = true;
1376 angular.forEach(Object.keys($scope.defaults.attributes), function (attr) {
1378 var value_hash = {};
1379 angular.forEach(item_list, function (item) {
1381 var v = item[attr]()
1382 if (angular.isObject(v)) {
1383 if (v.id) v = v.id();
1384 else if (v.code) v = v.code();
1390 if (Object.keys(value_hash).length == 1) {
1391 if (attr == 'circ_lib') {
1392 $scope.working[attr] = egCore.org.get(item_list[0][attr]());
1394 $scope.working[attr] = item_list[0][attr]();
1397 $scope.working[attr] = undefined;
1401 angular.forEach($scope.statcats, function (sc) {
1404 var value_hash = {};
1406 angular.forEach(item_list, function (item) {
1407 if (item.stat_cat_entries()) {
1408 if (item.stat_cat_entries().length > 0) {
1409 var right_sc = item.stat_cat_entries().filter(function (e) {
1410 return e.stat_cat() == sc.id() && !Boolean(e.isdeleted());
1413 if (right_sc.length > 0) {
1414 value_hash[right_sc[0].id()] = right_sc[0].id();
1424 if (!none && Object.keys(value_hash).length == 1) {
1425 $scope.working.statcats[sc.id()] = value_hash[Object.keys(value_hash)[0]];
1427 $scope.working.statcats[sc.id()] = undefined;
1432 $scope.clearWorking();
1437 $scope.$watch('data.copies.length', function () {
1438 if ($scope.data.copies) {
1439 var base_orgs = $scope.data.copies.map(function(cp){
1440 return cp.circ_lib()
1442 $scope.data.copies.map(function(cp){
1443 return cp.call_number().owning_lib()
1446 [egCore.auth.user().ws_ou()]
1447 ).filter(function(e,i,a){
1448 return a.lastIndexOf(e) === i;
1452 angular.forEach(base_orgs, function(o) {
1453 all_orgs = all_orgs.concat( egCore.org.fullPath(o, true) );
1456 var final_orgs = all_orgs.filter(function(e,i,a){
1457 return a.lastIndexOf(e) === i;
1458 }).sort(function(a, b){return parseInt(a)-parseInt(b)});
1460 if ($scope.location_orgs.toString() != final_orgs.toString()) {
1461 $scope.location_orgs = final_orgs;
1462 if ($scope.location_orgs.length) {
1463 itemSvc.get_locations($scope.location_orgs).then(function(list){
1464 angular.forEach(list, function(l) {
1465 $scope.location_cache[ ''+l.id() ] = l;
1467 $scope.location_list = list;
1470 $scope.statcat_filter_list = [];
1471 angular.forEach($scope.location_orgs, function (o) {
1472 $scope.statcat_filter_list.push(egCore.org.get(o));
1475 itemSvc.get_statcats($scope.location_orgs).then(function(list){
1476 $scope.statcats = list;
1477 angular.forEach($scope.statcats, function (s) {
1479 if (!$scope.working)
1480 $scope.working = { statcats: {}, statcat_filter: undefined};
1481 if (!$scope.working.statcats)
1482 $scope.working.statcats = {};
1484 if (!$scope.in_item_select) {
1485 $scope.working.statcats[s.id()] = undefined;
1487 createStatcatUpdateWatcher(s.id());
1489 $scope.in_item_select = false;
1490 // do a refresh here to work around a race
1491 // condition that can result in stat cats
1492 // not being selected.
1493 $scope.workingGridDataProvider.refresh();
1499 $scope.workingGridDataProvider.refresh();
1502 $scope.statcat_visible = function (sc_owner) {
1503 var visible = typeof $scope.working.statcat_filter === 'undefined' || !$scope.working.statcat_filter;
1504 angular.forEach(egCore.org.ancestors(sc_owner), function (ancestor_org) {
1505 if ($scope.working.statcat_filter == ancestor_org.id())
1511 $scope.suffix_list = [];
1512 itemSvc.get_suffixes(egCore.auth.user().ws_ou()).then(function(list){
1513 $scope.suffix_list = list;
1516 $scope.prefix_list = [];
1517 itemSvc.get_prefixes(egCore.auth.user().ws_ou()).then(function(list){
1518 $scope.prefix_list = list;
1521 $scope.classification_list = [];
1522 itemSvc.get_classifications().then(function(list){
1523 $scope.classification_list = list;
1526 $scope.$watch('completed_copies.length', function () {
1527 $scope.completedGridDataProvider.refresh();
1530 $scope.location_list = [];
1531 itemSvc.get_locations().then(function(list){
1532 $scope.location_list = list;
1534 createSimpleUpdateWatcher('location');
1536 $scope.status_list = [];
1537 itemSvc.get_magic_statuses().then(function(list){
1538 $scope.magic_status_list = list;
1539 createSimpleUpdateWatcher('status',$scope.magic_status_list);
1541 itemSvc.get_statuses().then(function(list){
1542 $scope.status_list = list;
1545 $scope.circ_modifier_list = [];
1546 itemSvc.get_circ_mods().then(function(list){
1547 $scope.circ_modifier_list = list;
1549 createSimpleUpdateWatcher('circ_modifier');
1551 $scope.circ_type_list = [];
1552 itemSvc.get_circ_types().then(function(list){
1553 $scope.circ_type_list = list;
1555 createSimpleUpdateWatcher('circ_as_type');
1557 $scope.age_protect_list = [];
1558 itemSvc.get_age_protects().then(function(list){
1559 $scope.age_protect_list = list;
1561 createSimpleUpdateWatcher('age_protect');
1563 $scope.floating_list = [];
1564 itemSvc.get_floating_groups().then(function(list){
1565 $scope.floating_list = list;
1567 createSimpleUpdateWatcher('floating');
1569 createSimpleUpdateWatcher('circ_lib');
1570 createSimpleUpdateWatcher('circulate');
1571 createSimpleUpdateWatcher('holdable');
1572 createSimpleUpdateWatcher('fine_level');
1573 createSimpleUpdateWatcher('loan_duration');
1574 createSimpleUpdateWatcher('price');
1575 createSimpleUpdateWatcher('cost');
1576 createSimpleUpdateWatcher('deposit');
1577 createSimpleUpdateWatcher('deposit_amount');
1578 createSimpleUpdateWatcher('mint_condition');
1579 createSimpleUpdateWatcher('opac_visible');
1580 createSimpleUpdateWatcher('ref');
1582 $scope.saveCompletedCopies = function (and_exit) {
1584 var perCnCopies = {};
1585 angular.forEach( $scope.completed_copies, function (cp) {
1586 var cn = cp.call_number();
1587 var cn_cps = cp.call_number().copies();
1588 cp.call_number().copies([]);
1589 var cn_id = cp.call_number().id();
1590 cp.call_number(cn_id); // prevent loops in JSON-ification
1591 if (!cnHash[cn_id]) {
1592 cnHash[cn_id] = egCore.idl.Clone(cn);
1593 perCnCopies[cn_id] = [egCore.idl.Clone(cp)];
1595 perCnCopies[cn_id].push(egCore.idl.Clone(cp));
1597 cp.call_number(cn); // put the data back
1598 cp.call_number().copies(cn_cps);
1599 if (typeof cnHash[cn_id].prefix() == 'object')
1600 cnHash[cn_id].prefix(cnHash[cn_id].prefix().id()); // un-object-ize some fields
1601 if (typeof cnHash[cn_id].suffix() == 'object')
1602 cnHash[cn_id].suffix(cnHash[cn_id].suffix().id()); // un-object-ize some fields
1605 angular.forEach(perCnCopies, function (v, k) {
1606 cnHash[k].copies(v);
1610 angular.forEach(cnHash, function (v, k) {
1616 'open-ils.cat.asset.volume.fleshed.batch.update.override',
1617 egCore.auth.token(), cnList, 1, { auto_merge_vols : 1, create_parts : 1, return_copy_ids : 1 }
1618 ).then(function(copy_ids) {
1620 $scope.dirty = false;
1621 if ($scope.defaults.print_item_labels) {
1624 'open-ils.actor.anon_cache.set_value',
1625 null, 'print-labels-these-copies', {
1628 ).then(function(key) {
1630 var url = egCore.env.basePath + 'cat/printlabels/' + key;
1631 $timeout(function() { $window.open(url, '_blank') }).then(
1632 function() { $timeout(function(){$window.close()}); }
1635 alert('Could not create anonymous cache key!');
1639 $timeout(function(){$window.close()});
1645 $scope.saveAndContinue = function () {
1646 $scope.saveCompletedCopies(false);
1649 $scope.workingSaveAndExit = function () {
1650 $scope.workingToComplete();
1651 $scope.saveAndExit();
1654 $scope.saveAndExit = function () {
1655 $scope.saveCompletedCopies(true);
1660 $scope.copy_notes_dialog = function(copy_list) {
1661 var default_pub = Boolean($scope.defaults.copy_notes_pub);
1662 if (!angular.isArray(copy_list)) copy_list = [copy_list];
1664 return $uibModal.open({
1665 templateUrl: './cat/volcopy/t_copy_notes',
1668 ['$scope','$uibModalInstance',
1669 function($scope , $uibModalInstance) {
1670 $scope.focusNote = true;
1672 creator : egCore.auth.user().id(),
1678 $scope.require_initials = false;
1679 egCore.org.settings([
1680 'ui.staff.require_initials.copy_notes'
1681 ]).then(function(set) {
1682 $scope.require_initials = Boolean(set['ui.staff.require_initials.copy_notes']);
1685 $scope.note_list = [];
1686 if (copy_list.length == 1) {
1687 $scope.note_list = copy_list[0].notes();
1690 $scope.ok = function(note) {
1692 if (note.initials) note.value += ' [' + note.initials + ']';
1693 angular.forEach(copy_list, function (cp) {
1694 if (!angular.isArray(cp.notes())) cp.notes([]);
1695 var n = new egCore.idl.acpn();
1697 n.creator(note.creator);
1699 n.title(note.title);
1700 n.value(note.value);
1701 n.owning_copy(cp.id());
1702 cp.notes().push( n );
1705 $uibModalInstance.close();
1708 $scope.cancel = function($event) {
1709 $uibModalInstance.dismiss();
1710 $event.preventDefault();
1716 $scope.copy_tags_dialog = function(copy_list) {
1717 if (!angular.isArray(copy_list)) copy_list = [copy_list];
1719 return $uibModal.open({
1720 templateUrl: './cat/volcopy/t_copy_tags',
1723 ['$scope','$uibModalInstance',
1724 function($scope , $uibModalInstance) {
1726 $scope.tag_map = [];
1728 var shared_tags = {};
1729 angular.forEach(copy_list, function (cp) {
1730 angular.forEach(cp.tags(), function(tag) {
1731 if (!(tag.tag().id() in shared_tags)) {
1732 shared_tags[tag.tag().id()] = 1;
1734 shared_tags[tag.tag().id()]++;
1736 if (!(tag.tag().id() in tag_hash)) {
1737 tag_hash[tag.tag().id()] = tag;
1741 angular.forEach(tag_hash, function(value, key) {
1742 if (shared_tags[key] == copy_list.length) {
1743 $scope.tag_map.push(value);
1747 $scope.tag_types = [];
1748 egCore.pcrud.retrieveAll('cctt', {order_by : { cctt : 'label' }}, {atomic : true}).then(function(list) {
1749 $scope.tag_types = list;
1750 $scope.tag_type = $scope.tag_types[0].code(); // just pick a default
1753 $scope.getTags = function(val) {
1754 return egCore.pcrud.search('acpt',
1756 owner : egCore.org.fullPath(egCore.auth.user().ws_ou(), true),
1757 label : { 'startwith' : {
1758 transform: 'evergreen.lowercase',
1759 value : [ 'evergreen.lowercase', val ]
1761 tag_type : $scope.tag_type
1763 { order_by : { 'acpt' : ['label'] } }, { atomic: true }
1764 ).then(function(list) {
1765 return list.map(function(item) {
1766 return item.label();
1771 $scope.addTag = function() {
1772 var tagLabel = $scope.selectedLabel;
1773 // clear the typeahead
1774 $scope.selectedLabel = "";
1776 // first, check tags already associated with the copy
1777 var foundMatch = false;
1778 angular.forEach($scope.tag_map, function(tag) {
1779 if (tag.tag().label() == tagLabel && tag.tag().tag_type() == $scope.tag_type) {
1781 if (tag.isdeleted()) tag.isdeleted(0); // just deleting the mapping
1785 egCore.pcrud.search('acpt',
1787 owner : egCore.org.fullPath(egCore.auth.user().ws_ou(), true),
1789 tag_type : $scope.tag_type
1791 { order_by : { 'acpt' : ['label'] } }, { atomic: true }
1792 ).then(function(list) {
1793 if (list.length > 0) {
1794 var newMap = new egCore.idl.acptcm();
1796 newMap.copy(copy_list[0].id());
1797 newMap.tag(egCore.idl.Clone(list[0]));
1798 $scope.tag_map.push(newMap);
1800 var newTag = new egCore.idl.acpt();
1802 newTag.owner(egCore.auth.user().ws_ou());
1803 newTag.label(tagLabel);
1805 newTag.tag_type($scope.tag_type);
1807 var newMap = new egCore.idl.acptcm();
1809 newMap.copy(copy_list[0].id());
1811 $scope.tag_map.push(newMap);
1817 $scope.ok = function(note) {
1818 // in the multi-item case, this works OK for
1819 // adding new maps to existing tags, but doesn't handle
1820 // all possibilities
1821 angular.forEach(copy_list, function (cp) {
1822 cp.tags($scope.tag_map);
1824 $uibModalInstance.close();
1827 $scope.cancel = function($event) {
1828 $uibModalInstance.dismiss();
1829 $event.preventDefault();
1837 .directive("egVolTemplate", function () {
1841 template: '<div ng-include="'+"'/eg/staff/cat/volcopy/t_attr_edit'"+'"></div>',
1845 controller : ['$scope','$window','itemSvc','egCore','ngToast',
1846 function ( $scope , $window , itemSvc , egCore , ngToast) {
1848 $scope.defaults = { // If defaults are not set at all, allow everything
1849 barcode_checkdigit : false,
1850 auto_gen_barcode : false,
1856 loan_duration : true,
1861 deposit_amount : true,
1862 opac_visible : true,
1865 mint_condition : true,
1868 circ_modifier : true,
1869 circ_as_type : true,
1877 $scope.fetchDefaults = function () {
1878 egCore.hatch.getItem('cat.copy.defaults').then(function(t) {
1880 $scope.defaults = t;
1881 $scope.working.statcat_filter = $scope.defaults.statcat_filter;
1883 typeof $scope.defaults.statcat_filter == 'object' &&
1884 Object.keys($scope.defaults.statcat_filter).length > 0
1886 // want fieldmapper object here...
1887 $scope.defaults.statcat_filter =
1888 egCore.idl.Clone($scope.defaults.statcat_filter);
1890 $scope.working.statcat_filter = $scope.defaults.statcat_filter.id();
1895 $scope.fetchDefaults();
1897 $scope.dirty = false;
1898 $scope.$watch('dirty',
1899 function(newVal, oldVal) {
1900 if (newVal && newVal != oldVal) {
1901 $($window).on('beforeunload.template', function(){
1902 return 'There is unsaved template data!'
1905 $($window).off('beforeunload.template');
1910 $scope.template_controls = true;
1912 $scope.fetchTemplates = function () {
1913 egCore.hatch.getItem('cat.copy.templates').then(function(t) {
1915 $scope.templates = t;
1916 $scope.template_name_list = Object.keys(t);
1920 $scope.fetchTemplates();
1922 $scope.applyTemplate = function (n) {
1923 angular.forEach($scope.templates[n], function (v,k) {
1924 if (k == 'circ_lib') {
1925 $scope.working[k] = egCore.org.get(v);
1926 } else if (!angular.isObject(v)) {
1927 $scope.working[k] = angular.copy(v);
1929 angular.forEach(v, function (sv,sk) {
1930 if (!(k in $scope.working))
1931 $scope.working[k] = {};
1932 $scope.working[k][sk] = angular.copy(sv);
1936 $scope.template_name = '';
1939 $scope.deleteTemplate = function (n) {
1941 delete $scope.templates[n]
1942 $scope.template_name_list = Object.keys($scope.templates);
1943 $scope.template_name = '';
1944 egCore.hatch.setItem('cat.copy.templates', $scope.templates);
1945 $scope.$parent.fetchTemplates();
1946 ngToast.create(egCore.strings.VOL_COPY_TEMPLATE_SUCCESS_DELETE);
1950 $scope.saveTemplate = function (n) {
1954 angular.forEach($scope.working, function (v,k) {
1955 if (angular.isObject(v)) { // we'll use the pkey
1956 if (v.id) v = v.id();
1957 else if (v.code) v = v.code();
1963 $scope.templates[n] = tmpl;
1964 $scope.template_name_list = Object.keys($scope.templates);
1966 egCore.hatch.setItem('cat.copy.templates', $scope.templates);
1967 $scope.$parent.fetchTemplates();
1969 $scope.dirty = false;
1971 // save all templates, as we might do after an import
1972 egCore.hatch.setItem('cat.copy.templates', $scope.templates);
1973 $scope.$parent.fetchTemplates();
1975 ngToast.create(egCore.strings.VOL_COPY_TEMPLATE_SUCCESS_SAVE);
1978 $scope.templates = {};
1979 $scope.imported_templates = { data : '' };
1980 $scope.template_name = '';
1981 $scope.template_name_list = [];
1983 $scope.$watch('imported_templates.data', function(newVal, oldVal) {
1984 if (newVal && newVal != oldVal) {
1986 var newTemplates = JSON.parse(newVal);
1987 if (!Object.keys(newTemplates).length) return;
1988 $scope.templates = newTemplates;
1989 $scope.template_name_list = Object.keys(newTemplates);
1990 $scope.template_name = '';
1992 console.log('tried to import an invalid copy template file');
1997 $scope.tracker = function (x,f) { if (x) return x[f]() };
1998 $scope.idTracker = function (x) { if (x) return $scope.tracker(x,'id') };
1999 $scope.cant_have_vols = function (id) { return !egCore.org.CanHaveVolumes(id); };
2001 $scope.orgById = function (id) { return egCore.org.get(id) }
2002 $scope.statusById = function (id) {
2003 return $scope.status_list.filter( function (s) { return s.id() == id } )[0];
2005 $scope.locationById = function (id) {
2006 return $scope.location_cache[''+id];
2009 createSimpleUpdateWatcher = function (field) {
2010 $scope.$watch('working.' + field, function () {
2011 var newval = $scope.working[field];
2013 if (typeof newval != 'undefined') {
2014 $scope.dirty = true;
2015 if (angular.isObject(newval)) { // we'll use the pkey
2016 if (newval.id) $scope.working[field] = newval.id();
2017 else if (newval.code) $scope.working[field] = newval.code();
2020 if (""+newval == "" || newval == null) {
2021 $scope.working[field] = undefined;
2030 statcat_filter: undefined
2033 $scope.statcat_visible = function (sc_owner) {
2034 var visible = typeof $scope.working.statcat_filter === 'undefined' || !$scope.working.statcat_filter;
2035 angular.forEach(egCore.org.ancestors(sc_owner), function (ancestor_org) {
2036 if ($scope.working.statcat_filter == ancestor_org.id())
2042 createStatcatUpdateWatcher = function (id) {
2043 return $scope.$watch('working.statcats[' + id + ']', function () {
2044 if ($scope.working.statcats) {
2045 var newval = $scope.working.statcats[id];
2047 if (typeof newval != 'undefined') {
2048 $scope.dirty = true;
2049 if (angular.isObject(newval)) { // we'll use the pkey
2050 newval = newval.id();
2053 if (""+newval == "" || newval == null) {
2054 $scope.working.statcats[id] = undefined;
2063 $scope.clearWorking = function () {
2064 angular.forEach($scope.working, function (v,k,o) {
2065 if (!angular.isObject(v)) {
2066 if (typeof v != 'undefined')
2067 $scope.working[k] = undefined;
2068 } else if (k != 'circ_lib') {
2069 angular.forEach(v, function (sv,sk) {
2070 $scope.working[k][sk] = undefined;
2074 $scope.working.circ_lib = undefined; // special
2075 $scope.dirty = false;
2078 $scope.working = {};
2079 $scope.location_orgs = [];
2080 $scope.location_cache = {};
2082 $scope.location_list = [];
2083 itemSvc.get_locations(
2084 egCore.org.fullPath( egCore.auth.user().ws_ou(), true )
2085 ).then(function(list){
2086 $scope.location_list = list;
2088 createSimpleUpdateWatcher('location');
2090 $scope.statcat_filter_list = egCore.org.fullPath( egCore.auth.user().ws_ou() );
2092 $scope.statcats = [];
2093 itemSvc.get_statcats(
2094 egCore.org.fullPath( egCore.auth.user().ws_ou(), true )
2095 ).then(function(list){
2096 $scope.statcats = list;
2097 angular.forEach($scope.statcats, function (s) {
2099 if (!$scope.working)
2100 $scope.working = { statcats: {}, statcat_filter: undefined};
2101 if (!$scope.working.statcats)
2102 $scope.working.statcats = {};
2104 $scope.working.statcats[s.id()] = undefined;
2105 createStatcatUpdateWatcher(s.id());
2109 $scope.status_list = [];
2110 itemSvc.get_magic_statuses().then(function(list){
2111 $scope.magic_status_list = list;
2113 itemSvc.get_statuses().then(function(list){
2114 $scope.status_list = list;
2116 createSimpleUpdateWatcher('status');
2118 $scope.circ_modifier_list = [];
2119 itemSvc.get_circ_mods().then(function(list){
2120 $scope.circ_modifier_list = list;
2122 createSimpleUpdateWatcher('circ_modifier');
2124 $scope.circ_type_list = [];
2125 itemSvc.get_circ_types().then(function(list){
2126 $scope.circ_type_list = list;
2128 createSimpleUpdateWatcher('circ_as_type');
2130 $scope.age_protect_list = [];
2131 itemSvc.get_age_protects().then(function(list){
2132 $scope.age_protect_list = list;
2134 createSimpleUpdateWatcher('age_protect');
2136 createSimpleUpdateWatcher('circulate');
2137 createSimpleUpdateWatcher('holdable');
2138 createSimpleUpdateWatcher('fine_level');
2139 createSimpleUpdateWatcher('loan_duration');
2140 createSimpleUpdateWatcher('cost');
2141 createSimpleUpdateWatcher('deposit');
2142 createSimpleUpdateWatcher('deposit_amount');
2143 createSimpleUpdateWatcher('mint_condition');
2144 createSimpleUpdateWatcher('opac_visible');
2145 createSimpleUpdateWatcher('ref');
2147 $scope.suffix_list = [];
2148 itemSvc.get_suffixes(egCore.auth.user().ws_ou()).then(function(list){
2149 $scope.suffix_list = list;
2152 $scope.prefix_list = [];
2153 itemSvc.get_prefixes(egCore.auth.user().ws_ou()).then(function(list){
2154 $scope.prefix_list = list;
2157 $scope.classification_list = [];
2158 itemSvc.get_classifications().then(function(list){
2159 $scope.classification_list = list;
2162 createSimpleUpdateWatcher('working.callnumber.classification');
2163 createSimpleUpdateWatcher('working.callnumber.prefix');
2164 createSimpleUpdateWatcher('working.callnumber.suffix');