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'],
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", function () {
490 '<div class="col-xs-5" ng-class="{'+"'has-error'"+':barcode_has_error}">'+
491 '<input id="{{callNumber.id()}}_{{copy.id()}}"'+
492 ' eg-enter="nextBarcode(copy.id())" class="form-control"'+
493 ' type="text" ng-model="barcode" ng-change="updateBarcode()"'+
494 ' ng-focus="selectOnFocus($event)" autofocus/>'+
495 '<div class="label label-danger" ng-if="duplicate_barcode">{{duplicate_barcode_string}}</div>'+
496 '<div class="label label-danger" ng-if="empty_barcode">{{empty_barcode_string}}</div>'+
498 '<div class="col-xs-3"><input class="form-control" type="number" min="1" ng-model="copy_number" ng-change="updateCopyNo()"/></div>'+
499 '<div class="col-xs-3"><eg-basic-combo-box list="parts" selected="part"></eg-basic-combo-box></div>'+
502 scope: { focusNext: "=", copy: "=", callNumber: "=", index: "@", record: "@" },
503 controller : ['$scope','itemSvc','egCore',
504 function ( $scope , itemSvc , egCore ) {
505 $scope.new_part_id = 0;
506 $scope.barcode_has_error = false;
507 $scope.duplicate_barcode = false;
508 $scope.empty_barcode = false;
509 $scope.duplicate_barcode_string = window.duplicate_barcode_string;
510 $scope.empty_barcode_string = window.empty_barcode_string;
512 if (!$scope.copy.barcode()) $scope.copy.empty_barcode = true;
514 $scope.selectOnFocus = function($event) {
515 if (!$scope.copy.empty_barcode)
516 $event.target.select();
519 $scope.nextBarcode = function (i) {
520 $scope.focusNext(i, $scope.barcode);
523 $scope.updateBarcode = function () {
524 if ($scope.barcode != '') {
525 $scope.copy.empty_barcode = $scope.empty_barcode = false;
526 $scope.barcode_has_error = !Boolean(itemSvc.checkBarcode($scope.barcode));
527 itemSvc.checkDuplicateBarcode($scope.barcode, $scope.copy.id())
528 .then(function (state) { $scope.copy.duplicate_barcode = $scope.duplicate_barcode = state });
530 $scope.copy.empty_barcode = $scope.empty_barcode = true;
533 $scope.copy.barcode($scope.barcode);
534 $scope.copy.ischanged(1);
535 if (itemSvc.currently_generating)
536 $scope.focusNext($scope.copy.id(), $scope.barcode);
539 $scope.updateCopyNo = function () { $scope.copy.copy_number($scope.copy_number); $scope.copy.ischanged(1); };
540 $scope.updatePart = function () {
542 var p = $scope.part_list.filter(function (x) {
543 return x.label() == $scope.part
545 if (p.length > 0) { // preexisting part
547 } else { // create one...
548 var part = new egCore.idl.bmp();
549 part.id( --$scope.new_part_id );
551 part.label( $scope.part );
552 part.record( $scope.callNumber.record() );
553 $scope.copy.parts([part]);
554 $scope.copy.ischanged(1);
557 $scope.copy.parts([]);
559 $scope.copy.ischanged(1);
563 $scope.part_list = [];
565 itemSvc.get_parts($scope.callNumber.record())
566 .then(function(list){
567 $scope.part_list = list;
568 angular.forEach(list, function(p){ $scope.parts.push(p.label()) });
569 $scope.parts = angular.copy($scope.parts);
571 $scope.$watch('part', $scope.updatePart);
572 if ($scope.copy.parts()) {
573 var the_part = $scope.copy.parts()[0];
574 if (the_part) $scope.part = the_part.label();
578 $scope.barcode = $scope.copy.barcode();
579 $scope.copy_number = $scope.copy.copy_number();
587 .directive("egVolRow", function () {
594 '<div class="col-xs-2">'+
595 '<button aria-label="Delete" style="margin:-5px -15px; float:left;" ng-hide="callNumber.not_ephemeral" type="button" class="close" ng-click="removeCN()">×</button>' +
596 '<select class="form-control" ng-model="classification" ng-change="updateClassification()" ng-options="cl.name() for cl in classification_list"/>'+
598 '<div class="col-xs-1">'+
599 '<select class="form-control" ng-model="prefix" ng-change="updatePrefix()" ng-options="p.label() for p in prefix_list"/>'+
601 '<div class="col-xs-2">'+
602 '<input class="form-control" type="text" ng-change="updateLabel()" ng-model="label"/>'+
603 '<div class="label label-danger" ng-if="empty_label">{{empty_label_string}}</div>'+
605 '<div class="col-xs-1">'+
606 '<select class="form-control" ng-model="suffix" ng-change="updateSuffix()" ng-options="s.label() for s in suffix_list"/>'+
608 '<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>'+
609 '<div ng-hide="onlyVols" class="col-xs-5">'+
610 '<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>'+
614 scope: {focusNext: "=", allcopies: "=", copies: "=", onlyVols: "=", record: "@", struct:"=" },
615 controller : ['$scope','itemSvc','egCore',
616 function ( $scope , itemSvc , egCore ) {
617 $scope.callNumber = $scope.copies[0].call_number();
618 if (!$scope.callNumber.label()) $scope.callNumber.empty_label = true;
620 $scope.empty_label = false;
621 $scope.empty_label_string = window.empty_label_string;
623 $scope.idTracker = function (x) { if (x && x.id) return x.id() };
625 // XXX $() is not working! arg
626 $scope.focusNextBarcode = function (i, prev_bc) {
629 angular.forEach($scope.copies, function (cp) {
637 if (yep) n = cp.id();
641 var next = '#' + $scope.callNumber.id() + '_' + n;
644 if (!itemSvc.currently_generating) el.focus();
645 if (prev_bc && itemSvc.auto_gen_barcode && el.val() == "") {
646 itemSvc.nextBarcode(prev_bc).then(function(bc){
649 el.trigger('change');
652 itemSvc.currently_generating = false;
656 $scope.focusNext($scope.callNumber.id(),prev_bc)
660 $scope.suffix_list = [];
661 itemSvc.get_suffixes($scope.callNumber.owning_lib()).then(function(list){
662 $scope.suffix_list = list;
663 $scope.$watch('callNumber.suffix()', function (v) {
664 if (angular.isObject(v)) v = v.id();
665 $scope.suffix = $scope.suffix_list.filter( function (s) {
671 $scope.updateSuffix = function () {
672 angular.forEach($scope.copies, function(cp) {
673 cp.call_number().suffix($scope.suffix);
674 cp.call_number().ischanged(1);
678 $scope.prefix_list = [];
679 itemSvc.get_prefixes($scope.callNumber.owning_lib()).then(function(list){
680 $scope.prefix_list = list;
681 $scope.$watch('callNumber.prefix()', function (v) {
682 if (angular.isObject(v)) v = v.id();
683 $scope.prefix = $scope.prefix_list.filter(function (p) {
689 $scope.updatePrefix = function () {
690 angular.forEach($scope.copies, function(cp) {
691 cp.call_number().prefix($scope.prefix);
692 cp.call_number().ischanged(1);
695 $scope.$watch('callNumber.owning_lib()', function(oldLib, newLib) {
696 if (oldLib == newLib) return;
697 var currentPrefix = $scope.callNumber.prefix();
698 if (angular.isObject(currentPrefix)) currentPrefix = currentPrefix.id();
699 itemSvc.get_prefixes($scope.callNumber.owning_lib()).then(function(list){
700 $scope.prefix_list = list;
701 var newPrefixId = $scope.prefix_list.filter(function (p) {
702 return p.id() == currentPrefix;
704 if (newPrefixId.id) newPrefixId = newPrefixId.id();
705 $scope.prefix = $scope.prefix_list.filter(function (p) {
706 return p.id() == newPrefixId;
708 if ($scope.newPrefixId != currentPrefix) {
709 $scope.callNumber.prefix($scope.prefix);
712 var currentSuffix = $scope.callNumber.suffix();
713 if (angular.isObject(currentSuffix)) currentSuffix = currentSuffix.id();
714 itemSvc.get_suffixes($scope.callNumber.owning_lib()).then(function(list){
715 $scope.suffix_list = list;
716 var newSuffixId = $scope.suffix_list.filter(function (s) {
717 return s.id() == currentSuffix;
719 if (newSuffixId.id) newSuffixId = newSuffixId.id();
720 $scope.suffix = $scope.suffix_list.filter(function (s) {
721 return s.id() == newSuffixId;
723 if ($scope.newSuffixId != currentSuffix) {
724 $scope.callNumber.suffix($scope.suffix);
729 $scope.classification_list = [];
730 itemSvc.get_classifications().then(function(list){
731 $scope.classification_list = list;
732 $scope.$watch('callNumber.label_class()', function (v) {
733 if (angular.isObject(v)) v = v.id();
734 $scope.classification = $scope.classification_list.filter(function (c) {
740 $scope.updateClassification = function () {
741 angular.forEach($scope.copies, function(cp) {
742 cp.call_number().label_class($scope.classification);
743 cp.call_number().ischanged(1);
747 $scope.updateLabel = function () {
748 angular.forEach($scope.copies, function(cp) {
749 cp.call_number().label($scope.label);
750 cp.call_number().ischanged(1);
754 $scope.$watch('callNumber.label()', function (v) {
756 if ($scope.label == '') {
757 $scope.callNumber.empty_label = $scope.empty_label = true;
759 $scope.callNumber.empty_label = $scope.empty_label = false;
763 $scope.prefix = $scope.callNumber.prefix();
764 $scope.suffix = $scope.callNumber.suffix();
765 $scope.classification = $scope.callNumber.label_class();
766 $scope.label = $scope.callNumber.label();
768 $scope.copy_count = $scope.copies.length;
769 $scope.orig_copy_count = $scope.copy_count;
771 $scope.removeCN = function(){
772 var cn = $scope.callNumber;
773 if (cn.not_ephemeral) return; // can't delete existing volumes
775 angular.forEach(Object.keys($scope.struct), function(k){
776 angular.forEach($scope.struct[k], function(cp){
777 var struct_cn = cp.call_number();
778 if (struct_cn.id() == cn.id()){
779 console.log("X'ed CN id" + cn.id() + " and struct CN id match!");
780 // remove any copies in $scope.struct[k]
781 angular.forEach($scope.copies, function(c){
782 var idx = $scope.allcopies.indexOf(c);
783 $scope.allcopies.splice(idx, 1);
788 delete $scope.struct[k];
793 // manually decrease cn_count numeric input
794 var cn_spinner = $("input[name='cn_count_lib"+ cn.owning_lib() +"']");
795 if (cn_spinner.val() > 0) cn_spinner.val(parseInt(cn_spinner.val()) - 1);
796 cn_spinner.trigger("change");
800 $scope.changeCPCount = function () {
801 while ($scope.copy_count > $scope.copies.length) {
802 var cp = itemSvc.generateNewCopy(
804 $scope.callNumber.owning_lib(),
808 $scope.copies.push( cp );
809 $scope.allcopies.push( cp );
813 if ($scope.copy_count >= $scope.orig_copy_count) {
814 var how_many = $scope.copies.length - $scope.copy_count;
816 var dead = $scope.copies.splice($scope.copy_count,how_many);
817 $scope.callNumber.copies($scope.copies);
819 // Trimming the global list is a bit more tricky
820 angular.forEach( dead, function (d) {
821 angular.forEach( $scope.allcopies, function (l, i) {
822 if (l === d) $scope.allcopies.splice(i,1);
835 .directive("egVolEdit", function () {
841 '<div class="col-xs-1"><eg-org-selector selected="owning_lib" disable-test="cant_have_vols"></eg-org-selector></div>'+
842 '<div class="col-xs-1"><input class="form-control" type="number" min="{{orig_cn_count}}" ng-model="cn_count" ng-change="changeCNCount()"/></div>'+
843 '<div class="col-xs-10">'+
844 '<eg-vol-row only-vols="onlyVols" record="{{record}}"'+
845 'ng-repeat="(cn,copies) in struct" '+
846 'focus-next="focusNextFirst" copies="copies" allcopies="allcopies" struct="struct">'+
851 scope: { focusNext: "=", allcopies: "=", struct: "=", lib: "@", record: "@", onlyVols: "=" },
852 controller : ['$scope','itemSvc','egCore',
853 function ( $scope , itemSvc , egCore ) {
854 $scope.first_cn = Object.keys($scope.struct)[0];
855 $scope.full_cn = $scope.struct[$scope.first_cn][0].call_number();
857 $scope.defaults = {};
858 egCore.hatch.getItem('cat.copy.defaults').then(function(t) {
864 $scope.focusNextFirst = function(prev_cn,prev_bc) {
867 angular.forEach(Object.keys($scope.struct).sort(), function (cn) {
879 var next = '#' + n + '_' + $scope.struct[n][0].id();
882 if (!itemSvc.currently_generating) el.focus();
883 if (prev_bc && itemSvc.auto_gen_barcode && el.val() == "") {
884 itemSvc.nextBarcode(prev_bc).then(function(bc){
887 el.trigger('change');
890 itemSvc.currently_generating = false;
894 $scope.focusNext($scope.lib, prev_bc);
898 $scope.cn_count = Object.keys($scope.struct).length;
899 $scope.orig_cn_count = $scope.cn_count;
901 $scope.owning_lib = egCore.org.get($scope.lib);
902 $scope.$watch('owning_lib', function (oldLib, newLib) {
903 if (oldLib == newLib) return;
904 angular.forEach( Object.keys($scope.struct), function (cn) {
905 $scope.struct[cn][0].call_number().owning_lib( $scope.owning_lib.id() );
906 $scope.struct[cn][0].call_number().ischanged(1);
910 $scope.cant_have_vols = function (id) { return !egCore.org.CanHaveVolumes(id); };
912 $scope.$watch('cn_count', function (n) {
913 var o = Object.keys($scope.struct).length;
914 if (n > o) { // adding
915 for (var i = o; o < n; o++) {
916 var cn = new egCore.idl.acn();
917 cn.id( --itemSvc.new_cn_id );
919 cn.prefix( $scope.defaults.prefix || -1 );
920 cn.suffix( $scope.defaults.suffix || -1 );
921 cn.label_class( $scope.defaults.classification || 1 );
922 cn.owning_lib( $scope.owning_lib.id() );
923 cn.record( $scope.full_cn.record() );
925 var cp = itemSvc.generateNewCopy(
927 $scope.owning_lib.id(),
932 $scope.struct[cn.id()] = [cp];
933 $scope.allcopies.push(cp);
934 if (!$scope.defaults.classification) {
936 ['cat.default_classification_scheme'],
938 ).then(function (val) {
939 cn.label_class(val['cat.default_classification_scheme']);
943 } else if (n < o && n >= $scope.orig_cn_count) { // removing
944 var how_many = o - n;
947 .sort(function(a, b){return parseInt(a)-parseInt(b)})
948 .filter(function(x){ return parseInt(x) <= 0 });
949 for (var i = 0; i < how_many; i++) {
950 // Trimming the global list is a bit more tricky
951 angular.forEach($scope.struct[list[i]], function (d) {
952 angular.forEach( $scope.allcopies, function (l, j) {
953 if (l === d) $scope.allcopies.splice(j,1);
956 delete $scope.struct[list[i]];
969 .controller('EditCtrl',
970 ['$scope','$q','$window','$routeParams','$location','$timeout','egCore','egNet','egGridDataProvider','itemSvc','$uibModal',
971 function($scope , $q , $window , $routeParams , $location , $timeout , egCore , egNet , egGridDataProvider , itemSvc , $uibModal) {
973 $scope.forms = {}; // Accessed by t_attr_edit.tt2
974 $scope.i18n = egCore.i18n;
976 $scope.defaults = { // If defaults are not set at all, allow everything
977 barcode_checkdigit : false,
978 auto_gen_barcode : false,
984 loan_duration : true,
989 deposit_amount : true,
993 mint_condition : true,
996 circ_modifier : true,
1006 $scope.new_lib_to_add = egCore.org.get(egCore.auth.user().ws_ou());
1007 $scope.changeNewLib = function (org) {
1008 $scope.new_lib_to_add = org;
1010 $scope.addLibToStruct = function () {
1011 var newLib = $scope.new_lib_to_add;
1012 var cn = new egCore.idl.acn();
1013 cn.id( --itemSvc.new_cn_id );
1015 cn.prefix( $scope.defaults.prefix || -1 );
1016 cn.suffix( $scope.defaults.suffix || -1 );
1017 cn.label_class( $scope.defaults.classification || 1 );
1018 cn.owning_lib( newLib.id() );
1019 cn.record( $scope.record_id );
1021 var cp = itemSvc.generateNewCopy(
1028 $scope.data.addCopy(cp);
1030 // manually increase cn_count numeric input
1031 var cn_spinner = $("input[name='cn_count_lib"+ newLib.id() +"']");
1032 cn_spinner.val(parseInt(cn_spinner.val()) + 1);
1033 cn_spinner.trigger("change");
1035 if (!$scope.defaults.classification) {
1036 egCore.org.settings(
1037 ['cat.default_classification_scheme'],
1039 ).then(function (val) {
1040 cn.label_class(val['cat.default_classification_scheme']);
1045 $scope.embedded = ($routeParams.mode && $routeParams.mode == 'embedded') ? true : false;
1046 $scope.edit_templates = ($location.path().match(/edit_template/)) ? true : false;
1048 $scope.saveDefaults = function () {
1049 egCore.hatch.setItem('cat.copy.defaults', $scope.defaults);
1052 $scope.fetchDefaults = function () {
1053 egCore.hatch.getItem('cat.copy.defaults').then(function(t) {
1055 $scope.defaults = t;
1056 if (!$scope.batch) $scope.batch = {};
1057 $scope.batch.classification = $scope.defaults.classification;
1058 $scope.batch.prefix = $scope.defaults.prefix;
1059 $scope.batch.suffix = $scope.defaults.suffix;
1060 $scope.working.statcat_filter = $scope.defaults.statcat_filter;
1062 typeof $scope.defaults.statcat_filter == 'object' &&
1063 Object.keys($scope.defaults.statcat_filter).length > 0
1065 // want fieldmapper object here...
1066 $scope.defaults.statcat_filter =
1067 egCore.idl.Clone($scope.defaults.statcat_filter);
1069 $scope.working.statcat_filter = $scope.defaults.statcat_filter.id();
1071 if ($scope.defaults.always_volumes) $scope.show_vols = true;
1072 if ($scope.defaults.barcode_checkdigit) itemSvc.barcode_checkdigit = true;
1073 if ($scope.defaults.auto_gen_barcode) itemSvc.auto_gen_barcode = true;
1076 // Fetch the list of bib-level callnumbers based on the applied
1077 // classification scheme. If none is defined, default to "1"
1078 // (Generic) since it provides the most options.
1081 'open-ils.cat.biblio.record.marc_cn.retrieve',
1083 $scope.batch.classification || 1
1084 ).then(function(list) {
1085 $scope.batch.marcCallNumbers = [];
1086 list.forEach(function(hash) {
1087 $scope.batch.marcCallNumbers.push(Object.values(hash)[0]);
1093 $scope.$watch('defaults.statcat_filter', function(n,o) {
1095 $scope.saveDefaults();
1097 $scope.$watch('defaults.auto_gen_barcode', function (n,o) {
1098 itemSvc.auto_gen_barcode = n
1101 $scope.$watch('defaults.barcode_checkdigit', function (n,o) {
1102 itemSvc.barcode_checkdigit = n
1105 $scope.dirty = false;
1106 $scope.$watch('dirty',
1107 function(newVal, oldVal) {
1108 if (newVal && newVal != oldVal) {
1109 $($window).on('beforeunload.edit', function(){
1110 return 'There is unsaved data!'
1113 $($window).off('beforeunload.edit');
1118 $scope.only_vols = false;
1119 $scope.show_vols = true;
1120 $scope.show_copies = true;
1122 $scope.tracker = function (x,f) { if (x) return x[f]() };
1123 $scope.idTracker = function (x) { if (x) return $scope.tracker(x,'id') };
1124 $scope.cant_have_vols = function (id) { return !egCore.org.CanHaveVolumes(id); };
1126 $scope.orgById = function (id) { return egCore.org.get(id) }
1127 $scope.statusById = function (id) {
1128 return $scope.status_list.filter( function (s) { return s.id() == id } )[0];
1130 $scope.locationById = function (id) {
1131 return $scope.location_cache[''+id];
1134 $scope.workingToComplete = function () {
1135 angular.forEach( $scope.workingGridControls.selectedItems(), function (c) {
1136 angular.forEach( itemSvc.copies, function (w, i) {
1138 $scope.completed_copies = $scope.completed_copies.concat(itemSvc.copies.splice(i,1));
1145 $scope.completeToWorking = function () {
1146 angular.forEach( $scope.completedGridControls.selectedItems(), function (c) {
1147 angular.forEach( $scope.completed_copies, function (w, i) {
1149 itemSvc.copies = itemSvc.copies.concat($scope.completed_copies.splice(i,1));
1156 createSimpleUpdateWatcher = function (field,exclude_copies_with_one_of_these_values) {
1157 return $scope.$watch('working.' + field, function () {
1158 var newval = $scope.working[field];
1160 if (typeof newval != 'undefined') {
1161 delete $scope.working.MultiMap[field];
1162 if (angular.isObject(newval)) { // we'll use the pkey
1163 if (newval.id) newval = newval.id();
1164 else if (newval.code) newval = newval.code();
1167 if (""+newval == "" || newval == null) {
1168 $scope.working[field] = undefined;
1172 if ($scope.workingGridControls && $scope.workingGridControls.selectedItems) {
1174 $scope.workingGridControls.selectedItems(),
1176 if (exclude_copies_with_one_of_these_values
1177 && exclude_copies_with_one_of_these_values.indexOf(cp[field](),0) > -1) {
1180 if (cp[field]() !== newval) {
1183 $scope.dirty = true;
1196 statcat_filter: undefined
1199 // Returns true if we are editing multiple copies and at least
1200 // one field contains multiple values.
1201 $scope.hasMulti = function() {
1202 var keys = Object.keys($scope.working.MultiMap);
1203 // for-loop for shortcut exit
1204 for (var i = 0; i < keys.length; i++) {
1205 if ($scope.working.MultiMap[keys[i]].length > 1) {
1212 $scope.copyAlertUpdate = function (alerts) {
1213 if (!$scope.in_item_select &&
1214 $scope.workingGridControls &&
1215 $scope.workingGridControls.selectedItems) {
1216 itemSvc.get_copy_alert_types().then(function(ccat) {
1218 $scope.alert_types = ccat;
1219 angular.forEach(ccat, function(t) {
1220 ccat_map[t.id()] = t;
1223 $scope.workingGridControls.selectedItems(),
1225 $scope.dirty = true;
1226 angular.forEach(alerts, function(alrt) {
1227 var a = egCore.idl.fromHash('aca', alrt);
1229 a.create_staff(egCore.auth.user().id());
1230 a.alert_type(ccat_map[a.alert_type()]);
1233 cp.copy_alerts().push( a );
1242 $scope.copyNoteUpdate = function (notes) {
1243 if (!$scope.in_item_select &&
1244 $scope.workingGridControls &&
1245 $scope.workingGridControls.selectedItems) {
1247 $scope.workingGridControls.selectedItems(),
1249 $scope.dirty = true;
1250 angular.forEach(notes, function(note) {
1251 var n = egCore.idl.fromHash('acpn', note);
1253 n.creator(egCore.auth.user().id());
1254 n.owning_copy(cp.id());
1255 cp.notes().push( n );
1264 $scope.statcatUpdate = function (id) {
1265 var newval = $scope.working.statcats[id];
1267 if (typeof newval != 'undefined') {
1268 if (angular.isObject(newval)) { // we'll use the pkey
1269 newval = newval.id();
1272 if (""+newval == "" || newval == null) {
1273 $scope.working.statcats[id] = undefined;
1277 if (!$scope.in_item_select && $scope.workingGridControls && $scope.workingGridControls.selectedItems) {
1279 $scope.workingGridControls.selectedItems(),
1281 $scope.dirty = true;
1283 cp.stat_cat_entries(
1284 angular.forEach( cp.stat_cat_entries(), function (e) {
1285 if (e.stat_cat() == id) { // mark deleted
1292 var e = new egCore.idl.asce();
1297 cp.stat_cat_entries(
1298 cp.stat_cat_entries() ?
1299 cp.stat_cat_entries().concat([ e ]) :
1305 // trim out all deleted ones; the API used to
1306 // do the update doesn't actually consult
1307 // isdeleted for stat cat entries
1308 if (cp.stat_cat_entries()) {
1309 cp.stat_cat_entries(
1310 cp.stat_cat_entries().filter(function (e) {
1311 return !Boolean(e.isdeleted());
1323 var dataKey = $routeParams.dataKey;
1324 console.debug('dataKey: ' + dataKey);
1326 if ((dataKey && dataKey.length > 0) || $scope.edit_templates) {
1328 $scope.templates = {};
1329 $scope.template_name = '';
1330 $scope.template_name_list = [];
1332 $scope.fetchTemplates = function () {
1333 itemSvc.get_acp_templates().then(function(t) {
1335 $scope.templates = t;
1336 $scope.template_name_list = Object.keys(t).sort();
1339 egCore.hatch.getItem('cat.copy.last_template').then(function(t) {
1340 if (t) $scope.template_name = t;
1343 $scope.fetchTemplates();
1345 $scope.applyTemplate = function (n) {
1346 angular.forEach($scope.templates[n], function (v,k) {
1347 if (k == 'circ_lib') {
1348 $scope.working[k] = egCore.org.get(v);
1349 } else if (k == 'copy_notes' && v.length) {
1350 $scope.copyNoteUpdate(v);
1351 } else if (k == 'copy_alerts' && v.length) {
1352 $scope.copyAlertUpdate(v);
1353 } else if (!angular.isObject(v)) {
1354 $scope.working[k] = angular.copy(v);
1356 angular.forEach(v, function (sv,sk) {
1357 if (k == 'callnumber') {
1358 angular.forEach(v, function (cnv,cnk) {
1359 $scope.batch[cnk] = cnv;
1361 $scope.applyBatchCNValues();
1363 $scope.working[k][sk] = angular.copy(sv);
1364 if (k == 'statcats') $scope.statcatUpdate(sk);
1368 delete $scope.working.MultiMap[k];
1370 egCore.hatch.setItem('cat.copy.last_template', n);
1373 $scope.copytab = 'working';
1374 $scope.tab = 'edit';
1375 $scope.summaryRecord = null;
1376 $scope.record_id = null;
1378 $scope.completed_copies = [];
1379 $scope.location_orgs = [];
1380 $scope.location_cache = {};
1381 $scope.statcats = [];
1382 if (!$scope.batch) $scope.batch = {};
1384 $scope.applyBatchCNValues = function () {
1385 if ($scope.data.tree) {
1386 angular.forEach($scope.data.tree, function(cn_hash) {
1387 angular.forEach(cn_hash, function(copies) {
1388 angular.forEach(copies, function(cp) {
1389 if (typeof $scope.batch.classification != 'undefined' && $scope.batch.classification != '') {
1390 var label_class = $scope.classification_list.filter(function(p){ return p.id() == $scope.batch.classification })[0];
1391 cp.call_number().label_class(label_class);
1392 cp.call_number().ischanged(1);
1393 $scope.dirty = true;
1395 if (typeof $scope.batch.prefix != 'undefined' && $scope.batch.prefix != '') {
1396 var prefix = $scope.prefix_list.filter(function(p){ return p.id() == $scope.batch.prefix })[0];
1397 cp.call_number().prefix(prefix);
1398 cp.call_number().ischanged(1);
1399 $scope.dirty = true;
1401 if (typeof $scope.batch.label != 'undefined' && $scope.batch.label != '') {
1402 cp.call_number().label($scope.batch.label);
1403 cp.call_number().ischanged(1);
1404 $scope.dirty = true;
1406 if (typeof $scope.batch.suffix != 'undefined' && $scope.batch.suffix != '') {
1407 var suffix = $scope.suffix_list.filter(function(p){ return p.id() == $scope.batch.suffix })[0];
1408 cp.call_number().suffix(suffix);
1409 cp.call_number().ischanged(1);
1410 $scope.dirty = true;
1418 $scope.clearWorking = function () {
1419 angular.forEach($scope.working, function (v,k,o) {
1420 if (k != 'MultiMap') $scope.working.MultiMap[k] = [];
1421 if (!angular.isObject(v)) {
1422 if (typeof v != 'undefined')
1423 $scope.working[k] = undefined;
1424 } else if (k != 'circ_lib' && k != 'MultiMap') {
1425 angular.forEach(v, function (sv,sk) {
1426 if (typeof v != 'undefined')
1427 $scope.working[k][sk] = undefined;
1431 $scope.working.circ_lib = undefined; // special
1434 $scope.completedGridDataProvider = egGridDataProvider.instance({
1435 get : function(offset, count) {
1436 //return provider.arrayNotifier(itemSvc.copies, offset, count);
1437 return this.arrayNotifier($scope.completed_copies, offset, count);
1441 $scope.completedGridControls = {};
1443 $scope.workingGridDataProvider = egGridDataProvider.instance({
1444 get : function(offset, count) {
1445 //return provider.arrayNotifier(itemSvc.copies, offset, count);
1446 return this.arrayNotifier(itemSvc.copies, offset, count);
1450 $scope.workingGridControls = {};
1451 $scope.add_vols_copies = false;
1452 $scope.is_fast_add = false;
1454 // Generate some functions for selecting items by column value in the working grid
1456 ['circulate','status','circ_lib','ref','location','opac_visible','circ_modifier','price',
1457 'loan_duration','cost','circ_as_type','deposit','holdable','deposit_amount','age_protect',
1458 'mint_condition','fine_level','floating'],
1460 $scope['select_by_' + field] = function (x) {
1461 $scope.workingGridControls.selectItemsByValue(field,x);
1466 var truthy = /^t|1/;
1467 $scope.labelYesNo = function (x) {
1468 return truthy.test(x) ? egCore.strings.YES : egCore.strings.NO;
1471 $scope.orgShortname = function (x) {
1472 return egCore.org.get(x).shortname();
1475 $scope.statusName = function (x) {
1476 var s = $scope.status_list.filter(function(y) {
1483 $scope.locationName = function (x) {
1484 var s = $scope.location_list.filter(function(y) {
1488 return $scope.i18n.ou_qualified_location_name(s[0]);
1491 $scope.durationLabel = function (x) {
1492 return [egCore.strings.SHORT, egCore.strings.NORMAL, egCore.strings.EXTENDED][-1 + x]
1495 $scope.fineLabel = function (x) {
1496 return [egCore.strings.LOW, egCore.strings.NORMAL, egCore.strings.HIGH][-1 + x]
1499 $scope.circTypeValue = function (x) {
1500 if (x === null || x === undefined) return egCore.strings.UNSET;
1501 var s = $scope.circ_type_list.filter(function(y) {
1502 return y.code() == x;
1505 return s[0].value();
1508 $scope.ageprotectName = function (x) {
1509 if (x === null || x === undefined) return egCore.strings.UNSET;
1510 var s = $scope.age_protect_list.filter(function(y) {
1517 $scope.floatingName = function (x) {
1518 if (x === null || x === undefined) return egCore.strings.UNSET;
1519 var s = $scope.floating_list.filter(function(y) {
1526 $scope.circmodName = function (x) {
1527 if (x === null || x === undefined) return egCore.strings.UNSET;
1528 var s = $scope.circ_modifier_list.filter(function(y) {
1529 return y.code() == x;
1537 'open-ils.actor.anon_cache.get_value',
1538 dataKey, 'edit-these-copies'
1539 ).then(function (data) {
1542 if (data.hide_vols && !$scope.defaults.always_volumes) $scope.show_vols = false;
1543 if (data.hide_copies) {
1544 $scope.show_copies = false;
1545 $scope.only_vols = true;
1548 $scope.record_id = data.record_id;
1551 $scope.fetchDefaults();
1553 function fetchRaw () {
1554 if (!$scope.only_vols) $scope.dirty = true;
1555 $scope.add_vols_copies = true;
1557 /* data.raw data structure looks like this:
1559 * callnumber : $cn_id, // optional, to add a copy to a cn
1560 * owner : $org, // optional, defaults to cn.owning_lib or ws_ou
1561 * label : $cn_label, // optional, to supply a label on a new cn
1562 * barcode : $cp_barcode // optional, to supply a barcode on a new cp
1563 * fast_add : boolean // optional, to specify whether this came
1567 * All can be left out and a completely empty vol/copy combo will be vivicated.
1574 if (proto.fast_add) $scope.is_fast_add = true;
1575 if (proto.callnumber) {
1576 promises.push(egCore.pcrud.retrieve('acn', proto.callnumber)
1577 .then(function(cn) {
1578 var cp = new itemSvc.generateNewCopy(
1580 proto.owner || cn.owning_lib(),
1582 ((!$scope.only_vols) ? true : false)
1585 if (proto.barcode) {
1586 cp.barcode( proto.barcode );
1587 cp.empty_barcode = false;
1593 var cn = new egCore.idl.acn();
1594 cn.id( --itemSvc.new_cn_id );
1596 cn.prefix( $scope.defaults.prefix || -1 );
1597 cn.suffix( $scope.defaults.suffix || -1 );
1598 cn.owning_lib( proto.owner || egCore.auth.user().ws_ou() );
1599 cn.record( $scope.record_id );
1600 egCore.org.settings(
1601 ['cat.default_classification_scheme'],
1603 ).then(function (val) {
1605 $scope.defaults.classification ||
1606 val['cat.default_classification_scheme'] ||
1610 cn.label( proto.label );
1614 'open-ils.cat.biblio.record.marc_cn.retrieve',
1617 ).then(function(cn_array) {
1618 if (cn_array.length > 0) {
1619 for (var field in cn_array[0]) {
1620 cn.label( cn_array[0][field] );
1628 // If we are adding an empty vol,
1629 // this is ultimately just a placeholder copy
1630 // which gets removed before saving.
1631 // TODO: consider ways to remove this
1633 var cp = new itemSvc.generateNewCopy(
1635 proto.owner || cn.owning_lib(),
1640 if (proto.barcode) {
1641 cp.barcode( proto.barcode );
1642 cp.empty_barcode = false;
1650 angular.forEach(itemSvc.copies, function(c){
1651 var cn = c.call_number();
1652 var copy_id = c.id();
1654 cn.not_ephemeral = true;
1658 return $q.all(promises);
1661 if (data.copies && data.copies.length)
1662 return itemSvc.fetchIds(data.copies).then(fetchRaw);
1668 }).then( function() {
1670 return itemSvc.fetch_locations(
1671 itemSvc.copies.map(function(cp){
1672 return cp.location();
1673 }).filter(function(e,i,a){
1674 return a.lastIndexOf(e) === i;
1676 ).then(function(list){
1677 $scope.data = itemSvc;
1678 $scope.location_list = list;
1679 $scope.workingGridDataProvider.refresh();
1684 $scope.can_save = false;
1685 function check_saveable () {
1686 var can_save = true;
1691 if (!$scope.only_vols) {
1692 if (i.duplicate_barcode || i.empty_barcode || i.call_number().empty_label) {
1695 } else if (i.call_number().empty_label) {
1701 if (!$scope.only_vols && $scope.forms.myForm && $scope.forms.myForm.$invalid) {
1705 $scope.can_save = can_save;
1708 $scope.disableSave = function () {
1710 return !$scope.can_save;
1713 $scope.focusNextFirst = function(prev_lib,prev_bc) {
1716 angular.forEach(Object.keys($scope.data.tree).sort(), function (lib) {
1719 if (lib == prev_lib) {
1728 var first_cn = Object.keys($scope.data.tree[n])[0];
1729 var next = '#' + first_cn + '_' + $scope.data.tree[n][first_cn][0].id();
1732 if (!itemSvc.currently_generating) el.focus();
1733 if (prev_bc && itemSvc.auto_gen_barcode && el.val() == "") {
1734 itemSvc.nextBarcode(prev_bc).then(function(bc){
1737 el.trigger('change');
1740 itemSvc.currently_generating = false;
1746 $scope.in_item_select = false;
1747 $scope.afterItemSelect = function() { $scope.in_item_select = false };
1748 $scope.handleItemSelect = function (item_list) {
1749 if (item_list && item_list.length > 0) {
1750 $scope.in_item_select = true;
1752 angular.forEach(Object.keys($scope.defaults.attributes), function (attr) {
1754 var value_hash = {};
1755 var value_list = [];
1756 angular.forEach(item_list, function (item) {
1758 var v = item[attr]()
1759 if (angular.isObject(v)) {
1760 if (v.id) v = v.id();
1761 else if (v.code) v = v.code();
1768 $scope.working.MultiMap[attr] = value_list;
1770 if (Object.keys(value_hash).length == 1) {
1771 if (attr == 'circ_lib') {
1772 $scope.working[attr] = egCore.org.get(item_list[0][attr]());
1774 $scope.working[attr] = item_list[0][attr]();
1777 $scope.working[attr] = undefined;
1781 angular.forEach($scope.statcats, function (sc) {
1784 var value_hash = {};
1786 angular.forEach(item_list, function (item) {
1787 if (item.stat_cat_entries()) {
1788 if (item.stat_cat_entries().length > 0) {
1789 var right_sc = item.stat_cat_entries().filter(function (e) {
1790 return e.stat_cat() == sc.id() && !Boolean(e.isdeleted());
1793 if (right_sc.length > 0) {
1794 value_hash[right_sc[0].id()] = right_sc[0].id();
1806 if (!none && Object.keys(value_hash).length == 1) {
1807 $scope.working.statcats[sc.id()] = value_hash[Object.keys(value_hash)[0]];
1808 $scope.working.statcats_multi[sc.id()] = false;
1809 } else if (item_list.length > 1 && Object.keys(value_hash).length > 0) {
1810 $scope.working.statcats[sc.id()] = undefined;
1811 $scope.working.statcats_multi[sc.id()] = true;
1813 $scope.working.statcats[sc.id()] = undefined;
1814 $scope.working.statcats_multi[sc.id()] = false;
1820 $scope.clearWorking();
1825 $scope.$watch('data.copies.length', function () {
1826 if ($scope.data.copies) {
1827 var base_orgs = $scope.data.copies.map(function(cp){
1828 if (isNaN(cp.circ_lib())) return Number(cp.circ_lib().id());
1829 return Number(cp.circ_lib());
1831 $scope.data.copies.map(function(cp){
1832 if (isNaN(cp.call_number().owning_lib())) return Number(cp.call_number().owning_lib().id());
1833 return Number(cp.call_number().owning_lib());
1836 [egCore.auth.user().ws_ou()]
1837 ).filter(function(e,i,a){
1838 return a.lastIndexOf(e) === i;
1842 angular.forEach(base_orgs, function(o) {
1843 all_orgs = all_orgs.concat( egCore.org.fullPath(o, true) );
1846 var final_orgs = all_orgs.filter(function(e,i,a){
1847 return a.lastIndexOf(e) === i;
1848 }).sort(function(a, b){return a-b});
1850 if ($scope.location_orgs.toString() != final_orgs.toString()) {
1851 $scope.location_orgs = final_orgs;
1852 if ($scope.location_orgs.length) {
1853 itemSvc.get_locations_by_org($scope.location_orgs).then(function(list){
1854 angular.forEach(list, function(l) {
1855 $scope.location_cache[ ''+l.id() ] = l;
1857 $scope.location_list = list;
1858 }).then(function() {
1859 $scope.statcat_filter_list = [];
1860 angular.forEach($scope.location_orgs, function (o) {
1861 $scope.statcat_filter_list.push(egCore.org.get(o));
1864 itemSvc.get_statcats($scope.location_orgs).then(function(list){
1865 $scope.statcats = list;
1866 angular.forEach($scope.statcats, function (s) {
1868 if (!$scope.working)
1869 $scope.working = { statcats_multi: {}, statcats: {}, statcat_filter: undefined};
1870 if (!$scope.working.statcats_multi)
1871 $scope.working.statcats_multi = {};
1872 if (!$scope.working.statcats)
1873 $scope.working.statcats = {};
1875 if (!$scope.in_item_select) {
1876 $scope.working.statcats[s.id()] = undefined;
1878 createStatcatUpdateWatcher(s.id());
1880 $scope.in_item_select = false;
1881 // do a refresh here to work around a race
1882 // condition that can result in stat cats
1883 // not being selected.
1884 $scope.workingGridDataProvider.refresh();
1889 $scope.workingGridDataProvider.refresh();
1894 $scope.statcat_visible = function (sc_owner) {
1895 var visible = typeof $scope.working.statcat_filter === 'undefined' || !$scope.working.statcat_filter;
1896 angular.forEach(egCore.org.ancestors(sc_owner), function (ancestor_org) {
1897 if ($scope.working.statcat_filter == ancestor_org.id())
1903 $scope.suffix_list = [];
1904 itemSvc.get_suffixes(egCore.auth.user().ws_ou()).then(function(list){
1905 $scope.suffix_list = list;
1908 $scope.prefix_list = [];
1909 itemSvc.get_prefixes(egCore.auth.user().ws_ou()).then(function(list){
1910 $scope.prefix_list = list;
1913 $scope.classification_list = [];
1914 itemSvc.get_classifications().then(function(list){
1915 $scope.classification_list = list;
1918 $scope.$watch('completed_copies.length', function () {
1919 $scope.completedGridDataProvider.refresh();
1922 $scope.location_list = [];
1923 createSimpleUpdateWatcher('location');
1925 $scope.status_list = [];
1926 itemSvc.get_magic_statuses().then(function(list){
1927 $scope.magic_status_list = list;
1928 createSimpleUpdateWatcher('status',$scope.magic_status_list);
1930 itemSvc.get_statuses().then(function(list){
1931 $scope.status_list = list;
1934 $scope.circ_modifier_list = [];
1935 itemSvc.get_circ_mods().then(function(list){
1936 $scope.circ_modifier_list = list;
1938 createSimpleUpdateWatcher('circ_modifier');
1940 $scope.circ_type_list = [];
1941 itemSvc.get_circ_types().then(function(list){
1942 $scope.circ_type_list = list;
1944 createSimpleUpdateWatcher('circ_as_type');
1946 $scope.age_protect_list = [];
1947 itemSvc.get_age_protects().then(function(list){
1948 $scope.age_protect_list = list;
1950 createSimpleUpdateWatcher('age_protect');
1952 $scope.floating_list = [];
1953 itemSvc.get_floating_groups().then(function(list){
1954 $scope.floating_list = list;
1956 createSimpleUpdateWatcher('floating');
1958 createSimpleUpdateWatcher('circ_lib');
1959 createSimpleUpdateWatcher('circulate');
1960 createSimpleUpdateWatcher('holdable');
1961 createSimpleUpdateWatcher('fine_level');
1962 createSimpleUpdateWatcher('loan_duration');
1963 createSimpleUpdateWatcher('price');
1964 createSimpleUpdateWatcher('cost');
1965 createSimpleUpdateWatcher('deposit');
1966 createSimpleUpdateWatcher('deposit_amount');
1967 createSimpleUpdateWatcher('mint_condition');
1968 createSimpleUpdateWatcher('opac_visible');
1969 createSimpleUpdateWatcher('ref');
1971 $scope.saveCompletedCopies = function (and_exit) {
1973 var perCnCopies = {};
1974 angular.forEach( $scope.completed_copies, function (cp) {
1975 var cn = cp.call_number();
1976 var cn_cps = cp.call_number().copies();
1977 cp.call_number().copies([]);
1978 var cn_id = cp.call_number().id();
1979 cp.call_number(cn_id); // prevent loops in JSON-ification
1980 if (!cnHash[cn_id]) {
1981 cnHash[cn_id] = egCore.idl.Clone(cn);
1982 perCnCopies[cn_id] = [egCore.idl.Clone(cp)];
1984 perCnCopies[cn_id].push(egCore.idl.Clone(cp));
1986 cp.call_number(cn); // put the data back
1987 cp.call_number().copies(cn_cps);
1988 if (typeof cnHash[cn_id].prefix() == 'object')
1989 cnHash[cn_id].prefix(cnHash[cn_id].prefix().id()); // un-object-ize some fields
1990 if (typeof cnHash[cn_id].suffix() == 'object')
1991 cnHash[cn_id].suffix(cnHash[cn_id].suffix().id()); // un-object-ize some fields
1994 if ($scope.only_vols) { // strip off copies when we're in vol-only mode
1995 angular.forEach(cnHash, function (v, k) {
1996 cnHash[k].copies([]);
1999 angular.forEach(perCnCopies, function (v, k) {
2000 cnHash[k].copies(v);
2005 angular.forEach(cnHash, function (v, k) {
2011 'open-ils.cat.asset.volume.fleshed.batch.update.override',
2012 egCore.auth.token(), cnList, 1, { auto_merge_vols : 1, create_parts : 1, return_copy_ids : 1 }
2013 ).then(function(copy_ids) {
2015 $scope.dirty = false;
2016 if ($scope.defaults.print_item_labels) {
2019 'open-ils.actor.anon_cache.set_value',
2020 null, 'print-labels-these-copies', {
2023 ).then(function(key) {
2025 var url = egCore.env.basePath + 'cat/printlabels/' + key;
2026 $timeout(function() { $window.open(url, '_blank') }).then(
2027 function() { $timeout(function(){$window.close()}); }
2030 alert('Could not create anonymous cache key!');
2034 $timeout(function(){
2035 if (typeof BroadcastChannel != 'undefined') {
2036 var bChannel = new BroadcastChannel("eg.holdings.update");
2037 var bre_ids = cnList && cnList.length > 0 ? cnList.map(function(cn){ return Number(cn.record()) }) : [];
2038 var cn_ids = cnList && cnList.length > 0 ? cnList.map(function(cn){ return cn.id() }) : [];
2039 bChannel.postMessage({
2053 $scope.saveAndContinue = function () {
2054 $scope.saveCompletedCopies(false);
2057 $scope.workingSaveAndExit = function () {
2058 $scope.workingToComplete();
2059 $scope.saveAndExit();
2062 $scope.saveAndExit = function () {
2063 $scope.saveCompletedCopies(true);
2068 $scope.copy_notes_dialog = function(copy_list) {
2069 var default_pub = Boolean($scope.defaults.copy_notes_pub);
2070 if (!angular.isArray(copy_list)) copy_list = [copy_list];
2072 return $uibModal.open({
2073 templateUrl: './cat/volcopy/t_copy_notes',
2077 ['$scope','$uibModalInstance',
2078 function($scope , $uibModalInstance) {
2079 $scope.focusNote = true;
2081 creator : egCore.auth.user().id(),
2087 $scope.require_initials = false;
2088 egCore.org.settings([
2089 'ui.staff.require_initials.copy_notes'
2090 ]).then(function(set) {
2091 $scope.require_initials_ous = Boolean(set['ui.staff.require_initials.copy_notes']);
2094 $scope.are_initials_required = function() {
2095 $scope.require_initials = $scope.require_initials_ous && ($scope.note.value.length > 0 || $scope.note.title.length > 0);
2098 $scope.$watch('note.value.length', $scope.are_initials_required);
2099 $scope.$watch('note.title.length', $scope.are_initials_required);
2101 $scope.note_list = [];
2102 if (copy_list.length == 1) {
2103 $scope.note_list = copy_list[0].notes();
2106 $scope.ok = function(note) {
2108 if (note.value.length > 0 || note.title.length > 0) {
2109 if ($scope.initials) {
2110 note.value = egCore.strings.$replace(
2111 egCore.strings.COPY_NOTE_INITIALS, {
2113 initials : $scope.initials,
2114 ws_ou : egCore.org.get(
2115 egCore.auth.user().ws_ou()).shortname()
2119 angular.forEach(copy_list, function (cp) {
2120 if (!angular.isArray(cp.notes())) cp.notes([]);
2121 var n = new egCore.idl.acpn();
2123 n.creator(note.creator);
2124 n.pub(note.pub ? 't' : 'f');
2125 n.title(note.title);
2126 n.value(note.value);
2127 n.owning_copy(cp.id());
2128 cp.notes().push( n );
2132 $uibModalInstance.close();
2135 $scope.cancel = function($event) {
2136 $uibModalInstance.dismiss();
2137 $event.preventDefault();
2143 $scope.copy_tags_dialog = function(copy_list) {
2144 if (!angular.isArray(copy_list)) copy_list = [copy_list];
2146 return $uibModal.open({
2147 templateUrl: './cat/volcopy/t_copy_tags',
2151 ['$scope','$uibModalInstance',
2152 function($scope , $uibModalInstance) {
2154 $scope.tag_map = [];
2156 var shared_tags = {};
2157 angular.forEach(copy_list, function (cp) {
2158 angular.forEach(cp.tags(), function(tag) {
2159 if (!(tag.tag().id() in shared_tags)) {
2160 shared_tags[tag.tag().id()] = 1;
2162 shared_tags[tag.tag().id()]++;
2164 if (!(tag.tag().id() in tag_hash)) {
2165 tag_hash[tag.tag().id()] = tag;
2169 angular.forEach(tag_hash, function(value, key) {
2170 if (shared_tags[key] == copy_list.length) {
2171 $scope.tag_map.push(value);
2175 $scope.tag_types = [];
2176 egCore.pcrud.retrieveAll('cctt', {order_by : { cctt : 'label' }}, {atomic : true}).then(function(list) {
2177 $scope.tag_types = list;
2178 $scope.tag_type = $scope.tag_types[0].code(); // just pick a default
2181 $scope.getTags = function(val) {
2182 return egCore.pcrud.search('acpt',
2184 owner : egCore.org.fullPath(egCore.auth.user().ws_ou(), true),
2185 label : { 'startwith' : {
2186 transform: 'evergreen.lowercase',
2187 value : [ 'evergreen.lowercase', val ]
2189 tag_type : $scope.tag_type
2191 { order_by : { 'acpt' : ['label'] } }, { atomic: true }
2192 ).then(function(list) {
2193 return list.map(function(item) {
2194 return item.label() + " (" + egCore.org.get(item.owner()).shortname() + ")";
2199 $scope.addTag = function() {
2200 var tagLabel = $scope.selectedLabel;
2201 // clear the typeahead
2202 $scope.selectedLabel = "";
2204 // first, check tags already associated with the copy
2205 var foundMatch = false;
2206 angular.forEach($scope.tag_map, function(tag) {
2207 if (tag.tag().label() == tagLabel && tag.tag().tag_type() == $scope.tag_type) {
2209 if (tag.isdeleted()) tag.isdeleted(0); // just deleting the mapping
2213 egCore.pcrud.search('acpt',
2215 owner : egCore.org.fullPath(egCore.auth.user().ws_ou(), true),
2217 tag_type : $scope.tag_type
2219 { order_by : { 'acpt' : ['label'] } }, { atomic: true }
2220 ).then(function(list) {
2221 if (list.length > 0) {
2222 var newMap = new egCore.idl.acptcm();
2224 newMap.copy(copy_list[0].id());
2225 newMap.tag(egCore.idl.Clone(list[0]));
2226 $scope.tag_map.push(newMap);
2228 var newTag = new egCore.idl.acpt();
2230 newTag.owner(egCore.auth.user().ws_ou());
2231 newTag.label(tagLabel);
2233 newTag.tag_type($scope.tag_type);
2235 var newMap = new egCore.idl.acptcm();
2237 newMap.copy(copy_list[0].id());
2239 $scope.tag_map.push(newMap);
2245 $scope.ok = function(note) {
2246 // in the multi-item case, this works OK for
2247 // adding new maps to existing tags, but doesn't handle
2248 // all possibilities
2249 angular.forEach(copy_list, function (cp) {
2250 cp.tags($scope.tag_map);
2252 $uibModalInstance.close();
2255 $scope.cancel = function($event) {
2256 $uibModalInstance.dismiss();
2257 $event.preventDefault();
2263 $scope.copy_alerts_dialog = function(copy_list) {
2264 if (!angular.isArray(copy_list)) copy_list = [copy_list];
2266 return $uibModal.open({
2267 templateUrl: './cat/volcopy/t_copy_alerts',
2270 ['$scope','$uibModalInstance',
2271 function($scope , $uibModalInstance) {
2273 itemSvc.get_copy_alert_types().then(function(ccat) {
2274 $scope.alert_types = ccat;
2277 $scope.focusNote = true;
2278 $scope.copy_alert = {
2279 create_staff : egCore.auth.user().id(),
2284 egCore.hatch.getItem('cat.copy.alerts.last_type').then(function(t) {
2285 if (t) $scope.copy_alert.alert_type = t;
2288 if (copy_list.length == 1) {
2289 $scope.copy_alert_list = copy_list[0].copy_alerts();
2292 $scope.ok = function(copy_alert) {
2294 if (typeof(copy_alert.note) != 'undefined' &&
2295 copy_alert.note != '') {
2296 angular.forEach(copy_list, function (cp) {
2297 var a = new egCore.idl.aca();
2299 a.create_staff(copy_alert.create_staff);
2300 a.note(copy_alert.note);
2301 a.temp(copy_alert.temp ? 't' : 'f');
2305 $scope.alert_types.filter(function(at) {
2306 return at.id() == copy_alert.alert_type;
2309 cp.copy_alerts().push( a );
2312 if (copy_alert.alert_type) {
2313 egCore.hatch.setItem(
2314 'cat.copy.alerts.last_type',
2315 copy_alert.alert_type
2321 $uibModalInstance.close();
2324 $scope.cancel = function($event) {
2325 $uibModalInstance.dismiss();
2326 $event.preventDefault();
2334 .directive("egVolTemplate", function () {
2338 template: '<div ng-include="'+"'/eg/staff/cat/volcopy/t_attr_edit'"+'"></div>',
2342 controller : ['$scope','$window','itemSvc','egCore','ngToast','$uibModal',
2343 function ( $scope , $window , itemSvc , egCore , ngToast , $uibModal) {
2345 $scope.i18n = egCore.i18n;
2347 $scope.defaults = { // If defaults are not set at all, allow everything
2348 barcode_checkdigit : false,
2349 auto_gen_barcode : false,
2356 loan_duration : true,
2361 deposit_amount : true,
2362 opac_visible : true,
2365 mint_condition : true,
2368 circ_modifier : true,
2369 circ_as_type : true,
2377 $scope.fetchDefaults = function () {
2378 egCore.hatch.getItem('cat.copy.defaults').then(function(t) {
2380 $scope.defaults = t;
2381 $scope.working.statcat_filter = $scope.defaults.statcat_filter;
2383 typeof $scope.defaults.statcat_filter == 'object' &&
2384 Object.keys($scope.defaults.statcat_filter).length > 0
2386 // want fieldmapper object here...
2387 $scope.defaults.statcat_filter =
2388 egCore.idl.Clone($scope.defaults.statcat_filter);
2390 $scope.working.statcat_filter = $scope.defaults.statcat_filter.id();
2395 $scope.fetchDefaults();
2397 $scope.dirty = false;
2398 $scope.$watch('dirty',
2399 function(newVal, oldVal) {
2400 if (newVal && newVal != oldVal) {
2401 $($window).on('beforeunload.template', function(){
2402 return 'There is unsaved template data!'
2405 $($window).off('beforeunload.template');
2410 $scope.template_controls = true;
2412 $scope.fetchTemplates = function () {
2413 itemSvc.get_acp_templates().then(function(t) {
2415 $scope.templates = t;
2416 $scope.template_name_list = Object.keys(t).sort();
2420 $scope.fetchTemplates();
2422 $scope.applyTemplate = function (n) {
2423 angular.forEach($scope.templates[n], function (v,k) {
2424 if (k == 'circ_lib') {
2425 $scope.working[k] = egCore.org.get(v);
2426 } else if (angular.isArray(v) || !angular.isObject(v)) {
2427 $scope.working[k] = angular.copy(v);
2429 angular.forEach(v, function (sv,sk) {
2430 if (!(k in $scope.working))
2431 $scope.working[k] = {};
2432 $scope.working[k][sk] = angular.copy(sv);
2436 $scope.template_name = '';
2439 $scope.deleteTemplate = function (n) {
2441 delete $scope.templates[n]
2442 $scope.template_name_list = Object.keys($scope.templates).sort();
2443 $scope.template_name = '';
2444 itemSvc.save_acp_templates($scope.templates);
2445 $scope.$parent.fetchTemplates();
2446 ngToast.create(egCore.strings.VOL_COPY_TEMPLATE_SUCCESS_DELETE);
2450 $scope.saveTemplate = function (n) {
2454 angular.forEach($scope.working, function (v,k) {
2455 if (angular.isObject(v)) { // we'll use the pkey
2456 if (v.id) v = v.id();
2457 else if (v.code) v = v.code();
2458 else v = angular.copy(v); // Should only be statcats and callnumbers currently
2464 $scope.templates[n] = tmpl;
2465 $scope.template_name_list = Object.keys($scope.templates).sort();
2467 itemSvc.save_acp_templates($scope.templates);
2468 $scope.$parent.fetchTemplates();
2470 $scope.dirty = false;
2472 // save all templates, as we might do after an import
2473 itemSvc.save_acp_templates($scope.templates);
2474 $scope.$parent.fetchTemplates();
2476 ngToast.create(egCore.strings.VOL_COPY_TEMPLATE_SUCCESS_SAVE);
2479 $scope.templates = {};
2480 $scope.imported_templates = { data : '' };
2481 $scope.template_name = '';
2482 $scope.template_name_list = [];
2484 $scope.$watch('imported_templates.data', function(newVal, oldVal) {
2485 if (newVal && newVal != oldVal) {
2487 var newTemplates = JSON.parse(newVal);
2488 if (!Object.keys(newTemplates).length) return;
2489 angular.forEach(Object.keys(newTemplates), function (k) {
2490 $scope.templates[k] = newTemplates[k];
2492 itemSvc.save_acp_templates($scope.templates);
2493 $scope.fetchTemplates();
2495 console.log('tried to import an invalid copy template file');
2500 $scope.tracker = function (x,f) { if (x) return x[f]() };
2501 $scope.idTracker = function (x) { if (x) return $scope.tracker(x,'id') };
2502 $scope.cant_have_vols = function (id) { return !egCore.org.CanHaveVolumes(id); };
2504 $scope.orgById = function (id) { return egCore.org.get(id) }
2505 $scope.statusById = function (id) {
2506 return $scope.status_list.filter( function (s) { return s.id() == id } )[0];
2508 $scope.locationById = function (id) {
2509 return $scope.location_cache[''+id];
2512 createSimpleUpdateWatcher = function (field) {
2513 $scope.$watch('working.' + field, function () {
2514 var newval = $scope.working[field];
2516 if (typeof newval != 'undefined') {
2517 $scope.dirty = true;
2518 if (angular.isObject(newval)) { // we'll use the pkey
2519 if (newval.id) $scope.working[field] = newval.id();
2520 else if (newval.code) $scope.working[field] = newval.code();
2523 if (""+newval == "" || newval == null) {
2524 $scope.working[field] = undefined;
2535 statcat_filter: undefined
2538 $scope.statcat_visible = function (sc_owner) {
2539 var visible = typeof $scope.working.statcat_filter === 'undefined' || !$scope.working.statcat_filter;
2540 angular.forEach(egCore.org.ancestors(sc_owner), function (ancestor_org) {
2541 if ($scope.working.statcat_filter == ancestor_org.id())
2547 createStatcatUpdateWatcher = function (id) {
2548 return $scope.$watch('working.statcats[' + id + ']', function () {
2549 if ($scope.working.statcats) {
2550 var newval = $scope.working.statcats[id];
2552 if (typeof newval != 'undefined') {
2553 $scope.dirty = true;
2554 if (angular.isObject(newval)) { // we'll use the pkey
2555 newval = newval.id();
2558 if (""+newval == "" || newval == null) {
2559 $scope.working.statcats[id] = undefined;
2568 $scope.clearWorking = function () {
2569 angular.forEach($scope.working, function (v,k,o) {
2570 if (k != 'MultiMap') $scope.working.MultiMap[k] = [];
2571 $scope.working.MultiMap[k] = [];
2572 if (!angular.isObject(v)) {
2573 if (typeof v != 'undefined')
2574 $scope.working[k] = undefined;
2575 } else if (k != 'circ_lib' && k != 'MultiMap') {
2576 angular.forEach(v, function (sv,sk) {
2577 $scope.working[k][sk] = undefined;
2581 $scope.working.circ_lib = undefined; // special
2582 $scope.dirty = false;
2585 $scope.working = {};
2586 $scope.location_orgs = [];
2587 $scope.location_cache = {};
2589 $scope.location_list = [];
2590 itemSvc.get_locations_by_org(
2591 egCore.org.fullPath( egCore.auth.user().ws_ou(), true )
2592 ).then(function(list){
2593 $scope.location_list = list;
2595 createSimpleUpdateWatcher('location');
2597 $scope.statcat_filter_list = egCore.org.fullPath( egCore.auth.user().ws_ou() );
2599 $scope.statcats = [];
2600 itemSvc.get_statcats(
2601 egCore.org.fullPath( egCore.auth.user().ws_ou(), true )
2602 ).then(function(list){
2603 $scope.statcats = list;
2604 angular.forEach($scope.statcats, function (s) {
2606 if (!$scope.working)
2607 $scope.working = { statcats: {}, statcat_filter: undefined};
2608 if (!$scope.working.statcats)
2609 $scope.working.statcats = {};
2611 $scope.working.statcats[s.id()] = undefined;
2612 createStatcatUpdateWatcher(s.id());
2616 $scope.copy_notes_dialog = function() {
2617 var default_pub = Boolean($scope.defaults.copy_notes_pub);
2618 var working = $scope.working;
2620 return $uibModal.open({
2621 templateUrl: './cat/volcopy/t_copy_notes',
2624 ['$scope','$uibModalInstance',
2625 function($scope , $uibModalInstance) {
2626 $scope.focusNote = true;
2633 $scope.require_initials = false;
2634 egCore.org.settings([
2635 'ui.staff.require_initials.copy_notes'
2636 ]).then(function(set) {
2637 $scope.require_initials = Boolean(set['ui.staff.require_initials.copy_notes']);
2640 $scope.note_list = [];
2641 angular.forEach(working.copy_notes, function(note) {
2642 var acpn = egCore.idl.fromHash('acpn', note);
2643 $scope.note_list.push(acpn);
2646 $scope.ok = function(note) {
2648 if (!working.copy_notes) {
2649 working.copy_notes = [];
2653 working.copy_notes.length = 0;
2654 angular.forEach($scope.note_list, function(existing_note) {
2655 if (!existing_note.isdeleted()) {
2656 working.copy_notes.push({
2657 pub : existing_note.pub() ? 't' : 'f',
2658 title : existing_note.title(),
2659 value : existing_note.value()
2664 // add new note, if any
2665 if (note.initials) note.value += ' [' + note.initials + ']';
2666 note.pub = note.pub ? 't' : 'f';
2667 if (note.title.length && note.value.length) {
2668 working.copy_notes.push(note);
2671 $uibModalInstance.close();
2674 $scope.cancel = function($event) {
2675 $uibModalInstance.dismiss();
2676 $event.preventDefault();
2682 $scope.copy_alerts_dialog = function() {
2683 var working = $scope.working;
2685 return $uibModal.open({
2686 templateUrl: './cat/volcopy/t_copy_alerts',
2689 ['$scope','$uibModalInstance',
2690 function($scope , $uibModalInstance) {
2692 itemSvc.get_copy_alert_types().then(function(ccat) {
2694 $scope.alert_types = ccat;
2695 angular.forEach(ccat, function(t) {
2696 ccat_map[t.id()] = t;
2698 $scope.copy_alert_list = [];
2699 angular.forEach(working.copy_alerts, function (alrt) {
2700 var aca = egCore.idl.fromHash('aca', alrt);
2701 aca.alert_type(ccat_map[alrt.alert_type]);
2703 $scope.copy_alert_list.push(aca);
2707 $scope.focusNote = true;
2708 $scope.copy_alert = {
2713 $scope.ok = function(copy_alert) {
2715 if (!working.copy_alerts) {
2716 working.copy_alerts = [];
2719 working.copy_alerts.length = 0;
2721 angular.forEach($scope.copy_alert_list, function(alrt) {
2722 if (alrt.ack_time() == null) {
2723 working.copy_alerts.push({
2726 alert_type : alrt.alert_type().id()
2731 if (typeof(copy_alert.note) != 'undefined' &&
2732 copy_alert.note != '') {
2733 working.copy_alerts.push({
2734 note : copy_alert.note,
2735 temp : copy_alert.temp ? 't' : 'f',
2736 alert_type : copy_alert.alert_type
2740 $uibModalInstance.close();
2743 $scope.cancel = function($event) {
2744 $uibModalInstance.dismiss();
2745 $event.preventDefault();
2751 $scope.status_list = [];
2752 itemSvc.get_magic_statuses().then(function(list){
2753 $scope.magic_status_list = list;
2755 itemSvc.get_statuses().then(function(list){
2756 $scope.status_list = list;
2758 createSimpleUpdateWatcher('status');
2760 $scope.circ_modifier_list = [];
2761 itemSvc.get_circ_mods().then(function(list){
2762 $scope.circ_modifier_list = list;
2764 createSimpleUpdateWatcher('circ_modifier');
2766 $scope.circ_type_list = [];
2767 itemSvc.get_circ_types().then(function(list){
2768 $scope.circ_type_list = list;
2770 createSimpleUpdateWatcher('circ_as_type');
2772 $scope.age_protect_list = [];
2773 itemSvc.get_age_protects().then(function(list){
2774 $scope.age_protect_list = list;
2776 createSimpleUpdateWatcher('age_protect');
2778 $scope.floating_list = [];
2779 itemSvc.get_floating_groups().then(function(list){
2780 $scope.floating_list = list;
2782 createSimpleUpdateWatcher('floating');
2784 createSimpleUpdateWatcher('circulate');
2785 createSimpleUpdateWatcher('holdable');
2786 createSimpleUpdateWatcher('fine_level');
2787 createSimpleUpdateWatcher('loan_duration');
2788 createSimpleUpdateWatcher('cost');
2789 createSimpleUpdateWatcher('deposit');
2790 createSimpleUpdateWatcher('deposit_amount');
2791 createSimpleUpdateWatcher('mint_condition');
2792 createSimpleUpdateWatcher('opac_visible');
2793 createSimpleUpdateWatcher('ref');
2795 $scope.suffix_list = [];
2796 itemSvc.get_suffixes(egCore.auth.user().ws_ou()).then(function(list){
2797 $scope.suffix_list = list;
2800 $scope.prefix_list = [];
2801 itemSvc.get_prefixes(egCore.auth.user().ws_ou()).then(function(list){
2802 $scope.prefix_list = list;
2805 $scope.classification_list = [];
2806 itemSvc.get_classifications().then(function(list){
2807 $scope.classification_list = list;
2810 createSimpleUpdateWatcher('working.callnumber.classification');
2811 createSimpleUpdateWatcher('working.callnumber.prefix');
2812 createSimpleUpdateWatcher('working.callnumber.suffix');