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'},
145 acpl : ['owning_lib']
147 order_by : { acpl : 'name' }
153 service.get_suffixes = function(org) {
154 return egCore.pcrud.search('acns',
155 {owning_lib : egCore.org.fullPath(org, true)},
156 {order_by : { acns : 'label_sortkey' }}, {atomic : true}
161 service.get_magic_statuses = function() {
162 /* TODO: make these more configurable per lp1616170 */
167 ,8 /* On holds shelf */
168 ,16 /* Long overdue */
169 ,18 /* Canceled Transit */
173 service.get_statuses = function() {
175 return $q.when(egCore.env.ccs.list);
177 return egCore.pcrud.retrieveAll('ccs', {order_by : { ccs : 'name' }}, {atomic : true}).then(
179 egCore.env.absorbList(list, 'ccs');
186 service.get_circ_mods = function() {
188 return $q.when(egCore.env.ccm.list);
190 return egCore.pcrud.retrieveAll('ccm', {}, {atomic : true}).then(
192 egCore.env.absorbList(list, 'ccm');
199 service.get_circ_types = function() {
201 return $q.when(egCore.env.citm.list);
203 return egCore.pcrud.retrieveAll('citm', {}, {atomic : true}).then(
205 egCore.env.absorbList(list, 'citm');
212 service.get_age_protects = function() {
213 if (egCore.env.crahp)
214 return $q.when(egCore.env.crahp.list);
216 return egCore.pcrud.retrieveAll('crahp', {}, {atomic : true}).then(
218 egCore.env.absorbList(list, 'crahp');
225 service.get_floating_groups = function() {
227 return $q.when(egCore.env.cfg.list);
229 return egCore.pcrud.retrieveAll('cfg', {}, {atomic : true}).then(
231 egCore.env.absorbList(list, 'cfg');
238 service.bmp_parts = {};
239 service.get_parts = function(rec) {
240 if (service.bmp_parts[rec])
241 return $q.when(service.bmp_parts[rec]);
243 return egCore.pcrud.search('bmp',
244 {record : rec, deleted : 'f'},
245 null, {atomic : true}
246 ).then(function(list) {
247 service.bmp_parts[rec] = list;
256 acp : ['call_number','parts','stat_cat_entries', 'notes', 'tags'],
257 acn : ['label_class','prefix','suffix'],
262 service.addCopy = function (cp) {
264 if (!cp.parts()) cp.parts([]); // just in case...
266 var lib = cp.call_number().owning_lib();
267 var cn = cp.call_number().id();
269 if (!service.tree[lib]) service.tree[lib] = {};
270 if (!service.tree[lib][cn]) service.tree[lib][cn] = [];
272 service.tree[lib][cn].push(cp);
273 service.copies.push(cp);
276 service.checkDuplicateBarcode = function(bc, id) {
278 return egCore.pcrud.search('acp', { deleted : 'f', 'barcode' : bc, id : { '!=' : id } })
280 function () { return final },
281 function () { return final },
282 function () { final = true; }
286 service.fetchIds = function(idList) {
287 service.tree = {}; // clear the tree on fetch
288 service.copies = []; // clear the copy list on fetch
289 return egCore.pcrud.search('acp', { 'id' : idList }, service.flesh).then(null,null,
291 service.addCopy(copy);
296 // create a new acp object with default values
297 // (both hard-coded and coming from OU settings)
298 service.generateNewCopy = function(callNumber, owningLib, isFastAdd, isNew) {
299 var cp = new egCore.idl.acp();
300 cp.id( --service.new_cp_id );
304 cp.circ_lib( owningLib );
305 cp.call_number( callNumber );
308 cp.deposit_amount(0);
309 cp.fine_level(2); // Normal
310 cp.loan_duration(2); // Normal
311 cp.location(1); // Stacks
314 cp.opac_visible('t');
316 cp.mint_condition('t');
317 cp.empty_barcode = true;
319 var status_setting = isFastAdd ?
320 'cat.default_copy_status_fast' :
321 'cat.default_copy_status_normal';
325 ).then(function(set) {
326 var default_ccs = parseInt(set[status_setting]);
327 if (isNaN(default_ccs))
328 default_ccs = (isFastAdd ? 0 : 5); // 0 is Available, 5 is In Process
329 cp.status(default_ccs);
338 .directive('stringToNumber', function() {
341 link: function(scope, element, attrs, ngModel) {
342 var precision = attrs.precision || 0;
343 ngModel.$parsers.push(function(value) {
347 function updateDisplay() {
348 var value = parseFloat(ngModel.$viewValue);
349 if ( isNaN(value) ) { return; }
350 element.val(value.toFixed(precision));
353 ngModel.$formatters.push(function(value) {
354 return parseFloat(value);
357 ngModel.$viewChangeListeners.push(updateDisplay);
359 ngModel.$render = function() {
366 .directive("egVolCopyEdit", function () {
372 '<div class="col-xs-5" ng-class="{'+"'has-error'"+':barcode_has_error}">'+
373 '<input id="{{callNumber.id()}}_{{copy.id()}}"'+
374 ' eg-enter="nextBarcode(copy.id())" class="form-control"'+
375 ' type="text" ng-model="barcode" ng-change="updateBarcode()"/>'+
376 '<div class="label label-danger" ng-if="duplicate_barcode">{{duplicate_barcode_string}}</div>'+
377 '<div class="label label-danger" ng-if="empty_barcode">{{empty_barcode_string}}</div>'+
379 '<div class="col-xs-3"><input class="form-control" type="number" min="1" ng-model="copy_number" ng-change="updateCopyNo()"/></div>'+
380 '<div class="col-xs-4"><eg-basic-combo-box eg-disabled="record == 0" list="parts" selected="part"></eg-basic-combo-box></div>'+
383 scope: { focusNext: "=", copy: "=", callNumber: "=", index: "@", record: "@" },
384 controller : ['$scope','itemSvc','egCore',
385 function ( $scope , itemSvc , egCore ) {
386 $scope.new_part_id = 0;
387 $scope.barcode_has_error = false;
388 $scope.duplicate_barcode = false;
389 $scope.empty_barcode = false;
390 $scope.duplicate_barcode_string = window.duplicate_barcode_string;
391 $scope.empty_barcode_string = window.empty_barcode_string;
393 if (!$scope.copy.barcode()) $scope.copy.empty_barcode = true;
395 $scope.nextBarcode = function (i) {
396 $scope.focusNext(i, $scope.barcode);
399 $scope.updateBarcode = function () {
400 if ($scope.barcode != '') {
401 $scope.copy.empty_barcode = $scope.empty_barcode = false;
402 $scope.barcode_has_error = !Boolean(itemSvc.checkBarcode($scope.barcode));
403 itemSvc.checkDuplicateBarcode($scope.barcode, $scope.copy.id())
404 .then(function (state) { $scope.copy.duplicate_barcode = $scope.duplicate_barcode = state });
406 $scope.copy.empty_barcode = $scope.empty_barcode = true;
409 $scope.copy.barcode($scope.barcode);
410 $scope.copy.ischanged(1);
411 if (itemSvc.currently_generating)
412 $scope.focusNext($scope.copy.id(), $scope.barcode);
415 $scope.updateCopyNo = function () { $scope.copy.copy_number($scope.copy_number); $scope.copy.ischanged(1); };
416 $scope.updatePart = function () {
418 var p = $scope.part_list.filter(function (x) {
419 return x.label() == $scope.part
421 if (p.length > 0) { // preexisting part
423 } else { // create one...
424 var part = new egCore.idl.bmp();
425 part.id( --$scope.new_part_id );
427 part.label( $scope.part );
428 part.record( $scope.callNumber.record() );
429 $scope.copy.parts([part]);
430 $scope.copy.ischanged(1);
433 $scope.copy.parts([]);
435 $scope.copy.ischanged(1);
437 $scope.$watch('part', $scope.updatePart);
439 $scope.barcode = $scope.copy.barcode();
440 $scope.copy_number = $scope.copy.copy_number();
442 if ($scope.copy.parts()) {
443 $scope.part = $scope.copy.parts()[0];
444 if ($scope.part) $scope.part = $scope.part.label();
448 $scope.part_list = [];
450 itemSvc.get_parts($scope.callNumber.record()).then(function(list){
451 $scope.part_list = list;
452 angular.forEach(list, function(p){ $scope.parts.push(p.label()) });
453 $scope.parts = angular.copy($scope.parts);
462 .directive("egVolRow", function () {
469 '<div class="col-xs-2">'+
470 '<select ng-disabled="record == 0" class="form-control" ng-model="classification" ng-change="updateClassification()" ng-options="cl.name() for cl in classification_list"/>'+
472 '<div class="col-xs-1">'+
473 '<select ng-disabled="record == 0" class="form-control" ng-model="prefix" ng-change="updatePrefix()" ng-options="p.label() for p in prefix_list"/>'+
475 '<div class="col-xs-2">'+
476 '<input ng-disabled="record == 0" class="form-control" type="text" ng-change="updateLabel()" ng-model="label"/>'+
477 '<div class="label label-danger" ng-if="empty_label">{{empty_label_string}}</div>'+
479 '<div class="col-xs-1">'+
480 '<select ng-disabled="record == 0" class="form-control" ng-model="suffix" ng-change="updateSuffix()" ng-options="s.label() for s in suffix_list"/>'+
482 '<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>'+
483 '<div ng-hide="onlyVols" class="col-xs-5">'+
484 '<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>'+
488 scope: {focusNext: "=", allcopies: "=", copies: "=", onlyVols: "=", record: "@" },
489 controller : ['$scope','itemSvc','egCore',
490 function ( $scope , itemSvc , egCore ) {
491 $scope.callNumber = $scope.copies[0].call_number();
492 if (!$scope.callNumber.label()) $scope.callNumber.emtpy_label = true;
494 $scope.empty_label = false;
495 $scope.empty_label_string = window.empty_label_string;
497 $scope.idTracker = function (x) { if (x && x.id) return x.id() };
499 // XXX $() is not working! arg
500 $scope.focusNextBarcode = function (i, prev_bc) {
503 angular.forEach($scope.copies, function (cp) {
511 if (yep) n = cp.id();
515 var next = '#' + $scope.callNumber.id() + '_' + n;
518 if (!itemSvc.currently_generating) el.focus();
519 if (prev_bc && itemSvc.auto_gen_barcode && el.val() == "") {
520 itemSvc.nextBarcode(prev_bc).then(function(bc){
523 el.trigger('change');
526 itemSvc.currently_generating = false;
530 $scope.focusNext($scope.callNumber.id(),prev_bc)
534 $scope.suffix_list = [];
535 itemSvc.get_suffixes($scope.callNumber.owning_lib()).then(function(list){
536 $scope.suffix_list = list;
537 $scope.$watch('callNumber.suffix()', function (v) {
538 if (angular.isObject(v)) v = v.id();
539 $scope.suffix = $scope.suffix_list.filter( function (s) {
545 $scope.updateSuffix = function () {
546 angular.forEach($scope.copies, function(cp) {
547 cp.call_number().suffix($scope.suffix);
548 cp.call_number().ischanged(1);
552 $scope.prefix_list = [];
553 itemSvc.get_prefixes($scope.callNumber.owning_lib()).then(function(list){
554 $scope.prefix_list = list;
555 $scope.$watch('callNumber.prefix()', function (v) {
556 if (angular.isObject(v)) v = v.id();
557 $scope.prefix = $scope.prefix_list.filter(function (p) {
563 $scope.updatePrefix = function () {
564 angular.forEach($scope.copies, function(cp) {
565 cp.call_number().prefix($scope.prefix);
566 cp.call_number().ischanged(1);
569 $scope.$watch('callNumber.owning_lib()', function(oldLib, newLib) {
570 if (oldLib == newLib) return;
571 var currentPrefix = $scope.callNumber.prefix();
572 if (angular.isObject(currentPrefix)) currentPrefix = currentPrefix.id();
573 itemSvc.get_prefixes($scope.callNumber.owning_lib()).then(function(list){
574 $scope.prefix_list = list;
575 var newPrefixId = $scope.prefix_list.filter(function (p) {
576 return p.id() == currentPrefix;
578 if (newPrefixId.id) newPrefixId = newPrefixId.id();
579 $scope.prefix = $scope.prefix_list.filter(function (p) {
580 return p.id() == newPrefixId;
582 if ($scope.newPrefixId != currentPrefix) {
583 $scope.callNumber.prefix($scope.prefix);
586 var currentSuffix = $scope.callNumber.suffix();
587 if (angular.isObject(currentSuffix)) currentSuffix = currentSuffix.id();
588 itemSvc.get_suffixes($scope.callNumber.owning_lib()).then(function(list){
589 $scope.suffix_list = list;
590 var newSuffixId = $scope.suffix_list.filter(function (s) {
591 return s.id() == currentSuffix;
593 if (newSuffixId.id) newSuffixId = newSuffixId.id();
594 $scope.suffix = $scope.suffix_list.filter(function (s) {
595 return s.id() == newSuffixId;
597 if ($scope.newSuffixId != currentSuffix) {
598 $scope.callNumber.suffix($scope.suffix);
603 $scope.classification_list = [];
604 itemSvc.get_classifications().then(function(list){
605 $scope.classification_list = list;
606 $scope.$watch('callNumber.label_class()', function (v) {
607 if (angular.isObject(v)) v = v.id();
608 $scope.classification = $scope.classification_list.filter(function (c) {
614 $scope.updateClassification = function () {
615 angular.forEach($scope.copies, function(cp) {
616 cp.call_number().label_class($scope.classification);
617 cp.call_number().ischanged(1);
621 $scope.updateLabel = function () {
622 if ($scope.label == '') {
623 $scope.callNumber.empty_label = $scope.empty_label = true;
625 $scope.callNumber.empty_label = $scope.empty_label = false;
627 angular.forEach($scope.copies, function(cp) {
628 cp.call_number().label($scope.label);
629 cp.call_number().ischanged(1);
633 $scope.$watch('callNumber.label()', function (v) {
637 $scope.prefix = $scope.callNumber.prefix();
638 $scope.suffix = $scope.callNumber.suffix();
639 $scope.classification = $scope.callNumber.label_class();
640 $scope.label = $scope.callNumber.label();
642 $scope.copy_count = $scope.copies.length;
643 $scope.orig_copy_count = $scope.copy_count;
645 $scope.changeCPCount = function () {
646 while ($scope.copy_count > $scope.copies.length) {
647 var cp = itemSvc.generateNewCopy(
649 $scope.callNumber.owning_lib(),
653 $scope.copies.push( cp );
654 $scope.allcopies.push( cp );
658 if ($scope.copy_count >= $scope.orig_copy_count) {
659 var how_many = $scope.copies.length - $scope.copy_count;
661 var dead = $scope.copies.splice($scope.copy_count,how_many);
662 $scope.callNumber.copies($scope.copies);
664 // Trimming the global list is a bit more tricky
665 angular.forEach( dead, function (d) {
666 angular.forEach( $scope.allcopies, function (l, i) {
667 if (l === d) $scope.allcopies.splice(i,1);
680 .directive("egVolEdit", function () {
686 '<div class="col-xs-1"><eg-org-selector alldisabled="{{record == 0}}" selected="owning_lib" disable-test="cant_have_vols"></eg-org-selector></div>'+
687 '<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>'+
688 '<div class="col-xs-10">'+
689 '<eg-vol-row only-vols="onlyVols" record="{{record}}"'+
690 'ng-repeat="(cn,copies) in struct" '+
691 'focus-next="focusNextFirst" copies="copies" allcopies="allcopies">'+
696 scope: { focusNext: "=", allcopies: "=", struct: "=", lib: "@", record: "@", onlyVols: "=" },
697 controller : ['$scope','itemSvc','egCore',
698 function ( $scope , itemSvc , egCore ) {
699 $scope.first_cn = Object.keys($scope.struct)[0];
700 $scope.full_cn = $scope.struct[$scope.first_cn][0].call_number();
702 $scope.defaults = {};
703 egCore.hatch.getItem('cat.copy.defaults').then(function(t) {
709 $scope.focusNextFirst = function(prev_cn,prev_bc) {
712 angular.forEach(Object.keys($scope.struct).sort(), function (cn) {
724 var next = '#' + n + '_' + $scope.struct[n][0].id();
727 if (!itemSvc.currently_generating) el.focus();
728 if (prev_bc && itemSvc.auto_gen_barcode && el.val() == "") {
729 itemSvc.nextBarcode(prev_bc).then(function(bc){
732 el.trigger('change');
735 itemSvc.currently_generating = false;
739 $scope.focusNext($scope.lib, prev_bc);
743 $scope.cn_count = Object.keys($scope.struct).length;
744 $scope.orig_cn_count = $scope.cn_count;
746 $scope.owning_lib = egCore.org.get($scope.lib);
747 $scope.$watch('owning_lib', function (oldLib, newLib) {
748 if (oldLib == newLib) return;
749 angular.forEach( Object.keys($scope.struct), function (cn) {
750 $scope.struct[cn][0].call_number().owning_lib( $scope.owning_lib.id() );
751 $scope.struct[cn][0].call_number().ischanged(1);
755 $scope.cant_have_vols = function (id) { return !egCore.org.CanHaveVolumes(id); };
757 $scope.$watch('cn_count', function (n) {
758 var o = Object.keys($scope.struct).length;
759 if (n > o) { // adding
760 for (var i = o; o < n; o++) {
761 var cn = new egCore.idl.acn();
762 cn.id( --itemSvc.new_cn_id );
764 cn.prefix( $scope.defaults.prefix || -1 );
765 cn.suffix( $scope.defaults.suffix || -1 );
766 cn.label_class( $scope.defaults.classification || 1 );
767 cn.owning_lib( $scope.owning_lib.id() );
768 cn.record( $scope.full_cn.record() );
770 var cp = itemSvc.generateNewCopy(
772 $scope.owning_lib.id(),
777 $scope.struct[cn.id()] = [cp];
778 $scope.allcopies.push(cp);
779 if (!$scope.defaults.classification) {
781 ['cat.default_classification_scheme'],
783 ).then(function (val) {
784 cn.label_class(val['cat.default_classification_scheme']);
788 } else if (n < o && n >= $scope.orig_cn_count) { // removing
789 var how_many = o - n;
792 .sort(function(a, b){return parseInt(a)-parseInt(b)})
793 .filter(function(x){ return parseInt(x) <= 0 });
794 for (var i = 0; i < how_many; i++) {
795 // Trimming the global list is a bit more tricky
796 angular.forEach($scope.struct[list[i]], function (d) {
797 angular.forEach( $scope.allcopies, function (l, j) {
798 if (l === d) $scope.allcopies.splice(j,1);
801 delete $scope.struct[list[i]];
814 .controller('EditCtrl',
815 ['$scope','$q','$window','$routeParams','$location','$timeout','egCore','egNet','egGridDataProvider','itemSvc','$uibModal',
816 function($scope , $q , $window , $routeParams , $location , $timeout , egCore , egNet , egGridDataProvider , itemSvc , $uibModal) {
818 $scope.forms = {}; // Accessed by t_attr_edit.tt2
819 $scope.i18n = egCore.i18n;
821 $scope.defaults = { // If defaults are not set at all, allow everything
822 barcode_checkdigit : false,
823 auto_gen_barcode : false,
829 loan_duration : true,
834 deposit_amount : true,
838 mint_condition : true,
841 circ_modifier : true,
850 $scope.new_lib_to_add = egCore.org.get(egCore.auth.user().ws_ou());
851 $scope.changeNewLib = function (org) {
852 $scope.new_lib_to_add = org;
854 $scope.addLibToStruct = function () {
855 var newLib = $scope.new_lib_to_add;
856 var cn = new egCore.idl.acn();
857 cn.id( --itemSvc.new_cn_id );
859 cn.prefix( $scope.defaults.prefix || -1 );
860 cn.suffix( $scope.defaults.suffix || -1 );
861 cn.label_class( $scope.defaults.classification || 1 );
862 cn.owning_lib( newLib.id() );
863 cn.record( $scope.record_id );
865 var cp = itemSvc.generateNewCopy(
872 $scope.data.addCopy(cp);
874 if (!$scope.defaults.classification) {
876 ['cat.default_classification_scheme'],
878 ).then(function (val) {
879 cn.label_class(val['cat.default_classification_scheme']);
884 $scope.embedded = ($routeParams.mode && $routeParams.mode == 'embedded') ? true : false;
885 $scope.edit_templates = ($location.path().match(/edit_template/)) ? true : false;
887 $scope.saveDefaults = function () {
888 egCore.hatch.setItem('cat.copy.defaults', $scope.defaults);
891 $scope.fetchDefaults = function () {
892 egCore.hatch.getItem('cat.copy.defaults').then(function(t) {
895 if (!$scope.batch) $scope.batch = {};
896 $scope.batch.classification = $scope.defaults.classification;
897 $scope.batch.prefix = $scope.defaults.prefix;
898 $scope.batch.suffix = $scope.defaults.suffix;
899 $scope.working.statcat_filter = $scope.defaults.statcat_filter;
901 typeof $scope.defaults.statcat_filter == 'object' &&
902 Object.keys($scope.defaults.statcat_filter).length > 0
904 // want fieldmapper object here...
905 $scope.defaults.statcat_filter =
906 egCore.idl.Clone($scope.defaults.statcat_filter);
908 $scope.working.statcat_filter = $scope.defaults.statcat_filter.id();
910 if ($scope.defaults.always_volumes) $scope.show_vols = true;
911 if ($scope.defaults.barcode_checkdigit) itemSvc.barcode_checkdigit = true;
912 if ($scope.defaults.auto_gen_barcode) itemSvc.auto_gen_barcode = true;
916 $scope.fetchDefaults();
918 $scope.$watch('defaults.statcat_filter', function() {
919 $scope.saveDefaults();
921 $scope.$watch('defaults.auto_gen_barcode', function (n,o) {
922 itemSvc.auto_gen_barcode = n
925 $scope.$watch('defaults.barcode_checkdigit', function (n,o) {
926 itemSvc.barcode_checkdigit = n
929 $scope.dirty = false;
930 $scope.$watch('dirty',
931 function(newVal, oldVal) {
932 if (newVal && newVal != oldVal) {
933 $($window).on('beforeunload.edit', function(){
934 return 'There is unsaved data!'
937 $($window).off('beforeunload.edit');
942 $scope.only_vols = false;
943 $scope.show_vols = true;
944 $scope.show_copies = true;
946 $scope.tracker = function (x,f) { if (x) return x[f]() };
947 $scope.idTracker = function (x) { if (x) return $scope.tracker(x,'id') };
948 $scope.cant_have_vols = function (id) { return !egCore.org.CanHaveVolumes(id); };
950 $scope.orgById = function (id) { return egCore.org.get(id) }
951 $scope.statusById = function (id) {
952 return $scope.status_list.filter( function (s) { return s.id() == id } )[0];
954 $scope.locationById = function (id) {
955 return $scope.location_cache[''+id];
958 $scope.workingToComplete = function () {
959 angular.forEach( $scope.workingGridControls.selectedItems(), function (c) {
960 angular.forEach( itemSvc.copies, function (w, i) {
962 $scope.completed_copies = $scope.completed_copies.concat(itemSvc.copies.splice(i,1));
969 $scope.completeToWorking = function () {
970 angular.forEach( $scope.completedGridControls.selectedItems(), function (c) {
971 angular.forEach( $scope.completed_copies, function (w, i) {
973 itemSvc.copies = itemSvc.copies.concat($scope.completed_copies.splice(i,1));
980 createSimpleUpdateWatcher = function (field,exclude_copies_with_one_of_these_values) {
981 return $scope.$watch('working.' + field, function () {
982 var newval = $scope.working[field];
984 if (typeof newval != 'undefined') {
985 if (angular.isObject(newval)) { // we'll use the pkey
986 if (newval.id) newval = newval.id();
987 else if (newval.code) newval = newval.code();
990 if (""+newval == "" || newval == null) {
991 $scope.working[field] = undefined;
995 if ($scope.workingGridControls && $scope.workingGridControls.selectedItems) {
997 $scope.workingGridControls.selectedItems(),
999 if (exclude_copies_with_one_of_these_values
1000 && exclude_copies_with_one_of_these_values.indexOf(cp[field](),0) > -1) {
1003 if (cp[field]() !== newval) {
1006 $scope.dirty = true;
1017 statcat_filter: undefined
1020 $scope.statcatUpdate = function (id) {
1021 var newval = $scope.working.statcats[id];
1023 if (typeof newval != 'undefined') {
1024 if (angular.isObject(newval)) { // we'll use the pkey
1025 newval = newval.id();
1028 if (""+newval == "" || newval == null) {
1029 $scope.working.statcats[id] = undefined;
1033 if (!$scope.in_item_select && $scope.workingGridControls && $scope.workingGridControls.selectedItems) {
1035 $scope.workingGridControls.selectedItems(),
1037 $scope.dirty = true;
1039 cp.stat_cat_entries(
1040 angular.forEach( cp.stat_cat_entries(), function (e) {
1041 if (e.stat_cat() == id) { // mark deleted
1048 var e = new egCore.idl.asce();
1053 cp.stat_cat_entries(
1054 cp.stat_cat_entries() ?
1055 cp.stat_cat_entries().concat([ e ]) :
1061 // trim out all deleted ones; the API used to
1062 // do the update doesn't actually consult
1063 // isdeleted for stat cat entries
1064 cp.stat_cat_entries(
1065 cp.stat_cat_entries().filter(function (e) {
1066 return !Boolean(e.isdeleted());
1077 var dataKey = $routeParams.dataKey;
1078 console.debug('dataKey: ' + dataKey);
1080 if ((dataKey && dataKey.length > 0) || $scope.edit_templates) {
1082 $scope.templates = {};
1083 $scope.template_name = '';
1084 $scope.template_name_list = [];
1086 $scope.fetchTemplates = function () {
1087 egCore.hatch.getItem('cat.copy.templates').then(function(t) {
1089 $scope.templates = t;
1090 $scope.template_name_list = Object.keys(t);
1093 egCore.hatch.getItem('cat.copy.last_template').then(function(t) {
1094 if (t) $scope.template_name = t;
1097 $scope.fetchTemplates();
1099 $scope.applyTemplate = function (n) {
1100 angular.forEach($scope.templates[n], function (v,k) {
1101 if (k == 'circ_lib') {
1102 $scope.working[k] = egCore.org.get(v);
1103 } else if (!angular.isObject(v)) {
1104 $scope.working[k] = angular.copy(v);
1106 angular.forEach(v, function (sv,sk) {
1107 if (k == 'callnumber') {
1108 angular.forEach(v, function (cnv,cnk) {
1109 $scope.batch[cnk] = cnv;
1111 $scope.applyBatchCNValues();
1113 $scope.working[k][sk] = angular.copy(sv);
1114 if (k == 'statcats') $scope.statcatUpdate(sk);
1119 egCore.hatch.setItem('cat.copy.last_template', n);
1122 $scope.copytab = 'working';
1123 $scope.tab = 'edit';
1124 $scope.summaryRecord = null;
1125 $scope.record_id = null;
1127 $scope.completed_copies = [];
1128 $scope.location_orgs = [];
1129 $scope.location_cache = {};
1130 $scope.statcats = [];
1131 if (!$scope.batch) $scope.batch = {};
1133 $scope.applyBatchCNValues = function () {
1134 if ($scope.data.tree) {
1135 angular.forEach($scope.data.tree, function(cn_hash) {
1136 angular.forEach(cn_hash, function(copies) {
1137 angular.forEach(copies, function(cp) {
1138 if (typeof $scope.batch.classification != 'undefined' && $scope.batch.classification != '') {
1139 var label_class = $scope.classification_list.filter(function(p){ return p.id() == $scope.batch.classification })[0];
1140 cp.call_number().label_class(label_class);
1141 cp.call_number().ischanged(1);
1142 $scope.dirty = true;
1144 if (typeof $scope.batch.prefix != 'undefined' && $scope.batch.prefix != '') {
1145 var prefix = $scope.prefix_list.filter(function(p){ return p.id() == $scope.batch.prefix })[0];
1146 cp.call_number().prefix(prefix);
1147 cp.call_number().ischanged(1);
1148 $scope.dirty = true;
1150 if (typeof $scope.batch.label != 'undefined' && $scope.batch.label != '') {
1151 cp.call_number().label($scope.batch.label);
1152 cp.call_number().ischanged(1);
1153 $scope.dirty = true;
1155 if (typeof $scope.batch.suffix != 'undefined' && $scope.batch.suffix != '') {
1156 var suffix = $scope.suffix_list.filter(function(p){ return p.id() == $scope.batch.suffix })[0];
1157 cp.call_number().suffix(suffix);
1158 cp.call_number().ischanged(1);
1159 $scope.dirty = true;
1167 $scope.clearWorking = function () {
1168 angular.forEach($scope.working, function (v,k,o) {
1169 if (!angular.isObject(v)) {
1170 if (typeof v != 'undefined')
1171 $scope.working[k] = undefined;
1172 } else if (k != 'circ_lib') {
1173 angular.forEach(v, function (sv,sk) {
1174 if (typeof v != 'undefined')
1175 $scope.working[k][sk] = undefined;
1179 $scope.working.circ_lib = undefined; // special
1182 $scope.completedGridDataProvider = egGridDataProvider.instance({
1183 get : function(offset, count) {
1184 //return provider.arrayNotifier(itemSvc.copies, offset, count);
1185 return this.arrayNotifier($scope.completed_copies, offset, count);
1189 $scope.completedGridControls = {};
1191 $scope.workingGridDataProvider = egGridDataProvider.instance({
1192 get : function(offset, count) {
1193 //return provider.arrayNotifier(itemSvc.copies, offset, count);
1194 return this.arrayNotifier(itemSvc.copies, offset, count);
1198 $scope.workingGridControls = {};
1199 $scope.add_vols_copies = false;
1200 $scope.is_fast_add = false;
1204 'open-ils.actor.anon_cache.get_value',
1205 dataKey, 'edit-these-copies'
1206 ).then(function (data) {
1209 if (data.hide_vols && !$scope.defaults.always_volumes) $scope.show_vols = false;
1210 if (data.hide_copies) {
1211 $scope.show_copies = false;
1212 $scope.only_vols = true;
1215 $scope.record_id = data.record_id;
1217 function fetchRaw () {
1218 if (!$scope.only_vols) $scope.dirty = true;
1219 $scope.add_vols_copies = true;
1221 /* data.raw data structure looks like this:
1223 * callnumber : $cn_id, // optional, to add a copy to a cn
1224 * owner : $org, // optional, defaults to ws_ou
1225 * label : $cn_label, // optional, to supply a label on a new cn
1226 * barcode : $cp_barcode // optional, to supply a barcode on a new cp
1227 * fast_add : boolean // optional, to specify whether this came
1231 * All can be left out and a completely empty vol/copy combo will be vivicated.
1237 if (proto.fast_add) $scope.is_fast_add = true;
1238 if (proto.callnumber) {
1239 return egCore.pcrud.retrieve('acn', proto.callnumber)
1240 .then(function(cn) {
1241 var cp = new itemSvc.generateNewCopy(
1243 proto.owner || egCore.auth.user().ws_ou(),
1245 ((!$scope.only_vols) ? true : false)
1248 if (proto.barcode) {
1249 cp.barcode( proto.barcode );
1250 cp.empty_barcode = false;
1256 var cn = new egCore.idl.acn();
1257 cn.id( --itemSvc.new_cn_id );
1259 cn.prefix( $scope.defaults.prefix || -1 );
1260 cn.suffix( $scope.defaults.suffix || -1 );
1261 cn.owning_lib( proto.owner || egCore.auth.user().ws_ou() );
1262 cn.record( $scope.record_id );
1263 egCore.org.settings(
1264 ['cat.default_classification_scheme'],
1266 ).then(function (val) {
1268 $scope.defaults.classification ||
1269 val['cat.default_classification_scheme'] ||
1273 cn.label( proto.label );
1277 'open-ils.cat.biblio.record.marc_cn.retrieve',
1280 ).then(function(cn_array) {
1281 if (cn_array.length > 0) {
1282 for (var field in cn_array[0]) {
1283 cn.label( cn_array[0][field] );
1291 var cp = new itemSvc.generateNewCopy(
1293 proto.owner || egCore.auth.user().ws_ou(),
1298 if (proto.barcode) {
1299 cp.barcode( proto.barcode );
1300 cp.empty_barcode = false;
1309 return itemSvc.copies;
1312 if (data.copies && data.copies.length)
1313 return itemSvc.fetchIds(data.copies).then(fetchRaw);
1319 }).then( function() {
1320 $scope.data = itemSvc;
1321 $scope.workingGridDataProvider.refresh();
1324 $scope.can_save = false;
1325 function check_saveable () {
1326 var can_save = true;
1330 if (i.duplicate_barcode || i.empty_barcode || i.call_number().empty_label)
1334 if ($scope.forms.myForm && $scope.forms.myForm.$invalid) {
1337 $scope.can_save = can_save;
1340 $scope.disableSave = function () {
1342 return !$scope.can_save;
1345 $scope.focusNextFirst = function(prev_lib,prev_bc) {
1348 angular.forEach(Object.keys($scope.data.tree).sort(), function (lib) {
1351 if (lib == prev_lib) {
1360 var first_cn = Object.keys($scope.data.tree[n])[0];
1361 var next = '#' + first_cn + '_' + $scope.data.tree[n][first_cn][0].id();
1364 if (!itemSvc.currently_generating) el.focus();
1365 if (prev_bc && itemSvc.auto_gen_barcode && el.val() == "") {
1366 itemSvc.nextBarcode(prev_bc).then(function(bc){
1369 el.trigger('change');
1372 itemSvc.currently_generating = false;
1378 $scope.in_item_select = false;
1379 $scope.afterItemSelect = function() { $scope.in_item_select = false };
1380 $scope.handleItemSelect = function (item_list) {
1381 if (item_list && item_list.length > 0) {
1382 $scope.in_item_select = true;
1384 angular.forEach(Object.keys($scope.defaults.attributes), function (attr) {
1386 var value_hash = {};
1387 angular.forEach(item_list, function (item) {
1389 var v = item[attr]()
1390 if (angular.isObject(v)) {
1391 if (v.id) v = v.id();
1392 else if (v.code) v = v.code();
1398 if (Object.keys(value_hash).length == 1) {
1399 if (attr == 'circ_lib') {
1400 $scope.working[attr] = egCore.org.get(item_list[0][attr]());
1402 $scope.working[attr] = item_list[0][attr]();
1405 $scope.working[attr] = undefined;
1409 angular.forEach($scope.statcats, function (sc) {
1412 var value_hash = {};
1414 angular.forEach(item_list, function (item) {
1415 if (item.stat_cat_entries()) {
1416 if (item.stat_cat_entries().length > 0) {
1417 var right_sc = item.stat_cat_entries().filter(function (e) {
1418 return e.stat_cat() == sc.id() && !Boolean(e.isdeleted());
1421 if (right_sc.length > 0) {
1422 value_hash[right_sc[0].id()] = right_sc[0].id();
1432 if (!none && Object.keys(value_hash).length == 1) {
1433 $scope.working.statcats[sc.id()] = value_hash[Object.keys(value_hash)[0]];
1435 $scope.working.statcats[sc.id()] = undefined;
1440 $scope.clearWorking();
1445 $scope.$watch('data.copies.length', function () {
1446 if ($scope.data.copies) {
1447 var base_orgs = $scope.data.copies.map(function(cp){
1448 return cp.circ_lib()
1450 $scope.data.copies.map(function(cp){
1451 return cp.call_number().owning_lib()
1454 [egCore.auth.user().ws_ou()]
1455 ).filter(function(e,i,a){
1456 return a.lastIndexOf(e) === i;
1460 angular.forEach(base_orgs, function(o) {
1461 all_orgs = all_orgs.concat( egCore.org.fullPath(o, true) );
1464 var final_orgs = all_orgs.filter(function(e,i,a){
1465 return a.lastIndexOf(e) === i;
1466 }).sort(function(a, b){return parseInt(a)-parseInt(b)});
1468 if ($scope.location_orgs.toString() != final_orgs.toString()) {
1469 $scope.location_orgs = final_orgs;
1470 if ($scope.location_orgs.length) {
1471 itemSvc.get_locations($scope.location_orgs).then(function(list){
1472 angular.forEach(list, function(l) {
1473 $scope.location_cache[ ''+l.id() ] = l;
1475 $scope.location_list = list;
1478 $scope.statcat_filter_list = [];
1479 angular.forEach($scope.location_orgs, function (o) {
1480 $scope.statcat_filter_list.push(egCore.org.get(o));
1483 itemSvc.get_statcats($scope.location_orgs).then(function(list){
1484 $scope.statcats = list;
1485 angular.forEach($scope.statcats, function (s) {
1487 if (!$scope.working)
1488 $scope.working = { statcats: {}, statcat_filter: undefined};
1489 if (!$scope.working.statcats)
1490 $scope.working.statcats = {};
1492 if (!$scope.in_item_select) {
1493 $scope.working.statcats[s.id()] = undefined;
1495 createStatcatUpdateWatcher(s.id());
1497 $scope.in_item_select = false;
1498 // do a refresh here to work around a race
1499 // condition that can result in stat cats
1500 // not being selected.
1501 $scope.workingGridDataProvider.refresh();
1507 $scope.workingGridDataProvider.refresh();
1510 $scope.statcat_visible = function (sc_owner) {
1511 var visible = typeof $scope.working.statcat_filter === 'undefined' || !$scope.working.statcat_filter;
1512 angular.forEach(egCore.org.ancestors(sc_owner), function (ancestor_org) {
1513 if ($scope.working.statcat_filter == ancestor_org.id())
1519 $scope.suffix_list = [];
1520 itemSvc.get_suffixes(egCore.auth.user().ws_ou()).then(function(list){
1521 $scope.suffix_list = list;
1524 $scope.prefix_list = [];
1525 itemSvc.get_prefixes(egCore.auth.user().ws_ou()).then(function(list){
1526 $scope.prefix_list = list;
1529 $scope.classification_list = [];
1530 itemSvc.get_classifications().then(function(list){
1531 $scope.classification_list = list;
1534 $scope.$watch('completed_copies.length', function () {
1535 $scope.completedGridDataProvider.refresh();
1538 $scope.location_list = [];
1539 itemSvc.get_locations().then(function(list){
1540 $scope.location_list = list;
1542 createSimpleUpdateWatcher('location');
1544 $scope.status_list = [];
1545 itemSvc.get_magic_statuses().then(function(list){
1546 $scope.magic_status_list = list;
1547 createSimpleUpdateWatcher('status',$scope.magic_status_list);
1549 itemSvc.get_statuses().then(function(list){
1550 $scope.status_list = list;
1553 $scope.circ_modifier_list = [];
1554 itemSvc.get_circ_mods().then(function(list){
1555 $scope.circ_modifier_list = list;
1557 createSimpleUpdateWatcher('circ_modifier');
1559 $scope.circ_type_list = [];
1560 itemSvc.get_circ_types().then(function(list){
1561 $scope.circ_type_list = list;
1563 createSimpleUpdateWatcher('circ_as_type');
1565 $scope.age_protect_list = [];
1566 itemSvc.get_age_protects().then(function(list){
1567 $scope.age_protect_list = list;
1569 createSimpleUpdateWatcher('age_protect');
1571 $scope.floating_list = [];
1572 itemSvc.get_floating_groups().then(function(list){
1573 $scope.floating_list = list;
1575 createSimpleUpdateWatcher('floating');
1577 createSimpleUpdateWatcher('circ_lib');
1578 createSimpleUpdateWatcher('circulate');
1579 createSimpleUpdateWatcher('holdable');
1580 createSimpleUpdateWatcher('fine_level');
1581 createSimpleUpdateWatcher('loan_duration');
1582 createSimpleUpdateWatcher('price');
1583 createSimpleUpdateWatcher('cost');
1584 createSimpleUpdateWatcher('deposit');
1585 createSimpleUpdateWatcher('deposit_amount');
1586 createSimpleUpdateWatcher('mint_condition');
1587 createSimpleUpdateWatcher('opac_visible');
1588 createSimpleUpdateWatcher('ref');
1590 $scope.saveCompletedCopies = function (and_exit) {
1592 var perCnCopies = {};
1593 angular.forEach( $scope.completed_copies, function (cp) {
1594 var cn = cp.call_number();
1595 var cn_cps = cp.call_number().copies();
1596 cp.call_number().copies([]);
1597 var cn_id = cp.call_number().id();
1598 cp.call_number(cn_id); // prevent loops in JSON-ification
1599 if (!cnHash[cn_id]) {
1600 cnHash[cn_id] = egCore.idl.Clone(cn);
1601 perCnCopies[cn_id] = [egCore.idl.Clone(cp)];
1603 perCnCopies[cn_id].push(egCore.idl.Clone(cp));
1605 cp.call_number(cn); // put the data back
1606 cp.call_number().copies(cn_cps);
1607 if (typeof cnHash[cn_id].prefix() == 'object')
1608 cnHash[cn_id].prefix(cnHash[cn_id].prefix().id()); // un-object-ize some fields
1609 if (typeof cnHash[cn_id].suffix() == 'object')
1610 cnHash[cn_id].suffix(cnHash[cn_id].suffix().id()); // un-object-ize some fields
1613 angular.forEach(perCnCopies, function (v, k) {
1614 cnHash[k].copies(v);
1618 angular.forEach(cnHash, function (v, k) {
1624 'open-ils.cat.asset.volume.fleshed.batch.update.override',
1625 egCore.auth.token(), cnList, 1, { auto_merge_vols : 1, create_parts : 1, return_copy_ids : 1 }
1626 ).then(function(copy_ids) {
1628 $scope.dirty = false;
1629 if ($scope.defaults.print_item_labels) {
1632 'open-ils.actor.anon_cache.set_value',
1633 null, 'print-labels-these-copies', {
1636 ).then(function(key) {
1638 var url = egCore.env.basePath + 'cat/printlabels/' + key;
1639 $timeout(function() { $window.open(url, '_blank') }).then(
1640 function() { $timeout(function(){$window.close()}); }
1643 alert('Could not create anonymous cache key!');
1647 $timeout(function(){$window.close()});
1653 $scope.saveAndContinue = function () {
1654 $scope.saveCompletedCopies(false);
1657 $scope.workingSaveAndExit = function () {
1658 $scope.workingToComplete();
1659 $scope.saveAndExit();
1662 $scope.saveAndExit = function () {
1663 $scope.saveCompletedCopies(true);
1668 $scope.copy_notes_dialog = function(copy_list) {
1669 var default_pub = Boolean($scope.defaults.copy_notes_pub);
1670 if (!angular.isArray(copy_list)) copy_list = [copy_list];
1672 return $uibModal.open({
1673 templateUrl: './cat/volcopy/t_copy_notes',
1676 ['$scope','$uibModalInstance',
1677 function($scope , $uibModalInstance) {
1678 $scope.focusNote = true;
1680 creator : egCore.auth.user().id(),
1686 $scope.require_initials = false;
1687 egCore.org.settings([
1688 'ui.staff.require_initials.copy_notes'
1689 ]).then(function(set) {
1690 $scope.require_initials = Boolean(set['ui.staff.require_initials.copy_notes']);
1693 $scope.note_list = [];
1694 if (copy_list.length == 1) {
1695 $scope.note_list = copy_list[0].notes();
1698 $scope.ok = function(note) {
1700 if ($scope.initials) {
1701 note.value = egCore.strings.$replace(
1702 egCore.strings.COPY_NOTE_INITIALS, {
1704 initials : $scope.initials,
1705 ws_ou : egCore.org.get(
1706 egCore.auth.user().ws_ou()).shortname()
1710 angular.forEach(copy_list, function (cp) {
1711 if (!angular.isArray(cp.notes())) cp.notes([]);
1712 var n = new egCore.idl.acpn();
1714 n.creator(note.creator);
1716 n.title(note.title);
1717 n.value(note.value);
1718 n.owning_copy(cp.id());
1719 cp.notes().push( n );
1722 $uibModalInstance.close();
1725 $scope.cancel = function($event) {
1726 $uibModalInstance.dismiss();
1727 $event.preventDefault();
1733 $scope.copy_tags_dialog = function(copy_list) {
1734 if (!angular.isArray(copy_list)) copy_list = [copy_list];
1736 return $uibModal.open({
1737 templateUrl: './cat/volcopy/t_copy_tags',
1740 ['$scope','$uibModalInstance',
1741 function($scope , $uibModalInstance) {
1743 $scope.tag_map = [];
1745 var shared_tags = {};
1746 angular.forEach(copy_list, function (cp) {
1747 angular.forEach(cp.tags(), function(tag) {
1748 if (!(tag.tag().id() in shared_tags)) {
1749 shared_tags[tag.tag().id()] = 1;
1751 shared_tags[tag.tag().id()]++;
1753 if (!(tag.tag().id() in tag_hash)) {
1754 tag_hash[tag.tag().id()] = tag;
1758 angular.forEach(tag_hash, function(value, key) {
1759 if (shared_tags[key] == copy_list.length) {
1760 $scope.tag_map.push(value);
1764 $scope.tag_types = [];
1765 egCore.pcrud.retrieveAll('cctt', {order_by : { cctt : 'label' }}, {atomic : true}).then(function(list) {
1766 $scope.tag_types = list;
1767 $scope.tag_type = $scope.tag_types[0].code(); // just pick a default
1770 $scope.getTags = function(val) {
1771 return egCore.pcrud.search('acpt',
1773 owner : egCore.org.fullPath(egCore.auth.user().ws_ou(), true),
1774 label : { 'startwith' : {
1775 transform: 'evergreen.lowercase',
1776 value : [ 'evergreen.lowercase', val ]
1778 tag_type : $scope.tag_type
1780 { order_by : { 'acpt' : ['label'] } }, { atomic: true }
1781 ).then(function(list) {
1782 return list.map(function(item) {
1783 return item.label();
1788 $scope.addTag = function() {
1789 var tagLabel = $scope.selectedLabel;
1790 // clear the typeahead
1791 $scope.selectedLabel = "";
1793 // first, check tags already associated with the copy
1794 var foundMatch = false;
1795 angular.forEach($scope.tag_map, function(tag) {
1796 if (tag.tag().label() == tagLabel && tag.tag().tag_type() == $scope.tag_type) {
1798 if (tag.isdeleted()) tag.isdeleted(0); // just deleting the mapping
1802 egCore.pcrud.search('acpt',
1804 owner : egCore.org.fullPath(egCore.auth.user().ws_ou(), true),
1806 tag_type : $scope.tag_type
1808 { order_by : { 'acpt' : ['label'] } }, { atomic: true }
1809 ).then(function(list) {
1810 if (list.length > 0) {
1811 var newMap = new egCore.idl.acptcm();
1813 newMap.copy(copy_list[0].id());
1814 newMap.tag(egCore.idl.Clone(list[0]));
1815 $scope.tag_map.push(newMap);
1817 var newTag = new egCore.idl.acpt();
1819 newTag.owner(egCore.auth.user().ws_ou());
1820 newTag.label(tagLabel);
1822 newTag.tag_type($scope.tag_type);
1824 var newMap = new egCore.idl.acptcm();
1826 newMap.copy(copy_list[0].id());
1828 $scope.tag_map.push(newMap);
1834 $scope.ok = function(note) {
1835 // in the multi-item case, this works OK for
1836 // adding new maps to existing tags, but doesn't handle
1837 // all possibilities
1838 angular.forEach(copy_list, function (cp) {
1839 cp.tags($scope.tag_map);
1841 $uibModalInstance.close();
1844 $scope.cancel = function($event) {
1845 $uibModalInstance.dismiss();
1846 $event.preventDefault();
1854 .directive("egVolTemplate", function () {
1858 template: '<div ng-include="'+"'/eg/staff/cat/volcopy/t_attr_edit'"+'"></div>',
1862 controller : ['$scope','$window','itemSvc','egCore','ngToast',
1863 function ( $scope , $window , itemSvc , egCore , ngToast) {
1865 $scope.i18n = egCore.i18n;
1867 $scope.defaults = { // If defaults are not set at all, allow everything
1868 barcode_checkdigit : false,
1869 auto_gen_barcode : false,
1875 loan_duration : true,
1880 deposit_amount : true,
1881 opac_visible : true,
1884 mint_condition : true,
1887 circ_modifier : true,
1888 circ_as_type : true,
1896 $scope.fetchDefaults = function () {
1897 egCore.hatch.getItem('cat.copy.defaults').then(function(t) {
1899 $scope.defaults = t;
1900 $scope.working.statcat_filter = $scope.defaults.statcat_filter;
1902 typeof $scope.defaults.statcat_filter == 'object' &&
1903 Object.keys($scope.defaults.statcat_filter).length > 0
1905 // want fieldmapper object here...
1906 $scope.defaults.statcat_filter =
1907 egCore.idl.Clone($scope.defaults.statcat_filter);
1909 $scope.working.statcat_filter = $scope.defaults.statcat_filter.id();
1914 $scope.fetchDefaults();
1916 $scope.dirty = false;
1917 $scope.$watch('dirty',
1918 function(newVal, oldVal) {
1919 if (newVal && newVal != oldVal) {
1920 $($window).on('beforeunload.template', function(){
1921 return 'There is unsaved template data!'
1924 $($window).off('beforeunload.template');
1929 $scope.template_controls = true;
1931 $scope.fetchTemplates = function () {
1932 egCore.hatch.getItem('cat.copy.templates').then(function(t) {
1934 $scope.templates = t;
1935 $scope.template_name_list = Object.keys(t);
1939 $scope.fetchTemplates();
1941 $scope.applyTemplate = function (n) {
1942 angular.forEach($scope.templates[n], function (v,k) {
1943 if (k == 'circ_lib') {
1944 $scope.working[k] = egCore.org.get(v);
1945 } else if (!angular.isObject(v)) {
1946 $scope.working[k] = angular.copy(v);
1948 angular.forEach(v, function (sv,sk) {
1949 if (!(k in $scope.working))
1950 $scope.working[k] = {};
1951 $scope.working[k][sk] = angular.copy(sv);
1955 $scope.template_name = '';
1958 $scope.deleteTemplate = function (n) {
1960 delete $scope.templates[n]
1961 $scope.template_name_list = Object.keys($scope.templates);
1962 $scope.template_name = '';
1963 egCore.hatch.setItem('cat.copy.templates', $scope.templates);
1964 $scope.$parent.fetchTemplates();
1965 ngToast.create(egCore.strings.VOL_COPY_TEMPLATE_SUCCESS_DELETE);
1969 $scope.saveTemplate = function (n) {
1973 angular.forEach($scope.working, function (v,k) {
1974 if (angular.isObject(v)) { // we'll use the pkey
1975 if (v.id) v = v.id();
1976 else if (v.code) v = v.code();
1982 $scope.templates[n] = tmpl;
1983 $scope.template_name_list = Object.keys($scope.templates);
1985 egCore.hatch.setItem('cat.copy.templates', $scope.templates);
1986 $scope.$parent.fetchTemplates();
1988 $scope.dirty = false;
1990 // save all templates, as we might do after an import
1991 egCore.hatch.setItem('cat.copy.templates', $scope.templates);
1992 $scope.$parent.fetchTemplates();
1994 ngToast.create(egCore.strings.VOL_COPY_TEMPLATE_SUCCESS_SAVE);
1997 $scope.templates = {};
1998 $scope.imported_templates = { data : '' };
1999 $scope.template_name = '';
2000 $scope.template_name_list = [];
2002 $scope.$watch('imported_templates.data', function(newVal, oldVal) {
2003 if (newVal && newVal != oldVal) {
2005 var newTemplates = JSON.parse(newVal);
2006 if (!Object.keys(newTemplates).length) return;
2007 $scope.templates = newTemplates;
2008 $scope.template_name_list = Object.keys(newTemplates);
2009 $scope.template_name = '';
2011 console.log('tried to import an invalid copy template file');
2016 $scope.tracker = function (x,f) { if (x) return x[f]() };
2017 $scope.idTracker = function (x) { if (x) return $scope.tracker(x,'id') };
2018 $scope.cant_have_vols = function (id) { return !egCore.org.CanHaveVolumes(id); };
2020 $scope.orgById = function (id) { return egCore.org.get(id) }
2021 $scope.statusById = function (id) {
2022 return $scope.status_list.filter( function (s) { return s.id() == id } )[0];
2024 $scope.locationById = function (id) {
2025 return $scope.location_cache[''+id];
2028 createSimpleUpdateWatcher = function (field) {
2029 $scope.$watch('working.' + field, function () {
2030 var newval = $scope.working[field];
2032 if (typeof newval != 'undefined') {
2033 $scope.dirty = true;
2034 if (angular.isObject(newval)) { // we'll use the pkey
2035 if (newval.id) $scope.working[field] = newval.id();
2036 else if (newval.code) $scope.working[field] = newval.code();
2039 if (""+newval == "" || newval == null) {
2040 $scope.working[field] = undefined;
2049 statcat_filter: undefined
2052 $scope.statcat_visible = function (sc_owner) {
2053 var visible = typeof $scope.working.statcat_filter === 'undefined' || !$scope.working.statcat_filter;
2054 angular.forEach(egCore.org.ancestors(sc_owner), function (ancestor_org) {
2055 if ($scope.working.statcat_filter == ancestor_org.id())
2061 createStatcatUpdateWatcher = function (id) {
2062 return $scope.$watch('working.statcats[' + id + ']', function () {
2063 if ($scope.working.statcats) {
2064 var newval = $scope.working.statcats[id];
2066 if (typeof newval != 'undefined') {
2067 $scope.dirty = true;
2068 if (angular.isObject(newval)) { // we'll use the pkey
2069 newval = newval.id();
2072 if (""+newval == "" || newval == null) {
2073 $scope.working.statcats[id] = undefined;
2082 $scope.clearWorking = function () {
2083 angular.forEach($scope.working, function (v,k,o) {
2084 if (!angular.isObject(v)) {
2085 if (typeof v != 'undefined')
2086 $scope.working[k] = undefined;
2087 } else if (k != 'circ_lib') {
2088 angular.forEach(v, function (sv,sk) {
2089 $scope.working[k][sk] = undefined;
2093 $scope.working.circ_lib = undefined; // special
2094 $scope.dirty = false;
2097 $scope.working = {};
2098 $scope.location_orgs = [];
2099 $scope.location_cache = {};
2101 $scope.location_list = [];
2102 itemSvc.get_locations(
2103 egCore.org.fullPath( egCore.auth.user().ws_ou(), true )
2104 ).then(function(list){
2105 $scope.location_list = list;
2107 createSimpleUpdateWatcher('location');
2109 $scope.statcat_filter_list = egCore.org.fullPath( egCore.auth.user().ws_ou() );
2111 $scope.statcats = [];
2112 itemSvc.get_statcats(
2113 egCore.org.fullPath( egCore.auth.user().ws_ou(), true )
2114 ).then(function(list){
2115 $scope.statcats = list;
2116 angular.forEach($scope.statcats, function (s) {
2118 if (!$scope.working)
2119 $scope.working = { statcats: {}, statcat_filter: undefined};
2120 if (!$scope.working.statcats)
2121 $scope.working.statcats = {};
2123 $scope.working.statcats[s.id()] = undefined;
2124 createStatcatUpdateWatcher(s.id());
2128 $scope.status_list = [];
2129 itemSvc.get_magic_statuses().then(function(list){
2130 $scope.magic_status_list = list;
2132 itemSvc.get_statuses().then(function(list){
2133 $scope.status_list = list;
2135 createSimpleUpdateWatcher('status');
2137 $scope.circ_modifier_list = [];
2138 itemSvc.get_circ_mods().then(function(list){
2139 $scope.circ_modifier_list = list;
2141 createSimpleUpdateWatcher('circ_modifier');
2143 $scope.circ_type_list = [];
2144 itemSvc.get_circ_types().then(function(list){
2145 $scope.circ_type_list = list;
2147 createSimpleUpdateWatcher('circ_as_type');
2149 $scope.age_protect_list = [];
2150 itemSvc.get_age_protects().then(function(list){
2151 $scope.age_protect_list = list;
2153 createSimpleUpdateWatcher('age_protect');
2155 createSimpleUpdateWatcher('circulate');
2156 createSimpleUpdateWatcher('holdable');
2157 createSimpleUpdateWatcher('fine_level');
2158 createSimpleUpdateWatcher('loan_duration');
2159 createSimpleUpdateWatcher('cost');
2160 createSimpleUpdateWatcher('deposit');
2161 createSimpleUpdateWatcher('deposit_amount');
2162 createSimpleUpdateWatcher('mint_condition');
2163 createSimpleUpdateWatcher('opac_visible');
2164 createSimpleUpdateWatcher('ref');
2166 $scope.suffix_list = [];
2167 itemSvc.get_suffixes(egCore.auth.user().ws_ou()).then(function(list){
2168 $scope.suffix_list = list;
2171 $scope.prefix_list = [];
2172 itemSvc.get_prefixes(egCore.auth.user().ws_ou()).then(function(list){
2173 $scope.prefix_list = list;
2176 $scope.classification_list = [];
2177 itemSvc.get_classifications().then(function(list){
2178 $scope.classification_list = list;
2181 createSimpleUpdateWatcher('working.callnumber.classification');
2182 createSimpleUpdateWatcher('working.callnumber.prefix');
2183 createSimpleUpdateWatcher('working.callnumber.suffix');