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()"/>'+
492 '<div class="label label-danger" ng-if="duplicate_barcode">{{duplicate_barcode_string}}</div>'+
493 '<div class="label label-danger" ng-if="empty_barcode">{{empty_barcode_string}}</div>'+
495 '<div class="col-xs-3"><input class="form-control" type="number" min="1" ng-model="copy_number" ng-change="updateCopyNo()"/></div>'+
496 '<div class="col-xs-3"><eg-basic-combo-box list="parts" selected="part"></eg-basic-combo-box></div>'+
499 scope: { focusNext: "=", copy: "=", callNumber: "=", index: "@", record: "@" },
500 controller : ['$scope','itemSvc','egCore',
501 function ( $scope , itemSvc , egCore ) {
502 $scope.new_part_id = 0;
503 $scope.barcode_has_error = false;
504 $scope.duplicate_barcode = false;
505 $scope.empty_barcode = false;
506 $scope.duplicate_barcode_string = window.duplicate_barcode_string;
507 $scope.empty_barcode_string = window.empty_barcode_string;
509 if (!$scope.copy.barcode()) $scope.copy.empty_barcode = true;
511 $scope.nextBarcode = function (i) {
512 $scope.focusNext(i, $scope.barcode);
515 $scope.updateBarcode = function () {
516 if ($scope.barcode != '') {
517 $scope.copy.empty_barcode = $scope.empty_barcode = false;
518 $scope.barcode_has_error = !Boolean(itemSvc.checkBarcode($scope.barcode));
519 itemSvc.checkDuplicateBarcode($scope.barcode, $scope.copy.id())
520 .then(function (state) { $scope.copy.duplicate_barcode = $scope.duplicate_barcode = state });
522 $scope.copy.empty_barcode = $scope.empty_barcode = true;
525 $scope.copy.barcode($scope.barcode);
526 $scope.copy.ischanged(1);
527 if (itemSvc.currently_generating)
528 $scope.focusNext($scope.copy.id(), $scope.barcode);
531 $scope.updateCopyNo = function () { $scope.copy.copy_number($scope.copy_number); $scope.copy.ischanged(1); };
532 $scope.updatePart = function () {
534 var p = $scope.part_list.filter(function (x) {
535 return x.label() == $scope.part
537 if (p.length > 0) { // preexisting part
539 } else { // create one...
540 var part = new egCore.idl.bmp();
541 part.id( --$scope.new_part_id );
543 part.label( $scope.part );
544 part.record( $scope.callNumber.record() );
545 $scope.copy.parts([part]);
546 $scope.copy.ischanged(1);
549 $scope.copy.parts([]);
551 $scope.copy.ischanged(1);
555 $scope.part_list = [];
557 itemSvc.get_parts($scope.callNumber.record())
558 .then(function(list){
559 $scope.part_list = list;
560 angular.forEach(list, function(p){ $scope.parts.push(p.label()) });
561 $scope.parts = angular.copy($scope.parts);
563 $scope.$watch('part', $scope.updatePart);
564 if ($scope.copy.parts()) {
565 var the_part = $scope.copy.parts()[0];
566 if (the_part) $scope.part = the_part.label();
570 $scope.barcode = $scope.copy.barcode();
571 $scope.copy_number = $scope.copy.copy_number();
579 .directive("egVolRow", function () {
586 '<div class="col-xs-2">'+
587 '<button aria-label="Delete" style="margin:-5px -15px; float:left;" ng-hide="callNumber.not_ephemeral" type="button" class="close" ng-click="removeCN()">×</button>' +
588 '<select class="form-control" ng-model="classification" ng-change="updateClassification()" ng-options="cl.name() for cl in classification_list"/>'+
590 '<div class="col-xs-1">'+
591 '<select class="form-control" ng-model="prefix" ng-change="updatePrefix()" ng-options="p.label() for p in prefix_list"/>'+
593 '<div class="col-xs-2">'+
594 '<input class="form-control" type="text" ng-change="updateLabel()" ng-model="label"/>'+
595 '<div class="label label-danger" ng-if="empty_label">{{empty_label_string}}</div>'+
597 '<div class="col-xs-1">'+
598 '<select class="form-control" ng-model="suffix" ng-change="updateSuffix()" ng-options="s.label() for s in suffix_list"/>'+
600 '<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>'+
601 '<div ng-hide="onlyVols" class="col-xs-5">'+
602 '<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>'+
606 scope: {focusNext: "=", allcopies: "=", copies: "=", onlyVols: "=", record: "@", struct:"=" },
607 controller : ['$scope','itemSvc','egCore',
608 function ( $scope , itemSvc , egCore ) {
609 $scope.callNumber = $scope.copies[0].call_number();
610 if (!$scope.callNumber.label()) $scope.callNumber.empty_label = true;
612 $scope.empty_label = false;
613 $scope.empty_label_string = window.empty_label_string;
615 $scope.idTracker = function (x) { if (x && x.id) return x.id() };
617 // XXX $() is not working! arg
618 $scope.focusNextBarcode = function (i, prev_bc) {
621 angular.forEach($scope.copies, function (cp) {
629 if (yep) n = cp.id();
633 var next = '#' + $scope.callNumber.id() + '_' + n;
636 if (!itemSvc.currently_generating) el.focus();
637 if (prev_bc && itemSvc.auto_gen_barcode && el.val() == "") {
638 itemSvc.nextBarcode(prev_bc).then(function(bc){
641 el.trigger('change');
644 itemSvc.currently_generating = false;
648 $scope.focusNext($scope.callNumber.id(),prev_bc)
652 $scope.suffix_list = [];
653 itemSvc.get_suffixes($scope.callNumber.owning_lib()).then(function(list){
654 $scope.suffix_list = list;
655 $scope.$watch('callNumber.suffix()', function (v) {
656 if (angular.isObject(v)) v = v.id();
657 $scope.suffix = $scope.suffix_list.filter( function (s) {
663 $scope.updateSuffix = function () {
664 angular.forEach($scope.copies, function(cp) {
665 cp.call_number().suffix($scope.suffix);
666 cp.call_number().ischanged(1);
670 $scope.prefix_list = [];
671 itemSvc.get_prefixes($scope.callNumber.owning_lib()).then(function(list){
672 $scope.prefix_list = list;
673 $scope.$watch('callNumber.prefix()', function (v) {
674 if (angular.isObject(v)) v = v.id();
675 $scope.prefix = $scope.prefix_list.filter(function (p) {
681 $scope.updatePrefix = function () {
682 angular.forEach($scope.copies, function(cp) {
683 cp.call_number().prefix($scope.prefix);
684 cp.call_number().ischanged(1);
687 $scope.$watch('callNumber.owning_lib()', function(oldLib, newLib) {
688 if (oldLib == newLib) return;
689 var currentPrefix = $scope.callNumber.prefix();
690 if (angular.isObject(currentPrefix)) currentPrefix = currentPrefix.id();
691 itemSvc.get_prefixes($scope.callNumber.owning_lib()).then(function(list){
692 $scope.prefix_list = list;
693 var newPrefixId = $scope.prefix_list.filter(function (p) {
694 return p.id() == currentPrefix;
696 if (newPrefixId.id) newPrefixId = newPrefixId.id();
697 $scope.prefix = $scope.prefix_list.filter(function (p) {
698 return p.id() == newPrefixId;
700 if ($scope.newPrefixId != currentPrefix) {
701 $scope.callNumber.prefix($scope.prefix);
704 var currentSuffix = $scope.callNumber.suffix();
705 if (angular.isObject(currentSuffix)) currentSuffix = currentSuffix.id();
706 itemSvc.get_suffixes($scope.callNumber.owning_lib()).then(function(list){
707 $scope.suffix_list = list;
708 var newSuffixId = $scope.suffix_list.filter(function (s) {
709 return s.id() == currentSuffix;
711 if (newSuffixId.id) newSuffixId = newSuffixId.id();
712 $scope.suffix = $scope.suffix_list.filter(function (s) {
713 return s.id() == newSuffixId;
715 if ($scope.newSuffixId != currentSuffix) {
716 $scope.callNumber.suffix($scope.suffix);
721 $scope.classification_list = [];
722 itemSvc.get_classifications().then(function(list){
723 $scope.classification_list = list;
724 $scope.$watch('callNumber.label_class()', function (v) {
725 if (angular.isObject(v)) v = v.id();
726 $scope.classification = $scope.classification_list.filter(function (c) {
732 $scope.updateClassification = function () {
733 angular.forEach($scope.copies, function(cp) {
734 cp.call_number().label_class($scope.classification);
735 cp.call_number().ischanged(1);
739 $scope.updateLabel = function () {
740 angular.forEach($scope.copies, function(cp) {
741 cp.call_number().label($scope.label);
742 cp.call_number().ischanged(1);
746 $scope.$watch('callNumber.label()', function (v) {
748 if ($scope.label == '') {
749 $scope.callNumber.empty_label = $scope.empty_label = true;
751 $scope.callNumber.empty_label = $scope.empty_label = false;
755 $scope.prefix = $scope.callNumber.prefix();
756 $scope.suffix = $scope.callNumber.suffix();
757 $scope.classification = $scope.callNumber.label_class();
758 $scope.label = $scope.callNumber.label();
760 $scope.copy_count = $scope.copies.length;
761 $scope.orig_copy_count = $scope.copy_count;
763 $scope.removeCN = function(){
764 var cn = $scope.callNumber;
765 if (cn.not_ephemeral) return; // can't delete existing volumes
767 angular.forEach(Object.keys($scope.struct), function(k){
768 angular.forEach($scope.struct[k], function(cp){
769 var struct_cn = cp.call_number();
770 if (struct_cn.id() == cn.id()){
771 console.log("X'ed CN id" + cn.id() + " and struct CN id match!");
772 // remove any copies in $scope.struct[k]
773 angular.forEach($scope.copies, function(c){
774 var idx = $scope.allcopies.indexOf(c);
775 $scope.allcopies.splice(idx, 1);
780 delete $scope.struct[k];
785 // manually decrease cn_count numeric input
786 var cn_spinner = $("input[name='cn_count_lib"+ cn.owning_lib() +"']");
787 if (cn_spinner.val() > 0) cn_spinner.val(parseInt(cn_spinner.val()) - 1);
788 cn_spinner.trigger("change");
792 $scope.changeCPCount = function () {
793 while ($scope.copy_count > $scope.copies.length) {
794 var cp = itemSvc.generateNewCopy(
796 $scope.callNumber.owning_lib(),
800 $scope.copies.push( cp );
801 $scope.allcopies.push( cp );
805 if ($scope.copy_count >= $scope.orig_copy_count) {
806 var how_many = $scope.copies.length - $scope.copy_count;
808 var dead = $scope.copies.splice($scope.copy_count,how_many);
809 $scope.callNumber.copies($scope.copies);
811 // Trimming the global list is a bit more tricky
812 angular.forEach( dead, function (d) {
813 angular.forEach( $scope.allcopies, function (l, i) {
814 if (l === d) $scope.allcopies.splice(i,1);
827 .directive("egVolEdit", function () {
833 '<div class="col-xs-1"><eg-org-selector selected="owning_lib" disable-test="cant_have_vols"></eg-org-selector></div>'+
834 '<div class="col-xs-1"><input class="form-control" type="number" min="{{orig_cn_count}}" ng-model="cn_count" ng-change="changeCNCount()"/></div>'+
835 '<div class="col-xs-10">'+
836 '<eg-vol-row only-vols="onlyVols" record="{{record}}"'+
837 'ng-repeat="(cn,copies) in struct" '+
838 'focus-next="focusNextFirst" copies="copies" allcopies="allcopies" struct="struct">'+
843 scope: { focusNext: "=", allcopies: "=", struct: "=", lib: "@", record: "@", onlyVols: "=" },
844 controller : ['$scope','itemSvc','egCore',
845 function ( $scope , itemSvc , egCore ) {
846 $scope.first_cn = Object.keys($scope.struct)[0];
847 $scope.full_cn = $scope.struct[$scope.first_cn][0].call_number();
849 $scope.defaults = {};
850 egCore.hatch.getItem('cat.copy.defaults').then(function(t) {
856 $scope.focusNextFirst = function(prev_cn,prev_bc) {
859 angular.forEach(Object.keys($scope.struct).sort(), function (cn) {
871 var next = '#' + n + '_' + $scope.struct[n][0].id();
874 if (!itemSvc.currently_generating) el.focus();
875 if (prev_bc && itemSvc.auto_gen_barcode && el.val() == "") {
876 itemSvc.nextBarcode(prev_bc).then(function(bc){
879 el.trigger('change');
882 itemSvc.currently_generating = false;
886 $scope.focusNext($scope.lib, prev_bc);
890 $scope.cn_count = Object.keys($scope.struct).length;
891 $scope.orig_cn_count = $scope.cn_count;
893 $scope.owning_lib = egCore.org.get($scope.lib);
894 $scope.$watch('owning_lib', function (oldLib, newLib) {
895 if (oldLib == newLib) return;
896 angular.forEach( Object.keys($scope.struct), function (cn) {
897 $scope.struct[cn][0].call_number().owning_lib( $scope.owning_lib.id() );
898 $scope.struct[cn][0].call_number().ischanged(1);
902 $scope.cant_have_vols = function (id) { return !egCore.org.CanHaveVolumes(id); };
904 $scope.$watch('cn_count', function (n) {
905 var o = Object.keys($scope.struct).length;
906 if (n > o) { // adding
907 for (var i = o; o < n; o++) {
908 var cn = new egCore.idl.acn();
909 cn.id( --itemSvc.new_cn_id );
911 cn.prefix( $scope.defaults.prefix || -1 );
912 cn.suffix( $scope.defaults.suffix || -1 );
913 cn.label_class( $scope.defaults.classification || 1 );
914 cn.owning_lib( $scope.owning_lib.id() );
915 cn.record( $scope.full_cn.record() );
917 var cp = itemSvc.generateNewCopy(
919 $scope.owning_lib.id(),
924 $scope.struct[cn.id()] = [cp];
925 $scope.allcopies.push(cp);
926 if (!$scope.defaults.classification) {
928 ['cat.default_classification_scheme'],
930 ).then(function (val) {
931 cn.label_class(val['cat.default_classification_scheme']);
935 } else if (n < o && n >= $scope.orig_cn_count) { // removing
936 var how_many = o - n;
939 .sort(function(a, b){return parseInt(a)-parseInt(b)})
940 .filter(function(x){ return parseInt(x) <= 0 });
941 for (var i = 0; i < how_many; i++) {
942 // Trimming the global list is a bit more tricky
943 angular.forEach($scope.struct[list[i]], function (d) {
944 angular.forEach( $scope.allcopies, function (l, j) {
945 if (l === d) $scope.allcopies.splice(j,1);
948 delete $scope.struct[list[i]];
961 .controller('EditCtrl',
962 ['$scope','$q','$window','$routeParams','$location','$timeout','egCore','egNet','egGridDataProvider','itemSvc','$uibModal',
963 function($scope , $q , $window , $routeParams , $location , $timeout , egCore , egNet , egGridDataProvider , itemSvc , $uibModal) {
965 $scope.forms = {}; // Accessed by t_attr_edit.tt2
966 $scope.i18n = egCore.i18n;
968 $scope.defaults = { // If defaults are not set at all, allow everything
969 barcode_checkdigit : false,
970 auto_gen_barcode : false,
976 loan_duration : true,
981 deposit_amount : true,
985 mint_condition : true,
988 circ_modifier : true,
998 $scope.new_lib_to_add = egCore.org.get(egCore.auth.user().ws_ou());
999 $scope.changeNewLib = function (org) {
1000 $scope.new_lib_to_add = org;
1002 $scope.addLibToStruct = function () {
1003 var newLib = $scope.new_lib_to_add;
1004 var cn = new egCore.idl.acn();
1005 cn.id( --itemSvc.new_cn_id );
1007 cn.prefix( $scope.defaults.prefix || -1 );
1008 cn.suffix( $scope.defaults.suffix || -1 );
1009 cn.label_class( $scope.defaults.classification || 1 );
1010 cn.owning_lib( newLib.id() );
1011 cn.record( $scope.record_id );
1013 var cp = itemSvc.generateNewCopy(
1020 $scope.data.addCopy(cp);
1022 // manually increase cn_count numeric input
1023 var cn_spinner = $("input[name='cn_count_lib"+ newLib.id() +"']");
1024 cn_spinner.val(parseInt(cn_spinner.val()) + 1);
1025 cn_spinner.trigger("change");
1027 if (!$scope.defaults.classification) {
1028 egCore.org.settings(
1029 ['cat.default_classification_scheme'],
1031 ).then(function (val) {
1032 cn.label_class(val['cat.default_classification_scheme']);
1037 $scope.embedded = ($routeParams.mode && $routeParams.mode == 'embedded') ? true : false;
1038 $scope.edit_templates = ($location.path().match(/edit_template/)) ? true : false;
1040 $scope.saveDefaults = function () {
1041 egCore.hatch.setItem('cat.copy.defaults', $scope.defaults);
1044 $scope.fetchDefaults = function () {
1045 egCore.hatch.getItem('cat.copy.defaults').then(function(t) {
1047 $scope.defaults = t;
1048 if (!$scope.batch) $scope.batch = {};
1049 $scope.batch.classification = $scope.defaults.classification;
1050 $scope.batch.prefix = $scope.defaults.prefix;
1051 $scope.batch.suffix = $scope.defaults.suffix;
1052 $scope.working.statcat_filter = $scope.defaults.statcat_filter;
1054 typeof $scope.defaults.statcat_filter == 'object' &&
1055 Object.keys($scope.defaults.statcat_filter).length > 0
1057 // want fieldmapper object here...
1058 $scope.defaults.statcat_filter =
1059 egCore.idl.Clone($scope.defaults.statcat_filter);
1061 $scope.working.statcat_filter = $scope.defaults.statcat_filter.id();
1063 if ($scope.defaults.always_volumes) $scope.show_vols = true;
1064 if ($scope.defaults.barcode_checkdigit) itemSvc.barcode_checkdigit = true;
1065 if ($scope.defaults.auto_gen_barcode) itemSvc.auto_gen_barcode = true;
1068 // Fetch the list of bib-level callnumbers based on the applied
1069 // classification scheme. If none is defined, default to "1"
1070 // (Generic) since it provides the most options.
1073 'open-ils.cat.biblio.record.marc_cn.retrieve',
1075 $scope.batch.classification || 1
1076 ).then(function(list) {
1077 $scope.batch.marcCallNumbers = [];
1078 list.forEach(function(hash) {
1079 $scope.batch.marcCallNumbers.push(Object.values(hash)[0]);
1085 $scope.$watch('defaults.statcat_filter', function() {
1086 $scope.saveDefaults();
1088 $scope.$watch('defaults.auto_gen_barcode', function (n,o) {
1089 itemSvc.auto_gen_barcode = n
1092 $scope.$watch('defaults.barcode_checkdigit', function (n,o) {
1093 itemSvc.barcode_checkdigit = n
1096 $scope.dirty = false;
1097 $scope.$watch('dirty',
1098 function(newVal, oldVal) {
1099 if (newVal && newVal != oldVal) {
1100 $($window).on('beforeunload.edit', function(){
1101 return 'There is unsaved data!'
1104 $($window).off('beforeunload.edit');
1109 $scope.only_vols = false;
1110 $scope.show_vols = true;
1111 $scope.show_copies = true;
1113 $scope.tracker = function (x,f) { if (x) return x[f]() };
1114 $scope.idTracker = function (x) { if (x) return $scope.tracker(x,'id') };
1115 $scope.cant_have_vols = function (id) { return !egCore.org.CanHaveVolumes(id); };
1117 $scope.orgById = function (id) { return egCore.org.get(id) }
1118 $scope.statusById = function (id) {
1119 return $scope.status_list.filter( function (s) { return s.id() == id } )[0];
1121 $scope.locationById = function (id) {
1122 return $scope.location_cache[''+id];
1125 $scope.workingToComplete = function () {
1126 angular.forEach( $scope.workingGridControls.selectedItems(), function (c) {
1127 angular.forEach( itemSvc.copies, function (w, i) {
1129 $scope.completed_copies = $scope.completed_copies.concat(itemSvc.copies.splice(i,1));
1136 $scope.completeToWorking = function () {
1137 angular.forEach( $scope.completedGridControls.selectedItems(), function (c) {
1138 angular.forEach( $scope.completed_copies, function (w, i) {
1140 itemSvc.copies = itemSvc.copies.concat($scope.completed_copies.splice(i,1));
1147 createSimpleUpdateWatcher = function (field,exclude_copies_with_one_of_these_values) {
1148 return $scope.$watch('working.' + field, function () {
1149 var newval = $scope.working[field];
1151 if (typeof newval != 'undefined') {
1152 delete $scope.working.MultiMap[field];
1153 if (angular.isObject(newval)) { // we'll use the pkey
1154 if (newval.id) newval = newval.id();
1155 else if (newval.code) newval = newval.code();
1158 if (""+newval == "" || newval == null) {
1159 $scope.working[field] = undefined;
1163 if ($scope.workingGridControls && $scope.workingGridControls.selectedItems) {
1165 $scope.workingGridControls.selectedItems(),
1167 if (exclude_copies_with_one_of_these_values
1168 && exclude_copies_with_one_of_these_values.indexOf(cp[field](),0) > -1) {
1171 if (cp[field]() !== newval) {
1174 $scope.dirty = true;
1187 statcat_filter: undefined
1190 // Returns true if we are editing multiple copies and at least
1191 // one field contains multiple values.
1192 $scope.hasMulti = function() {
1193 var keys = Object.keys($scope.working.MultiMap);
1194 // for-loop for shortcut exit
1195 for (var i = 0; i < keys.length; i++) {
1196 if ($scope.working.MultiMap[keys[i]].length > 1) {
1203 $scope.copyAlertUpdate = function (alerts) {
1204 if (!$scope.in_item_select &&
1205 $scope.workingGridControls &&
1206 $scope.workingGridControls.selectedItems) {
1207 itemSvc.get_copy_alert_types().then(function(ccat) {
1209 $scope.alert_types = ccat;
1210 angular.forEach(ccat, function(t) {
1211 ccat_map[t.id()] = t;
1214 $scope.workingGridControls.selectedItems(),
1216 $scope.dirty = true;
1217 angular.forEach(alerts, function(alrt) {
1218 var a = egCore.idl.fromHash('aca', alrt);
1220 a.create_staff(egCore.auth.user().id());
1221 a.alert_type(ccat_map[a.alert_type()]);
1224 cp.copy_alerts().push( a );
1233 $scope.copyNoteUpdate = function (notes) {
1234 if (!$scope.in_item_select &&
1235 $scope.workingGridControls &&
1236 $scope.workingGridControls.selectedItems) {
1238 $scope.workingGridControls.selectedItems(),
1240 $scope.dirty = true;
1241 angular.forEach(notes, function(note) {
1242 var n = egCore.idl.fromHash('acpn', note);
1244 n.creator(egCore.auth.user().id());
1245 n.owning_copy(cp.id());
1246 cp.notes().push( n );
1255 $scope.statcatUpdate = function (id) {
1256 var newval = $scope.working.statcats[id];
1258 if (typeof newval != 'undefined') {
1259 if (angular.isObject(newval)) { // we'll use the pkey
1260 newval = newval.id();
1263 if (""+newval == "" || newval == null) {
1264 $scope.working.statcats[id] = undefined;
1268 if (!$scope.in_item_select && $scope.workingGridControls && $scope.workingGridControls.selectedItems) {
1270 $scope.workingGridControls.selectedItems(),
1272 $scope.dirty = true;
1274 cp.stat_cat_entries(
1275 angular.forEach( cp.stat_cat_entries(), function (e) {
1276 if (e.stat_cat() == id) { // mark deleted
1283 var e = new egCore.idl.asce();
1288 cp.stat_cat_entries(
1289 cp.stat_cat_entries() ?
1290 cp.stat_cat_entries().concat([ e ]) :
1296 // trim out all deleted ones; the API used to
1297 // do the update doesn't actually consult
1298 // isdeleted for stat cat entries
1299 cp.stat_cat_entries(
1300 cp.stat_cat_entries().filter(function (e) {
1301 return !Boolean(e.isdeleted());
1312 var dataKey = $routeParams.dataKey;
1313 console.debug('dataKey: ' + dataKey);
1315 if ((dataKey && dataKey.length > 0) || $scope.edit_templates) {
1317 $scope.templates = {};
1318 $scope.template_name = '';
1319 $scope.template_name_list = [];
1321 $scope.fetchTemplates = function () {
1322 itemSvc.get_acp_templates().then(function(t) {
1324 $scope.templates = t;
1325 $scope.template_name_list = Object.keys(t).sort();
1328 egCore.hatch.getItem('cat.copy.last_template').then(function(t) {
1329 if (t) $scope.template_name = t;
1332 $scope.fetchTemplates();
1334 $scope.applyTemplate = function (n) {
1335 angular.forEach($scope.templates[n], function (v,k) {
1336 if (k == 'circ_lib') {
1337 $scope.working[k] = egCore.org.get(v);
1338 } else if (k == 'copy_notes' && v.length) {
1339 $scope.copyNoteUpdate(v);
1340 } else if (k == 'copy_alerts' && v.length) {
1341 $scope.copyAlertUpdate(v);
1342 } else if (!angular.isObject(v)) {
1343 $scope.working[k] = angular.copy(v);
1345 angular.forEach(v, function (sv,sk) {
1346 if (k == 'callnumber') {
1347 angular.forEach(v, function (cnv,cnk) {
1348 $scope.batch[cnk] = cnv;
1350 $scope.applyBatchCNValues();
1352 $scope.working[k][sk] = angular.copy(sv);
1353 if (k == 'statcats') $scope.statcatUpdate(sk);
1357 delete $scope.working.MultiMap[k];
1359 egCore.hatch.setItem('cat.copy.last_template', n);
1362 $scope.copytab = 'working';
1363 $scope.tab = 'edit';
1364 $scope.summaryRecord = null;
1365 $scope.record_id = null;
1367 $scope.completed_copies = [];
1368 $scope.location_orgs = [];
1369 $scope.location_cache = {};
1370 $scope.statcats = [];
1371 if (!$scope.batch) $scope.batch = {};
1373 $scope.applyBatchCNValues = function () {
1374 if ($scope.data.tree) {
1375 angular.forEach($scope.data.tree, function(cn_hash) {
1376 angular.forEach(cn_hash, function(copies) {
1377 angular.forEach(copies, function(cp) {
1378 if (typeof $scope.batch.classification != 'undefined' && $scope.batch.classification != '') {
1379 var label_class = $scope.classification_list.filter(function(p){ return p.id() == $scope.batch.classification })[0];
1380 cp.call_number().label_class(label_class);
1381 cp.call_number().ischanged(1);
1382 $scope.dirty = true;
1384 if (typeof $scope.batch.prefix != 'undefined' && $scope.batch.prefix != '') {
1385 var prefix = $scope.prefix_list.filter(function(p){ return p.id() == $scope.batch.prefix })[0];
1386 cp.call_number().prefix(prefix);
1387 cp.call_number().ischanged(1);
1388 $scope.dirty = true;
1390 if (typeof $scope.batch.label != 'undefined' && $scope.batch.label != '') {
1391 cp.call_number().label($scope.batch.label);
1392 cp.call_number().ischanged(1);
1393 $scope.dirty = true;
1395 if (typeof $scope.batch.suffix != 'undefined' && $scope.batch.suffix != '') {
1396 var suffix = $scope.suffix_list.filter(function(p){ return p.id() == $scope.batch.suffix })[0];
1397 cp.call_number().suffix(suffix);
1398 cp.call_number().ischanged(1);
1399 $scope.dirty = true;
1407 $scope.clearWorking = function () {
1408 angular.forEach($scope.working, function (v,k,o) {
1409 if (!angular.isObject(v)) {
1410 if (typeof v != 'undefined')
1411 $scope.working[k] = undefined;
1412 } else if (k != 'circ_lib') {
1413 angular.forEach(v, function (sv,sk) {
1414 if (typeof v != 'undefined')
1415 $scope.working[k][sk] = undefined;
1419 $scope.working.circ_lib = undefined; // special
1422 $scope.completedGridDataProvider = egGridDataProvider.instance({
1423 get : function(offset, count) {
1424 //return provider.arrayNotifier(itemSvc.copies, offset, count);
1425 return this.arrayNotifier($scope.completed_copies, offset, count);
1429 $scope.completedGridControls = {};
1431 $scope.workingGridDataProvider = egGridDataProvider.instance({
1432 get : function(offset, count) {
1433 //return provider.arrayNotifier(itemSvc.copies, offset, count);
1434 return this.arrayNotifier(itemSvc.copies, offset, count);
1438 $scope.workingGridControls = {};
1439 $scope.add_vols_copies = false;
1440 $scope.is_fast_add = false;
1442 // Generate some functions for selecting items by column value in the working grid
1444 ['circulate','status','circ_lib','ref','location','opac_visible','circ_modifier','price',
1445 'loan_duration','cost','circ_as_type','deposit','holdable','deposit_amount','age_protect',
1446 'mint_condition','fine_level','floating'],
1448 $scope['select_by_' + field] = function (x) {
1449 $scope.workingGridControls.selectItemsByValue(field,x);
1454 var truthy = /^t|1/;
1455 $scope.labelYesNo = function (x) {
1456 return truthy.test(x) ? egCore.strings.YES : egCore.strings.NO;
1459 $scope.orgShortname = function (x) {
1460 return egCore.org.get(x).shortname();
1463 $scope.statusName = function (x) {
1464 var s = $scope.status_list.filter(function(y) {
1471 $scope.locationName = function (x) {
1472 var s = $scope.location_list.filter(function(y) {
1476 return $scope.i18n.ou_qualified_location_name(s[0]);
1479 $scope.durationLabel = function (x) {
1480 return [egCore.strings.SHORT, egCore.strings.NORMAL, egCore.strings.EXTENDED][-1 + x]
1483 $scope.fineLabel = function (x) {
1484 return [egCore.strings.LOW, egCore.strings.NORMAL, egCore.strings.HIGH][-1 + x]
1487 $scope.circTypeValue = function (x) {
1488 if (x === null || x === undefined) return egCore.strings.UNSET;
1489 var s = $scope.circ_type_list.filter(function(y) {
1490 return y.code() == x;
1493 return s[0].value();
1496 $scope.ageprotectName = function (x) {
1497 if (x === null || x === undefined) return egCore.strings.UNSET;
1498 var s = $scope.age_protect_list.filter(function(y) {
1505 $scope.floatingName = function (x) {
1506 if (x === null || x === undefined) return egCore.strings.UNSET;
1507 var s = $scope.floating_list.filter(function(y) {
1514 $scope.circmodName = function (x) {
1515 if (x === null || x === undefined) return egCore.strings.UNSET;
1516 var s = $scope.circ_modifier_list.filter(function(y) {
1517 return y.code() == x;
1525 'open-ils.actor.anon_cache.get_value',
1526 dataKey, 'edit-these-copies'
1527 ).then(function (data) {
1530 if (data.hide_vols && !$scope.defaults.always_volumes) $scope.show_vols = false;
1531 if (data.hide_copies) {
1532 $scope.show_copies = false;
1533 $scope.only_vols = true;
1536 $scope.record_id = data.record_id;
1539 $scope.fetchDefaults();
1541 function fetchRaw () {
1542 if (!$scope.only_vols) $scope.dirty = true;
1543 $scope.add_vols_copies = true;
1545 /* data.raw data structure looks like this:
1547 * callnumber : $cn_id, // optional, to add a copy to a cn
1548 * owner : $org, // optional, defaults to cn.owning_lib or ws_ou
1549 * label : $cn_label, // optional, to supply a label on a new cn
1550 * barcode : $cp_barcode // optional, to supply a barcode on a new cp
1551 * fast_add : boolean // optional, to specify whether this came
1555 * All can be left out and a completely empty vol/copy combo will be vivicated.
1562 if (proto.fast_add) $scope.is_fast_add = true;
1563 if (proto.callnumber) {
1564 promises.push(egCore.pcrud.retrieve('acn', proto.callnumber)
1565 .then(function(cn) {
1566 var cp = new itemSvc.generateNewCopy(
1568 proto.owner || cn.owning_lib(),
1570 ((!$scope.only_vols) ? true : false)
1573 if (proto.barcode) {
1574 cp.barcode( proto.barcode );
1575 cp.empty_barcode = false;
1581 var cn = new egCore.idl.acn();
1582 cn.id( --itemSvc.new_cn_id );
1584 cn.prefix( $scope.defaults.prefix || -1 );
1585 cn.suffix( $scope.defaults.suffix || -1 );
1586 cn.owning_lib( proto.owner || egCore.auth.user().ws_ou() );
1587 cn.record( $scope.record_id );
1588 egCore.org.settings(
1589 ['cat.default_classification_scheme'],
1591 ).then(function (val) {
1593 $scope.defaults.classification ||
1594 val['cat.default_classification_scheme'] ||
1598 cn.label( proto.label );
1602 'open-ils.cat.biblio.record.marc_cn.retrieve',
1605 ).then(function(cn_array) {
1606 if (cn_array.length > 0) {
1607 for (var field in cn_array[0]) {
1608 cn.label( cn_array[0][field] );
1616 // If we are adding an empty vol,
1617 // this is ultimately just a placeholder copy
1618 // which gets removed before saving.
1619 // TODO: consider ways to remove this
1621 var cp = new itemSvc.generateNewCopy(
1623 proto.owner || cn.owning_lib(),
1628 if (proto.barcode) {
1629 cp.barcode( proto.barcode );
1630 cp.empty_barcode = false;
1638 angular.forEach(itemSvc.copies, function(c){
1639 var cn = c.call_number();
1640 var copy_id = c.id();
1642 cn.not_ephemeral = true;
1646 return $q.all(promises);
1649 if (data.copies && data.copies.length)
1650 return itemSvc.fetchIds(data.copies).then(fetchRaw);
1656 }).then( function() {
1658 return itemSvc.fetch_locations(
1659 itemSvc.copies.map(function(cp){
1660 return cp.location();
1661 }).filter(function(e,i,a){
1662 return a.lastIndexOf(e) === i;
1664 ).then(function(list){
1665 $scope.data = itemSvc;
1666 $scope.location_list = list;
1667 $scope.workingGridDataProvider.refresh();
1672 $scope.can_save = false;
1673 function check_saveable () {
1674 var can_save = true;
1679 if (!$scope.only_vols) {
1680 if (i.duplicate_barcode || i.empty_barcode || i.call_number().empty_label) {
1683 } else if (i.call_number().empty_label) {
1689 if (!$scope.only_vols && $scope.forms.myForm && $scope.forms.myForm.$invalid) {
1693 $scope.can_save = can_save;
1696 $scope.disableSave = function () {
1698 return !$scope.can_save;
1701 $scope.focusNextFirst = function(prev_lib,prev_bc) {
1704 angular.forEach(Object.keys($scope.data.tree).sort(), function (lib) {
1707 if (lib == prev_lib) {
1716 var first_cn = Object.keys($scope.data.tree[n])[0];
1717 var next = '#' + first_cn + '_' + $scope.data.tree[n][first_cn][0].id();
1720 if (!itemSvc.currently_generating) el.focus();
1721 if (prev_bc && itemSvc.auto_gen_barcode && el.val() == "") {
1722 itemSvc.nextBarcode(prev_bc).then(function(bc){
1725 el.trigger('change');
1728 itemSvc.currently_generating = false;
1734 $scope.in_item_select = false;
1735 $scope.afterItemSelect = function() { $scope.in_item_select = false };
1736 $scope.handleItemSelect = function (item_list) {
1737 if (item_list && item_list.length > 0) {
1738 $scope.in_item_select = true;
1740 angular.forEach(Object.keys($scope.defaults.attributes), function (attr) {
1742 var value_hash = {};
1743 var value_list = [];
1744 angular.forEach(item_list, function (item) {
1746 var v = item[attr]()
1747 if (angular.isObject(v)) {
1748 if (v.id) v = v.id();
1749 else if (v.code) v = v.code();
1756 $scope.working.MultiMap[attr] = value_list;
1758 if (Object.keys(value_hash).length == 1) {
1759 if (attr == 'circ_lib') {
1760 $scope.working[attr] = egCore.org.get(item_list[0][attr]());
1762 $scope.working[attr] = item_list[0][attr]();
1765 $scope.working[attr] = undefined;
1769 angular.forEach($scope.statcats, function (sc) {
1772 var value_hash = {};
1774 angular.forEach(item_list, function (item) {
1775 if (item.stat_cat_entries()) {
1776 if (item.stat_cat_entries().length > 0) {
1777 var right_sc = item.stat_cat_entries().filter(function (e) {
1778 return e.stat_cat() == sc.id() && !Boolean(e.isdeleted());
1781 if (right_sc.length > 0) {
1782 value_hash[right_sc[0].id()] = right_sc[0].id();
1794 if (!none && Object.keys(value_hash).length == 1) {
1795 $scope.working.statcats[sc.id()] = value_hash[Object.keys(value_hash)[0]];
1796 $scope.working.statcats_multi[sc.id()] = false;
1797 } else if (item_list.length > 1 && Object.keys(value_hash).length > 0) {
1798 $scope.working.statcats[sc.id()] = undefined;
1799 $scope.working.statcats_multi[sc.id()] = true;
1801 $scope.working.statcats[sc.id()] = undefined;
1802 $scope.working.statcats_multi[sc.id()] = false;
1808 $scope.clearWorking();
1813 $scope.$watch('data.copies.length', function () {
1814 if ($scope.data.copies) {
1815 var base_orgs = $scope.data.copies.map(function(cp){
1816 if (isNaN(cp.circ_lib())) return Number(cp.circ_lib().id());
1817 return Number(cp.circ_lib());
1819 $scope.data.copies.map(function(cp){
1820 if (isNaN(cp.call_number().owning_lib())) return Number(cp.call_number().owning_lib().id());
1821 return Number(cp.call_number().owning_lib());
1824 [egCore.auth.user().ws_ou()]
1825 ).filter(function(e,i,a){
1826 return a.lastIndexOf(e) === i;
1830 angular.forEach(base_orgs, function(o) {
1831 all_orgs = all_orgs.concat( egCore.org.fullPath(o, true) );
1834 var final_orgs = all_orgs.filter(function(e,i,a){
1835 return a.lastIndexOf(e) === i;
1836 }).sort(function(a, b){return a-b});
1838 if ($scope.location_orgs.toString() != final_orgs.toString()) {
1839 $scope.location_orgs = final_orgs;
1840 if ($scope.location_orgs.length) {
1841 itemSvc.get_locations_by_org($scope.location_orgs).then(function(list){
1842 angular.forEach(list, function(l) {
1843 $scope.location_cache[ ''+l.id() ] = l;
1845 $scope.location_list = list;
1846 }).then(function() {
1847 $scope.statcat_filter_list = [];
1848 angular.forEach($scope.location_orgs, function (o) {
1849 $scope.statcat_filter_list.push(egCore.org.get(o));
1852 itemSvc.get_statcats($scope.location_orgs).then(function(list){
1853 $scope.statcats = list;
1854 angular.forEach($scope.statcats, function (s) {
1856 if (!$scope.working)
1857 $scope.working = { statcats_multi: {}, statcats: {}, statcat_filter: undefined};
1858 if (!$scope.working.statcats_multi)
1859 $scope.working.statcats_multi = {};
1860 if (!$scope.working.statcats)
1861 $scope.working.statcats = {};
1863 if (!$scope.in_item_select) {
1864 $scope.working.statcats[s.id()] = undefined;
1866 createStatcatUpdateWatcher(s.id());
1868 $scope.in_item_select = false;
1869 // do a refresh here to work around a race
1870 // condition that can result in stat cats
1871 // not being selected.
1872 $scope.workingGridDataProvider.refresh();
1877 $scope.workingGridDataProvider.refresh();
1882 $scope.statcat_visible = function (sc_owner) {
1883 var visible = typeof $scope.working.statcat_filter === 'undefined' || !$scope.working.statcat_filter;
1884 angular.forEach(egCore.org.ancestors(sc_owner), function (ancestor_org) {
1885 if ($scope.working.statcat_filter == ancestor_org.id())
1891 $scope.suffix_list = [];
1892 itemSvc.get_suffixes(egCore.auth.user().ws_ou()).then(function(list){
1893 $scope.suffix_list = list;
1896 $scope.prefix_list = [];
1897 itemSvc.get_prefixes(egCore.auth.user().ws_ou()).then(function(list){
1898 $scope.prefix_list = list;
1901 $scope.classification_list = [];
1902 itemSvc.get_classifications().then(function(list){
1903 $scope.classification_list = list;
1906 $scope.$watch('completed_copies.length', function () {
1907 $scope.completedGridDataProvider.refresh();
1910 $scope.location_list = [];
1911 createSimpleUpdateWatcher('location');
1913 $scope.status_list = [];
1914 itemSvc.get_magic_statuses().then(function(list){
1915 $scope.magic_status_list = list;
1916 createSimpleUpdateWatcher('status',$scope.magic_status_list);
1918 itemSvc.get_statuses().then(function(list){
1919 $scope.status_list = list;
1922 $scope.circ_modifier_list = [];
1923 itemSvc.get_circ_mods().then(function(list){
1924 $scope.circ_modifier_list = list;
1926 createSimpleUpdateWatcher('circ_modifier');
1928 $scope.circ_type_list = [];
1929 itemSvc.get_circ_types().then(function(list){
1930 $scope.circ_type_list = list;
1932 createSimpleUpdateWatcher('circ_as_type');
1934 $scope.age_protect_list = [];
1935 itemSvc.get_age_protects().then(function(list){
1936 $scope.age_protect_list = list;
1938 createSimpleUpdateWatcher('age_protect');
1940 $scope.floating_list = [];
1941 itemSvc.get_floating_groups().then(function(list){
1942 $scope.floating_list = list;
1944 createSimpleUpdateWatcher('floating');
1946 createSimpleUpdateWatcher('circ_lib');
1947 createSimpleUpdateWatcher('circulate');
1948 createSimpleUpdateWatcher('holdable');
1949 createSimpleUpdateWatcher('fine_level');
1950 createSimpleUpdateWatcher('loan_duration');
1951 createSimpleUpdateWatcher('price');
1952 createSimpleUpdateWatcher('cost');
1953 createSimpleUpdateWatcher('deposit');
1954 createSimpleUpdateWatcher('deposit_amount');
1955 createSimpleUpdateWatcher('mint_condition');
1956 createSimpleUpdateWatcher('opac_visible');
1957 createSimpleUpdateWatcher('ref');
1959 $scope.saveCompletedCopies = function (and_exit) {
1961 var perCnCopies = {};
1962 angular.forEach( $scope.completed_copies, function (cp) {
1963 var cn = cp.call_number();
1964 var cn_cps = cp.call_number().copies();
1965 cp.call_number().copies([]);
1966 var cn_id = cp.call_number().id();
1967 cp.call_number(cn_id); // prevent loops in JSON-ification
1968 if (!cnHash[cn_id]) {
1969 cnHash[cn_id] = egCore.idl.Clone(cn);
1970 perCnCopies[cn_id] = [egCore.idl.Clone(cp)];
1972 perCnCopies[cn_id].push(egCore.idl.Clone(cp));
1974 cp.call_number(cn); // put the data back
1975 cp.call_number().copies(cn_cps);
1976 if (typeof cnHash[cn_id].prefix() == 'object')
1977 cnHash[cn_id].prefix(cnHash[cn_id].prefix().id()); // un-object-ize some fields
1978 if (typeof cnHash[cn_id].suffix() == 'object')
1979 cnHash[cn_id].suffix(cnHash[cn_id].suffix().id()); // un-object-ize some fields
1982 if ($scope.only_vols) { // strip off copies when we're in vol-only mode
1983 angular.forEach(cnHash, function (v, k) {
1984 cnHash[k].copies([]);
1987 angular.forEach(perCnCopies, function (v, k) {
1988 cnHash[k].copies(v);
1993 angular.forEach(cnHash, function (v, k) {
1999 'open-ils.cat.asset.volume.fleshed.batch.update.override',
2000 egCore.auth.token(), cnList, 1, { auto_merge_vols : 1, create_parts : 1, return_copy_ids : 1 }
2001 ).then(function(copy_ids) {
2003 $scope.dirty = false;
2004 if ($scope.defaults.print_item_labels) {
2007 'open-ils.actor.anon_cache.set_value',
2008 null, 'print-labels-these-copies', {
2011 ).then(function(key) {
2013 var url = egCore.env.basePath + 'cat/printlabels/' + key;
2014 $timeout(function() { $window.open(url, '_blank') }).then(
2015 function() { $timeout(function(){$window.close()}); }
2018 alert('Could not create anonymous cache key!');
2022 $timeout(function(){
2023 if (typeof BroadcastChannel != 'undefined') {
2024 var bChannel = new BroadcastChannel("eg.holdings.update");
2025 var bre_ids = cnList && cnList.length > 0 ? cnList.map(function(cn){ return Number(cn.record()) }) : [];
2026 var cn_ids = cnList && cnList.length > 0 ? cnList.map(function(cn){ return cn.id() }) : [];
2027 bChannel.postMessage({
2041 $scope.saveAndContinue = function () {
2042 $scope.saveCompletedCopies(false);
2045 $scope.workingSaveAndExit = function () {
2046 $scope.workingToComplete();
2047 $scope.saveAndExit();
2050 $scope.saveAndExit = function () {
2051 $scope.saveCompletedCopies(true);
2056 $scope.copy_notes_dialog = function(copy_list) {
2057 var default_pub = Boolean($scope.defaults.copy_notes_pub);
2058 if (!angular.isArray(copy_list)) copy_list = [copy_list];
2060 return $uibModal.open({
2061 templateUrl: './cat/volcopy/t_copy_notes',
2065 ['$scope','$uibModalInstance',
2066 function($scope , $uibModalInstance) {
2067 $scope.focusNote = true;
2069 creator : egCore.auth.user().id(),
2075 $scope.require_initials = false;
2076 egCore.org.settings([
2077 'ui.staff.require_initials.copy_notes'
2078 ]).then(function(set) {
2079 $scope.require_initials_ous = Boolean(set['ui.staff.require_initials.copy_notes']);
2082 $scope.are_initials_required = function() {
2083 $scope.require_initials = $scope.require_initials_ous && ($scope.note.value.length > 0 || $scope.note.title.length > 0);
2086 $scope.$watch('note.value.length', $scope.are_initials_required);
2087 $scope.$watch('note.title.length', $scope.are_initials_required);
2089 $scope.note_list = [];
2090 if (copy_list.length == 1) {
2091 $scope.note_list = copy_list[0].notes();
2094 $scope.ok = function(note) {
2096 if (note.value.length > 0 || note.title.length > 0) {
2097 if ($scope.initials) {
2098 note.value = egCore.strings.$replace(
2099 egCore.strings.COPY_NOTE_INITIALS, {
2101 initials : $scope.initials,
2102 ws_ou : egCore.org.get(
2103 egCore.auth.user().ws_ou()).shortname()
2107 angular.forEach(copy_list, function (cp) {
2108 if (!angular.isArray(cp.notes())) cp.notes([]);
2109 var n = new egCore.idl.acpn();
2111 n.creator(note.creator);
2112 n.pub(note.pub ? 't' : 'f');
2113 n.title(note.title);
2114 n.value(note.value);
2115 n.owning_copy(cp.id());
2116 cp.notes().push( n );
2120 $uibModalInstance.close();
2123 $scope.cancel = function($event) {
2124 $uibModalInstance.dismiss();
2125 $event.preventDefault();
2131 $scope.copy_tags_dialog = function(copy_list) {
2132 if (!angular.isArray(copy_list)) copy_list = [copy_list];
2134 return $uibModal.open({
2135 templateUrl: './cat/volcopy/t_copy_tags',
2139 ['$scope','$uibModalInstance',
2140 function($scope , $uibModalInstance) {
2142 $scope.tag_map = [];
2144 var shared_tags = {};
2145 angular.forEach(copy_list, function (cp) {
2146 angular.forEach(cp.tags(), function(tag) {
2147 if (!(tag.tag().id() in shared_tags)) {
2148 shared_tags[tag.tag().id()] = 1;
2150 shared_tags[tag.tag().id()]++;
2152 if (!(tag.tag().id() in tag_hash)) {
2153 tag_hash[tag.tag().id()] = tag;
2157 angular.forEach(tag_hash, function(value, key) {
2158 if (shared_tags[key] == copy_list.length) {
2159 $scope.tag_map.push(value);
2163 $scope.tag_types = [];
2164 egCore.pcrud.retrieveAll('cctt', {order_by : { cctt : 'label' }}, {atomic : true}).then(function(list) {
2165 $scope.tag_types = list;
2166 $scope.tag_type = $scope.tag_types[0].code(); // just pick a default
2169 $scope.getTags = function(val) {
2170 return egCore.pcrud.search('acpt',
2172 owner : egCore.org.fullPath(egCore.auth.user().ws_ou(), true),
2173 label : { 'startwith' : {
2174 transform: 'evergreen.lowercase',
2175 value : [ 'evergreen.lowercase', val ]
2177 tag_type : $scope.tag_type
2179 { order_by : { 'acpt' : ['label'] } }, { atomic: true }
2180 ).then(function(list) {
2181 return list.map(function(item) {
2182 return item.label() + " (" + egCore.org.get(item.owner()).shortname() + ")";
2187 $scope.addTag = function() {
2188 var tagLabel = $scope.selectedLabel;
2189 // clear the typeahead
2190 $scope.selectedLabel = "";
2192 // first, check tags already associated with the copy
2193 var foundMatch = false;
2194 angular.forEach($scope.tag_map, function(tag) {
2195 if (tag.tag().label() == tagLabel && tag.tag().tag_type() == $scope.tag_type) {
2197 if (tag.isdeleted()) tag.isdeleted(0); // just deleting the mapping
2201 egCore.pcrud.search('acpt',
2203 owner : egCore.org.fullPath(egCore.auth.user().ws_ou(), true),
2205 tag_type : $scope.tag_type
2207 { order_by : { 'acpt' : ['label'] } }, { atomic: true }
2208 ).then(function(list) {
2209 if (list.length > 0) {
2210 var newMap = new egCore.idl.acptcm();
2212 newMap.copy(copy_list[0].id());
2213 newMap.tag(egCore.idl.Clone(list[0]));
2214 $scope.tag_map.push(newMap);
2216 var newTag = new egCore.idl.acpt();
2218 newTag.owner(egCore.auth.user().ws_ou());
2219 newTag.label(tagLabel);
2221 newTag.tag_type($scope.tag_type);
2223 var newMap = new egCore.idl.acptcm();
2225 newMap.copy(copy_list[0].id());
2227 $scope.tag_map.push(newMap);
2233 $scope.ok = function(note) {
2234 // in the multi-item case, this works OK for
2235 // adding new maps to existing tags, but doesn't handle
2236 // all possibilities
2237 angular.forEach(copy_list, function (cp) {
2238 cp.tags($scope.tag_map);
2240 $uibModalInstance.close();
2243 $scope.cancel = function($event) {
2244 $uibModalInstance.dismiss();
2245 $event.preventDefault();
2251 $scope.copy_alerts_dialog = function(copy_list) {
2252 if (!angular.isArray(copy_list)) copy_list = [copy_list];
2254 return $uibModal.open({
2255 templateUrl: './cat/volcopy/t_copy_alerts',
2258 ['$scope','$uibModalInstance',
2259 function($scope , $uibModalInstance) {
2261 itemSvc.get_copy_alert_types().then(function(ccat) {
2262 $scope.alert_types = ccat;
2265 $scope.focusNote = true;
2266 $scope.copy_alert = {
2267 create_staff : egCore.auth.user().id(),
2272 egCore.hatch.getItem('cat.copy.alerts.last_type').then(function(t) {
2273 if (t) $scope.copy_alert.alert_type = t;
2276 if (copy_list.length == 1) {
2277 $scope.copy_alert_list = copy_list[0].copy_alerts();
2280 $scope.ok = function(copy_alert) {
2282 if (typeof(copy_alert.note) != 'undefined' &&
2283 copy_alert.note != '') {
2284 angular.forEach(copy_list, function (cp) {
2285 var a = new egCore.idl.aca();
2287 a.create_staff(copy_alert.create_staff);
2288 a.note(copy_alert.note);
2289 a.temp(copy_alert.temp ? 't' : 'f');
2293 $scope.alert_types.filter(function(at) {
2294 return at.id() == copy_alert.alert_type;
2297 cp.copy_alerts().push( a );
2300 if (copy_alert.alert_type) {
2301 egCore.hatch.setItem(
2302 'cat.copy.alerts.last_type',
2303 copy_alert.alert_type
2309 $uibModalInstance.close();
2312 $scope.cancel = function($event) {
2313 $uibModalInstance.dismiss();
2314 $event.preventDefault();
2322 .directive("egVolTemplate", function () {
2326 template: '<div ng-include="'+"'/eg/staff/cat/volcopy/t_attr_edit'"+'"></div>',
2330 controller : ['$scope','$window','itemSvc','egCore','ngToast','$uibModal',
2331 function ( $scope , $window , itemSvc , egCore , ngToast , $uibModal) {
2333 $scope.i18n = egCore.i18n;
2335 $scope.defaults = { // If defaults are not set at all, allow everything
2336 barcode_checkdigit : false,
2337 auto_gen_barcode : false,
2344 loan_duration : true,
2349 deposit_amount : true,
2350 opac_visible : true,
2353 mint_condition : true,
2356 circ_modifier : true,
2357 circ_as_type : true,
2365 $scope.fetchDefaults = function () {
2366 egCore.hatch.getItem('cat.copy.defaults').then(function(t) {
2368 $scope.defaults = t;
2369 $scope.working.statcat_filter = $scope.defaults.statcat_filter;
2371 typeof $scope.defaults.statcat_filter == 'object' &&
2372 Object.keys($scope.defaults.statcat_filter).length > 0
2374 // want fieldmapper object here...
2375 $scope.defaults.statcat_filter =
2376 egCore.idl.Clone($scope.defaults.statcat_filter);
2378 $scope.working.statcat_filter = $scope.defaults.statcat_filter.id();
2383 $scope.fetchDefaults();
2385 $scope.dirty = false;
2386 $scope.$watch('dirty',
2387 function(newVal, oldVal) {
2388 if (newVal && newVal != oldVal) {
2389 $($window).on('beforeunload.template', function(){
2390 return 'There is unsaved template data!'
2393 $($window).off('beforeunload.template');
2398 $scope.template_controls = true;
2400 $scope.fetchTemplates = function () {
2401 itemSvc.get_acp_templates().then(function(t) {
2403 $scope.templates = t;
2404 $scope.template_name_list = Object.keys(t).sort();
2408 $scope.fetchTemplates();
2410 $scope.applyTemplate = function (n) {
2411 angular.forEach($scope.templates[n], function (v,k) {
2412 if (k == 'circ_lib') {
2413 $scope.working[k] = egCore.org.get(v);
2414 } else if (angular.isArray(v) || !angular.isObject(v)) {
2415 $scope.working[k] = angular.copy(v);
2417 angular.forEach(v, function (sv,sk) {
2418 if (!(k in $scope.working))
2419 $scope.working[k] = {};
2420 $scope.working[k][sk] = angular.copy(sv);
2424 $scope.template_name = '';
2427 $scope.deleteTemplate = function (n) {
2429 delete $scope.templates[n]
2430 $scope.template_name_list = Object.keys($scope.templates).sort();
2431 $scope.template_name = '';
2432 itemSvc.save_acp_templates($scope.templates);
2433 $scope.$parent.fetchTemplates();
2434 ngToast.create(egCore.strings.VOL_COPY_TEMPLATE_SUCCESS_DELETE);
2438 $scope.saveTemplate = function (n) {
2442 angular.forEach($scope.working, function (v,k) {
2443 if (angular.isObject(v)) { // we'll use the pkey
2444 if (v.id) v = v.id();
2445 else if (v.code) v = v.code();
2446 else v = angular.copy(v); // Should only be statcats and callnumbers currently
2452 $scope.templates[n] = tmpl;
2453 $scope.template_name_list = Object.keys($scope.templates).sort();
2455 itemSvc.save_acp_templates($scope.templates);
2456 $scope.$parent.fetchTemplates();
2458 $scope.dirty = false;
2460 // save all templates, as we might do after an import
2461 itemSvc.save_acp_templates($scope.templates);
2462 $scope.$parent.fetchTemplates();
2464 ngToast.create(egCore.strings.VOL_COPY_TEMPLATE_SUCCESS_SAVE);
2467 $scope.templates = {};
2468 $scope.imported_templates = { data : '' };
2469 $scope.template_name = '';
2470 $scope.template_name_list = [];
2472 $scope.$watch('imported_templates.data', function(newVal, oldVal) {
2473 if (newVal && newVal != oldVal) {
2475 var newTemplates = JSON.parse(newVal);
2476 if (!Object.keys(newTemplates).length) return;
2477 angular.forEach(Object.keys(newTemplates), function (k) {
2478 $scope.templates[k] = newTemplates[k];
2480 itemSvc.save_acp_templates($scope.templates);
2481 $scope.fetchTemplates();
2483 console.log('tried to import an invalid copy template file');
2488 $scope.tracker = function (x,f) { if (x) return x[f]() };
2489 $scope.idTracker = function (x) { if (x) return $scope.tracker(x,'id') };
2490 $scope.cant_have_vols = function (id) { return !egCore.org.CanHaveVolumes(id); };
2492 $scope.orgById = function (id) { return egCore.org.get(id) }
2493 $scope.statusById = function (id) {
2494 return $scope.status_list.filter( function (s) { return s.id() == id } )[0];
2496 $scope.locationById = function (id) {
2497 return $scope.location_cache[''+id];
2500 createSimpleUpdateWatcher = function (field) {
2501 $scope.$watch('working.' + field, function () {
2502 var newval = $scope.working[field];
2504 if (typeof newval != 'undefined') {
2505 $scope.dirty = true;
2506 if (angular.isObject(newval)) { // we'll use the pkey
2507 if (newval.id) $scope.working[field] = newval.id();
2508 else if (newval.code) $scope.working[field] = newval.code();
2511 if (""+newval == "" || newval == null) {
2512 $scope.working[field] = undefined;
2523 statcat_filter: undefined
2526 $scope.statcat_visible = function (sc_owner) {
2527 var visible = typeof $scope.working.statcat_filter === 'undefined' || !$scope.working.statcat_filter;
2528 angular.forEach(egCore.org.ancestors(sc_owner), function (ancestor_org) {
2529 if ($scope.working.statcat_filter == ancestor_org.id())
2535 createStatcatUpdateWatcher = function (id) {
2536 return $scope.$watch('working.statcats[' + id + ']', function () {
2537 if ($scope.working.statcats) {
2538 var newval = $scope.working.statcats[id];
2540 if (typeof newval != 'undefined') {
2541 $scope.dirty = true;
2542 if (angular.isObject(newval)) { // we'll use the pkey
2543 newval = newval.id();
2546 if (""+newval == "" || newval == null) {
2547 $scope.working.statcats[id] = undefined;
2556 $scope.clearWorking = function () {
2557 angular.forEach($scope.working, function (v,k,o) {
2558 $scope.working.MultiMap[k] = [];
2559 if (!angular.isObject(v)) {
2560 if (typeof v != 'undefined')
2561 $scope.working[k] = undefined;
2562 } else if (k != 'circ_lib') {
2563 angular.forEach(v, function (sv,sk) {
2564 $scope.working[k][sk] = undefined;
2568 $scope.working.circ_lib = undefined; // special
2569 $scope.dirty = false;
2572 $scope.working = {};
2573 $scope.location_orgs = [];
2574 $scope.location_cache = {};
2576 $scope.location_list = [];
2577 itemSvc.get_locations_by_org(
2578 egCore.org.fullPath( egCore.auth.user().ws_ou(), true )
2579 ).then(function(list){
2580 $scope.location_list = list;
2582 createSimpleUpdateWatcher('location');
2584 $scope.statcat_filter_list = egCore.org.fullPath( egCore.auth.user().ws_ou() );
2586 $scope.statcats = [];
2587 itemSvc.get_statcats(
2588 egCore.org.fullPath( egCore.auth.user().ws_ou(), true )
2589 ).then(function(list){
2590 $scope.statcats = list;
2591 angular.forEach($scope.statcats, function (s) {
2593 if (!$scope.working)
2594 $scope.working = { statcats: {}, statcat_filter: undefined};
2595 if (!$scope.working.statcats)
2596 $scope.working.statcats = {};
2598 $scope.working.statcats[s.id()] = undefined;
2599 createStatcatUpdateWatcher(s.id());
2603 $scope.copy_notes_dialog = function() {
2604 var default_pub = Boolean($scope.defaults.copy_notes_pub);
2605 var working = $scope.working;
2607 return $uibModal.open({
2608 templateUrl: './cat/volcopy/t_copy_notes',
2611 ['$scope','$uibModalInstance',
2612 function($scope , $uibModalInstance) {
2613 $scope.focusNote = true;
2620 $scope.require_initials = false;
2621 egCore.org.settings([
2622 'ui.staff.require_initials.copy_notes'
2623 ]).then(function(set) {
2624 $scope.require_initials = Boolean(set['ui.staff.require_initials.copy_notes']);
2627 $scope.note_list = [];
2628 angular.forEach(working.copy_notes, function(note) {
2629 var acpn = egCore.idl.fromHash('acpn', note);
2630 $scope.note_list.push(acpn);
2633 $scope.ok = function(note) {
2635 if (!working.copy_notes) {
2636 working.copy_notes = [];
2640 working.copy_notes.length = 0;
2641 angular.forEach($scope.note_list, function(existing_note) {
2642 if (!existing_note.isdeleted()) {
2643 working.copy_notes.push({
2644 pub : existing_note.pub() ? 't' : 'f',
2645 title : existing_note.title(),
2646 value : existing_note.value()
2651 // add new note, if any
2652 if (note.initials) note.value += ' [' + note.initials + ']';
2653 note.pub = note.pub ? 't' : 'f';
2654 if (note.title.length && note.value.length) {
2655 working.copy_notes.push(note);
2658 $uibModalInstance.close();
2661 $scope.cancel = function($event) {
2662 $uibModalInstance.dismiss();
2663 $event.preventDefault();
2669 $scope.copy_alerts_dialog = function() {
2670 var working = $scope.working;
2672 return $uibModal.open({
2673 templateUrl: './cat/volcopy/t_copy_alerts',
2676 ['$scope','$uibModalInstance',
2677 function($scope , $uibModalInstance) {
2679 itemSvc.get_copy_alert_types().then(function(ccat) {
2681 $scope.alert_types = ccat;
2682 angular.forEach(ccat, function(t) {
2683 ccat_map[t.id()] = t;
2685 $scope.copy_alert_list = [];
2686 angular.forEach(working.copy_alerts, function (alrt) {
2687 var aca = egCore.idl.fromHash('aca', alrt);
2688 aca.alert_type(ccat_map[alrt.alert_type]);
2690 $scope.copy_alert_list.push(aca);
2694 $scope.focusNote = true;
2695 $scope.copy_alert = {
2700 $scope.ok = function(copy_alert) {
2702 if (!working.copy_alerts) {
2703 working.copy_alerts = [];
2706 working.copy_alerts.length = 0;
2708 angular.forEach($scope.copy_alert_list, function(alrt) {
2709 if (alrt.ack_time() == null) {
2710 working.copy_alerts.push({
2713 alert_type : alrt.alert_type().id()
2718 if (typeof(copy_alert.note) != 'undefined' &&
2719 copy_alert.note != '') {
2720 working.copy_alerts.push({
2721 note : copy_alert.note,
2722 temp : copy_alert.temp ? 't' : 'f',
2723 alert_type : copy_alert.alert_type
2727 $uibModalInstance.close();
2730 $scope.cancel = function($event) {
2731 $uibModalInstance.dismiss();
2732 $event.preventDefault();
2738 $scope.status_list = [];
2739 itemSvc.get_magic_statuses().then(function(list){
2740 $scope.magic_status_list = list;
2742 itemSvc.get_statuses().then(function(list){
2743 $scope.status_list = list;
2745 createSimpleUpdateWatcher('status');
2747 $scope.circ_modifier_list = [];
2748 itemSvc.get_circ_mods().then(function(list){
2749 $scope.circ_modifier_list = list;
2751 createSimpleUpdateWatcher('circ_modifier');
2753 $scope.circ_type_list = [];
2754 itemSvc.get_circ_types().then(function(list){
2755 $scope.circ_type_list = list;
2757 createSimpleUpdateWatcher('circ_as_type');
2759 $scope.age_protect_list = [];
2760 itemSvc.get_age_protects().then(function(list){
2761 $scope.age_protect_list = list;
2763 createSimpleUpdateWatcher('age_protect');
2765 $scope.floating_list = [];
2766 itemSvc.get_floating_groups().then(function(list){
2767 $scope.floating_list = list;
2769 createSimpleUpdateWatcher('floating');
2771 createSimpleUpdateWatcher('circulate');
2772 createSimpleUpdateWatcher('holdable');
2773 createSimpleUpdateWatcher('fine_level');
2774 createSimpleUpdateWatcher('loan_duration');
2775 createSimpleUpdateWatcher('cost');
2776 createSimpleUpdateWatcher('deposit');
2777 createSimpleUpdateWatcher('deposit_amount');
2778 createSimpleUpdateWatcher('mint_condition');
2779 createSimpleUpdateWatcher('opac_visible');
2780 createSimpleUpdateWatcher('ref');
2782 $scope.suffix_list = [];
2783 itemSvc.get_suffixes(egCore.auth.user().ws_ou()).then(function(list){
2784 $scope.suffix_list = list;
2787 $scope.prefix_list = [];
2788 itemSvc.get_prefixes(egCore.auth.user().ws_ou()).then(function(list){
2789 $scope.prefix_list = list;
2792 $scope.classification_list = [];
2793 itemSvc.get_classifications().then(function(list){
2794 $scope.classification_list = list;
2797 createSimpleUpdateWatcher('working.callnumber.classification');
2798 createSimpleUpdateWatcher('working.callnumber.prefix');
2799 createSimpleUpdateWatcher('working.callnumber.suffix');