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?|mailto|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_copy_alert_types = function(orgs) {
140 return egCore.pcrud.search('ccat',
147 service.get_copy_alerts = function(copy_id) {
148 return egCore.pcrud.search('aca', { copy : copy_id, ack_time : null },
149 { flesh : 1, flesh_fields : { aca : ['alert_type'] } },
154 service.get_locations_by_org = function(orgs) {
155 return egCore.pcrud.search('acpl',
156 {owning_lib : orgs, deleted : 'f'},
160 acpl : ['owning_lib']
162 order_by : { acpl : 'name' }
168 service.fetch_locations = function(locs) {
169 return egCore.pcrud.search('acpl',
174 acpl : ['owning_lib']
176 order_by : { acpl : 'name' }
182 service.get_suffixes = function(org) {
183 return egCore.pcrud.search('acns',
184 {owning_lib : egCore.org.fullPath(org, true)},
185 {order_by : { acns : 'label_sortkey' }}, {atomic : true}
190 service.get_magic_statuses = function() {
191 /* TODO: make these more configurable per lp1616170 */
196 ,8 /* On holds shelf */
197 ,16 /* Long overdue */
198 ,18 /* Canceled Transit */
202 service.get_statuses = function() {
204 return $q.when(egCore.env.ccs.list);
206 return egCore.pcrud.retrieveAll('ccs', {order_by : { ccs : 'name' }}, {atomic : true}).then(
208 egCore.env.absorbList(list, 'ccs');
215 service.get_circ_mods = function() {
217 return $q.when(egCore.env.ccm.list);
219 return egCore.pcrud.retrieveAll('ccm', {}, {atomic : true}).then(
221 egCore.env.absorbList(list, 'ccm');
228 service.get_circ_types = function() {
230 return $q.when(egCore.env.citm.list);
232 return egCore.pcrud.retrieveAll('citm', {}, {atomic : true}).then(
234 egCore.env.absorbList(list, 'citm');
241 service.get_age_protects = function() {
242 if (egCore.env.crahp)
243 return $q.when(egCore.env.crahp.list);
245 return egCore.pcrud.retrieveAll('crahp', {}, {atomic : true}).then(
247 egCore.env.absorbList(list, 'crahp');
254 service.get_floating_groups = function() {
256 return $q.when(egCore.env.cfg.list);
258 return egCore.pcrud.retrieveAll('cfg', {}, {atomic : true}).then(
260 egCore.env.absorbList(list, 'cfg');
267 service.bmp_parts = {};
268 service.get_parts = function(rec) {
269 if (service.bmp_parts[rec])
270 return $q.when(service.bmp_parts[rec]);
272 return egCore.pcrud.search('bmp',
273 {record : rec, deleted : 'f'},
274 null, {atomic : true}
275 ).then(function(list) {
276 service.bmp_parts[rec] = list;
282 service.get_acp_templates = function() {
283 // Already downloaded for this user? Return local copy. Changing users or logging out causes another download
284 // so users always have their own templates, and any changes made on other machines appear as expected.
285 if (egCore.hatch.getSessionItem('cat.copy.templates.usr') == egCore.auth.user().id()) {
286 return egCore.hatch.getItem('cat.copy.templates').then(function(templ) {
290 // this can be disabled for debugging to force a re-download and translation of test templates
291 egCore.hatch.setSessionItem('cat.copy.templates.usr', egCore.auth.user().id());
292 return service.load_remote_acp_templates();
297 service.save_acp_templates = function(t) {
298 egCore.hatch.setItem('cat.copy.templates', t);
299 egCore.net.request('open-ils.actor', 'open-ils.actor.patron.settings.update',
300 egCore.auth.token(), egCore.auth.user().id(), { "webstaff.cat.copy.templates": t });
301 // console.warn('Saved ' + JSON.stringify({"webstaff.cat.copy.templates": t}));
304 service.load_remote_acp_templates = function() {
305 // After the XUL Client is completely removed everything related
306 // to staff_client.copy_editor.templates and convert_xul_templates
307 // can be thrown away.
308 return egCore.net.request('open-ils.actor', 'open-ils.actor.patron.settings.retrieve.authoritative',
309 egCore.auth.token(), egCore.auth.user().id(),
310 ['webstaff.cat.copy.templates','staff_client.copy_editor.templates']).then(function(settings) {
311 if (settings['webstaff.cat.copy.templates']) {
312 egCore.hatch.setItem('cat.copy.templates', settings['webstaff.cat.copy.templates']);
313 return settings['webstaff.cat.copy.templates'];
315 if (settings['staff_client.copy_editor.templates']) {
316 var new_templ = service.convert_xul_templates(settings['staff_client.copy_editor.templates']);
317 egCore.hatch.setItem('cat.copy.templates', new_templ);
318 // console.warn('Saving: ' + JSON.stringify({'webstaff.cat.copy.templates' : new_templ}));
319 egCore.net.request('open-ils.actor', 'open-ils.actor.patron.settings.update',
320 egCore.auth.token(), egCore.auth.user().id(), {'webstaff.cat.copy.templates' : new_templ});
328 service.convert_xul_templates = function(xultempl) {
330 var templ_names = Object.keys(xultempl);
341 for (i=0; i < templ_names.length; i++) {
342 name = templ_names[i];
345 xul_t = xultempl[name];
346 fields = Object.keys(xul_t);
348 if (fields.length > 0) {
349 for (j=0; j < fields.length; j++) {
350 curr_field = xul_t[fields[j]];
351 var field_name = curr_field["field"];
353 if ( field_name == null ) { continue; }
354 if ( curr_field["value"] == "<HACK:KLUDGE:NULL>" ) { continue; }
356 // floating changed from a boolean to an integer at one point;
357 // take this opportunity to remove the boolean from any old templates
358 if ( curr_field["type"] === "attribute" && field_name === "floating" ) {
359 if ( curr_field["value"].match(/[tf]/) ) { continue; }
362 if ( curr_field["type"] === "stat_cat" ) {
363 stat_cats[field_name] = parseInt(curr_field["value"]);
365 tmp_val = curr_field['value'];
366 if ( tmp_val.toString().match(/^[-0-9.]+$/)) {
367 tmp_val = parseFloat(tmp_val);
370 if (field_name.match(/^batch_.*_menulist$/)) {
371 // special handling for volume fields
372 if (!("callnumber" in curr_templ)) curr_templ["callnumber"] = {};
373 if (field_name === "batch_class_menulist") curr_templ["callnumber"]["classification"] = tmp_val;
374 if (field_name === "batch_prefix_menulist") curr_templ["callnumber"]["prefix"] = tmp_val;
375 if (field_name === "batch_suffix_menulist") curr_templ["callnumber"]["suffix"] = tmp_val;
377 curr_templ[field_name] = tmp_val;
382 if ( (Object.keys(stat_cats)).length > 0 ) {
383 curr_templ["statcats"] = stat_cats;
386 conv_templ[name] = curr_templ;
396 acp : ['call_number','parts','stat_cat_entries', 'notes', 'tags'],
397 acn : ['label_class','prefix','suffix'],
402 service.addCopy = function (cp) {
404 if (!cp.parts()) cp.parts([]); // just in case...
406 service.get_copy_alerts(cp.id()).then(function(aca) {
410 var lib = cp.call_number().owning_lib();
411 var cn = cp.call_number().id();
413 if (!service.tree[lib]) service.tree[lib] = {};
414 if (!service.tree[lib][cn]) service.tree[lib][cn] = [];
416 service.tree[lib][cn].push(cp);
417 service.copies.push(cp);
420 service.checkDuplicateBarcode = function(bc, id) {
422 return egCore.pcrud.search('acp', { deleted : 'f', 'barcode' : bc, id : { '!=' : id } })
424 function () { return final },
425 function () { return final },
426 function () { final = true; }
430 service.fetchIds = function(idList) {
431 service.tree = {}; // clear the tree on fetch
432 service.copies = []; // clear the copy list on fetch
433 return egCore.pcrud.search('acp', { 'id' : idList }, service.flesh).then(null,null,
435 service.addCopy(copy);
440 // create a new acp object with default values
441 // (both hard-coded and coming from OU settings)
442 service.generateNewCopy = function(callNumber, owningLib, isFastAdd, isNew) {
443 var cp = new egCore.idl.acp();
444 cp.id( --service.new_cp_id );
448 cp.circ_lib( owningLib );
449 cp.call_number( callNumber );
452 cp.deposit_amount(0);
453 cp.fine_level(2); // Normal
454 cp.loan_duration(2); // Normal
455 cp.location(1); // Stacks
458 cp.opac_visible('t');
460 cp.mint_condition('t');
461 cp.empty_barcode = true;
463 var status_setting = isFastAdd ?
464 'cat.default_copy_status_fast' :
465 'cat.default_copy_status_normal';
469 ).then(function(set) {
470 var default_ccs = parseInt(set[status_setting]);
471 if (isNaN(default_ccs))
472 default_ccs = (isFastAdd ? 0 : 5); // 0 is Available, 5 is In Process
473 cp.status(default_ccs);
482 .directive("egVolCopyEdit", function () {
488 '<div class="col-xs-5" ng-class="{'+"'has-error'"+':barcode_has_error}">'+
489 '<input id="{{callNumber.id()}}_{{copy.id()}}"'+
490 ' eg-enter="nextBarcode(copy.id())" class="form-control"'+
491 ' type="text" ng-model="barcode" ng-change="updateBarcode()"'+
493 '<div class="label label-danger" ng-if="duplicate_barcode">{{duplicate_barcode_string}}</div>'+
494 '<div class="label label-danger" ng-if="empty_barcode">{{empty_barcode_string}}</div>'+
496 '<div class="col-xs-3"><input class="form-control" type="number" min="1" ng-model="copy_number" ng-change="updateCopyNo()"/></div>'+
497 '<div class="col-xs-3"><eg-basic-combo-box list="parts" selected="part"></eg-basic-combo-box></div>'+
500 scope: { focusNext: "=", copy: "=", callNumber: "=", index: "@", record: "@" },
501 controller : ['$scope','itemSvc','egCore',
502 function ( $scope , itemSvc , egCore ) {
503 $scope.new_part_id = 0;
504 $scope.barcode_has_error = false;
505 $scope.duplicate_barcode = false;
506 $scope.empty_barcode = false;
507 $scope.duplicate_barcode_string = window.duplicate_barcode_string;
508 $scope.empty_barcode_string = window.empty_barcode_string;
510 if (!$scope.copy.barcode()) $scope.copy.empty_barcode = true;
512 $scope.nextBarcode = function (i) {
513 $scope.focusNext(i, $scope.barcode);
516 $scope.updateBarcode = function () {
517 if ($scope.barcode != '') {
518 $scope.copy.empty_barcode = $scope.empty_barcode = false;
519 $scope.barcode_has_error = !Boolean(itemSvc.checkBarcode($scope.barcode));
520 itemSvc.checkDuplicateBarcode($scope.barcode, $scope.copy.id())
521 .then(function (state) { $scope.copy.duplicate_barcode = $scope.duplicate_barcode = state });
523 $scope.copy.empty_barcode = $scope.empty_barcode = true;
526 $scope.copy.barcode($scope.barcode);
527 $scope.copy.ischanged(1);
528 if (itemSvc.currently_generating)
529 $scope.focusNext($scope.copy.id(), $scope.barcode);
532 $scope.updateCopyNo = function () { $scope.copy.copy_number($scope.copy_number); $scope.copy.ischanged(1); };
533 $scope.updatePart = function () {
535 var p = $scope.part_list.filter(function (x) {
536 return x.label() == $scope.part
538 if (p.length > 0) { // preexisting part
540 } else { // create one...
541 var part = new egCore.idl.bmp();
542 part.id( --$scope.new_part_id );
544 part.label( $scope.part );
545 part.record( $scope.callNumber.record() );
546 $scope.copy.parts([part]);
547 $scope.copy.ischanged(1);
550 $scope.copy.parts([]);
552 $scope.copy.ischanged(1);
556 $scope.part_list = [];
558 itemSvc.get_parts($scope.callNumber.record())
559 .then(function(list){
560 $scope.part_list = list;
561 angular.forEach(list, function(p){ $scope.parts.push(p.label()) });
562 $scope.parts = angular.copy($scope.parts);
564 $scope.$watch('part', $scope.updatePart);
565 if ($scope.copy.parts()) {
566 var the_part = $scope.copy.parts()[0];
567 if (the_part) $scope.part = the_part.label();
571 $scope.barcode = $scope.copy.barcode();
572 $scope.copy_number = $scope.copy.copy_number();
580 .directive("egVolRow", function () {
587 '<div class="col-xs-2">'+
588 '<button aria-label="Delete" style="margin:-5px -15px; float:left;" ng-hide="callNumber.not_ephemeral" type="button" class="close" ng-click="removeCN()">×</button>' +
589 '<select class="form-control" ng-model="classification" ng-change="updateClassification()" ng-options="cl.name() for cl in classification_list"/>'+
591 '<div class="col-xs-1">'+
592 '<select class="form-control" ng-model="prefix" ng-change="updatePrefix()" ng-options="p.label() for p in prefix_list"/>'+
594 '<div class="col-xs-2">'+
595 '<input class="form-control" type="text" ng-change="updateLabel()" ng-model="label"/>'+
596 '<div class="label label-danger" ng-if="empty_label">{{empty_label_string}}</div>'+
598 '<div class="col-xs-1">'+
599 '<select class="form-control" ng-model="suffix" ng-change="updateSuffix()" ng-options="s.label() for s in suffix_list"/>'+
601 '<div ng-hide="onlyVols" class="col-xs-1"><input class="form-control" type="number" ng-model="copy_count" min="{{orig_copy_count}}" ng-change="changeCPCount()"></div>'+
602 '<div ng-hide="onlyVols" class="col-xs-5">'+
603 '<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>'+
607 scope: {focusNext: "=", allcopies: "=", copies: "=", onlyVols: "=", record: "@", struct:"=" },
608 controller : ['$scope','itemSvc','egCore',
609 function ( $scope , itemSvc , egCore ) {
610 $scope.callNumber = $scope.copies[0].call_number();
611 if (!$scope.callNumber.label()) $scope.callNumber.empty_label = true;
613 $scope.empty_label = false;
614 $scope.empty_label_string = window.empty_label_string;
616 $scope.idTracker = function (x) { if (x && x.id) return x.id() };
618 // XXX $() is not working! arg
619 $scope.focusNextBarcode = function (i, prev_bc) {
622 angular.forEach($scope.copies, function (cp) {
630 if (yep) n = cp.id();
634 var next = '#' + $scope.callNumber.id() + '_' + n;
637 if (!itemSvc.currently_generating) el.focus();
638 if (prev_bc && itemSvc.auto_gen_barcode && el.val() == "") {
639 itemSvc.nextBarcode(prev_bc).then(function(bc){
642 el.trigger('change');
645 itemSvc.currently_generating = false;
649 $scope.focusNext($scope.callNumber.id(),prev_bc)
653 $scope.suffix_list = [];
654 itemSvc.get_suffixes($scope.callNumber.owning_lib()).then(function(list){
655 $scope.suffix_list = list;
656 $scope.$watch('callNumber.suffix()', function (v) {
657 if (angular.isObject(v)) v = v.id();
658 $scope.suffix = $scope.suffix_list.filter( function (s) {
664 $scope.updateSuffix = function () {
665 angular.forEach($scope.copies, function(cp) {
666 cp.call_number().suffix($scope.suffix);
667 cp.call_number().ischanged(1);
671 $scope.prefix_list = [];
672 itemSvc.get_prefixes($scope.callNumber.owning_lib()).then(function(list){
673 $scope.prefix_list = list;
674 $scope.$watch('callNumber.prefix()', function (v) {
675 if (angular.isObject(v)) v = v.id();
676 $scope.prefix = $scope.prefix_list.filter(function (p) {
682 $scope.updatePrefix = function () {
683 angular.forEach($scope.copies, function(cp) {
684 cp.call_number().prefix($scope.prefix);
685 cp.call_number().ischanged(1);
688 $scope.$watch('callNumber.owning_lib()', function(oldLib, newLib) {
689 if (oldLib == newLib) return;
690 var currentPrefix = $scope.callNumber.prefix();
691 if (angular.isObject(currentPrefix)) currentPrefix = currentPrefix.id();
692 itemSvc.get_prefixes($scope.callNumber.owning_lib()).then(function(list){
693 $scope.prefix_list = list;
694 var newPrefixId = $scope.prefix_list.filter(function (p) {
695 return p.id() == currentPrefix;
697 if (newPrefixId.id) newPrefixId = newPrefixId.id();
698 $scope.prefix = $scope.prefix_list.filter(function (p) {
699 return p.id() == newPrefixId;
701 if ($scope.newPrefixId != currentPrefix) {
702 $scope.callNumber.prefix($scope.prefix);
705 var currentSuffix = $scope.callNumber.suffix();
706 if (angular.isObject(currentSuffix)) currentSuffix = currentSuffix.id();
707 itemSvc.get_suffixes($scope.callNumber.owning_lib()).then(function(list){
708 $scope.suffix_list = list;
709 var newSuffixId = $scope.suffix_list.filter(function (s) {
710 return s.id() == currentSuffix;
712 if (newSuffixId.id) newSuffixId = newSuffixId.id();
713 $scope.suffix = $scope.suffix_list.filter(function (s) {
714 return s.id() == newSuffixId;
716 if ($scope.newSuffixId != currentSuffix) {
717 $scope.callNumber.suffix($scope.suffix);
722 $scope.classification_list = [];
723 itemSvc.get_classifications().then(function(list){
724 $scope.classification_list = list;
725 $scope.$watch('callNumber.label_class()', function (v) {
726 if (angular.isObject(v)) v = v.id();
727 $scope.classification = $scope.classification_list.filter(function (c) {
733 $scope.updateClassification = function () {
734 angular.forEach($scope.copies, function(cp) {
735 cp.call_number().label_class($scope.classification);
736 cp.call_number().ischanged(1);
740 $scope.updateLabel = function () {
741 angular.forEach($scope.copies, function(cp) {
742 cp.call_number().label($scope.label);
743 cp.call_number().ischanged(1);
747 $scope.$watch('callNumber.label()', function (v) {
749 if ($scope.label == '') {
750 $scope.callNumber.empty_label = $scope.empty_label = true;
752 $scope.callNumber.empty_label = $scope.empty_label = false;
756 $scope.prefix = $scope.callNumber.prefix();
757 $scope.suffix = $scope.callNumber.suffix();
758 $scope.classification = $scope.callNumber.label_class();
759 $scope.label = $scope.callNumber.label();
761 $scope.copy_count = $scope.copies.length;
762 $scope.orig_copy_count = $scope.copy_count;
764 $scope.removeCN = function(){
765 var cn = $scope.callNumber;
766 if (cn.not_ephemeral) return; // can't delete existing volumes
768 angular.forEach(Object.keys($scope.struct), function(k){
769 angular.forEach($scope.struct[k], function(cp){
770 var struct_cn = cp.call_number();
771 if (struct_cn.id() == cn.id()){
772 console.log("X'ed CN id" + cn.id() + " and struct CN id match!");
773 // remove any copies in $scope.struct[k]
774 angular.forEach($scope.copies, function(c){
775 var idx = $scope.allcopies.indexOf(c);
776 $scope.allcopies.splice(idx, 1);
781 delete $scope.struct[k];
786 // manually decrease cn_count numeric input
787 var cn_spinner = $("input[name='cn_count_lib"+ cn.owning_lib() +"']");
788 if (cn_spinner.val() > 0) cn_spinner.val(parseInt(cn_spinner.val()) - 1);
789 cn_spinner.trigger("change");
793 $scope.changeCPCount = function () {
794 while ($scope.copy_count > $scope.copies.length) {
795 var cp = itemSvc.generateNewCopy(
797 $scope.callNumber.owning_lib(),
801 $scope.copies.push( cp );
802 $scope.allcopies.push( cp );
806 if ($scope.copy_count >= $scope.orig_copy_count) {
807 var how_many = $scope.copies.length - $scope.copy_count;
809 var dead = $scope.copies.splice($scope.copy_count,how_many);
810 $scope.callNumber.copies($scope.copies);
812 // Trimming the global list is a bit more tricky
813 angular.forEach( dead, function (d) {
814 angular.forEach( $scope.allcopies, function (l, i) {
815 if (l === d) $scope.allcopies.splice(i,1);
828 .directive("egVolEdit", function () {
834 '<div class="col-xs-1"><eg-org-selector selected="owning_lib" disable-test="cant_have_vols"></eg-org-selector></div>'+
835 '<div class="col-xs-1"><input class="form-control" type="number" min="{{orig_cn_count}}" ng-model="cn_count" ng-change="changeCNCount()"/></div>'+
836 '<div class="col-xs-10">'+
837 '<eg-vol-row only-vols="onlyVols" record="{{record}}"'+
838 'ng-repeat="(cn,copies) in struct" '+
839 'focus-next="focusNextFirst" copies="copies" allcopies="allcopies" struct="struct">'+
844 scope: { focusNext: "=", allcopies: "=", struct: "=", lib: "@", record: "@", onlyVols: "=" },
845 controller : ['$scope','itemSvc','egCore',
846 function ( $scope , itemSvc , egCore ) {
847 $scope.first_cn = Object.keys($scope.struct)[0];
848 $scope.full_cn = $scope.struct[$scope.first_cn][0].call_number();
850 $scope.defaults = {};
851 egCore.hatch.getItem('cat.copy.defaults').then(function(t) {
857 $scope.focusNextFirst = function(prev_cn,prev_bc) {
860 angular.forEach(Object.keys($scope.struct).sort(), function (cn) {
872 var next = '#' + n + '_' + $scope.struct[n][0].id();
875 if (!itemSvc.currently_generating) el.focus();
876 if (prev_bc && itemSvc.auto_gen_barcode && el.val() == "") {
877 itemSvc.nextBarcode(prev_bc).then(function(bc){
880 el.trigger('change');
883 itemSvc.currently_generating = false;
887 $scope.focusNext($scope.lib, prev_bc);
891 $scope.cn_count = Object.keys($scope.struct).length;
892 $scope.orig_cn_count = $scope.cn_count;
894 $scope.owning_lib = egCore.org.get($scope.lib);
895 $scope.$watch('owning_lib', function (oldLib, newLib) {
896 if (oldLib == newLib) return;
897 angular.forEach( Object.keys($scope.struct), function (cn) {
898 $scope.struct[cn][0].call_number().owning_lib( $scope.owning_lib.id() );
899 $scope.struct[cn][0].call_number().ischanged(1);
903 $scope.cant_have_vols = function (id) { return !egCore.org.CanHaveVolumes(id); };
905 $scope.$watch('cn_count', function (n) {
906 var o = Object.keys($scope.struct).length;
907 if (n > o) { // adding
908 for (var i = o; o < n; o++) {
909 var cn = new egCore.idl.acn();
910 cn.id( --itemSvc.new_cn_id );
912 cn.prefix( $scope.defaults.prefix || -1 );
913 cn.suffix( $scope.defaults.suffix || -1 );
914 cn.label_class( $scope.defaults.classification || 1 );
915 cn.owning_lib( $scope.owning_lib.id() );
916 cn.record( $scope.full_cn.record() );
918 var cp = itemSvc.generateNewCopy(
920 $scope.owning_lib.id(),
925 $scope.struct[cn.id()] = [cp];
926 $scope.allcopies.push(cp);
927 if (!$scope.defaults.classification) {
929 ['cat.default_classification_scheme'],
931 ).then(function (val) {
932 cn.label_class(val['cat.default_classification_scheme']);
936 } else if (n < o && n >= $scope.orig_cn_count) { // removing
937 var how_many = o - n;
940 .sort(function(a, b){return parseInt(a)-parseInt(b)})
941 .filter(function(x){ return parseInt(x) <= 0 });
942 for (var i = 0; i < how_many; i++) {
943 // Trimming the global list is a bit more tricky
944 angular.forEach($scope.struct[list[i]], function (d) {
945 angular.forEach( $scope.allcopies, function (l, j) {
946 if (l === d) $scope.allcopies.splice(j,1);
949 delete $scope.struct[list[i]];
962 .controller('EditCtrl',
963 ['$scope','$q','$window','$routeParams','$location','$timeout','egCore','egNet','egGridDataProvider','itemSvc','$uibModal',
964 function($scope , $q , $window , $routeParams , $location , $timeout , egCore , egNet , egGridDataProvider , itemSvc , $uibModal) {
966 $scope.forms = {}; // Accessed by t_attr_edit.tt2
967 $scope.i18n = egCore.i18n;
969 $scope.defaults = { // If defaults are not set at all, allow everything
970 barcode_checkdigit : false,
971 auto_gen_barcode : false,
977 loan_duration : true,
982 deposit_amount : true,
986 mint_condition : true,
989 circ_modifier : true,
999 $scope.new_lib_to_add = egCore.org.get(egCore.auth.user().ws_ou());
1000 $scope.changeNewLib = function (org) {
1001 $scope.new_lib_to_add = org;
1003 $scope.addLibToStruct = function () {
1004 var newLib = $scope.new_lib_to_add;
1005 var cn = new egCore.idl.acn();
1006 cn.id( --itemSvc.new_cn_id );
1008 cn.prefix( $scope.defaults.prefix || -1 );
1009 cn.suffix( $scope.defaults.suffix || -1 );
1010 cn.label_class( $scope.defaults.classification || 1 );
1011 cn.owning_lib( newLib.id() );
1012 cn.record( $scope.record_id );
1014 var cp = itemSvc.generateNewCopy(
1021 $scope.data.addCopy(cp);
1023 // manually increase cn_count numeric input
1024 var cn_spinner = $("input[name='cn_count_lib"+ newLib.id() +"']");
1025 cn_spinner.val(parseInt(cn_spinner.val()) + 1);
1026 cn_spinner.trigger("change");
1028 if (!$scope.defaults.classification) {
1029 egCore.org.settings(
1030 ['cat.default_classification_scheme'],
1032 ).then(function (val) {
1033 cn.label_class(val['cat.default_classification_scheme']);
1038 $scope.embedded = ($routeParams.mode && $routeParams.mode == 'embedded') ? true : false;
1039 $scope.edit_templates = ($location.path().match(/edit_template/)) ? true : false;
1041 $scope.saveDefaults = function () {
1042 egCore.hatch.setItem('cat.copy.defaults', $scope.defaults);
1045 $scope.fetchDefaults = function () {
1046 egCore.hatch.getItem('cat.copy.defaults').then(function(t) {
1048 $scope.defaults = t;
1049 if (!$scope.batch) $scope.batch = {};
1050 $scope.batch.classification = $scope.defaults.classification;
1051 $scope.batch.prefix = $scope.defaults.prefix;
1052 $scope.batch.suffix = $scope.defaults.suffix;
1053 $scope.working.statcat_filter = $scope.defaults.statcat_filter;
1055 typeof $scope.defaults.statcat_filter == 'object' &&
1056 Object.keys($scope.defaults.statcat_filter).length > 0
1058 // want fieldmapper object here...
1059 $scope.defaults.statcat_filter =
1060 egCore.idl.Clone($scope.defaults.statcat_filter);
1062 $scope.working.statcat_filter = $scope.defaults.statcat_filter.id();
1064 if ($scope.defaults.always_volumes) $scope.show_vols = true;
1065 if ($scope.defaults.barcode_checkdigit) itemSvc.barcode_checkdigit = true;
1066 if ($scope.defaults.auto_gen_barcode) itemSvc.auto_gen_barcode = true;
1069 // Fetch the list of bib-level callnumbers based on the applied
1070 // classification scheme. If none is defined, default to "1"
1071 // (Generic) since it provides the most options.
1074 'open-ils.cat.biblio.record.marc_cn.retrieve',
1076 $scope.batch.classification || 1
1077 ).then(function(list) {
1078 $scope.batch.marcCallNumbers = [];
1079 list.forEach(function(hash) {
1080 $scope.batch.marcCallNumbers.push(Object.values(hash)[0]);
1086 $scope.$watch('defaults.statcat_filter', function() {
1087 $scope.saveDefaults();
1089 $scope.$watch('defaults.auto_gen_barcode', function (n,o) {
1090 itemSvc.auto_gen_barcode = n
1093 $scope.$watch('defaults.barcode_checkdigit', function (n,o) {
1094 itemSvc.barcode_checkdigit = n
1097 $scope.dirty = false;
1098 $scope.$watch('dirty',
1099 function(newVal, oldVal) {
1100 if (newVal && newVal != oldVal) {
1101 $($window).on('beforeunload.edit', function(){
1102 return 'There is unsaved data!'
1105 $($window).off('beforeunload.edit');
1110 $scope.only_vols = false;
1111 $scope.show_vols = true;
1112 $scope.show_copies = true;
1114 $scope.tracker = function (x,f) { if (x) return x[f]() };
1115 $scope.idTracker = function (x) { if (x) return $scope.tracker(x,'id') };
1116 $scope.cant_have_vols = function (id) { return !egCore.org.CanHaveVolumes(id); };
1118 $scope.orgById = function (id) { return egCore.org.get(id) }
1119 $scope.statusById = function (id) {
1120 return $scope.status_list.filter( function (s) { return s.id() == id } )[0];
1122 $scope.locationById = function (id) {
1123 return $scope.location_cache[''+id];
1126 $scope.workingToComplete = function () {
1127 angular.forEach( $scope.workingGridControls.selectedItems(), function (c) {
1128 angular.forEach( itemSvc.copies, function (w, i) {
1130 $scope.completed_copies = $scope.completed_copies.concat(itemSvc.copies.splice(i,1));
1137 $scope.completeToWorking = function () {
1138 angular.forEach( $scope.completedGridControls.selectedItems(), function (c) {
1139 angular.forEach( $scope.completed_copies, function (w, i) {
1141 itemSvc.copies = itemSvc.copies.concat($scope.completed_copies.splice(i,1));
1148 createSimpleUpdateWatcher = function (field,exclude_copies_with_one_of_these_values) {
1149 return $scope.$watch('working.' + field, function () {
1150 var newval = $scope.working[field];
1152 if (typeof newval != 'undefined') {
1153 delete $scope.working.MultiMap[field];
1154 if (angular.isObject(newval)) { // we'll use the pkey
1155 if (newval.id) newval = newval.id();
1156 else if (newval.code) newval = newval.code();
1159 if (""+newval == "" || newval == null) {
1160 $scope.working[field] = undefined;
1164 if ($scope.workingGridControls && $scope.workingGridControls.selectedItems) {
1166 $scope.workingGridControls.selectedItems(),
1168 if (exclude_copies_with_one_of_these_values
1169 && exclude_copies_with_one_of_these_values.indexOf(cp[field](),0) > -1) {
1172 if (cp[field]() !== newval) {
1175 $scope.dirty = true;
1188 statcat_filter: undefined
1191 $scope.copyAlertUpdate = function (alerts) {
1192 if (!$scope.in_item_select &&
1193 $scope.workingGridControls &&
1194 $scope.workingGridControls.selectedItems) {
1195 itemSvc.get_copy_alert_types().then(function(ccat) {
1197 $scope.alert_types = ccat;
1198 angular.forEach(ccat, function(t) {
1199 ccat_map[t.id()] = t;
1202 $scope.workingGridControls.selectedItems(),
1204 $scope.dirty = true;
1205 angular.forEach(alerts, function(alrt) {
1206 var a = egCore.idl.fromHash('aca', alrt);
1208 a.create_staff(egCore.auth.user().id());
1209 a.alert_type(ccat_map[a.alert_type()]);
1212 cp.copy_alerts().push( a );
1221 $scope.copyNoteUpdate = function (notes) {
1222 if (!$scope.in_item_select &&
1223 $scope.workingGridControls &&
1224 $scope.workingGridControls.selectedItems) {
1226 $scope.workingGridControls.selectedItems(),
1228 $scope.dirty = true;
1229 angular.forEach(notes, function(note) {
1230 var n = egCore.idl.fromHash('acpn', note);
1232 n.creator(egCore.auth.user().id());
1233 n.owning_copy(cp.id());
1234 cp.notes().push( n );
1243 $scope.statcatUpdate = function (id) {
1244 var newval = $scope.working.statcats[id];
1246 if (typeof newval != 'undefined') {
1247 if (angular.isObject(newval)) { // we'll use the pkey
1248 newval = newval.id();
1251 if (""+newval == "" || newval == null) {
1252 $scope.working.statcats[id] = undefined;
1256 if (!$scope.in_item_select && $scope.workingGridControls && $scope.workingGridControls.selectedItems) {
1258 $scope.workingGridControls.selectedItems(),
1260 $scope.dirty = true;
1262 cp.stat_cat_entries(
1263 angular.forEach( cp.stat_cat_entries(), function (e) {
1264 if (e.stat_cat() == id) { // mark deleted
1271 var e = new egCore.idl.asce();
1276 cp.stat_cat_entries(
1277 cp.stat_cat_entries() ?
1278 cp.stat_cat_entries().concat([ e ]) :
1284 // trim out all deleted ones; the API used to
1285 // do the update doesn't actually consult
1286 // isdeleted for stat cat entries
1287 cp.stat_cat_entries(
1288 cp.stat_cat_entries().filter(function (e) {
1289 return !Boolean(e.isdeleted());
1300 var dataKey = $routeParams.dataKey;
1301 console.debug('dataKey: ' + dataKey);
1303 if ((dataKey && dataKey.length > 0) || $scope.edit_templates) {
1305 $scope.templates = {};
1306 $scope.template_name = '';
1307 $scope.template_name_list = [];
1309 $scope.fetchTemplates = function () {
1310 itemSvc.get_acp_templates().then(function(t) {
1312 $scope.templates = t;
1313 $scope.template_name_list = Object.keys(t).sort();
1316 egCore.hatch.getItem('cat.copy.last_template').then(function(t) {
1317 if (t) $scope.template_name = t;
1320 $scope.fetchTemplates();
1322 $scope.applyTemplate = function (n) {
1323 angular.forEach($scope.templates[n], function (v,k) {
1324 if (k == 'circ_lib') {
1325 $scope.working[k] = egCore.org.get(v);
1326 } else if (k == 'copy_notes' && v.length) {
1327 $scope.copyNoteUpdate(v);
1328 } else if (k == 'copy_alerts' && v.length) {
1329 $scope.copyAlertUpdate(v);
1330 } else if (!angular.isObject(v)) {
1331 $scope.working[k] = angular.copy(v);
1333 angular.forEach(v, function (sv,sk) {
1334 if (k == 'callnumber') {
1335 angular.forEach(v, function (cnv,cnk) {
1336 $scope.batch[cnk] = cnv;
1338 $scope.applyBatchCNValues();
1340 $scope.working[k][sk] = angular.copy(sv);
1341 if (k == 'statcats') $scope.statcatUpdate(sk);
1345 delete $scope.working.MultiMap[k];
1347 egCore.hatch.setItem('cat.copy.last_template', n);
1350 $scope.copytab = 'working';
1351 $scope.tab = 'edit';
1352 $scope.summaryRecord = null;
1353 $scope.record_id = null;
1355 $scope.completed_copies = [];
1356 $scope.location_orgs = [];
1357 $scope.location_cache = {};
1358 $scope.statcats = [];
1359 if (!$scope.batch) $scope.batch = {};
1361 $scope.applyBatchCNValues = function () {
1362 if ($scope.data.tree) {
1363 angular.forEach($scope.data.tree, function(cn_hash) {
1364 angular.forEach(cn_hash, function(copies) {
1365 angular.forEach(copies, function(cp) {
1366 if (typeof $scope.batch.classification != 'undefined' && $scope.batch.classification != '') {
1367 var label_class = $scope.classification_list.filter(function(p){ return p.id() == $scope.batch.classification })[0];
1368 cp.call_number().label_class(label_class);
1369 cp.call_number().ischanged(1);
1370 $scope.dirty = true;
1372 if (typeof $scope.batch.prefix != 'undefined' && $scope.batch.prefix != '') {
1373 var prefix = $scope.prefix_list.filter(function(p){ return p.id() == $scope.batch.prefix })[0];
1374 cp.call_number().prefix(prefix);
1375 cp.call_number().ischanged(1);
1376 $scope.dirty = true;
1378 if (typeof $scope.batch.label != 'undefined' && $scope.batch.label != '') {
1379 cp.call_number().label($scope.batch.label);
1380 cp.call_number().ischanged(1);
1381 $scope.dirty = true;
1383 if (typeof $scope.batch.suffix != 'undefined' && $scope.batch.suffix != '') {
1384 var suffix = $scope.suffix_list.filter(function(p){ return p.id() == $scope.batch.suffix })[0];
1385 cp.call_number().suffix(suffix);
1386 cp.call_number().ischanged(1);
1387 $scope.dirty = true;
1395 $scope.clearWorking = function () {
1396 angular.forEach($scope.working, function (v,k,o) {
1397 if (!angular.isObject(v)) {
1398 if (typeof v != 'undefined')
1399 $scope.working[k] = undefined;
1400 } else if (k != 'circ_lib') {
1401 angular.forEach(v, function (sv,sk) {
1402 if (typeof v != 'undefined')
1403 $scope.working[k][sk] = undefined;
1407 $scope.working.circ_lib = undefined; // special
1410 $scope.completedGridDataProvider = egGridDataProvider.instance({
1411 get : function(offset, count) {
1412 //return provider.arrayNotifier(itemSvc.copies, offset, count);
1413 return this.arrayNotifier($scope.completed_copies, offset, count);
1417 $scope.completedGridControls = {};
1419 $scope.workingGridDataProvider = egGridDataProvider.instance({
1420 get : function(offset, count) {
1421 //return provider.arrayNotifier(itemSvc.copies, offset, count);
1422 return this.arrayNotifier(itemSvc.copies, offset, count);
1426 $scope.workingGridControls = {};
1427 $scope.add_vols_copies = false;
1428 $scope.is_fast_add = false;
1430 // Generate some functions for selecting items by column value in the working grid
1432 ['circulate','status','circ_lib','ref','location','opac_visible','circ_modifier','price',
1433 'loan_duration','cost','circ_as_type','deposit','holdable','deposit_amount','age_protect',
1434 'mint_condition','fine_level','floating'],
1436 $scope['select_by_' + field] = function (x) {
1437 $scope.workingGridControls.selectItemsByValue(field,x);
1442 var truthy = /^t|1/;
1443 $scope.labelYesNo = function (x) {
1444 return truthy.test(x) ? egCore.strings.YES : egCore.strings.NO;
1447 $scope.orgShortname = function (x) {
1448 return egCore.org.get(x).shortname();
1451 $scope.statusName = function (x) {
1452 var s = $scope.status_list.filter(function(y) {
1459 $scope.locationName = function (x) {
1460 var s = $scope.location_list.filter(function(y) {
1464 return $scope.i18n.ou_qualified_location_name(s[0]);
1467 $scope.durationLabel = function (x) {
1468 return [egCore.strings.SHORT, egCore.strings.NORMAL, egCore.strings.EXTENDED][-1 + x]
1471 $scope.fineLabel = function (x) {
1472 return [egCore.strings.LOW, egCore.strings.NORMAL, egCore.strings.HIGH][-1 + x]
1475 $scope.circTypeValue = function (x) {
1476 if (x === null || x === undefined) return egCore.strings.UNSET;
1477 var s = $scope.circ_type_list.filter(function(y) {
1478 return y.code() == x;
1481 return s[0].value();
1484 $scope.ageprotectName = function (x) {
1485 if (x === null || x === undefined) return egCore.strings.UNSET;
1486 var s = $scope.age_protect_list.filter(function(y) {
1493 $scope.floatingName = function (x) {
1494 if (x === null || x === undefined) return egCore.strings.UNSET;
1495 var s = $scope.floating_list.filter(function(y) {
1502 $scope.circmodName = function (x) {
1503 if (x === null || x === undefined) return egCore.strings.UNSET;
1504 var s = $scope.circ_modifier_list.filter(function(y) {
1505 return y.code() == x;
1513 'open-ils.actor.anon_cache.get_value',
1514 dataKey, 'edit-these-copies'
1515 ).then(function (data) {
1518 if (data.hide_vols && !$scope.defaults.always_volumes) $scope.show_vols = false;
1519 if (data.hide_copies) {
1520 $scope.show_copies = false;
1521 $scope.only_vols = true;
1524 $scope.record_id = data.record_id;
1527 $scope.fetchDefaults();
1529 function fetchRaw () {
1530 if (!$scope.only_vols) $scope.dirty = true;
1531 $scope.add_vols_copies = true;
1533 /* data.raw data structure looks like this:
1535 * callnumber : $cn_id, // optional, to add a copy to a cn
1536 * owner : $org, // optional, defaults to cn.owning_lib or ws_ou
1537 * label : $cn_label, // optional, to supply a label on a new cn
1538 * barcode : $cp_barcode // optional, to supply a barcode on a new cp
1539 * fast_add : boolean // optional, to specify whether this came
1543 * All can be left out and a completely empty vol/copy combo will be vivicated.
1550 if (proto.fast_add) $scope.is_fast_add = true;
1551 if (proto.callnumber) {
1552 promises.push(egCore.pcrud.retrieve('acn', proto.callnumber)
1553 .then(function(cn) {
1554 var cp = new itemSvc.generateNewCopy(
1556 proto.owner || cn.owning_lib(),
1558 ((!$scope.only_vols) ? true : false)
1561 if (proto.barcode) {
1562 cp.barcode( proto.barcode );
1563 cp.empty_barcode = false;
1569 var cn = new egCore.idl.acn();
1570 cn.id( --itemSvc.new_cn_id );
1572 cn.prefix( $scope.defaults.prefix || -1 );
1573 cn.suffix( $scope.defaults.suffix || -1 );
1574 cn.owning_lib( proto.owner || egCore.auth.user().ws_ou() );
1575 cn.record( $scope.record_id );
1576 egCore.org.settings(
1577 ['cat.default_classification_scheme'],
1579 ).then(function (val) {
1581 $scope.defaults.classification ||
1582 val['cat.default_classification_scheme'] ||
1586 cn.label( proto.label );
1590 'open-ils.cat.biblio.record.marc_cn.retrieve',
1593 ).then(function(cn_array) {
1594 if (cn_array.length > 0) {
1595 for (var field in cn_array[0]) {
1596 cn.label( cn_array[0][field] );
1604 // If we are adding an empty vol,
1605 // this is ultimately just a placeholder copy
1606 // which gets removed before saving.
1607 // TODO: consider ways to remove this
1609 var cp = new itemSvc.generateNewCopy(
1611 proto.owner || cn.owning_lib(),
1616 if (proto.barcode) {
1617 cp.barcode( proto.barcode );
1618 cp.empty_barcode = false;
1626 angular.forEach(itemSvc.copies, function(c){
1627 var cn = c.call_number();
1628 var copy_id = c.id();
1630 cn.not_ephemeral = true;
1634 return $q.all(promises);
1637 if (data.copies && data.copies.length)
1638 return itemSvc.fetchIds(data.copies).then(fetchRaw);
1644 }).then( function() {
1646 return itemSvc.fetch_locations(
1647 itemSvc.copies.map(function(cp){
1648 return cp.location();
1649 }).filter(function(e,i,a){
1650 return a.lastIndexOf(e) === i;
1652 ).then(function(list){
1653 $scope.data = itemSvc;
1654 $scope.location_list = list;
1655 $scope.workingGridDataProvider.refresh();
1660 $scope.can_save = false;
1661 function check_saveable () {
1662 var can_save = true;
1667 if (!$scope.only_vols) {
1668 if (i.duplicate_barcode || i.empty_barcode || i.call_number().empty_label) {
1671 } else if (i.call_number().empty_label) {
1677 if (!$scope.only_vols && $scope.forms.myForm && $scope.forms.myForm.$invalid) {
1681 $scope.can_save = can_save;
1684 $scope.disableSave = function () {
1686 return !$scope.can_save;
1689 $scope.focusNextFirst = function(prev_lib,prev_bc) {
1692 angular.forEach(Object.keys($scope.data.tree).sort(), function (lib) {
1695 if (lib == prev_lib) {
1704 var first_cn = Object.keys($scope.data.tree[n])[0];
1705 var next = '#' + first_cn + '_' + $scope.data.tree[n][first_cn][0].id();
1708 if (!itemSvc.currently_generating) el.focus();
1709 if (prev_bc && itemSvc.auto_gen_barcode && el.val() == "") {
1710 itemSvc.nextBarcode(prev_bc).then(function(bc){
1713 el.trigger('change');
1716 itemSvc.currently_generating = false;
1722 $scope.in_item_select = false;
1723 $scope.afterItemSelect = function() { $scope.in_item_select = false };
1724 $scope.handleItemSelect = function (item_list) {
1725 if (item_list && item_list.length > 0) {
1726 $scope.in_item_select = true;
1728 angular.forEach(Object.keys($scope.defaults.attributes), function (attr) {
1730 var value_hash = {};
1731 var value_list = [];
1732 angular.forEach(item_list, function (item) {
1734 var v = item[attr]()
1735 if (angular.isObject(v)) {
1736 if (v.id) v = v.id();
1737 else if (v.code) v = v.code();
1744 $scope.working.MultiMap[attr] = value_list;
1746 if (Object.keys(value_hash).length == 1) {
1747 if (attr == 'circ_lib') {
1748 $scope.working[attr] = egCore.org.get(item_list[0][attr]());
1750 $scope.working[attr] = item_list[0][attr]();
1753 $scope.working[attr] = undefined;
1757 angular.forEach($scope.statcats, function (sc) {
1760 var value_hash = {};
1762 angular.forEach(item_list, function (item) {
1763 if (item.stat_cat_entries()) {
1764 if (item.stat_cat_entries().length > 0) {
1765 var right_sc = item.stat_cat_entries().filter(function (e) {
1766 return e.stat_cat() == sc.id() && !Boolean(e.isdeleted());
1769 if (right_sc.length > 0) {
1770 value_hash[right_sc[0].id()] = right_sc[0].id();
1782 if (!none && Object.keys(value_hash).length == 1) {
1783 $scope.working.statcats[sc.id()] = value_hash[Object.keys(value_hash)[0]];
1784 $scope.working.statcats_multi[sc.id()] = false;
1785 } else if (item_list.length > 1 && Object.keys(value_hash).length > 0) {
1786 $scope.working.statcats[sc.id()] = undefined;
1787 $scope.working.statcats_multi[sc.id()] = true;
1789 $scope.working.statcats[sc.id()] = undefined;
1790 $scope.working.statcats_multi[sc.id()] = false;
1796 $scope.clearWorking();
1801 $scope.$watch('data.copies.length', function () {
1802 if ($scope.data.copies) {
1803 var base_orgs = $scope.data.copies.map(function(cp){
1804 if (isNaN(cp.circ_lib())) return Number(cp.circ_lib().id());
1805 return Number(cp.circ_lib());
1807 $scope.data.copies.map(function(cp){
1808 if (isNaN(cp.call_number().owning_lib())) return Number(cp.call_number().owning_lib().id());
1809 return Number(cp.call_number().owning_lib());
1812 [egCore.auth.user().ws_ou()]
1813 ).filter(function(e,i,a){
1814 return a.lastIndexOf(e) === i;
1818 angular.forEach(base_orgs, function(o) {
1819 all_orgs = all_orgs.concat( egCore.org.fullPath(o, true) );
1822 var final_orgs = all_orgs.filter(function(e,i,a){
1823 return a.lastIndexOf(e) === i;
1824 }).sort(function(a, b){return a-b});
1826 if ($scope.location_orgs.toString() != final_orgs.toString()) {
1827 $scope.location_orgs = final_orgs;
1828 if ($scope.location_orgs.length) {
1829 itemSvc.get_locations_by_org($scope.location_orgs).then(function(list){
1830 angular.forEach(list, function(l) {
1831 $scope.location_cache[ ''+l.id() ] = l;
1833 $scope.location_list = list;
1834 }).then(function() {
1835 $scope.statcat_filter_list = [];
1836 angular.forEach($scope.location_orgs, function (o) {
1837 $scope.statcat_filter_list.push(egCore.org.get(o));
1840 itemSvc.get_statcats($scope.location_orgs).then(function(list){
1841 $scope.statcats = list;
1842 angular.forEach($scope.statcats, function (s) {
1844 if (!$scope.working)
1845 $scope.working = { statcats_multi: {}, statcats: {}, statcat_filter: undefined};
1846 if (!$scope.working.statcats_multi)
1847 $scope.working.statcats_multi = {};
1848 if (!$scope.working.statcats)
1849 $scope.working.statcats = {};
1851 if (!$scope.in_item_select) {
1852 $scope.working.statcats[s.id()] = undefined;
1854 createStatcatUpdateWatcher(s.id());
1856 $scope.in_item_select = false;
1857 // do a refresh here to work around a race
1858 // condition that can result in stat cats
1859 // not being selected.
1860 $scope.workingGridDataProvider.refresh();
1865 $scope.workingGridDataProvider.refresh();
1870 $scope.statcat_visible = function (sc_owner) {
1871 var visible = typeof $scope.working.statcat_filter === 'undefined' || !$scope.working.statcat_filter;
1872 angular.forEach(egCore.org.ancestors(sc_owner), function (ancestor_org) {
1873 if ($scope.working.statcat_filter == ancestor_org.id())
1879 $scope.suffix_list = [];
1880 itemSvc.get_suffixes(egCore.auth.user().ws_ou()).then(function(list){
1881 $scope.suffix_list = list;
1884 $scope.prefix_list = [];
1885 itemSvc.get_prefixes(egCore.auth.user().ws_ou()).then(function(list){
1886 $scope.prefix_list = list;
1889 $scope.classification_list = [];
1890 itemSvc.get_classifications().then(function(list){
1891 $scope.classification_list = list;
1894 $scope.$watch('completed_copies.length', function () {
1895 $scope.completedGridDataProvider.refresh();
1898 $scope.location_list = [];
1899 createSimpleUpdateWatcher('location');
1901 $scope.status_list = [];
1902 itemSvc.get_magic_statuses().then(function(list){
1903 $scope.magic_status_list = list;
1904 createSimpleUpdateWatcher('status',$scope.magic_status_list);
1906 itemSvc.get_statuses().then(function(list){
1907 $scope.status_list = list;
1910 $scope.circ_modifier_list = [];
1911 itemSvc.get_circ_mods().then(function(list){
1912 $scope.circ_modifier_list = list;
1914 createSimpleUpdateWatcher('circ_modifier');
1916 $scope.circ_type_list = [];
1917 itemSvc.get_circ_types().then(function(list){
1918 $scope.circ_type_list = list;
1920 createSimpleUpdateWatcher('circ_as_type');
1922 $scope.age_protect_list = [];
1923 itemSvc.get_age_protects().then(function(list){
1924 $scope.age_protect_list = list;
1926 createSimpleUpdateWatcher('age_protect');
1928 $scope.floating_list = [];
1929 itemSvc.get_floating_groups().then(function(list){
1930 $scope.floating_list = list;
1932 createSimpleUpdateWatcher('floating');
1934 createSimpleUpdateWatcher('circ_lib');
1935 createSimpleUpdateWatcher('circulate');
1936 createSimpleUpdateWatcher('holdable');
1937 createSimpleUpdateWatcher('fine_level');
1938 createSimpleUpdateWatcher('loan_duration');
1939 createSimpleUpdateWatcher('price');
1940 createSimpleUpdateWatcher('cost');
1941 createSimpleUpdateWatcher('deposit');
1942 createSimpleUpdateWatcher('deposit_amount');
1943 createSimpleUpdateWatcher('mint_condition');
1944 createSimpleUpdateWatcher('opac_visible');
1945 createSimpleUpdateWatcher('ref');
1947 $scope.saveCompletedCopies = function (and_exit) {
1949 var perCnCopies = {};
1950 angular.forEach( $scope.completed_copies, function (cp) {
1951 var cn = cp.call_number();
1952 var cn_cps = cp.call_number().copies();
1953 cp.call_number().copies([]);
1954 var cn_id = cp.call_number().id();
1955 cp.call_number(cn_id); // prevent loops in JSON-ification
1956 if (!cnHash[cn_id]) {
1957 cnHash[cn_id] = egCore.idl.Clone(cn);
1958 perCnCopies[cn_id] = [egCore.idl.Clone(cp)];
1960 perCnCopies[cn_id].push(egCore.idl.Clone(cp));
1962 cp.call_number(cn); // put the data back
1963 cp.call_number().copies(cn_cps);
1964 if (typeof cnHash[cn_id].prefix() == 'object')
1965 cnHash[cn_id].prefix(cnHash[cn_id].prefix().id()); // un-object-ize some fields
1966 if (typeof cnHash[cn_id].suffix() == 'object')
1967 cnHash[cn_id].suffix(cnHash[cn_id].suffix().id()); // un-object-ize some fields
1970 if ($scope.only_vols) { // strip off copies when we're in vol-only mode
1971 angular.forEach(cnHash, function (v, k) {
1972 cnHash[k].copies([]);
1975 angular.forEach(perCnCopies, function (v, k) {
1976 cnHash[k].copies(v);
1981 angular.forEach(cnHash, function (v, k) {
1987 'open-ils.cat.asset.volume.fleshed.batch.update.override',
1988 egCore.auth.token(), cnList, 1, { auto_merge_vols : 1, create_parts : 1, return_copy_ids : 1 }
1989 ).then(function(copy_ids) {
1991 $scope.dirty = false;
1992 if ($scope.defaults.print_item_labels) {
1995 'open-ils.actor.anon_cache.set_value',
1996 null, 'print-labels-these-copies', {
1999 ).then(function(key) {
2001 var url = egCore.env.basePath + 'cat/printlabels/' + key;
2002 $timeout(function() { $window.open(url, '_blank') }).then(
2003 function() { $timeout(function(){$window.close()}); }
2006 alert('Could not create anonymous cache key!');
2010 $timeout(function(){
2011 if (typeof BroadcastChannel != 'undefined') {
2012 var bChannel = new BroadcastChannel("eg.holdings.update");
2013 var bre_ids = cnList && cnList.length > 0 ? cnList.map(function(cn){ return Number(cn.record()) }) : [];
2014 var cn_ids = cnList && cnList.length > 0 ? cnList.map(function(cn){ return cn.id() }) : [];
2015 bChannel.postMessage({
2029 $scope.saveAndContinue = function () {
2030 $scope.saveCompletedCopies(false);
2033 $scope.workingSaveAndExit = function () {
2034 $scope.workingToComplete();
2035 $scope.saveAndExit();
2038 $scope.saveAndExit = function () {
2039 $scope.saveCompletedCopies(true);
2044 $scope.copy_notes_dialog = function(copy_list) {
2045 var default_pub = Boolean($scope.defaults.copy_notes_pub);
2046 if (!angular.isArray(copy_list)) copy_list = [copy_list];
2048 return $uibModal.open({
2049 templateUrl: './cat/volcopy/t_copy_notes',
2053 ['$scope','$uibModalInstance',
2054 function($scope , $uibModalInstance) {
2055 $scope.focusNote = true;
2057 creator : egCore.auth.user().id(),
2063 $scope.require_initials = false;
2064 egCore.org.settings([
2065 'ui.staff.require_initials.copy_notes'
2066 ]).then(function(set) {
2067 $scope.require_initials_ous = Boolean(set['ui.staff.require_initials.copy_notes']);
2070 $scope.are_initials_required = function() {
2071 $scope.require_initials = $scope.require_initials_ous && ($scope.note.value.length > 0 || $scope.note.title.length > 0);
2074 $scope.$watch('note.value.length', $scope.are_initials_required);
2075 $scope.$watch('note.title.length', $scope.are_initials_required);
2077 $scope.note_list = [];
2078 if (copy_list.length == 1) {
2079 $scope.note_list = copy_list[0].notes();
2082 $scope.ok = function(note) {
2084 if (note.value.length > 0 || note.title.length > 0) {
2085 if ($scope.initials) {
2086 note.value = egCore.strings.$replace(
2087 egCore.strings.COPY_NOTE_INITIALS, {
2089 initials : $scope.initials,
2090 ws_ou : egCore.org.get(
2091 egCore.auth.user().ws_ou()).shortname()
2095 angular.forEach(copy_list, function (cp) {
2096 if (!angular.isArray(cp.notes())) cp.notes([]);
2097 var n = new egCore.idl.acpn();
2099 n.creator(note.creator);
2100 n.pub(note.pub ? 't' : 'f');
2101 n.title(note.title);
2102 n.value(note.value);
2103 n.owning_copy(cp.id());
2104 cp.notes().push( n );
2108 $uibModalInstance.close();
2111 $scope.cancel = function($event) {
2112 $uibModalInstance.dismiss();
2113 $event.preventDefault();
2119 $scope.copy_tags_dialog = function(copy_list) {
2120 if (!angular.isArray(copy_list)) copy_list = [copy_list];
2122 return $uibModal.open({
2123 templateUrl: './cat/volcopy/t_copy_tags',
2127 ['$scope','$uibModalInstance',
2128 function($scope , $uibModalInstance) {
2130 $scope.tag_map = [];
2132 var shared_tags = {};
2133 angular.forEach(copy_list, function (cp) {
2134 angular.forEach(cp.tags(), function(tag) {
2135 if (!(tag.tag().id() in shared_tags)) {
2136 shared_tags[tag.tag().id()] = 1;
2138 shared_tags[tag.tag().id()]++;
2140 if (!(tag.tag().id() in tag_hash)) {
2141 tag_hash[tag.tag().id()] = tag;
2145 angular.forEach(tag_hash, function(value, key) {
2146 if (shared_tags[key] == copy_list.length) {
2147 $scope.tag_map.push(value);
2151 $scope.tag_types = [];
2152 egCore.pcrud.retrieveAll('cctt', {order_by : { cctt : 'label' }}, {atomic : true}).then(function(list) {
2153 $scope.tag_types = list;
2154 $scope.tag_type = $scope.tag_types[0].code(); // just pick a default
2157 $scope.getTags = function(val) {
2158 return egCore.pcrud.search('acpt',
2160 owner : egCore.org.fullPath(egCore.auth.user().ws_ou(), true),
2161 label : { 'startwith' : {
2162 transform: 'evergreen.lowercase',
2163 value : [ 'evergreen.lowercase', val ]
2165 tag_type : $scope.tag_type
2167 { order_by : { 'acpt' : ['label'] } }, { atomic: true }
2168 ).then(function(list) {
2169 return list.map(function(item) {
2170 return item.label() + " (" + egCore.org.get(item.owner()).shortname() + ")";
2175 $scope.addTag = function() {
2176 var tagLabel = $scope.selectedLabel;
2177 // clear the typeahead
2178 $scope.selectedLabel = "";
2180 // first, check tags already associated with the copy
2181 var foundMatch = false;
2182 angular.forEach($scope.tag_map, function(tag) {
2183 if (tag.tag().label() == tagLabel && tag.tag().tag_type() == $scope.tag_type) {
2185 if (tag.isdeleted()) tag.isdeleted(0); // just deleting the mapping
2189 egCore.pcrud.search('acpt',
2191 owner : egCore.org.fullPath(egCore.auth.user().ws_ou(), true),
2193 tag_type : $scope.tag_type
2195 { order_by : { 'acpt' : ['label'] } }, { atomic: true }
2196 ).then(function(list) {
2197 if (list.length > 0) {
2198 var newMap = new egCore.idl.acptcm();
2200 newMap.copy(copy_list[0].id());
2201 newMap.tag(egCore.idl.Clone(list[0]));
2202 $scope.tag_map.push(newMap);
2204 var newTag = new egCore.idl.acpt();
2206 newTag.owner(egCore.auth.user().ws_ou());
2207 newTag.label(tagLabel);
2209 newTag.tag_type($scope.tag_type);
2211 var newMap = new egCore.idl.acptcm();
2213 newMap.copy(copy_list[0].id());
2215 $scope.tag_map.push(newMap);
2221 $scope.ok = function(note) {
2222 // in the multi-item case, this works OK for
2223 // adding new maps to existing tags, but doesn't handle
2224 // all possibilities
2225 angular.forEach(copy_list, function (cp) {
2226 cp.tags($scope.tag_map);
2228 $uibModalInstance.close();
2231 $scope.cancel = function($event) {
2232 $uibModalInstance.dismiss();
2233 $event.preventDefault();
2239 $scope.copy_alerts_dialog = function(copy_list) {
2240 if (!angular.isArray(copy_list)) copy_list = [copy_list];
2242 return $uibModal.open({
2243 templateUrl: './cat/volcopy/t_copy_alerts',
2246 ['$scope','$uibModalInstance',
2247 function($scope , $uibModalInstance) {
2249 itemSvc.get_copy_alert_types().then(function(ccat) {
2250 $scope.alert_types = ccat;
2253 $scope.focusNote = true;
2254 $scope.copy_alert = {
2255 create_staff : egCore.auth.user().id(),
2260 egCore.hatch.getItem('cat.copy.alerts.last_type').then(function(t) {
2261 if (t) $scope.copy_alert.alert_type = t;
2264 if (copy_list.length == 1) {
2265 $scope.copy_alert_list = copy_list[0].copy_alerts();
2268 $scope.ok = function(copy_alert) {
2270 if (typeof(copy_alert.note) != 'undefined' &&
2271 copy_alert.note != '') {
2272 angular.forEach(copy_list, function (cp) {
2273 var a = new egCore.idl.aca();
2275 a.create_staff(copy_alert.create_staff);
2276 a.note(copy_alert.note);
2277 a.temp(copy_alert.temp ? 't' : 'f');
2281 $scope.alert_types.filter(function(at) {
2282 return at.id() == copy_alert.alert_type;
2285 cp.copy_alerts().push( a );
2288 if (copy_alert.alert_type) {
2289 egCore.hatch.setItem(
2290 'cat.copy.alerts.last_type',
2291 copy_alert.alert_type
2297 $uibModalInstance.close();
2300 $scope.cancel = function($event) {
2301 $uibModalInstance.dismiss();
2302 $event.preventDefault();
2310 .directive("egVolTemplate", function () {
2314 template: '<div ng-include="'+"'/eg/staff/cat/volcopy/t_attr_edit'"+'"></div>',
2318 controller : ['$scope','$window','itemSvc','egCore','ngToast','$uibModal',
2319 function ( $scope , $window , itemSvc , egCore , ngToast , $uibModal) {
2321 $scope.i18n = egCore.i18n;
2323 $scope.defaults = { // If defaults are not set at all, allow everything
2324 barcode_checkdigit : false,
2325 auto_gen_barcode : false,
2332 loan_duration : true,
2337 deposit_amount : true,
2338 opac_visible : true,
2341 mint_condition : true,
2344 circ_modifier : true,
2345 circ_as_type : true,
2353 $scope.fetchDefaults = function () {
2354 egCore.hatch.getItem('cat.copy.defaults').then(function(t) {
2356 $scope.defaults = t;
2357 $scope.working.statcat_filter = $scope.defaults.statcat_filter;
2359 typeof $scope.defaults.statcat_filter == 'object' &&
2360 Object.keys($scope.defaults.statcat_filter).length > 0
2362 // want fieldmapper object here...
2363 $scope.defaults.statcat_filter =
2364 egCore.idl.Clone($scope.defaults.statcat_filter);
2366 $scope.working.statcat_filter = $scope.defaults.statcat_filter.id();
2371 $scope.fetchDefaults();
2373 $scope.dirty = false;
2374 $scope.$watch('dirty',
2375 function(newVal, oldVal) {
2376 if (newVal && newVal != oldVal) {
2377 $($window).on('beforeunload.template', function(){
2378 return 'There is unsaved template data!'
2381 $($window).off('beforeunload.template');
2386 $scope.template_controls = true;
2388 $scope.fetchTemplates = function () {
2389 itemSvc.get_acp_templates().then(function(t) {
2391 $scope.templates = t;
2392 $scope.template_name_list = Object.keys(t).sort();
2396 $scope.fetchTemplates();
2398 $scope.applyTemplate = function (n) {
2399 angular.forEach($scope.templates[n], function (v,k) {
2400 if (k == 'circ_lib') {
2401 $scope.working[k] = egCore.org.get(v);
2402 } else if (angular.isArray(v) || !angular.isObject(v)) {
2403 $scope.working[k] = angular.copy(v);
2405 angular.forEach(v, function (sv,sk) {
2406 if (!(k in $scope.working))
2407 $scope.working[k] = {};
2408 $scope.working[k][sk] = angular.copy(sv);
2412 $scope.template_name = '';
2415 $scope.deleteTemplate = function (n) {
2417 delete $scope.templates[n]
2418 $scope.template_name_list = Object.keys($scope.templates).sort();
2419 $scope.template_name = '';
2420 itemSvc.save_acp_templates($scope.templates);
2421 $scope.$parent.fetchTemplates();
2422 ngToast.create(egCore.strings.VOL_COPY_TEMPLATE_SUCCESS_DELETE);
2426 $scope.saveTemplate = function (n) {
2430 angular.forEach($scope.working, function (v,k) {
2431 if (angular.isObject(v)) { // we'll use the pkey
2432 if (v.id) v = v.id();
2433 else if (v.code) v = v.code();
2434 else v = angular.copy(v); // Should only be statcats and callnumbers currently
2440 $scope.templates[n] = tmpl;
2441 $scope.template_name_list = Object.keys($scope.templates).sort();
2443 itemSvc.save_acp_templates($scope.templates);
2444 $scope.$parent.fetchTemplates();
2446 $scope.dirty = false;
2448 // save all templates, as we might do after an import
2449 itemSvc.save_acp_templates($scope.templates);
2450 $scope.$parent.fetchTemplates();
2452 ngToast.create(egCore.strings.VOL_COPY_TEMPLATE_SUCCESS_SAVE);
2455 $scope.templates = {};
2456 $scope.imported_templates = { data : '' };
2457 $scope.template_name = '';
2458 $scope.template_name_list = [];
2460 $scope.$watch('imported_templates.data', function(newVal, oldVal) {
2461 if (newVal && newVal != oldVal) {
2463 var newTemplates = JSON.parse(newVal);
2464 if (!Object.keys(newTemplates).length) return;
2465 angular.forEach(Object.keys(newTemplates), function (k) {
2466 $scope.templates[k] = newTemplates[k];
2468 itemSvc.save_acp_templates($scope.templates);
2469 $scope.fetchTemplates();
2471 console.log('tried to import an invalid copy template file');
2476 $scope.tracker = function (x,f) { if (x) return x[f]() };
2477 $scope.idTracker = function (x) { if (x) return $scope.tracker(x,'id') };
2478 $scope.cant_have_vols = function (id) { return !egCore.org.CanHaveVolumes(id); };
2480 $scope.orgById = function (id) { return egCore.org.get(id) }
2481 $scope.statusById = function (id) {
2482 return $scope.status_list.filter( function (s) { return s.id() == id } )[0];
2484 $scope.locationById = function (id) {
2485 return $scope.location_cache[''+id];
2488 createSimpleUpdateWatcher = function (field) {
2489 $scope.$watch('working.' + field, function () {
2490 var newval = $scope.working[field];
2492 if (typeof newval != 'undefined') {
2493 $scope.dirty = true;
2494 if (angular.isObject(newval)) { // we'll use the pkey
2495 if (newval.id) $scope.working[field] = newval.id();
2496 else if (newval.code) $scope.working[field] = newval.code();
2499 if (""+newval == "" || newval == null) {
2500 $scope.working[field] = undefined;
2511 statcat_filter: undefined
2514 $scope.statcat_visible = function (sc_owner) {
2515 var visible = typeof $scope.working.statcat_filter === 'undefined' || !$scope.working.statcat_filter;
2516 angular.forEach(egCore.org.ancestors(sc_owner), function (ancestor_org) {
2517 if ($scope.working.statcat_filter == ancestor_org.id())
2523 createStatcatUpdateWatcher = function (id) {
2524 return $scope.$watch('working.statcats[' + id + ']', function () {
2525 if ($scope.working.statcats) {
2526 var newval = $scope.working.statcats[id];
2528 if (typeof newval != 'undefined') {
2529 $scope.dirty = true;
2530 if (angular.isObject(newval)) { // we'll use the pkey
2531 newval = newval.id();
2534 if (""+newval == "" || newval == null) {
2535 $scope.working.statcats[id] = undefined;
2544 $scope.clearWorking = function () {
2545 angular.forEach($scope.working, function (v,k,o) {
2546 $scope.working.MultiMap[k] = [];
2547 if (!angular.isObject(v)) {
2548 if (typeof v != 'undefined')
2549 $scope.working[k] = undefined;
2550 } else if (k != 'circ_lib') {
2551 angular.forEach(v, function (sv,sk) {
2552 $scope.working[k][sk] = undefined;
2556 $scope.working.circ_lib = undefined; // special
2557 $scope.dirty = false;
2560 $scope.working = {};
2561 $scope.location_orgs = [];
2562 $scope.location_cache = {};
2564 $scope.location_list = [];
2565 itemSvc.get_locations_by_org(
2566 egCore.org.fullPath( egCore.auth.user().ws_ou(), true )
2567 ).then(function(list){
2568 $scope.location_list = list;
2570 createSimpleUpdateWatcher('location');
2572 $scope.statcat_filter_list = egCore.org.fullPath( egCore.auth.user().ws_ou() );
2574 $scope.statcats = [];
2575 itemSvc.get_statcats(
2576 egCore.org.fullPath( egCore.auth.user().ws_ou(), true )
2577 ).then(function(list){
2578 $scope.statcats = list;
2579 angular.forEach($scope.statcats, function (s) {
2581 if (!$scope.working)
2582 $scope.working = { statcats: {}, statcat_filter: undefined};
2583 if (!$scope.working.statcats)
2584 $scope.working.statcats = {};
2586 $scope.working.statcats[s.id()] = undefined;
2587 createStatcatUpdateWatcher(s.id());
2591 $scope.copy_notes_dialog = function() {
2592 var default_pub = Boolean($scope.defaults.copy_notes_pub);
2593 var working = $scope.working;
2595 return $uibModal.open({
2596 templateUrl: './cat/volcopy/t_copy_notes',
2599 ['$scope','$uibModalInstance',
2600 function($scope , $uibModalInstance) {
2601 $scope.focusNote = true;
2608 $scope.require_initials = false;
2609 egCore.org.settings([
2610 'ui.staff.require_initials.copy_notes'
2611 ]).then(function(set) {
2612 $scope.require_initials = Boolean(set['ui.staff.require_initials.copy_notes']);
2615 $scope.note_list = [];
2616 angular.forEach(working.copy_notes, function(note) {
2617 var acpn = egCore.idl.fromHash('acpn', note);
2618 $scope.note_list.push(acpn);
2621 $scope.ok = function(note) {
2623 if (!working.copy_notes) {
2624 working.copy_notes = [];
2628 working.copy_notes.length = 0;
2629 angular.forEach($scope.note_list, function(existing_note) {
2630 if (!existing_note.isdeleted()) {
2631 working.copy_notes.push({
2632 pub : existing_note.pub() ? 't' : 'f',
2633 title : existing_note.title(),
2634 value : existing_note.value()
2639 // add new note, if any
2640 if (note.initials) note.value += ' [' + note.initials + ']';
2641 note.pub = note.pub ? 't' : 'f';
2642 if (note.title.length && note.value.length) {
2643 working.copy_notes.push(note);
2646 $uibModalInstance.close();
2649 $scope.cancel = function($event) {
2650 $uibModalInstance.dismiss();
2651 $event.preventDefault();
2657 $scope.copy_alerts_dialog = function() {
2658 var working = $scope.working;
2660 return $uibModal.open({
2661 templateUrl: './cat/volcopy/t_copy_alerts',
2664 ['$scope','$uibModalInstance',
2665 function($scope , $uibModalInstance) {
2667 itemSvc.get_copy_alert_types().then(function(ccat) {
2669 $scope.alert_types = ccat;
2670 angular.forEach(ccat, function(t) {
2671 ccat_map[t.id()] = t;
2673 $scope.copy_alert_list = [];
2674 angular.forEach(working.copy_alerts, function (alrt) {
2675 var aca = egCore.idl.fromHash('aca', alrt);
2676 aca.alert_type(ccat_map[alrt.alert_type]);
2678 $scope.copy_alert_list.push(aca);
2682 $scope.focusNote = true;
2683 $scope.copy_alert = {
2688 $scope.ok = function(copy_alert) {
2690 if (!working.copy_alerts) {
2691 working.copy_alerts = [];
2694 working.copy_alerts.length = 0;
2696 angular.forEach($scope.copy_alert_list, function(alrt) {
2697 if (alrt.ack_time() == null) {
2698 working.copy_alerts.push({
2701 alert_type : alrt.alert_type().id()
2706 if (typeof(copy_alert.note) != 'undefined' &&
2707 copy_alert.note != '') {
2708 working.copy_alerts.push({
2709 note : copy_alert.note,
2710 temp : copy_alert.temp ? 't' : 'f',
2711 alert_type : copy_alert.alert_type
2715 $uibModalInstance.close();
2718 $scope.cancel = function($event) {
2719 $uibModalInstance.dismiss();
2720 $event.preventDefault();
2726 $scope.status_list = [];
2727 itemSvc.get_magic_statuses().then(function(list){
2728 $scope.magic_status_list = list;
2730 itemSvc.get_statuses().then(function(list){
2731 $scope.status_list = list;
2733 createSimpleUpdateWatcher('status');
2735 $scope.circ_modifier_list = [];
2736 itemSvc.get_circ_mods().then(function(list){
2737 $scope.circ_modifier_list = list;
2739 createSimpleUpdateWatcher('circ_modifier');
2741 $scope.circ_type_list = [];
2742 itemSvc.get_circ_types().then(function(list){
2743 $scope.circ_type_list = list;
2745 createSimpleUpdateWatcher('circ_as_type');
2747 $scope.age_protect_list = [];
2748 itemSvc.get_age_protects().then(function(list){
2749 $scope.age_protect_list = list;
2751 createSimpleUpdateWatcher('age_protect');
2753 $scope.floating_list = [];
2754 itemSvc.get_floating_groups().then(function(list){
2755 $scope.floating_list = list;
2757 createSimpleUpdateWatcher('floating');
2759 createSimpleUpdateWatcher('circulate');
2760 createSimpleUpdateWatcher('holdable');
2761 createSimpleUpdateWatcher('fine_level');
2762 createSimpleUpdateWatcher('loan_duration');
2763 createSimpleUpdateWatcher('cost');
2764 createSimpleUpdateWatcher('deposit');
2765 createSimpleUpdateWatcher('deposit_amount');
2766 createSimpleUpdateWatcher('mint_condition');
2767 createSimpleUpdateWatcher('opac_visible');
2768 createSimpleUpdateWatcher('ref');
2770 $scope.suffix_list = [];
2771 itemSvc.get_suffixes(egCore.auth.user().ws_ou()).then(function(list){
2772 $scope.suffix_list = list;
2775 $scope.prefix_list = [];
2776 itemSvc.get_prefixes(egCore.auth.user().ws_ou()).then(function(list){
2777 $scope.prefix_list = list;
2780 $scope.classification_list = [];
2781 itemSvc.get_classifications().then(function(list){
2782 $scope.classification_list = list;
2785 createSimpleUpdateWatcher('working.callnumber.classification');
2786 createSimpleUpdateWatcher('working.callnumber.prefix');
2787 createSimpleUpdateWatcher('working.callnumber.suffix');