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']
134 order_by : [{'class':'asc', 'field':'owner'},{'class':'asc', 'field':'name'},{'class':'asce', 'field':'value'} ]
140 service.get_copy_alert_types = function(orgs) {
141 return egCore.pcrud.search('ccat',
148 service.get_copy_alerts = function(copy_id) {
149 return egCore.pcrud.search('aca', { copy : copy_id, ack_time : null },
150 { flesh : 1, flesh_fields : { aca : ['alert_type'] } },
155 service.get_locations_by_org = function(orgs) {
156 return egCore.pcrud.search('acpl',
157 {owning_lib : orgs, deleted : 'f'},
161 acpl : ['owning_lib']
163 order_by : { acpl : 'name' }
169 service.fetch_locations = function(locs) {
170 return egCore.pcrud.search('acpl',
175 acpl : ['owning_lib']
177 order_by : { acpl : 'name' }
183 service.get_suffixes = function(org) {
184 return egCore.pcrud.search('acns',
185 {owning_lib : egCore.org.fullPath(org, true)},
186 {order_by : { acns : 'label_sortkey' }}, {atomic : true}
191 service.get_magic_statuses = function() {
192 /* TODO: make these more configurable per lp1616170 */
197 ,8 /* On holds shelf */
198 ,16 /* Long overdue */
199 ,18 /* Canceled Transit */
203 service.get_statuses = function() {
205 return $q.when(egCore.env.ccs.list);
207 return egCore.pcrud.retrieveAll('ccs', {order_by : { ccs : 'name' }}, {atomic : true}).then(
209 egCore.env.absorbList(list, 'ccs');
216 service.get_circ_mods = function() {
218 return $q.when(egCore.env.ccm.list);
220 return egCore.pcrud.retrieveAll('ccm', {}, {atomic : true}).then(
222 egCore.env.absorbList(list, 'ccm');
229 service.get_circ_types = function() {
231 return $q.when(egCore.env.citm.list);
233 return egCore.pcrud.retrieveAll('citm', {}, {atomic : true}).then(
235 egCore.env.absorbList(list, 'citm');
242 service.get_age_protects = function() {
243 if (egCore.env.crahp)
244 return $q.when(egCore.env.crahp.list);
246 return egCore.pcrud.retrieveAll('crahp', {}, {atomic : true}).then(
248 egCore.env.absorbList(list, 'crahp');
255 service.get_floating_groups = function() {
257 return $q.when(egCore.env.cfg.list);
259 return egCore.pcrud.retrieveAll('cfg', {}, {atomic : true}).then(
261 egCore.env.absorbList(list, 'cfg');
268 service.bmp_parts = {};
269 service.get_parts = function(rec) {
270 if (service.bmp_parts[rec])
271 return $q.when(service.bmp_parts[rec]);
273 return egCore.pcrud.search('bmp',
274 {record : rec, deleted : 'f'},
275 {order_by: {bmp : 'label_sortkey DESC'}},
277 ).then(function(list) {
278 service.bmp_parts[rec] = list;
284 service.get_acp_templates = function() {
285 // Already downloaded for this user? Return local copy. Changing users or logging out causes another download
286 // so users always have their own templates, and any changes made on other machines appear as expected.
287 if (egCore.hatch.getSessionItem('cat.copy.templates.usr') == egCore.auth.user().id()) {
288 return egCore.hatch.getItem('cat.copy.templates').then(function(templ) {
292 // this can be disabled for debugging to force a re-download and translation of test templates
293 egCore.hatch.setSessionItem('cat.copy.templates.usr', egCore.auth.user().id());
294 return service.load_remote_acp_templates();
299 service.save_acp_templates = function(t) {
300 egCore.hatch.setItem('cat.copy.templates', t);
301 egCore.net.request('open-ils.actor', 'open-ils.actor.patron.settings.update',
302 egCore.auth.token(), egCore.auth.user().id(), { "webstaff.cat.copy.templates": t });
303 // console.warn('Saved ' + JSON.stringify({"webstaff.cat.copy.templates": t}));
306 service.load_remote_acp_templates = function() {
307 // After the XUL Client is completely removed everything related
308 // to staff_client.copy_editor.templates and convert_xul_templates
309 // can be thrown away.
310 return egCore.net.request('open-ils.actor', 'open-ils.actor.patron.settings.retrieve.authoritative',
311 egCore.auth.token(), egCore.auth.user().id(),
312 ['webstaff.cat.copy.templates','staff_client.copy_editor.templates']).then(function(settings) {
313 if (settings['webstaff.cat.copy.templates']) {
314 egCore.hatch.setItem('cat.copy.templates', settings['webstaff.cat.copy.templates']);
315 return settings['webstaff.cat.copy.templates'];
317 if (settings['staff_client.copy_editor.templates']) {
318 var new_templ = service.convert_xul_templates(settings['staff_client.copy_editor.templates']);
319 egCore.hatch.setItem('cat.copy.templates', new_templ);
320 // console.warn('Saving: ' + JSON.stringify({'webstaff.cat.copy.templates' : new_templ}));
321 egCore.net.request('open-ils.actor', 'open-ils.actor.patron.settings.update',
322 egCore.auth.token(), egCore.auth.user().id(), {'webstaff.cat.copy.templates' : new_templ});
330 service.convert_xul_templates = function(xultempl) {
332 var templ_names = Object.keys(xultempl);
343 for (i=0; i < templ_names.length; i++) {
344 name = templ_names[i];
347 xul_t = xultempl[name];
348 fields = Object.keys(xul_t);
350 if (fields.length > 0) {
351 for (j=0; j < fields.length; j++) {
352 curr_field = xul_t[fields[j]];
353 var field_name = curr_field["field"];
355 if ( field_name == null ) { continue; }
356 if ( curr_field["value"] == "<HACK:KLUDGE:NULL>" ) { continue; }
358 // floating changed from a boolean to an integer at one point;
359 // take this opportunity to remove the boolean from any old templates
360 if ( curr_field["type"] === "attribute" && field_name === "floating" ) {
361 if ( curr_field["value"].match(/[tf]/) ) { continue; }
364 if ( curr_field["type"] === "stat_cat" ) {
365 stat_cats[field_name] = parseInt(curr_field["value"]);
367 tmp_val = curr_field['value'];
368 if ( tmp_val.toString().match(/^[-0-9.]+$/)) {
369 tmp_val = parseFloat(tmp_val);
372 if (field_name.match(/^batch_.*_menulist$/)) {
373 // special handling for volume fields
374 if (!("callnumber" in curr_templ)) curr_templ["callnumber"] = {};
375 if (field_name === "batch_class_menulist") curr_templ["callnumber"]["classification"] = tmp_val;
376 if (field_name === "batch_prefix_menulist") curr_templ["callnumber"]["prefix"] = tmp_val;
377 if (field_name === "batch_suffix_menulist") curr_templ["callnumber"]["suffix"] = tmp_val;
379 curr_templ[field_name] = tmp_val;
384 if ( (Object.keys(stat_cats)).length > 0 ) {
385 curr_templ["statcats"] = stat_cats;
388 conv_templ[name] = curr_templ;
398 acp : ['call_number','parts','stat_cat_entries', 'notes', 'tags', 'creator', 'editor'],
399 acn : ['label_class','prefix','suffix'],
404 service.addCopy = function (cp) {
406 if (!cp.parts()) cp.parts([]); // just in case...
408 service.get_copy_alerts(cp.id()).then(function(aca) {
412 var lib = cp.call_number().owning_lib();
413 var cn = cp.call_number().id();
415 if (!service.tree[lib]) service.tree[lib] = {};
416 if (!service.tree[lib][cn]) service.tree[lib][cn] = [];
418 service.tree[lib][cn].push(cp);
419 service.copies.push(cp);
422 service.checkDuplicateBarcode = function(bc, id) {
424 return egCore.pcrud.search('acp', { deleted : 'f', 'barcode' : bc, id : { '!=' : id } })
426 function () { return final },
427 function () { return final },
428 function () { final = true; }
432 service.fetchIds = function(idList) {
433 service.tree = {}; // clear the tree on fetch
434 service.copies = []; // clear the copy list on fetch
435 return egCore.pcrud.search('acp', { 'id' : idList }, service.flesh).then(null,null,
437 service.addCopy(copy);
442 // create a new acp object with default values
443 // (both hard-coded and coming from OU settings)
444 service.generateNewCopy = function(callNumber, owningLib, isFastAdd, isNew) {
445 var cp = new egCore.idl.acp();
446 cp.id( --service.new_cp_id );
450 cp.circ_lib( owningLib );
451 cp.call_number( callNumber );
454 cp.deposit_amount(0);
455 cp.fine_level(2); // Normal
456 cp.loan_duration(2); // Normal
457 cp.location(1); // Stacks
460 cp.opac_visible('t');
462 cp.mint_condition('t');
463 cp.empty_barcode = true;
465 var status_setting = isFastAdd ?
466 'cat.default_copy_status_fast' :
467 'cat.default_copy_status_normal';
471 ).then(function(set) {
472 var default_ccs = parseInt(set[status_setting]);
473 if (isNaN(default_ccs))
474 default_ccs = (isFastAdd ? 0 : 5); // 0 is Available, 5 is In Process
475 cp.status(default_ccs);
484 .directive("egVolCopyEdit", ['egCore', function (egCore) {
489 '<div class="row" ng-class="{'+"'new-cp'"+':is_new}">'+
490 '<span ng-if="is_new" class="sr-only">' + egCore.strings.VOL_COPY_NEW_ITEM + '</span>' +
491 '<div class="col-xs-5" ng-class="{'+"'has-error'"+':barcode_has_error}">'+
492 '<input id="{{callNumber.id()}}_{{copy.id()}}"'+
493 ' eg-enter="nextBarcode(copy.id())" class="form-control"'+
494 ' type="text" ng-model="barcode" ng-change="updateBarcode()"'+
495 ' ng-focus="selectOnFocus($event)" autofocus/>'+
496 '<div class="label label-danger" ng-if="duplicate_barcode">{{duplicate_barcode_string}}</div>'+
497 '<div class="label label-danger" ng-if="empty_barcode">{{empty_barcode_string}}</div>'+
499 '<div class="col-xs-3"><input class="form-control" type="number" min="1" ng-model="copy_number" ng-change="updateCopyNo()"/></div>'+
500 '<div class="col-xs-3"><eg-basic-combo-box list="parts" selected="part"></eg-basic-combo-box></div>'+
503 scope: { focusNext: "=", copy: "=", callNumber: "=", index: "@", record: "@" },
504 controller : ['$scope','itemSvc','egCore',
505 function ( $scope , itemSvc , egCore ) {
506 $scope.new_part_id = 0;
507 $scope.barcode_has_error = false;
508 $scope.duplicate_barcode = false;
509 $scope.empty_barcode = false;
510 $scope.is_new = false;
511 $scope.duplicate_barcode_string = window.duplicate_barcode_string;
512 $scope.empty_barcode_string = window.empty_barcode_string;
513 var duplicate_check_count = 0;
515 if (!$scope.copy.barcode()) $scope.copy.empty_barcode = true;
516 if ($scope.copy.isnew() || $scope.copy.id() < 0) $scope.copy.is_new = $scope.is_new = true;
518 $scope.selectOnFocus = function($event) {
519 if (!$scope.copy.empty_barcode)
520 $event.target.select();
523 $scope.nextBarcode = function (i) {
524 $scope.focusNext(i, $scope.barcode);
527 $scope.updateBarcode = function () {
528 if ($scope.barcode != '') {
529 $scope.copy.empty_barcode = $scope.empty_barcode = false;
530 $scope.barcode_has_error = !Boolean(itemSvc.checkBarcode($scope.barcode));
532 var duplicate_check_id = ++duplicate_check_count;
533 itemSvc.checkDuplicateBarcode($scope.barcode, $scope.copy.id())
534 .then(function (state) {
535 if (duplicate_check_id == duplicate_check_count)
536 $scope.copy.duplicate_barcode = $scope.duplicate_barcode = state;
539 $scope.copy.empty_barcode = $scope.empty_barcode = true;
542 $scope.copy.barcode($scope.barcode);
543 $scope.copy.ischanged(1);
544 if (itemSvc.currently_generating)
545 $scope.focusNext($scope.copy.id(), $scope.barcode);
548 $scope.updateCopyNo = function () { $scope.copy.copy_number($scope.copy_number); $scope.copy.ischanged(1); };
549 $scope.updatePart = function () {
551 var p = $scope.part_list.filter(function (x) {
552 return x.label() == $scope.part
554 if (p.length > 0) { // preexisting part
556 } else { // create one...
557 var part = new egCore.idl.bmp();
558 part.id( --$scope.new_part_id );
560 part.label( $scope.part );
561 part.record( $scope.callNumber.record() );
562 $scope.copy.parts([part]);
563 $scope.copy.ischanged(1);
566 $scope.copy.parts([]);
568 $scope.copy.ischanged(1);
572 $scope.part_list = [];
574 itemSvc.get_parts($scope.callNumber.record())
575 .then(function(list){
576 $scope.part_list = list;
577 angular.forEach(list, function(p){ $scope.parts.push(p.label()) });
578 $scope.parts = angular.copy($scope.parts);
580 $scope.$watch('part', $scope.updatePart);
581 if ($scope.copy.parts()) {
582 var the_part = $scope.copy.parts()[0];
583 if (the_part) $scope.part = the_part.label();
587 $scope.barcode = $scope.copy.barcode();
588 $scope.copy_number = $scope.copy.copy_number();
596 .directive("egVolRow", ['egCore', function (egCore) {
602 '<div class="row" ng-class="{'+"'new-cn'"+':!callNumber.not_ephemeral}">'+
603 '<span ng-if="!callNumber.not_ephemeral" class="sr-only">' + egCore.strings.VOL_COPY_NEW_CALL_NUMBER + '</span>' +
604 '<div class="col-xs-2">'+
605 '<button aria-label="Delete" style="margin:-5px -15px; float:left;" ng-hide="callNumber.not_ephemeral" type="button" class="close" ng-click="removeCN()">×</button>' +
606 '<select class="form-control" ng-model="classification" ng-change="updateClassification()" ng-options="cl.name() for cl in classification_list"></select>'+
608 '<div class="col-xs-1">'+
609 '<select class="form-control" ng-model="prefix" ng-change="updatePrefix()" ng-options="p.label() for p in prefix_list"></select>'+
611 '<div class="col-xs-2">'+
612 '<input class="form-control" type="text" ng-change="updateLabel()" ng-model="label"/>'+
613 '<div class="label label-danger" ng-if="empty_label">{{empty_label_string}}</div>'+
615 '<div class="col-xs-1">'+
616 '<select class="form-control" ng-model="suffix" ng-change="updateSuffix()" ng-options="s.label() for s in suffix_list"></select>'+
618 '<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>'+
619 '<div ng-hide="onlyVols" class="col-xs-5">'+
620 '<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>'+
624 scope: {focusNext: "=", allcopies: "=", copies: "=", onlyVols: "=", record: "@", struct:"=" },
625 controller : ['$scope','itemSvc','egCore',
626 function ( $scope , itemSvc , egCore ) {
627 $scope.callNumber = $scope.copies[0].call_number();
628 if (!$scope.callNumber.label()) $scope.callNumber.empty_label = true;
630 $scope.empty_label = false;
631 $scope.empty_label_string = window.empty_label_string;
633 $scope.idTracker = function (x) { if (x && x.id) return x.id() };
635 // XXX $() is not working! arg
636 $scope.focusNextBarcode = function (i, prev_bc) {
639 angular.forEach($scope.copies, function (cp) {
647 if (yep) n = cp.id();
651 var next = '#' + $scope.callNumber.id() + '_' + n;
654 if (!itemSvc.currently_generating) el.focus();
655 if (prev_bc && itemSvc.auto_gen_barcode && el.val() == "") {
656 itemSvc.nextBarcode(prev_bc).then(function(bc){
659 el.trigger('change');
662 itemSvc.currently_generating = false;
666 $scope.focusNext($scope.callNumber.id(),prev_bc)
670 $scope.suffix_list = [];
671 itemSvc.get_suffixes($scope.callNumber.owning_lib()).then(function(list){
672 $scope.suffix_list = list;
673 $scope.$watch('callNumber.suffix()', function (v) {
674 if (angular.isObject(v)) v = v.id();
675 $scope.suffix = $scope.suffix_list.filter( function (s) {
681 $scope.updateSuffix = function () {
682 angular.forEach($scope.copies, function(cp) {
683 cp.call_number().suffix($scope.suffix);
684 cp.call_number().ischanged(1);
688 $scope.prefix_list = [];
689 itemSvc.get_prefixes($scope.callNumber.owning_lib()).then(function(list){
690 $scope.prefix_list = list;
691 $scope.$watch('callNumber.prefix()', function (v) {
692 if (angular.isObject(v)) v = v.id();
693 $scope.prefix = $scope.prefix_list.filter(function (p) {
699 $scope.updatePrefix = function () {
700 angular.forEach($scope.copies, function(cp) {
701 cp.call_number().prefix($scope.prefix);
702 cp.call_number().ischanged(1);
705 $scope.$watch('callNumber.owning_lib()', function(oldLib, newLib) {
706 if (oldLib == newLib) return;
707 var currentPrefix = $scope.callNumber.prefix();
708 if (angular.isObject(currentPrefix)) currentPrefix = currentPrefix.id();
709 itemSvc.get_prefixes($scope.callNumber.owning_lib()).then(function(list){
710 $scope.prefix_list = list;
711 var newPrefixId = $scope.prefix_list.filter(function (p) {
712 return p.id() == currentPrefix;
714 if (newPrefixId.id) newPrefixId = newPrefixId.id();
715 $scope.prefix = $scope.prefix_list.filter(function (p) {
716 return p.id() == newPrefixId;
718 if ($scope.newPrefixId != currentPrefix) {
719 $scope.callNumber.prefix($scope.prefix);
722 var currentSuffix = $scope.callNumber.suffix();
723 if (angular.isObject(currentSuffix)) currentSuffix = currentSuffix.id();
724 itemSvc.get_suffixes($scope.callNumber.owning_lib()).then(function(list){
725 $scope.suffix_list = list;
726 var newSuffixId = $scope.suffix_list.filter(function (s) {
727 return s.id() == currentSuffix;
729 if (newSuffixId.id) newSuffixId = newSuffixId.id();
730 $scope.suffix = $scope.suffix_list.filter(function (s) {
731 return s.id() == newSuffixId;
733 if ($scope.newSuffixId != currentSuffix) {
734 $scope.callNumber.suffix($scope.suffix);
739 $scope.classification_list = [];
740 itemSvc.get_classifications().then(function(list){
741 $scope.classification_list = list;
742 $scope.$watch('callNumber.label_class()', function (v) {
743 if (angular.isObject(v)) v = v.id();
744 $scope.classification = $scope.classification_list.filter(function (c) {
750 $scope.updateClassification = function () {
751 angular.forEach($scope.copies, function(cp) {
752 cp.call_number().label_class($scope.classification);
753 cp.call_number().ischanged(1);
757 $scope.updateLabel = function () {
758 angular.forEach($scope.copies, function(cp) {
759 cp.call_number().label($scope.label);
760 cp.call_number().ischanged(1);
764 $scope.$watch('callNumber.label()', function (v) {
766 if ($scope.label == '') {
767 $scope.callNumber.empty_label = $scope.empty_label = true;
769 $scope.callNumber.empty_label = $scope.empty_label = false;
773 $scope.prefix = $scope.callNumber.prefix();
774 $scope.suffix = $scope.callNumber.suffix();
775 $scope.classification = $scope.callNumber.label_class();
776 $scope.label = $scope.callNumber.label();
778 $scope.copy_count = $scope.copies.length;
779 $scope.orig_copy_count = $scope.copy_count;
781 $scope.removeCN = function(){
782 var cn = $scope.callNumber;
783 if (cn.not_ephemeral) return; // can't delete existing volumes
785 angular.forEach(Object.keys($scope.struct), function(k){
786 angular.forEach($scope.struct[k], function(cp){
787 var struct_cn = cp.call_number();
788 if (struct_cn.id() == cn.id()){
789 console.log("X'ed CN id" + cn.id() + " and struct CN id match!");
790 // remove any copies in $scope.struct[k]
791 angular.forEach($scope.copies, function(c){
792 var idx = $scope.allcopies.indexOf(c);
793 $scope.allcopies.splice(idx, 1);
798 delete $scope.struct[k];
803 // manually decrease cn_count numeric input
804 var cn_spinner = $("input[name='cn_count_lib"+ cn.owning_lib() +"']");
805 if (cn_spinner.val() > 0) cn_spinner.val(parseInt(cn_spinner.val()) - 1);
806 cn_spinner.trigger("change");
810 $scope.changeCPCount = function () {
811 while ($scope.copy_count > $scope.copies.length) {
812 var cp = itemSvc.generateNewCopy(
814 $scope.callNumber.owning_lib(),
818 $scope.copies.push( cp );
819 $scope.allcopies.push( cp );
823 if ($scope.copy_count >= $scope.orig_copy_count) {
824 var how_many = $scope.copies.length - $scope.copy_count;
826 var dead = $scope.copies.splice($scope.copy_count,how_many);
827 $scope.callNumber.copies($scope.copies);
829 // Trimming the global list is a bit more tricky
830 angular.forEach( dead, function (d) {
831 angular.forEach( $scope.allcopies, function (l, i) {
832 if (l === d) $scope.allcopies.splice(i,1);
845 .directive("egVolEdit", function () {
851 '<div class="col-xs-1"><eg-org-selector selected="owning_lib" disable-test="cant_have_vols"></eg-org-selector></div>'+
852 '<div class="col-xs-1"><input class="form-control" type="number" min="{{orig_cn_count}}" ng-model="cn_count" ng-change="changeCNCount()"/></div>'+
853 '<div class="col-xs-10">'+
854 '<eg-vol-row only-vols="onlyVols" record="{{record}}"'+
855 'ng-repeat="(cn,copies) in struct" '+
856 'focus-next="focusNextFirst" copies="copies" allcopies="allcopies" struct="struct">'+
861 scope: { focusNext: "=", allcopies: "=", struct: "=", lib: "@", record: "@", onlyVols: "=" },
862 controller : ['$scope','itemSvc','egCore',
863 function ( $scope , itemSvc , egCore ) {
864 $scope.first_cn = Object.keys($scope.struct)[0];
865 $scope.full_cn = $scope.struct[$scope.first_cn][0].call_number();
867 $scope.defaults = {};
868 egCore.hatch.getItem('cat.copy.defaults').then(function(t) {
874 $scope.focusNextFirst = function(prev_cn,prev_bc) {
877 angular.forEach(Object.keys($scope.struct).sort(), function (cn) {
889 var next = '#' + n + '_' + $scope.struct[n][0].id();
892 if (!itemSvc.currently_generating) el.focus();
893 if (prev_bc && itemSvc.auto_gen_barcode && el.val() == "") {
894 itemSvc.nextBarcode(prev_bc).then(function(bc){
897 el.trigger('change');
900 itemSvc.currently_generating = false;
904 $scope.focusNext($scope.lib, prev_bc);
908 $scope.cn_count = Object.keys($scope.struct).length;
909 $scope.orig_cn_count = $scope.cn_count;
911 $scope.owning_lib = egCore.org.get($scope.lib);
912 $scope.$watch('owning_lib', function (oldLib, newLib) {
913 if (oldLib == newLib) return;
914 angular.forEach( Object.keys($scope.struct), function (cn) {
915 $scope.struct[cn][0].call_number().owning_lib( $scope.owning_lib.id() );
916 $scope.struct[cn][0].call_number().ischanged(1);
920 $scope.cant_have_vols = function (id) { return !egCore.org.CanHaveVolumes(id); };
922 $scope.$watch('cn_count', function (n) {
923 var o = Object.keys($scope.struct).length;
924 if (n > o) { // adding
925 for (var i = o; o < n; o++) {
926 var cn = new egCore.idl.acn();
927 cn.id( --itemSvc.new_cn_id );
929 cn.prefix( $scope.defaults.prefix || -1 );
930 cn.suffix( $scope.defaults.suffix || -1 );
931 cn.label_class( $scope.defaults.classification || 1 );
932 cn.owning_lib( $scope.owning_lib.id() );
933 cn.record( $scope.full_cn.record() );
935 var cp = itemSvc.generateNewCopy(
937 $scope.owning_lib.id(),
942 $scope.struct[cn.id()] = [cp];
943 $scope.allcopies.push(cp);
944 if (!$scope.defaults.classification) {
946 ['cat.default_classification_scheme'],
948 ).then(function (val) {
949 cn.label_class(val['cat.default_classification_scheme']);
953 } else if (n < o && n >= $scope.orig_cn_count) { // removing
954 var how_many = o - n;
957 .sort(function(a, b){return parseInt(a)-parseInt(b)})
958 .filter(function(x){ return parseInt(x) <= 0 });
959 for (var i = 0; i < how_many; i++) {
960 // Trimming the global list is a bit more tricky
961 angular.forEach($scope.struct[list[i]], function (d) {
962 angular.forEach( $scope.allcopies, function (l, j) {
963 if (l === d) $scope.allcopies.splice(j,1);
966 delete $scope.struct[list[i]];
979 .controller('EditCtrl',
980 ['$scope','$q','$window','$routeParams','$location','$timeout','egCore','egNet','egGridDataProvider','itemSvc','$uibModal',
981 function($scope , $q , $window , $routeParams , $location , $timeout , egCore , egNet , egGridDataProvider , itemSvc , $uibModal) {
983 $scope.forms = {}; // Accessed by t_attr_edit.tt2
984 $scope.i18n = egCore.i18n;
986 $scope.defaults = { // If defaults are not set at all, allow everything
987 barcode_checkdigit : false,
988 auto_gen_barcode : false,
994 loan_duration : true,
999 deposit_amount : true,
1000 opac_visible : true,
1003 mint_condition : true,
1006 circ_modifier : true,
1007 circ_as_type : true,
1016 $scope.new_lib_to_add = egCore.org.get(egCore.auth.user().ws_ou());
1017 $scope.changeNewLib = function (org) {
1018 $scope.new_lib_to_add = org;
1020 $scope.addLibToStruct = function () {
1021 var newLib = $scope.new_lib_to_add;
1022 var cn = new egCore.idl.acn();
1023 cn.id( --itemSvc.new_cn_id );
1025 cn.prefix( $scope.defaults.prefix || -1 );
1026 cn.suffix( $scope.defaults.suffix || -1 );
1027 cn.label_class( $scope.defaults.classification || 1 );
1028 cn.owning_lib( newLib.id() );
1029 cn.record( $scope.record_id );
1031 var cp = itemSvc.generateNewCopy(
1038 $scope.data.addCopy(cp);
1040 // manually increase cn_count numeric input
1041 var cn_spinner = $("input[name='cn_count_lib"+ newLib.id() +"']");
1042 cn_spinner.val(parseInt(cn_spinner.val()) + 1);
1043 cn_spinner.trigger("change");
1045 if (!$scope.defaults.classification) {
1046 egCore.org.settings(
1047 ['cat.default_classification_scheme'],
1049 ).then(function (val) {
1050 cn.label_class(val['cat.default_classification_scheme']);
1055 $scope.embedded = ($routeParams.mode && $routeParams.mode == 'embedded') ? true : false;
1056 $scope.edit_templates = ($location.path().match(/edit_template/)) ? true : false;
1058 $scope.saveDefaults = function () {
1059 egCore.hatch.setItem('cat.copy.defaults', $scope.defaults);
1062 $scope.fetchDefaults = function () {
1063 egCore.hatch.getItem('cat.copy.defaults').then(function(t) {
1065 $scope.defaults = t;
1066 if (!$scope.batch) $scope.batch = {};
1067 $scope.batch.classification = $scope.defaults.classification;
1068 $scope.batch.prefix = $scope.defaults.prefix;
1069 $scope.batch.suffix = $scope.defaults.suffix;
1070 $scope.working.statcat_filter = $scope.defaults.statcat_filter;
1072 typeof $scope.defaults.statcat_filter == 'object' &&
1073 Object.keys($scope.defaults.statcat_filter).length > 0
1075 // want fieldmapper object here...
1076 $scope.defaults.statcat_filter =
1077 egCore.idl.Clone($scope.defaults.statcat_filter);
1079 $scope.working.statcat_filter = $scope.defaults.statcat_filter.id();
1081 if ($scope.defaults.always_volumes) $scope.show_vols = true;
1082 if ($scope.defaults.barcode_checkdigit) itemSvc.barcode_checkdigit = true;
1083 if ($scope.defaults.auto_gen_barcode) itemSvc.auto_gen_barcode = true;
1086 // Fetch the list of bib-level callnumbers based on the applied
1087 // classification scheme. If none is defined, default to "1"
1088 // (Generic) since it provides the most options.
1091 'open-ils.cat.biblio.record.marc_cn.retrieve',
1093 $scope.batch.classification || 1
1094 ).then(function(list) {
1095 $scope.batch.marcCallNumbers = [];
1096 list.forEach(function(hash) {
1097 $scope.batch.marcCallNumbers.push(Object.values(hash)[0]);
1103 $scope.$watch('defaults.statcat_filter', function(n,o) {
1105 $scope.saveDefaults();
1107 $scope.$watch('defaults.auto_gen_barcode', function (n,o) {
1108 itemSvc.auto_gen_barcode = n
1111 $scope.$watch('defaults.barcode_checkdigit', function (n,o) {
1112 itemSvc.barcode_checkdigit = n
1115 $scope.dirty = false;
1116 $scope.$watch('dirty',
1117 function(newVal, oldVal) {
1118 if (newVal && newVal != oldVal) {
1119 $($window).on('beforeunload.edit', function(){
1120 return 'There is unsaved data!'
1123 $($window).off('beforeunload.edit');
1128 $scope.only_vols = false;
1129 $scope.show_vols = true;
1130 $scope.show_copies = true;
1132 $scope.tracker = function (x,f) { if (x) return x[f]() };
1133 $scope.idTracker = function (x) { if (x) return $scope.tracker(x,'id') };
1134 $scope.cant_have_vols = function (id) { return !egCore.org.CanHaveVolumes(id); };
1136 $scope.orgById = function (id) { return egCore.org.get(id) }
1137 $scope.statusById = function (id) {
1138 return $scope.status_list.filter( function (s) { return s.id() == id } )[0];
1140 $scope.locationById = function (id) {
1141 return $scope.location_cache[''+id];
1144 $scope.workingToComplete = function () {
1145 angular.forEach( $scope.workingGridControls.selectedItems(), function (c) {
1146 angular.forEach( itemSvc.copies, function (w, i) {
1148 $scope.completed_copies = $scope.completed_copies.concat(itemSvc.copies.splice(i,1));
1155 $scope.changed_fields = [];
1157 $scope.completeToWorking = function () {
1158 angular.forEach( $scope.completedGridControls.selectedItems(), function (c) {
1159 angular.forEach( $scope.completed_copies, function (w, i) {
1161 itemSvc.copies = itemSvc.copies.concat($scope.completed_copies.splice(i,1));
1168 createSimpleUpdateWatcher = function (field,exclude_copies_with_one_of_these_values) {
1169 return $scope.$watch('working.' + field, function () {
1170 var newval = $scope.working[field];
1172 if (typeof newval != 'undefined') {
1173 delete $scope.working.MultiMap[field];
1174 if (angular.isObject(newval)) { // we'll use the pkey
1175 if (newval.id) newval = newval.id();
1176 else if (newval.code) newval = newval.code();
1179 if (""+newval == "" || newval == null) {
1180 $scope.working[field] = undefined;
1184 if ($scope.workingGridControls && $scope.workingGridControls.selectedItems) {
1186 $scope.workingGridControls.selectedItems(),
1188 if (exclude_copies_with_one_of_these_values
1189 && exclude_copies_with_one_of_these_values.indexOf(cp[field](),0) > -1) {
1192 if (cp[field]() !== newval) {
1193 $scope.changed_fields[cp.$$hashKey+field] = true;
1196 $scope.dirty = true;
1205 // determine if any of the selected copies have had changed their value for this field:
1206 $scope.field_changed = function (field){
1207 // if objects controlling selection don't exist, assume the fields haven't changed
1208 if(!$scope.workingGridControls || !$scope.workingGridControls.selectedItems){ return false; }
1209 var selected = $scope.workingGridControls.selectedItems();
1210 return selected.reduce((acc, cp) => acc || $scope.changed_fields[cp.$$hashKey+field], false);
1217 statcat_filter: undefined
1220 // Returns true if we are editing multiple copies and at least
1221 // one field contains multiple values.
1222 $scope.hasMulti = function() {
1223 var keys = Object.keys($scope.working.MultiMap);
1224 // for-loop for shortcut exit
1225 for (var i = 0; i < keys.length; i++) {
1226 if ($scope.working.MultiMap[keys[i]] &&
1227 $scope.working.MultiMap[keys[i]].length > 1) {
1234 $scope.copyAlertUpdate = function (alerts) {
1235 if (!$scope.in_item_select &&
1236 $scope.workingGridControls &&
1237 $scope.workingGridControls.selectedItems) {
1238 itemSvc.get_copy_alert_types().then(function(ccat) {
1240 $scope.alert_types = ccat;
1241 angular.forEach(ccat, function(t) {
1242 ccat_map[t.id()] = t;
1245 $scope.workingGridControls.selectedItems(),
1247 if (!angular.isArray(cp.copy_alerts())) cp.copy_alerts([]);
1248 $scope.dirty = true;
1249 angular.forEach(alerts, function(alrt) {
1250 var a = egCore.idl.fromHash('aca', alrt);
1252 a.create_staff(egCore.auth.user().id());
1253 a.alert_type(ccat_map[a.alert_type()]);
1256 cp.copy_alerts().push( a );
1265 $scope.copyNoteUpdate = function (notes) {
1266 if (!$scope.in_item_select &&
1267 $scope.workingGridControls &&
1268 $scope.workingGridControls.selectedItems) {
1270 $scope.workingGridControls.selectedItems(),
1272 if (!angular.isArray(cp.notes())) cp.notes([]);
1273 $scope.dirty = true;
1274 angular.forEach(notes, function(note) {
1275 var n = egCore.idl.fromHash('acpn', note);
1277 n.creator(egCore.auth.user().id());
1278 n.owning_copy(cp.id());
1279 cp.notes().push( n );
1288 $scope.statcatUpdate = function (id) {
1289 var newval = $scope.working.statcats[id];
1291 if (typeof newval != 'undefined') {
1292 if (angular.isObject(newval)) { // we'll use the pkey
1293 newval = newval.id();
1296 if (""+newval == "" || newval == null) {
1297 $scope.working.statcats[id] = undefined;
1301 if (!$scope.in_item_select && $scope.workingGridControls && $scope.workingGridControls.selectedItems) {
1303 $scope.workingGridControls.selectedItems(),
1305 $scope.dirty = true;
1307 cp.stat_cat_entries(
1308 angular.forEach( cp.stat_cat_entries(), function (e) {
1309 if (e.stat_cat() == id) { // mark deleted
1316 var e = new egCore.idl.asce();
1321 cp.stat_cat_entries(
1322 cp.stat_cat_entries() ?
1323 cp.stat_cat_entries().concat([ e ]) :
1329 // trim out all deleted ones; the API used to
1330 // do the update doesn't actually consult
1331 // isdeleted for stat cat entries
1332 if (cp.stat_cat_entries()) {
1333 cp.stat_cat_entries(
1334 cp.stat_cat_entries().filter(function (e) {
1335 return !Boolean(e.isdeleted());
1347 var dataKey = $routeParams.dataKey;
1348 console.debug('dataKey: ' + dataKey);
1350 if ((dataKey && dataKey.length > 0) || $scope.edit_templates) {
1352 $scope.templates = {};
1353 $scope.template_name = '';
1354 $scope.template_name_list = [];
1356 $scope.fetchTemplates = function () {
1357 itemSvc.get_acp_templates().then(function(t) {
1359 $scope.templates = t;
1360 $scope.template_name_list = Object.keys(t).sort();
1363 egCore.hatch.getItem('cat.copy.last_template').then(function(t) {
1364 if (t) $scope.template_name = t;
1367 $scope.fetchTemplates();
1369 $scope.applyTemplate = function (n) {
1370 angular.forEach($scope.templates[n], function (v,k) {
1371 if (k == 'circ_lib') {
1372 $scope.working[k] = egCore.org.get(v);
1373 } else if (k == 'copy_notes' && v.length) {
1374 $scope.copyNoteUpdate(v);
1375 } else if (k == 'copy_alerts' && v.length) {
1376 $scope.copyAlertUpdate(v);
1377 } else if (!angular.isObject(v)) {
1378 $scope.working[k] = angular.copy(v);
1380 angular.forEach(v, function (sv,sk) {
1381 if (k == 'callnumber') {
1382 angular.forEach(v, function (cnv,cnk) {
1383 $scope.batch[cnk] = cnv;
1385 $scope.applyBatchCNValues();
1387 $scope.working[k][sk] = angular.copy(sv);
1388 if (k == 'statcats') $scope.statcatUpdate(sk);
1392 delete $scope.working.MultiMap[k];
1394 egCore.hatch.setItem('cat.copy.last_template', n);
1397 $scope.copytab = 'working';
1398 $scope.tab = 'edit';
1399 $scope.summaryRecord = null;
1400 $scope.record_id = null;
1402 $scope.completed_copies = [];
1403 $scope.location_orgs = [];
1404 $scope.location_cache = {};
1405 $scope.statcats = [];
1406 if (!$scope.batch) $scope.batch = {};
1408 $scope.applyBatchCNValues = function () {
1409 if ($scope.data.tree) {
1410 angular.forEach($scope.data.tree, function(cn_hash) {
1411 angular.forEach(cn_hash, function(copies) {
1412 angular.forEach(copies, function(cp) {
1413 if (typeof $scope.batch.classification != 'undefined' && $scope.batch.classification != '') {
1414 var label_class = $scope.classification_list.filter(function(p){ return p.id() == $scope.batch.classification })[0];
1415 cp.call_number().label_class(label_class);
1416 cp.call_number().ischanged(1);
1417 $scope.dirty = true;
1419 if (typeof $scope.batch.prefix != 'undefined' && $scope.batch.prefix != '') {
1420 var prefix = $scope.prefix_list.filter(function(p){ return p.id() == $scope.batch.prefix })[0];
1421 cp.call_number().prefix(prefix);
1422 cp.call_number().ischanged(1);
1423 $scope.dirty = true;
1425 if (typeof $scope.batch.label != 'undefined' && $scope.batch.label != '') {
1426 cp.call_number().label($scope.batch.label);
1427 cp.call_number().ischanged(1);
1428 $scope.dirty = true;
1430 if (typeof $scope.batch.suffix != 'undefined' && $scope.batch.suffix != '') {
1431 var suffix = $scope.suffix_list.filter(function(p){ return p.id() == $scope.batch.suffix })[0];
1432 cp.call_number().suffix(suffix);
1433 cp.call_number().ischanged(1);
1434 $scope.dirty = true;
1442 $scope.clearWorking = function () {
1443 angular.forEach($scope.working, function (v,k,o) {
1444 if (k != 'MultiMap') $scope.working.MultiMap[k] = [];
1445 if (!angular.isObject(v)) {
1446 if (typeof v != 'undefined')
1447 $scope.working[k] = undefined;
1448 } else if (k != 'circ_lib' && k != 'MultiMap') {
1449 angular.forEach(v, function (sv,sk) {
1450 if (typeof v != 'undefined')
1451 $scope.working[k][sk] = undefined;
1455 $scope.working.circ_lib = undefined; // special
1458 $scope.completedGridDataProvider = egGridDataProvider.instance({
1459 get : function(offset, count) {
1460 //return provider.arrayNotifier(itemSvc.copies, offset, count);
1461 return this.arrayNotifier($scope.completed_copies, offset, count);
1465 $scope.completedGridControls = {};
1467 $scope.workingGridDataProvider = egGridDataProvider.instance({
1468 get : function(offset, count) {
1469 //return provider.arrayNotifier(itemSvc.copies, offset, count);
1470 return this.arrayNotifier(itemSvc.copies, offset, count);
1474 $scope.workingGridControls = {};
1475 $scope.add_vols_copies = false;
1476 $scope.is_fast_add = false;
1478 // Generate some functions for selecting items by column value in the working grid
1480 ['circulate','status','circ_lib','ref','location','opac_visible','circ_modifier','price',
1481 'loan_duration','cost','circ_as_type','deposit','holdable','deposit_amount','age_protect',
1482 'mint_condition','fine_level','floating'],
1484 $scope['select_by_' + field] = function (x) {
1485 $scope.workingGridControls.selectItemsByValue(field,x);
1490 var truthy = /^t|1/;
1491 $scope.labelYesNo = function (x) {
1492 return truthy.test(x) ? egCore.strings.YES : egCore.strings.NO;
1495 $scope.orgShortname = function (x) {
1496 return egCore.org.get(x).shortname();
1499 $scope.statusName = function (x) {
1500 var s = $scope.status_list.filter(function(y) {
1507 $scope.locationName = function (x) {
1508 var s = $scope.location_list.filter(function(y) {
1512 return $scope.i18n.ou_qualified_location_name(s[0]);
1515 $scope.durationLabel = function (x) {
1516 return [egCore.strings.SHORT, egCore.strings.NORMAL, egCore.strings.EXTENDED][-1 + x]
1519 $scope.fineLabel = function (x) {
1520 return [egCore.strings.LOW, egCore.strings.NORMAL, egCore.strings.HIGH][-1 + x]
1523 $scope.circTypeValue = function (x) {
1524 if (x === null || x === undefined) return egCore.strings.UNSET;
1525 var s = $scope.circ_type_list.filter(function(y) {
1526 return y.code() == x;
1529 return s[0].value();
1532 $scope.ageprotectName = function (x) {
1533 if (x === null || x === undefined) return egCore.strings.UNSET;
1534 var s = $scope.age_protect_list.filter(function(y) {
1541 $scope.floatingName = function (x) {
1542 if (x === null || x === undefined) return egCore.strings.UNSET;
1543 var s = $scope.floating_list.filter(function(y) {
1550 $scope.circmodName = function (x) {
1551 if (x === null || x === undefined) return egCore.strings.UNSET;
1552 var s = $scope.circ_modifier_list.filter(function(y) {
1553 return y.code() == x;
1561 'open-ils.actor.anon_cache.get_value',
1562 dataKey, 'edit-these-copies'
1563 ).then(function (data) {
1566 if (data.hide_vols && !$scope.defaults.always_volumes) $scope.show_vols = false;
1567 if (data.hide_copies) {
1568 $scope.show_copies = false;
1569 $scope.only_vols = true;
1572 $scope.record_id = data.record_id;
1575 $scope.fetchDefaults();
1577 function fetchRaw () {
1578 if (!$scope.only_vols) $scope.dirty = true;
1579 $scope.add_vols_copies = true;
1581 /* data.raw data structure looks like this:
1583 * callnumber : $cn_id, // optional, to add a copy to a cn
1584 * owner : $org, // optional, defaults to cn.owning_lib or ws_ou
1585 * label : $cn_label, // optional, to supply a label on a new cn
1586 * barcode : $cp_barcode // optional, to supply a barcode on a new cp
1587 * fast_add : boolean // optional, to specify whether this came
1591 * All can be left out and a completely empty vol/copy combo will be vivicated.
1598 if (proto.fast_add) $scope.is_fast_add = true;
1599 if (proto.callnumber) {
1600 promises.push(egCore.pcrud.retrieve('acn', proto.callnumber)
1601 .then(function(cn) {
1602 var cp = new itemSvc.generateNewCopy(
1604 proto.owner || cn.owning_lib(),
1606 ((!$scope.only_vols) ? true : false)
1609 if (proto.barcode) {
1610 cp.barcode( proto.barcode );
1611 cp.empty_barcode = false;
1617 var cn = new egCore.idl.acn();
1618 cn.id( --itemSvc.new_cn_id );
1620 cn.prefix( $scope.defaults.prefix || -1 );
1621 cn.suffix( $scope.defaults.suffix || -1 );
1622 cn.owning_lib( proto.owner || egCore.auth.user().ws_ou() );
1623 cn.record( $scope.record_id );
1624 egCore.org.settings(
1625 ['cat.default_classification_scheme'],
1627 ).then(function (val) {
1629 $scope.defaults.classification ||
1630 val['cat.default_classification_scheme'] ||
1634 cn.label( proto.label );
1638 'open-ils.cat.biblio.record.marc_cn.retrieve',
1641 ).then(function(cn_array) {
1642 if (cn_array.length > 0) {
1643 for (var field in cn_array[0]) {
1644 cn.label( cn_array[0][field] );
1652 // If we are adding an empty vol,
1653 // this is ultimately just a placeholder copy
1654 // which gets removed before saving.
1655 // TODO: consider ways to remove this
1657 var cp = new itemSvc.generateNewCopy(
1659 proto.owner || cn.owning_lib(),
1664 if (proto.barcode) {
1665 cp.barcode( proto.barcode );
1666 cp.empty_barcode = false;
1674 angular.forEach(itemSvc.copies, function(c){
1675 var cn = c.call_number();
1676 var copy_id = c.id();
1678 cn.not_ephemeral = true;
1682 return $q.all(promises);
1685 if (data.copies && data.copies.length)
1686 return itemSvc.fetchIds(data.copies).then(fetchRaw);
1692 }).then( function() {
1694 return itemSvc.fetch_locations(
1695 itemSvc.copies.map(function(cp){
1696 return cp.location();
1697 }).filter(function(e,i,a){
1698 return a.lastIndexOf(e) === i;
1700 ).then(function(list){
1701 $scope.data = itemSvc;
1702 $scope.location_list = list;
1703 $scope.workingGridDataProvider.refresh();
1708 $scope.can_save = false;
1709 function check_saveable () {
1710 var can_save = true;
1715 if (!$scope.only_vols) {
1716 if (i.duplicate_barcode || i.empty_barcode || i.call_number().empty_label) {
1719 } else if (i.call_number().empty_label) {
1725 if (!$scope.only_vols && $scope.forms.myForm && $scope.forms.myForm.$invalid) {
1729 $scope.can_save = can_save;
1732 $scope.disableSave = function () {
1734 return !$scope.can_save;
1737 $scope.focusNextFirst = function(prev_lib,prev_bc) {
1740 angular.forEach(Object.keys($scope.data.tree).sort(), function (lib) {
1743 if (lib == prev_lib) {
1752 var first_cn = Object.keys($scope.data.tree[n])[0];
1753 var next = '#' + first_cn + '_' + $scope.data.tree[n][first_cn][0].id();
1756 if (!itemSvc.currently_generating) el.focus();
1757 if (prev_bc && itemSvc.auto_gen_barcode && el.val() == "") {
1758 itemSvc.nextBarcode(prev_bc).then(function(bc){
1761 el.trigger('change');
1764 itemSvc.currently_generating = false;
1770 $scope.in_item_select = false;
1771 $scope.afterItemSelect = function() { $scope.in_item_select = false };
1772 $scope.handleItemSelect = function (item_list) {
1773 if (item_list && item_list.length > 0) {
1774 $scope.in_item_select = true;
1776 angular.forEach(Object.keys($scope.defaults.attributes), function (attr) {
1778 var value_hash = {};
1779 var value_list = [];
1780 angular.forEach(item_list, function (item) {
1782 var v = item[attr]()
1783 if (angular.isObject(v)) {
1784 if (v.id) v = v.id();
1785 else if (v.code) v = v.code();
1792 $scope.working.MultiMap[attr] = value_list;
1794 if (Object.keys(value_hash).length == 1) {
1795 if (attr == 'circ_lib') {
1796 $scope.working[attr] = egCore.org.get(item_list[0][attr]());
1798 $scope.working[attr] = item_list[0][attr]();
1801 $scope.working[attr] = undefined;
1805 angular.forEach($scope.statcats, function (sc) {
1808 var value_hash = {};
1810 angular.forEach(item_list, function (item) {
1811 if (item.stat_cat_entries()) {
1812 if (item.stat_cat_entries().length > 0) {
1813 var right_sc = item.stat_cat_entries().filter(function (e) {
1814 return e.stat_cat() == sc.id() && !Boolean(e.isdeleted());
1817 if (right_sc.length > 0) {
1818 value_hash[right_sc[0].id()] = right_sc[0].id();
1830 if (!none && Object.keys(value_hash).length == 1) {
1831 $scope.working.statcats[sc.id()] = value_hash[Object.keys(value_hash)[0]];
1832 $scope.working.statcats_multi[sc.id()] = false;
1833 } else if (item_list.length > 1 && Object.keys(value_hash).length > 0) {
1834 $scope.working.statcats[sc.id()] = undefined;
1835 $scope.working.statcats_multi[sc.id()] = true;
1837 $scope.working.statcats[sc.id()] = undefined;
1838 $scope.working.statcats_multi[sc.id()] = false;
1844 $scope.clearWorking();
1849 $scope.$watch('data.copies.length', function () {
1850 if ($scope.data.copies) {
1851 var base_orgs = $scope.data.copies.map(function(cp){
1852 if (isNaN(cp.circ_lib())) return Number(cp.circ_lib().id());
1853 return Number(cp.circ_lib());
1855 $scope.data.copies.map(function(cp){
1856 if (isNaN(cp.call_number().owning_lib())) return Number(cp.call_number().owning_lib().id());
1857 return Number(cp.call_number().owning_lib());
1860 [egCore.auth.user().ws_ou()]
1861 ).filter(function(e,i,a){
1862 return a.lastIndexOf(e) === i;
1866 angular.forEach(base_orgs, function(o) {
1867 all_orgs = all_orgs.concat( egCore.org.fullPath(o, true) );
1870 var final_orgs = all_orgs.filter(function(e,i,a){
1871 return a.lastIndexOf(e) === i;
1872 }).sort(function(a, b){return a-b});
1874 if ($scope.location_orgs.toString() != final_orgs.toString()) {
1875 $scope.location_orgs = final_orgs;
1876 if ($scope.location_orgs.length) {
1877 itemSvc.get_locations_by_org($scope.location_orgs).then(function(list){
1878 angular.forEach(list, function(l) {
1879 $scope.location_cache[ ''+l.id() ] = l;
1881 $scope.location_list = list;
1882 }).then(function() {
1883 $scope.statcat_filter_list = [];
1884 angular.forEach($scope.location_orgs, function (o) {
1885 $scope.statcat_filter_list.push(egCore.org.get(o));
1888 itemSvc.get_statcats($scope.location_orgs).then(function(list){
1889 $scope.statcats = list;
1890 angular.forEach($scope.statcats, function (s) {
1892 if (!$scope.working)
1893 $scope.working = { statcats_multi: {}, statcats: {}, statcat_filter: undefined};
1894 if (!$scope.working.statcats_multi)
1895 $scope.working.statcats_multi = {};
1896 if (!$scope.working.statcats)
1897 $scope.working.statcats = {};
1899 if (!$scope.in_item_select) {
1900 $scope.working.statcats[s.id()] = undefined;
1902 createStatcatUpdateWatcher(s.id());
1904 $scope.in_item_select = false;
1905 // do a refresh here to work around a race
1906 // condition that can result in stat cats
1907 // not being selected.
1908 $scope.workingGridDataProvider.refresh();
1913 $scope.workingGridDataProvider.refresh();
1918 $scope.statcat_visible = function (sc_owner) {
1919 var visible = typeof $scope.working.statcat_filter === 'undefined' || !$scope.working.statcat_filter;
1920 angular.forEach(egCore.org.ancestors(sc_owner), function (ancestor_org) {
1921 if ($scope.working.statcat_filter == ancestor_org.id())
1927 $scope.suffix_list = [];
1928 itemSvc.get_suffixes(egCore.auth.user().ws_ou()).then(function(list){
1929 $scope.suffix_list = list;
1932 $scope.prefix_list = [];
1933 itemSvc.get_prefixes(egCore.auth.user().ws_ou()).then(function(list){
1934 $scope.prefix_list = list;
1937 $scope.classification_list = [];
1938 itemSvc.get_classifications().then(function(list){
1939 $scope.classification_list = list;
1942 $scope.$watch('completed_copies.length', function () {
1943 $scope.completedGridDataProvider.refresh();
1946 $scope.location_list = [];
1947 createSimpleUpdateWatcher('location');
1949 $scope.status_list = [];
1950 itemSvc.get_magic_statuses().then(function(list){
1951 $scope.magic_status_list = list;
1952 createSimpleUpdateWatcher('status',$scope.magic_status_list);
1954 itemSvc.get_statuses().then(function(list){
1955 $scope.status_list = list;
1958 $scope.circ_modifier_list = [];
1959 itemSvc.get_circ_mods().then(function(list){
1960 $scope.circ_modifier_list = list;
1962 createSimpleUpdateWatcher('circ_modifier');
1964 $scope.circ_type_list = [];
1965 itemSvc.get_circ_types().then(function(list){
1966 $scope.circ_type_list = list;
1968 createSimpleUpdateWatcher('circ_as_type');
1970 $scope.age_protect_list = [];
1971 itemSvc.get_age_protects().then(function(list){
1972 $scope.age_protect_list = list;
1974 createSimpleUpdateWatcher('age_protect');
1976 $scope.floating_list = [];
1977 itemSvc.get_floating_groups().then(function(list){
1978 $scope.floating_list = list;
1980 createSimpleUpdateWatcher('floating');
1982 createSimpleUpdateWatcher('circ_lib');
1983 createSimpleUpdateWatcher('circulate');
1984 createSimpleUpdateWatcher('holdable');
1985 createSimpleUpdateWatcher('fine_level');
1986 createSimpleUpdateWatcher('loan_duration');
1987 createSimpleUpdateWatcher('price');
1988 createSimpleUpdateWatcher('cost');
1989 createSimpleUpdateWatcher('deposit');
1990 createSimpleUpdateWatcher('deposit_amount');
1991 createSimpleUpdateWatcher('mint_condition');
1992 createSimpleUpdateWatcher('opac_visible');
1993 createSimpleUpdateWatcher('ref');
1995 $scope.saveCompletedCopies = function (and_exit) {
1997 var perCnCopies = {};
1998 angular.forEach( $scope.completed_copies, function (cp) {
1999 var cn = cp.call_number();
2000 var cn_cps = cp.call_number().copies();
2001 cp.call_number().copies([]);
2002 var cn_id = cp.call_number().id();
2003 cp.call_number(cn_id); // prevent loops in JSON-ification
2004 if (!cnHash[cn_id]) {
2005 cnHash[cn_id] = egCore.idl.Clone(cn);
2006 perCnCopies[cn_id] = [egCore.idl.Clone(cp)];
2008 perCnCopies[cn_id].push(egCore.idl.Clone(cp));
2010 cp.call_number(cn); // put the data back
2011 cp.call_number().copies(cn_cps);
2012 if (typeof cnHash[cn_id].prefix() == 'object')
2013 cnHash[cn_id].prefix(cnHash[cn_id].prefix().id()); // un-object-ize some fields
2014 if (typeof cnHash[cn_id].suffix() == 'object')
2015 cnHash[cn_id].suffix(cnHash[cn_id].suffix().id()); // un-object-ize some fields
2018 if ($scope.only_vols) { // strip off copies when we're in vol-only mode
2019 angular.forEach(cnHash, function (v, k) {
2020 cnHash[k].copies([]);
2023 angular.forEach(perCnCopies, function (v, k) {
2024 cnHash[k].copies(v);
2029 angular.forEach(cnHash, function (v, k) {
2035 'open-ils.cat.asset.volume.fleshed.batch.update.override',
2036 egCore.auth.token(), cnList, 1, { auto_merge_vols : 1, create_parts : 1, return_copy_ids : 1 }
2037 ).then(function(copy_ids) {
2039 $scope.dirty = false;
2040 if ($scope.defaults.print_item_labels) {
2043 'open-ils.actor.anon_cache.set_value',
2044 null, 'print-labels-these-copies', {
2047 ).then(function(key) {
2049 var url = egCore.env.basePath + 'cat/printlabels/' + key;
2050 $timeout(function() { $window.open(url, '_blank') }).then(
2051 function() { $timeout(function(){$window.close()}); }
2054 alert('Could not create anonymous cache key!');
2058 $timeout(function(){
2059 if (typeof BroadcastChannel != 'undefined') {
2060 var bChannel = new BroadcastChannel("eg.holdings.update");
2061 var bre_ids = cnList && cnList.length > 0 ? cnList.map(function(cn){ return Number(cn.record()) }) : [];
2062 var cn_ids = cnList && cnList.length > 0 ? cnList.map(function(cn){ return cn.id() }) : [];
2063 bChannel.postMessage({
2077 $scope.saveAndContinue = function () {
2078 $scope.saveCompletedCopies(false);
2081 $scope.workingSaveAndExit = function () {
2082 $scope.workingToComplete();
2083 $scope.saveAndExit();
2086 $scope.saveAndExit = function () {
2087 $scope.saveCompletedCopies(true);
2092 $scope.copy_notes_dialog = function(copy_list) {
2093 var default_pub = Boolean($scope.defaults.copy_notes_pub);
2094 if (!angular.isArray(copy_list)) copy_list = [copy_list];
2096 return $uibModal.open({
2097 templateUrl: './cat/volcopy/t_copy_notes',
2101 ['$scope','$uibModalInstance',
2102 function($scope , $uibModalInstance) {
2103 $scope.focusNote = true;
2105 creator : egCore.auth.user().id(),
2111 $scope.require_initials = false;
2112 egCore.org.settings([
2113 'ui.staff.require_initials.copy_notes'
2114 ]).then(function(set) {
2115 $scope.require_initials_ous = Boolean(set['ui.staff.require_initials.copy_notes']);
2118 $scope.are_initials_required = function() {
2119 $scope.require_initials = $scope.require_initials_ous && ($scope.note.value.length > 0 || $scope.note.title.length > 0);
2122 $scope.$watch('note.value.length', $scope.are_initials_required);
2123 $scope.$watch('note.title.length', $scope.are_initials_required);
2125 $scope.note_list = [];
2126 if (copy_list.length == 1) {
2127 $scope.note_list = copy_list[0].notes();
2130 $scope.ok = function(note) {
2132 if (note.value.length > 0 || note.title.length > 0) {
2133 if ($scope.initials) {
2134 note.value = egCore.strings.$replace(
2135 egCore.strings.COPY_NOTE_INITIALS, {
2137 initials : $scope.initials,
2138 ws_ou : egCore.org.get(
2139 egCore.auth.user().ws_ou()).shortname()
2143 angular.forEach(copy_list, function (cp) {
2144 if (!angular.isArray(cp.notes())) cp.notes([]);
2145 var n = new egCore.idl.acpn();
2147 n.creator(note.creator);
2148 n.pub(note.pub ? 't' : 'f');
2149 n.title(note.title);
2150 n.value(note.value);
2151 n.owning_copy(cp.id());
2152 cp.notes().push( n );
2156 $uibModalInstance.close();
2159 $scope.cancel = function($event) {
2160 $uibModalInstance.dismiss();
2161 $event.preventDefault();
2167 $scope.copy_tags_dialog = function(copy_list) {
2168 if (!angular.isArray(copy_list)) copy_list = [copy_list];
2170 return $uibModal.open({
2171 templateUrl: './cat/volcopy/t_copy_tags',
2175 ['$scope','$uibModalInstance',
2176 function($scope , $uibModalInstance) {
2178 $scope.tag_map = [];
2180 var shared_tags = {};
2181 angular.forEach(copy_list, function (cp) {
2182 angular.forEach(cp.tags(), function(tag) {
2183 if (!(tag.tag().id() in shared_tags)) {
2184 shared_tags[tag.tag().id()] = 1;
2186 shared_tags[tag.tag().id()]++;
2188 if (!(tag.tag().id() in tag_hash)) {
2189 tag_hash[tag.tag().id()] = tag;
2193 angular.forEach(tag_hash, function(value, key) {
2194 if (shared_tags[key] == copy_list.length) {
2195 $scope.tag_map.push(value);
2199 $scope.tag_types = [];
2200 egCore.pcrud.retrieveAll('cctt', {order_by : { cctt : 'label' }}, {atomic : true}).then(function(list) {
2201 $scope.tag_types = list;
2202 $scope.tag_type = $scope.tag_types[0].code(); // just pick a default
2205 $scope.getTags = function(val) {
2206 return egCore.pcrud.search('acpt',
2208 owner : egCore.org.fullPath(egCore.auth.user().ws_ou(), true),
2209 label : { 'startwith' : {
2210 transform: 'evergreen.lowercase',
2211 value : [ 'evergreen.lowercase', val ]
2213 tag_type : $scope.tag_type
2215 { order_by : { 'acpt' : ['label'] } }, { atomic: true }
2216 ).then(function(list) {
2217 return list.map(function(item) {
2218 return { value: item.label(), display: item.label() + " (" + egCore.org.get(item.owner()).shortname() + ")" };
2223 $scope.addTag = function() {
2224 var tagLabel = $scope.selectedLabel;
2225 // clear the typeahead
2226 $scope.selectedLabel = "";
2228 // first, check tags already associated with the copy
2229 var foundMatch = false;
2230 angular.forEach($scope.tag_map, function(tag) {
2231 if (tag.tag().label() == tagLabel && tag.tag().tag_type() == $scope.tag_type) {
2233 if (tag.isdeleted()) tag.isdeleted(0); // just deleting the mapping
2237 egCore.pcrud.search('acpt',
2239 owner : egCore.org.fullPath(egCore.auth.user().ws_ou(), true),
2241 tag_type : $scope.tag_type
2243 { order_by : { 'acpt' : ['label'] } }, { atomic: true }
2244 ).then(function(list) {
2245 if (list.length > 0) {
2246 var newMap = new egCore.idl.acptcm();
2248 newMap.copy(copy_list[0].id());
2249 newMap.tag(egCore.idl.Clone(list[0]));
2250 $scope.tag_map.push(newMap);
2252 var newTag = new egCore.idl.acpt();
2254 newTag.owner(egCore.auth.user().ws_ou());
2255 newTag.label(tagLabel);
2257 newTag.tag_type($scope.tag_type);
2259 var newMap = new egCore.idl.acptcm();
2261 newMap.copy(copy_list[0].id());
2263 $scope.tag_map.push(newMap);
2269 $scope.ok = function(note) {
2270 // in the multi-item case, this works OK for
2271 // adding new maps to existing tags, but doesn't handle
2272 // all possibilities
2273 angular.forEach(copy_list, function (cp) {
2274 cp.tags($scope.tag_map);
2276 $uibModalInstance.close();
2279 $scope.cancel = function($event) {
2280 $uibModalInstance.dismiss();
2281 $event.preventDefault();
2287 $scope.copy_alerts_dialog = function(copy_list) {
2288 if (!angular.isArray(copy_list)) copy_list = [copy_list];
2290 return $uibModal.open({
2291 templateUrl: './cat/volcopy/t_copy_alerts',
2294 ['$scope','$uibModalInstance',
2295 function($scope , $uibModalInstance) {
2297 itemSvc.get_copy_alert_types().then(function(ccat) {
2298 $scope.alert_types = ccat;
2301 $scope.focusNote = true;
2302 $scope.copy_alert = {
2303 create_staff : egCore.auth.user().id(),
2308 egCore.hatch.getItem('cat.copy.alerts.last_type').then(function(t) {
2309 if (t) $scope.copy_alert.alert_type = t;
2312 if (copy_list.length == 1) {
2313 $scope.copy_alert_list = copy_list[0].copy_alerts();
2316 $scope.ok = function(copy_alert) {
2318 if (typeof(copy_alert.note) != 'undefined' &&
2319 copy_alert.note != '') {
2320 angular.forEach(copy_list, function (cp) {
2321 if (!angular.isArray(cp.copy_alerts())) cp.copy_alerts([]);
2322 var a = new egCore.idl.aca();
2324 a.create_staff(copy_alert.create_staff);
2325 a.note(copy_alert.note);
2326 a.temp(copy_alert.temp ? 't' : 'f');
2330 $scope.alert_types.filter(function(at) {
2331 return at.id() == copy_alert.alert_type;
2334 cp.copy_alerts().push( a );
2337 if (copy_alert.alert_type) {
2338 egCore.hatch.setItem(
2339 'cat.copy.alerts.last_type',
2340 copy_alert.alert_type
2346 $uibModalInstance.close();
2349 $scope.cancel = function($event) {
2350 $uibModalInstance.dismiss();
2351 $event.preventDefault();
2359 .directive("egVolTemplate", function () {
2363 template: '<div ng-include="'+"'/eg/staff/cat/volcopy/t_attr_edit'"+'"></div>',
2367 controller : ['$scope','$window','itemSvc','egCore','ngToast','$uibModal',
2368 function ( $scope , $window , itemSvc , egCore , ngToast , $uibModal) {
2370 $scope.i18n = egCore.i18n;
2372 $scope.defaults = { // If defaults are not set at all, allow everything
2373 barcode_checkdigit : false,
2374 auto_gen_barcode : false,
2381 loan_duration : true,
2386 deposit_amount : true,
2387 opac_visible : true,
2390 mint_condition : true,
2393 circ_modifier : true,
2394 circ_as_type : true,
2402 $scope.fetchDefaults = function () {
2403 egCore.hatch.getItem('cat.copy.defaults').then(function(t) {
2405 $scope.defaults = t;
2406 $scope.working.statcat_filter = $scope.defaults.statcat_filter;
2408 typeof $scope.defaults.statcat_filter == 'object' &&
2409 Object.keys($scope.defaults.statcat_filter).length > 0
2411 // want fieldmapper object here...
2412 $scope.defaults.statcat_filter =
2413 egCore.idl.Clone($scope.defaults.statcat_filter);
2415 $scope.working.statcat_filter = $scope.defaults.statcat_filter.id();
2420 $scope.fetchDefaults();
2422 $scope.dirty = false;
2423 $scope.$watch('dirty',
2424 function(newVal, oldVal) {
2425 if (newVal && newVal != oldVal) {
2426 $($window).on('beforeunload.template', function(){
2427 return 'There is unsaved template data!'
2430 $($window).off('beforeunload.template');
2435 $scope.template_controls = true;
2437 $scope.fetchTemplates = function () {
2438 itemSvc.get_acp_templates().then(function(t) {
2440 $scope.templates = t;
2441 $scope.template_name_list = Object.keys(t).sort();
2445 $scope.fetchTemplates();
2447 $scope.applyTemplate = function (n) {
2448 angular.forEach($scope.templates[n], function (v,k) {
2449 if (k == 'circ_lib') {
2450 $scope.working[k] = egCore.org.get(v);
2451 } else if (angular.isArray(v) || !angular.isObject(v)) {
2452 $scope.working[k] = angular.copy(v);
2454 angular.forEach(v, function (sv,sk) {
2455 if (!(k in $scope.working))
2456 $scope.working[k] = {};
2457 $scope.working[k][sk] = angular.copy(sv);
2461 $scope.template_name = '';
2464 $scope.deleteTemplate = function (n) {
2466 delete $scope.templates[n]
2467 $scope.template_name_list = Object.keys($scope.templates).sort();
2468 $scope.template_name = '';
2469 itemSvc.save_acp_templates($scope.templates);
2470 $scope.$parent.fetchTemplates();
2471 ngToast.create(egCore.strings.VOL_COPY_TEMPLATE_SUCCESS_DELETE);
2475 $scope.saveTemplate = function (n) {
2479 angular.forEach($scope.working, function (v,k) {
2480 if (angular.isObject(v)) { // we'll use the pkey
2481 if (v.id) v = v.id();
2482 else if (v.code) v = v.code();
2483 else v = angular.copy(v); // Should only be statcats and callnumbers currently
2489 $scope.templates[n] = tmpl;
2490 $scope.template_name_list = Object.keys($scope.templates).sort();
2492 itemSvc.save_acp_templates($scope.templates);
2493 $scope.$parent.fetchTemplates();
2495 $scope.dirty = false;
2497 // save all templates, as we might do after an import
2498 itemSvc.save_acp_templates($scope.templates);
2499 $scope.$parent.fetchTemplates();
2501 ngToast.create(egCore.strings.VOL_COPY_TEMPLATE_SUCCESS_SAVE);
2504 $scope.templates = {};
2505 $scope.imported_templates = { data : '' };
2506 $scope.template_name = '';
2507 $scope.template_name_list = [];
2509 $scope.$watch('imported_templates.data', function(newVal, oldVal) {
2510 if (newVal && newVal != oldVal) {
2512 var newTemplates = JSON.parse(newVal);
2513 if (!Object.keys(newTemplates).length) return;
2514 angular.forEach(Object.keys(newTemplates), function (k) {
2515 $scope.templates[k] = newTemplates[k];
2517 itemSvc.save_acp_templates($scope.templates);
2518 $scope.fetchTemplates();
2520 console.log('tried to import an invalid copy template file');
2525 $scope.tracker = function (x,f) { if (x) return x[f]() };
2526 $scope.idTracker = function (x) { if (x) return $scope.tracker(x,'id') };
2527 $scope.cant_have_vols = function (id) { return !egCore.org.CanHaveVolumes(id); };
2529 $scope.orgById = function (id) { return egCore.org.get(id) }
2530 $scope.statusById = function (id) {
2531 return $scope.status_list.filter( function (s) { return s.id() == id } )[0];
2533 $scope.locationById = function (id) {
2534 return $scope.location_cache[''+id];
2537 createSimpleUpdateWatcher = function (field) {
2538 $scope.$watch('working.' + field, function () {
2539 var newval = $scope.working[field];
2541 if (typeof newval != 'undefined') {
2542 $scope.dirty = true;
2543 if (angular.isObject(newval)) { // we'll use the pkey
2544 if (newval.id) $scope.working[field] = newval.id();
2545 else if (newval.code) $scope.working[field] = newval.code();
2548 if (""+newval == "" || newval == null) {
2549 $scope.working[field] = undefined;
2560 statcat_filter: undefined
2563 $scope.statcat_visible = function (sc_owner) {
2564 var visible = typeof $scope.working.statcat_filter === 'undefined' || !$scope.working.statcat_filter;
2565 angular.forEach(egCore.org.ancestors(sc_owner), function (ancestor_org) {
2566 if ($scope.working.statcat_filter == ancestor_org.id())
2572 createStatcatUpdateWatcher = function (id) {
2573 return $scope.$watch('working.statcats[' + id + ']', function () {
2574 if ($scope.working.statcats) {
2575 var newval = $scope.working.statcats[id];
2577 if (typeof newval != 'undefined') {
2578 $scope.dirty = true;
2579 if (angular.isObject(newval)) { // we'll use the pkey
2580 newval = newval.id();
2583 if (""+newval == "" || newval == null) {
2584 $scope.working.statcats[id] = undefined;
2593 $scope.clearWorking = function () {
2594 angular.forEach($scope.working, function (v,k,o) {
2595 if (!angular.isObject(v)) {
2596 if (typeof v != 'undefined')
2597 $scope.working[k] = undefined;
2598 } else if (k != 'circ_lib' && k != 'MultiMap') {
2599 angular.forEach(v, function (sv,sk) {
2600 $scope.working[k][sk] = undefined;
2604 $scope.working.circ_lib = undefined; // special
2605 $scope.dirty = false;
2608 $scope.working = {};
2609 $scope.location_orgs = [];
2610 $scope.location_cache = {};
2612 $scope.location_list = [];
2613 itemSvc.get_locations_by_org(
2614 egCore.org.fullPath( egCore.auth.user().ws_ou(), true )
2615 ).then(function(list){
2616 $scope.location_list = list;
2618 createSimpleUpdateWatcher('location');
2620 $scope.statcat_filter_list = egCore.org.fullPath( egCore.auth.user().ws_ou() );
2622 $scope.statcats = [];
2623 itemSvc.get_statcats(
2624 egCore.org.fullPath( egCore.auth.user().ws_ou(), true )
2625 ).then(function(list){
2626 $scope.statcats = list;
2627 angular.forEach($scope.statcats, function (s) {
2629 if (!$scope.working)
2630 $scope.working = { statcats: {}, statcat_filter: undefined};
2631 if (!$scope.working.statcats)
2632 $scope.working.statcats = {};
2634 $scope.working.statcats[s.id()] = undefined;
2635 createStatcatUpdateWatcher(s.id());
2639 $scope.copy_notes_dialog = function() {
2640 var default_pub = Boolean($scope.defaults.copy_notes_pub);
2641 var working = $scope.working;
2643 return $uibModal.open({
2644 templateUrl: './cat/volcopy/t_copy_notes',
2647 ['$scope','$uibModalInstance',
2648 function($scope , $uibModalInstance) {
2649 $scope.focusNote = true;
2656 $scope.require_initials = false;
2657 egCore.org.settings([
2658 'ui.staff.require_initials.copy_notes'
2659 ]).then(function(set) {
2660 $scope.require_initials = Boolean(set['ui.staff.require_initials.copy_notes']);
2663 $scope.note_list = [];
2664 angular.forEach(working.copy_notes, function(note) {
2665 var acpn = egCore.idl.fromHash('acpn', note);
2666 $scope.note_list.push(acpn);
2669 $scope.ok = function(note) {
2671 if (!working.copy_notes) {
2672 working.copy_notes = [];
2676 working.copy_notes.length = 0;
2677 angular.forEach($scope.note_list, function(existing_note) {
2678 if (!existing_note.isdeleted()) {
2679 working.copy_notes.push({
2680 pub : existing_note.pub() ? 't' : 'f',
2681 title : existing_note.title(),
2682 value : existing_note.value()
2687 // add new note, if any
2688 if (note.initials) note.value += ' [' + note.initials + ']';
2689 note.pub = note.pub ? 't' : 'f';
2690 if (note.title.length && note.value.length) {
2691 working.copy_notes.push(note);
2694 $uibModalInstance.close();
2697 $scope.cancel = function($event) {
2698 $uibModalInstance.dismiss();
2699 $event.preventDefault();
2705 $scope.copy_alerts_dialog = function() {
2706 var working = $scope.working;
2708 return $uibModal.open({
2709 templateUrl: './cat/volcopy/t_copy_alerts',
2712 ['$scope','$uibModalInstance',
2713 function($scope , $uibModalInstance) {
2715 itemSvc.get_copy_alert_types().then(function(ccat) {
2717 $scope.alert_types = ccat;
2718 angular.forEach(ccat, function(t) {
2719 ccat_map[t.id()] = t;
2721 $scope.copy_alert_list = [];
2722 angular.forEach(working.copy_alerts, function (alrt) {
2723 var aca = egCore.idl.fromHash('aca', alrt);
2724 aca.alert_type(ccat_map[alrt.alert_type]);
2726 $scope.copy_alert_list.push(aca);
2730 $scope.focusNote = true;
2731 $scope.copy_alert = {
2736 $scope.ok = function(copy_alert) {
2738 if (!working.copy_alerts) {
2739 working.copy_alerts = [];
2742 working.copy_alerts.length = 0;
2744 angular.forEach($scope.copy_alert_list, function(alrt) {
2745 if (alrt.ack_time() == null) {
2746 working.copy_alerts.push({
2749 alert_type : alrt.alert_type().id()
2754 if (typeof(copy_alert.note) != 'undefined' &&
2755 copy_alert.note != '') {
2756 working.copy_alerts.push({
2757 note : copy_alert.note,
2758 temp : copy_alert.temp ? 't' : 'f',
2759 alert_type : copy_alert.alert_type
2763 $uibModalInstance.close();
2766 $scope.cancel = function($event) {
2767 $uibModalInstance.dismiss();
2768 $event.preventDefault();
2774 $scope.status_list = [];
2775 itemSvc.get_magic_statuses().then(function(list){
2776 $scope.magic_status_list = list;
2778 itemSvc.get_statuses().then(function(list){
2779 $scope.status_list = list;
2781 createSimpleUpdateWatcher('status');
2783 $scope.circ_modifier_list = [];
2784 itemSvc.get_circ_mods().then(function(list){
2785 $scope.circ_modifier_list = list;
2787 createSimpleUpdateWatcher('circ_modifier');
2789 $scope.circ_type_list = [];
2790 itemSvc.get_circ_types().then(function(list){
2791 $scope.circ_type_list = list;
2793 createSimpleUpdateWatcher('circ_as_type');
2795 $scope.age_protect_list = [];
2796 itemSvc.get_age_protects().then(function(list){
2797 $scope.age_protect_list = list;
2799 createSimpleUpdateWatcher('age_protect');
2801 $scope.floating_list = [];
2802 itemSvc.get_floating_groups().then(function(list){
2803 $scope.floating_list = list;
2805 createSimpleUpdateWatcher('floating');
2807 createSimpleUpdateWatcher('circulate');
2808 createSimpleUpdateWatcher('holdable');
2809 createSimpleUpdateWatcher('fine_level');
2810 createSimpleUpdateWatcher('loan_duration');
2811 createSimpleUpdateWatcher('cost');
2812 createSimpleUpdateWatcher('deposit');
2813 createSimpleUpdateWatcher('deposit_amount');
2814 createSimpleUpdateWatcher('mint_condition');
2815 createSimpleUpdateWatcher('opac_visible');
2816 createSimpleUpdateWatcher('ref');
2818 $scope.suffix_list = [];
2819 itemSvc.get_suffixes(egCore.auth.user().ws_ou()).then(function(list){
2820 $scope.suffix_list = list;
2823 $scope.prefix_list = [];
2824 itemSvc.get_prefixes(egCore.auth.user().ws_ou()).then(function(list){
2825 $scope.prefix_list = list;
2828 $scope.classification_list = [];
2829 itemSvc.get_classifications().then(function(list){
2830 $scope.classification_list = list;
2833 createSimpleUpdateWatcher('working.callnumber.classification');
2834 createSimpleUpdateWatcher('working.callnumber.prefix');
2835 createSimpleUpdateWatcher('working.callnumber.suffix');