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;
511 var duplicate_check_count = 0;
513 if (!$scope.copy.barcode()) $scope.copy.empty_barcode = true;
515 $scope.selectOnFocus = function($event) {
516 if (!$scope.copy.empty_barcode)
517 $event.target.select();
520 $scope.nextBarcode = function (i) {
521 $scope.focusNext(i, $scope.barcode);
524 $scope.updateBarcode = function () {
525 if ($scope.barcode != '') {
526 $scope.copy.empty_barcode = $scope.empty_barcode = false;
527 $scope.barcode_has_error = !Boolean(itemSvc.checkBarcode($scope.barcode));
529 var duplicate_check_id = ++duplicate_check_count;
530 itemSvc.checkDuplicateBarcode($scope.barcode, $scope.copy.id())
531 .then(function (state) {
532 if (duplicate_check_id == duplicate_check_count)
533 $scope.copy.duplicate_barcode = $scope.duplicate_barcode = state;
536 $scope.copy.empty_barcode = $scope.empty_barcode = true;
539 $scope.copy.barcode($scope.barcode);
540 $scope.copy.ischanged(1);
541 if (itemSvc.currently_generating)
542 $scope.focusNext($scope.copy.id(), $scope.barcode);
545 $scope.updateCopyNo = function () { $scope.copy.copy_number($scope.copy_number); $scope.copy.ischanged(1); };
546 $scope.updatePart = function () {
548 var p = $scope.part_list.filter(function (x) {
549 return x.label() == $scope.part
551 if (p.length > 0) { // preexisting part
553 } else { // create one...
554 var part = new egCore.idl.bmp();
555 part.id( --$scope.new_part_id );
557 part.label( $scope.part );
558 part.record( $scope.callNumber.record() );
559 $scope.copy.parts([part]);
560 $scope.copy.ischanged(1);
563 $scope.copy.parts([]);
565 $scope.copy.ischanged(1);
569 $scope.part_list = [];
571 itemSvc.get_parts($scope.callNumber.record())
572 .then(function(list){
573 $scope.part_list = list;
574 angular.forEach(list, function(p){ $scope.parts.push(p.label()) });
575 $scope.parts = angular.copy($scope.parts);
577 $scope.$watch('part', $scope.updatePart);
578 if ($scope.copy.parts()) {
579 var the_part = $scope.copy.parts()[0];
580 if (the_part) $scope.part = the_part.label();
584 $scope.barcode = $scope.copy.barcode();
585 $scope.copy_number = $scope.copy.copy_number();
593 .directive("egVolRow", function () {
600 '<div class="col-xs-2">'+
601 '<button aria-label="Delete" style="margin:-5px -15px; float:left;" ng-hide="callNumber.not_ephemeral" type="button" class="close" ng-click="removeCN()">×</button>' +
602 '<select class="form-control" ng-model="classification" ng-change="updateClassification()" ng-options="cl.name() for cl in classification_list"/>'+
604 '<div class="col-xs-1">'+
605 '<select class="form-control" ng-model="prefix" ng-change="updatePrefix()" ng-options="p.label() for p in prefix_list"/>'+
607 '<div class="col-xs-2">'+
608 '<input class="form-control" type="text" ng-change="updateLabel()" ng-model="label"/>'+
609 '<div class="label label-danger" ng-if="empty_label">{{empty_label_string}}</div>'+
611 '<div class="col-xs-1">'+
612 '<select class="form-control" ng-model="suffix" ng-change="updateSuffix()" ng-options="s.label() for s in suffix_list"/>'+
614 '<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>'+
615 '<div ng-hide="onlyVols" class="col-xs-5">'+
616 '<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>'+
620 scope: {focusNext: "=", allcopies: "=", copies: "=", onlyVols: "=", record: "@", struct:"=" },
621 controller : ['$scope','itemSvc','egCore',
622 function ( $scope , itemSvc , egCore ) {
623 $scope.callNumber = $scope.copies[0].call_number();
624 if (!$scope.callNumber.label()) $scope.callNumber.empty_label = true;
626 $scope.empty_label = false;
627 $scope.empty_label_string = window.empty_label_string;
629 $scope.idTracker = function (x) { if (x && x.id) return x.id() };
631 // XXX $() is not working! arg
632 $scope.focusNextBarcode = function (i, prev_bc) {
635 angular.forEach($scope.copies, function (cp) {
643 if (yep) n = cp.id();
647 var next = '#' + $scope.callNumber.id() + '_' + n;
650 if (!itemSvc.currently_generating) el.focus();
651 if (prev_bc && itemSvc.auto_gen_barcode && el.val() == "") {
652 itemSvc.nextBarcode(prev_bc).then(function(bc){
655 el.trigger('change');
658 itemSvc.currently_generating = false;
662 $scope.focusNext($scope.callNumber.id(),prev_bc)
666 $scope.suffix_list = [];
667 itemSvc.get_suffixes($scope.callNumber.owning_lib()).then(function(list){
668 $scope.suffix_list = list;
669 $scope.$watch('callNumber.suffix()', function (v) {
670 if (angular.isObject(v)) v = v.id();
671 $scope.suffix = $scope.suffix_list.filter( function (s) {
677 $scope.updateSuffix = function () {
678 angular.forEach($scope.copies, function(cp) {
679 cp.call_number().suffix($scope.suffix);
680 cp.call_number().ischanged(1);
684 $scope.prefix_list = [];
685 itemSvc.get_prefixes($scope.callNumber.owning_lib()).then(function(list){
686 $scope.prefix_list = list;
687 $scope.$watch('callNumber.prefix()', function (v) {
688 if (angular.isObject(v)) v = v.id();
689 $scope.prefix = $scope.prefix_list.filter(function (p) {
695 $scope.updatePrefix = function () {
696 angular.forEach($scope.copies, function(cp) {
697 cp.call_number().prefix($scope.prefix);
698 cp.call_number().ischanged(1);
701 $scope.$watch('callNumber.owning_lib()', function(oldLib, newLib) {
702 if (oldLib == newLib) return;
703 var currentPrefix = $scope.callNumber.prefix();
704 if (angular.isObject(currentPrefix)) currentPrefix = currentPrefix.id();
705 itemSvc.get_prefixes($scope.callNumber.owning_lib()).then(function(list){
706 $scope.prefix_list = list;
707 var newPrefixId = $scope.prefix_list.filter(function (p) {
708 return p.id() == currentPrefix;
710 if (newPrefixId.id) newPrefixId = newPrefixId.id();
711 $scope.prefix = $scope.prefix_list.filter(function (p) {
712 return p.id() == newPrefixId;
714 if ($scope.newPrefixId != currentPrefix) {
715 $scope.callNumber.prefix($scope.prefix);
718 var currentSuffix = $scope.callNumber.suffix();
719 if (angular.isObject(currentSuffix)) currentSuffix = currentSuffix.id();
720 itemSvc.get_suffixes($scope.callNumber.owning_lib()).then(function(list){
721 $scope.suffix_list = list;
722 var newSuffixId = $scope.suffix_list.filter(function (s) {
723 return s.id() == currentSuffix;
725 if (newSuffixId.id) newSuffixId = newSuffixId.id();
726 $scope.suffix = $scope.suffix_list.filter(function (s) {
727 return s.id() == newSuffixId;
729 if ($scope.newSuffixId != currentSuffix) {
730 $scope.callNumber.suffix($scope.suffix);
735 $scope.classification_list = [];
736 itemSvc.get_classifications().then(function(list){
737 $scope.classification_list = list;
738 $scope.$watch('callNumber.label_class()', function (v) {
739 if (angular.isObject(v)) v = v.id();
740 $scope.classification = $scope.classification_list.filter(function (c) {
746 $scope.updateClassification = function () {
747 angular.forEach($scope.copies, function(cp) {
748 cp.call_number().label_class($scope.classification);
749 cp.call_number().ischanged(1);
753 $scope.updateLabel = function () {
754 angular.forEach($scope.copies, function(cp) {
755 cp.call_number().label($scope.label);
756 cp.call_number().ischanged(1);
760 $scope.$watch('callNumber.label()', function (v) {
762 if ($scope.label == '') {
763 $scope.callNumber.empty_label = $scope.empty_label = true;
765 $scope.callNumber.empty_label = $scope.empty_label = false;
769 $scope.prefix = $scope.callNumber.prefix();
770 $scope.suffix = $scope.callNumber.suffix();
771 $scope.classification = $scope.callNumber.label_class();
772 $scope.label = $scope.callNumber.label();
774 $scope.copy_count = $scope.copies.length;
775 $scope.orig_copy_count = $scope.copy_count;
777 $scope.removeCN = function(){
778 var cn = $scope.callNumber;
779 if (cn.not_ephemeral) return; // can't delete existing volumes
781 angular.forEach(Object.keys($scope.struct), function(k){
782 angular.forEach($scope.struct[k], function(cp){
783 var struct_cn = cp.call_number();
784 if (struct_cn.id() == cn.id()){
785 console.log("X'ed CN id" + cn.id() + " and struct CN id match!");
786 // remove any copies in $scope.struct[k]
787 angular.forEach($scope.copies, function(c){
788 var idx = $scope.allcopies.indexOf(c);
789 $scope.allcopies.splice(idx, 1);
794 delete $scope.struct[k];
799 // manually decrease cn_count numeric input
800 var cn_spinner = $("input[name='cn_count_lib"+ cn.owning_lib() +"']");
801 if (cn_spinner.val() > 0) cn_spinner.val(parseInt(cn_spinner.val()) - 1);
802 cn_spinner.trigger("change");
806 $scope.changeCPCount = function () {
807 while ($scope.copy_count > $scope.copies.length) {
808 var cp = itemSvc.generateNewCopy(
810 $scope.callNumber.owning_lib(),
814 $scope.copies.push( cp );
815 $scope.allcopies.push( cp );
819 if ($scope.copy_count >= $scope.orig_copy_count) {
820 var how_many = $scope.copies.length - $scope.copy_count;
822 var dead = $scope.copies.splice($scope.copy_count,how_many);
823 $scope.callNumber.copies($scope.copies);
825 // Trimming the global list is a bit more tricky
826 angular.forEach( dead, function (d) {
827 angular.forEach( $scope.allcopies, function (l, i) {
828 if (l === d) $scope.allcopies.splice(i,1);
841 .directive("egVolEdit", function () {
847 '<div class="col-xs-1"><eg-org-selector selected="owning_lib" disable-test="cant_have_vols"></eg-org-selector></div>'+
848 '<div class="col-xs-1"><input class="form-control" type="number" min="{{orig_cn_count}}" ng-model="cn_count" ng-change="changeCNCount()"/></div>'+
849 '<div class="col-xs-10">'+
850 '<eg-vol-row only-vols="onlyVols" record="{{record}}"'+
851 'ng-repeat="(cn,copies) in struct" '+
852 'focus-next="focusNextFirst" copies="copies" allcopies="allcopies" struct="struct">'+
857 scope: { focusNext: "=", allcopies: "=", struct: "=", lib: "@", record: "@", onlyVols: "=" },
858 controller : ['$scope','itemSvc','egCore',
859 function ( $scope , itemSvc , egCore ) {
860 $scope.first_cn = Object.keys($scope.struct)[0];
861 $scope.full_cn = $scope.struct[$scope.first_cn][0].call_number();
863 $scope.defaults = {};
864 egCore.hatch.getItem('cat.copy.defaults').then(function(t) {
870 $scope.focusNextFirst = function(prev_cn,prev_bc) {
873 angular.forEach(Object.keys($scope.struct).sort(), function (cn) {
885 var next = '#' + n + '_' + $scope.struct[n][0].id();
888 if (!itemSvc.currently_generating) el.focus();
889 if (prev_bc && itemSvc.auto_gen_barcode && el.val() == "") {
890 itemSvc.nextBarcode(prev_bc).then(function(bc){
893 el.trigger('change');
896 itemSvc.currently_generating = false;
900 $scope.focusNext($scope.lib, prev_bc);
904 $scope.cn_count = Object.keys($scope.struct).length;
905 $scope.orig_cn_count = $scope.cn_count;
907 $scope.owning_lib = egCore.org.get($scope.lib);
908 $scope.$watch('owning_lib', function (oldLib, newLib) {
909 if (oldLib == newLib) return;
910 angular.forEach( Object.keys($scope.struct), function (cn) {
911 $scope.struct[cn][0].call_number().owning_lib( $scope.owning_lib.id() );
912 $scope.struct[cn][0].call_number().ischanged(1);
916 $scope.cant_have_vols = function (id) { return !egCore.org.CanHaveVolumes(id); };
918 $scope.$watch('cn_count', function (n) {
919 var o = Object.keys($scope.struct).length;
920 if (n > o) { // adding
921 for (var i = o; o < n; o++) {
922 var cn = new egCore.idl.acn();
923 cn.id( --itemSvc.new_cn_id );
925 cn.prefix( $scope.defaults.prefix || -1 );
926 cn.suffix( $scope.defaults.suffix || -1 );
927 cn.label_class( $scope.defaults.classification || 1 );
928 cn.owning_lib( $scope.owning_lib.id() );
929 cn.record( $scope.full_cn.record() );
931 var cp = itemSvc.generateNewCopy(
933 $scope.owning_lib.id(),
938 $scope.struct[cn.id()] = [cp];
939 $scope.allcopies.push(cp);
940 if (!$scope.defaults.classification) {
942 ['cat.default_classification_scheme'],
944 ).then(function (val) {
945 cn.label_class(val['cat.default_classification_scheme']);
949 } else if (n < o && n >= $scope.orig_cn_count) { // removing
950 var how_many = o - n;
953 .sort(function(a, b){return parseInt(a)-parseInt(b)})
954 .filter(function(x){ return parseInt(x) <= 0 });
955 for (var i = 0; i < how_many; i++) {
956 // Trimming the global list is a bit more tricky
957 angular.forEach($scope.struct[list[i]], function (d) {
958 angular.forEach( $scope.allcopies, function (l, j) {
959 if (l === d) $scope.allcopies.splice(j,1);
962 delete $scope.struct[list[i]];
975 .controller('EditCtrl',
976 ['$scope','$q','$window','$routeParams','$location','$timeout','egCore','egNet','egGridDataProvider','itemSvc','$uibModal',
977 function($scope , $q , $window , $routeParams , $location , $timeout , egCore , egNet , egGridDataProvider , itemSvc , $uibModal) {
979 $scope.forms = {}; // Accessed by t_attr_edit.tt2
980 $scope.i18n = egCore.i18n;
982 $scope.defaults = { // If defaults are not set at all, allow everything
983 barcode_checkdigit : false,
984 auto_gen_barcode : false,
990 loan_duration : true,
995 deposit_amount : true,
999 mint_condition : true,
1002 circ_modifier : true,
1003 circ_as_type : true,
1012 $scope.new_lib_to_add = egCore.org.get(egCore.auth.user().ws_ou());
1013 $scope.changeNewLib = function (org) {
1014 $scope.new_lib_to_add = org;
1016 $scope.addLibToStruct = function () {
1017 var newLib = $scope.new_lib_to_add;
1018 var cn = new egCore.idl.acn();
1019 cn.id( --itemSvc.new_cn_id );
1021 cn.prefix( $scope.defaults.prefix || -1 );
1022 cn.suffix( $scope.defaults.suffix || -1 );
1023 cn.label_class( $scope.defaults.classification || 1 );
1024 cn.owning_lib( newLib.id() );
1025 cn.record( $scope.record_id );
1027 var cp = itemSvc.generateNewCopy(
1034 $scope.data.addCopy(cp);
1036 // manually increase cn_count numeric input
1037 var cn_spinner = $("input[name='cn_count_lib"+ newLib.id() +"']");
1038 cn_spinner.val(parseInt(cn_spinner.val()) + 1);
1039 cn_spinner.trigger("change");
1041 if (!$scope.defaults.classification) {
1042 egCore.org.settings(
1043 ['cat.default_classification_scheme'],
1045 ).then(function (val) {
1046 cn.label_class(val['cat.default_classification_scheme']);
1051 $scope.embedded = ($routeParams.mode && $routeParams.mode == 'embedded') ? true : false;
1052 $scope.edit_templates = ($location.path().match(/edit_template/)) ? true : false;
1054 $scope.saveDefaults = function () {
1055 egCore.hatch.setItem('cat.copy.defaults', $scope.defaults);
1058 $scope.fetchDefaults = function () {
1059 egCore.hatch.getItem('cat.copy.defaults').then(function(t) {
1061 $scope.defaults = t;
1062 if (!$scope.batch) $scope.batch = {};
1063 $scope.batch.classification = $scope.defaults.classification;
1064 $scope.batch.prefix = $scope.defaults.prefix;
1065 $scope.batch.suffix = $scope.defaults.suffix;
1066 $scope.working.statcat_filter = $scope.defaults.statcat_filter;
1068 typeof $scope.defaults.statcat_filter == 'object' &&
1069 Object.keys($scope.defaults.statcat_filter).length > 0
1071 // want fieldmapper object here...
1072 $scope.defaults.statcat_filter =
1073 egCore.idl.Clone($scope.defaults.statcat_filter);
1075 $scope.working.statcat_filter = $scope.defaults.statcat_filter.id();
1077 if ($scope.defaults.always_volumes) $scope.show_vols = true;
1078 if ($scope.defaults.barcode_checkdigit) itemSvc.barcode_checkdigit = true;
1079 if ($scope.defaults.auto_gen_barcode) itemSvc.auto_gen_barcode = true;
1082 // Fetch the list of bib-level callnumbers based on the applied
1083 // classification scheme. If none is defined, default to "1"
1084 // (Generic) since it provides the most options.
1087 'open-ils.cat.biblio.record.marc_cn.retrieve',
1089 $scope.batch.classification || 1
1090 ).then(function(list) {
1091 $scope.batch.marcCallNumbers = [];
1092 list.forEach(function(hash) {
1093 $scope.batch.marcCallNumbers.push(Object.values(hash)[0]);
1099 $scope.$watch('defaults.statcat_filter', function(n,o) {
1101 $scope.saveDefaults();
1103 $scope.$watch('defaults.auto_gen_barcode', function (n,o) {
1104 itemSvc.auto_gen_barcode = n
1107 $scope.$watch('defaults.barcode_checkdigit', function (n,o) {
1108 itemSvc.barcode_checkdigit = n
1111 $scope.dirty = false;
1112 $scope.$watch('dirty',
1113 function(newVal, oldVal) {
1114 if (newVal && newVal != oldVal) {
1115 $($window).on('beforeunload.edit', function(){
1116 return 'There is unsaved data!'
1119 $($window).off('beforeunload.edit');
1124 $scope.only_vols = false;
1125 $scope.show_vols = true;
1126 $scope.show_copies = true;
1128 $scope.tracker = function (x,f) { if (x) return x[f]() };
1129 $scope.idTracker = function (x) { if (x) return $scope.tracker(x,'id') };
1130 $scope.cant_have_vols = function (id) { return !egCore.org.CanHaveVolumes(id); };
1132 $scope.orgById = function (id) { return egCore.org.get(id) }
1133 $scope.statusById = function (id) {
1134 return $scope.status_list.filter( function (s) { return s.id() == id } )[0];
1136 $scope.locationById = function (id) {
1137 return $scope.location_cache[''+id];
1140 $scope.workingToComplete = function () {
1141 angular.forEach( $scope.workingGridControls.selectedItems(), function (c) {
1142 angular.forEach( itemSvc.copies, function (w, i) {
1144 $scope.completed_copies = $scope.completed_copies.concat(itemSvc.copies.splice(i,1));
1151 $scope.completeToWorking = function () {
1152 angular.forEach( $scope.completedGridControls.selectedItems(), function (c) {
1153 angular.forEach( $scope.completed_copies, function (w, i) {
1155 itemSvc.copies = itemSvc.copies.concat($scope.completed_copies.splice(i,1));
1162 createSimpleUpdateWatcher = function (field,exclude_copies_with_one_of_these_values) {
1163 return $scope.$watch('working.' + field, function () {
1164 var newval = $scope.working[field];
1166 if (typeof newval != 'undefined') {
1167 delete $scope.working.MultiMap[field];
1168 if (angular.isObject(newval)) { // we'll use the pkey
1169 if (newval.id) newval = newval.id();
1170 else if (newval.code) newval = newval.code();
1173 if (""+newval == "" || newval == null) {
1174 $scope.working[field] = undefined;
1178 if ($scope.workingGridControls && $scope.workingGridControls.selectedItems) {
1180 $scope.workingGridControls.selectedItems(),
1182 if (exclude_copies_with_one_of_these_values
1183 && exclude_copies_with_one_of_these_values.indexOf(cp[field](),0) > -1) {
1186 if (cp[field]() !== newval) {
1189 $scope.dirty = true;
1202 statcat_filter: undefined
1205 // Returns true if we are editing multiple copies and at least
1206 // one field contains multiple values.
1207 $scope.hasMulti = function() {
1208 var keys = Object.keys($scope.working.MultiMap);
1209 // for-loop for shortcut exit
1210 for (var i = 0; i < keys.length; i++) {
1211 if ($scope.working.MultiMap[keys[i]] &&
1212 $scope.working.MultiMap[keys[i]].length > 1) {
1219 $scope.copyAlertUpdate = function (alerts) {
1220 if (!$scope.in_item_select &&
1221 $scope.workingGridControls &&
1222 $scope.workingGridControls.selectedItems) {
1223 itemSvc.get_copy_alert_types().then(function(ccat) {
1225 $scope.alert_types = ccat;
1226 angular.forEach(ccat, function(t) {
1227 ccat_map[t.id()] = t;
1230 $scope.workingGridControls.selectedItems(),
1232 if (!angular.isArray(cp.copy_alerts())) cp.copy_alerts([]);
1233 $scope.dirty = true;
1234 angular.forEach(alerts, function(alrt) {
1235 var a = egCore.idl.fromHash('aca', alrt);
1237 a.create_staff(egCore.auth.user().id());
1238 a.alert_type(ccat_map[a.alert_type()]);
1241 cp.copy_alerts().push( a );
1250 $scope.copyNoteUpdate = function (notes) {
1251 if (!$scope.in_item_select &&
1252 $scope.workingGridControls &&
1253 $scope.workingGridControls.selectedItems) {
1255 $scope.workingGridControls.selectedItems(),
1257 if (!angular.isArray(cp.notes())) cp.notes([]);
1258 $scope.dirty = true;
1259 angular.forEach(notes, function(note) {
1260 var n = egCore.idl.fromHash('acpn', note);
1262 n.creator(egCore.auth.user().id());
1263 n.owning_copy(cp.id());
1264 cp.notes().push( n );
1273 $scope.statcatUpdate = function (id) {
1274 var newval = $scope.working.statcats[id];
1276 if (typeof newval != 'undefined') {
1277 if (angular.isObject(newval)) { // we'll use the pkey
1278 newval = newval.id();
1281 if (""+newval == "" || newval == null) {
1282 $scope.working.statcats[id] = undefined;
1286 if (!$scope.in_item_select && $scope.workingGridControls && $scope.workingGridControls.selectedItems) {
1288 $scope.workingGridControls.selectedItems(),
1290 $scope.dirty = true;
1292 cp.stat_cat_entries(
1293 angular.forEach( cp.stat_cat_entries(), function (e) {
1294 if (e.stat_cat() == id) { // mark deleted
1301 var e = new egCore.idl.asce();
1306 cp.stat_cat_entries(
1307 cp.stat_cat_entries() ?
1308 cp.stat_cat_entries().concat([ e ]) :
1314 // trim out all deleted ones; the API used to
1315 // do the update doesn't actually consult
1316 // isdeleted for stat cat entries
1317 if (cp.stat_cat_entries()) {
1318 cp.stat_cat_entries(
1319 cp.stat_cat_entries().filter(function (e) {
1320 return !Boolean(e.isdeleted());
1332 var dataKey = $routeParams.dataKey;
1333 console.debug('dataKey: ' + dataKey);
1335 if ((dataKey && dataKey.length > 0) || $scope.edit_templates) {
1337 $scope.templates = {};
1338 $scope.template_name = '';
1339 $scope.template_name_list = [];
1341 $scope.fetchTemplates = function () {
1342 itemSvc.get_acp_templates().then(function(t) {
1344 $scope.templates = t;
1345 $scope.template_name_list = Object.keys(t).sort();
1348 egCore.hatch.getItem('cat.copy.last_template').then(function(t) {
1349 if (t) $scope.template_name = t;
1352 $scope.fetchTemplates();
1354 $scope.applyTemplate = function (n) {
1355 angular.forEach($scope.templates[n], function (v,k) {
1356 if (k == 'circ_lib') {
1357 $scope.working[k] = egCore.org.get(v);
1358 } else if (k == 'copy_notes' && v.length) {
1359 $scope.copyNoteUpdate(v);
1360 } else if (k == 'copy_alerts' && v.length) {
1361 $scope.copyAlertUpdate(v);
1362 } else if (!angular.isObject(v)) {
1363 $scope.working[k] = angular.copy(v);
1365 angular.forEach(v, function (sv,sk) {
1366 if (k == 'callnumber') {
1367 angular.forEach(v, function (cnv,cnk) {
1368 $scope.batch[cnk] = cnv;
1370 $scope.applyBatchCNValues();
1372 $scope.working[k][sk] = angular.copy(sv);
1373 if (k == 'statcats') $scope.statcatUpdate(sk);
1377 delete $scope.working.MultiMap[k];
1379 egCore.hatch.setItem('cat.copy.last_template', n);
1382 $scope.copytab = 'working';
1383 $scope.tab = 'edit';
1384 $scope.summaryRecord = null;
1385 $scope.record_id = null;
1387 $scope.completed_copies = [];
1388 $scope.location_orgs = [];
1389 $scope.location_cache = {};
1390 $scope.statcats = [];
1391 if (!$scope.batch) $scope.batch = {};
1393 $scope.applyBatchCNValues = function () {
1394 if ($scope.data.tree) {
1395 angular.forEach($scope.data.tree, function(cn_hash) {
1396 angular.forEach(cn_hash, function(copies) {
1397 angular.forEach(copies, function(cp) {
1398 if (typeof $scope.batch.classification != 'undefined' && $scope.batch.classification != '') {
1399 var label_class = $scope.classification_list.filter(function(p){ return p.id() == $scope.batch.classification })[0];
1400 cp.call_number().label_class(label_class);
1401 cp.call_number().ischanged(1);
1402 $scope.dirty = true;
1404 if (typeof $scope.batch.prefix != 'undefined' && $scope.batch.prefix != '') {
1405 var prefix = $scope.prefix_list.filter(function(p){ return p.id() == $scope.batch.prefix })[0];
1406 cp.call_number().prefix(prefix);
1407 cp.call_number().ischanged(1);
1408 $scope.dirty = true;
1410 if (typeof $scope.batch.label != 'undefined' && $scope.batch.label != '') {
1411 cp.call_number().label($scope.batch.label);
1412 cp.call_number().ischanged(1);
1413 $scope.dirty = true;
1415 if (typeof $scope.batch.suffix != 'undefined' && $scope.batch.suffix != '') {
1416 var suffix = $scope.suffix_list.filter(function(p){ return p.id() == $scope.batch.suffix })[0];
1417 cp.call_number().suffix(suffix);
1418 cp.call_number().ischanged(1);
1419 $scope.dirty = true;
1427 $scope.clearWorking = function () {
1428 angular.forEach($scope.working, function (v,k,o) {
1429 if (k != 'MultiMap') $scope.working.MultiMap[k] = [];
1430 if (!angular.isObject(v)) {
1431 if (typeof v != 'undefined')
1432 $scope.working[k] = undefined;
1433 } else if (k != 'circ_lib' && k != 'MultiMap') {
1434 angular.forEach(v, function (sv,sk) {
1435 if (typeof v != 'undefined')
1436 $scope.working[k][sk] = undefined;
1440 $scope.working.circ_lib = undefined; // special
1443 $scope.completedGridDataProvider = egGridDataProvider.instance({
1444 get : function(offset, count) {
1445 //return provider.arrayNotifier(itemSvc.copies, offset, count);
1446 return this.arrayNotifier($scope.completed_copies, offset, count);
1450 $scope.completedGridControls = {};
1452 $scope.workingGridDataProvider = egGridDataProvider.instance({
1453 get : function(offset, count) {
1454 //return provider.arrayNotifier(itemSvc.copies, offset, count);
1455 return this.arrayNotifier(itemSvc.copies, offset, count);
1459 $scope.workingGridControls = {};
1460 $scope.add_vols_copies = false;
1461 $scope.is_fast_add = false;
1463 // Generate some functions for selecting items by column value in the working grid
1465 ['circulate','status','circ_lib','ref','location','opac_visible','circ_modifier','price',
1466 'loan_duration','cost','circ_as_type','deposit','holdable','deposit_amount','age_protect',
1467 'mint_condition','fine_level','floating'],
1469 $scope['select_by_' + field] = function (x) {
1470 $scope.workingGridControls.selectItemsByValue(field,x);
1475 var truthy = /^t|1/;
1476 $scope.labelYesNo = function (x) {
1477 return truthy.test(x) ? egCore.strings.YES : egCore.strings.NO;
1480 $scope.orgShortname = function (x) {
1481 return egCore.org.get(x).shortname();
1484 $scope.statusName = function (x) {
1485 var s = $scope.status_list.filter(function(y) {
1492 $scope.locationName = function (x) {
1493 var s = $scope.location_list.filter(function(y) {
1497 return $scope.i18n.ou_qualified_location_name(s[0]);
1500 $scope.durationLabel = function (x) {
1501 return [egCore.strings.SHORT, egCore.strings.NORMAL, egCore.strings.EXTENDED][-1 + x]
1504 $scope.fineLabel = function (x) {
1505 return [egCore.strings.LOW, egCore.strings.NORMAL, egCore.strings.HIGH][-1 + x]
1508 $scope.circTypeValue = function (x) {
1509 if (x === null || x === undefined) return egCore.strings.UNSET;
1510 var s = $scope.circ_type_list.filter(function(y) {
1511 return y.code() == x;
1514 return s[0].value();
1517 $scope.ageprotectName = function (x) {
1518 if (x === null || x === undefined) return egCore.strings.UNSET;
1519 var s = $scope.age_protect_list.filter(function(y) {
1526 $scope.floatingName = function (x) {
1527 if (x === null || x === undefined) return egCore.strings.UNSET;
1528 var s = $scope.floating_list.filter(function(y) {
1535 $scope.circmodName = function (x) {
1536 if (x === null || x === undefined) return egCore.strings.UNSET;
1537 var s = $scope.circ_modifier_list.filter(function(y) {
1538 return y.code() == x;
1546 'open-ils.actor.anon_cache.get_value',
1547 dataKey, 'edit-these-copies'
1548 ).then(function (data) {
1551 if (data.hide_vols && !$scope.defaults.always_volumes) $scope.show_vols = false;
1552 if (data.hide_copies) {
1553 $scope.show_copies = false;
1554 $scope.only_vols = true;
1557 $scope.record_id = data.record_id;
1560 $scope.fetchDefaults();
1562 function fetchRaw () {
1563 if (!$scope.only_vols) $scope.dirty = true;
1564 $scope.add_vols_copies = true;
1566 /* data.raw data structure looks like this:
1568 * callnumber : $cn_id, // optional, to add a copy to a cn
1569 * owner : $org, // optional, defaults to cn.owning_lib or ws_ou
1570 * label : $cn_label, // optional, to supply a label on a new cn
1571 * barcode : $cp_barcode // optional, to supply a barcode on a new cp
1572 * fast_add : boolean // optional, to specify whether this came
1576 * All can be left out and a completely empty vol/copy combo will be vivicated.
1583 if (proto.fast_add) $scope.is_fast_add = true;
1584 if (proto.callnumber) {
1585 promises.push(egCore.pcrud.retrieve('acn', proto.callnumber)
1586 .then(function(cn) {
1587 var cp = new itemSvc.generateNewCopy(
1589 proto.owner || cn.owning_lib(),
1591 ((!$scope.only_vols) ? true : false)
1594 if (proto.barcode) {
1595 cp.barcode( proto.barcode );
1596 cp.empty_barcode = false;
1602 var cn = new egCore.idl.acn();
1603 cn.id( --itemSvc.new_cn_id );
1605 cn.prefix( $scope.defaults.prefix || -1 );
1606 cn.suffix( $scope.defaults.suffix || -1 );
1607 cn.owning_lib( proto.owner || egCore.auth.user().ws_ou() );
1608 cn.record( $scope.record_id );
1609 egCore.org.settings(
1610 ['cat.default_classification_scheme'],
1612 ).then(function (val) {
1614 $scope.defaults.classification ||
1615 val['cat.default_classification_scheme'] ||
1619 cn.label( proto.label );
1623 'open-ils.cat.biblio.record.marc_cn.retrieve',
1626 ).then(function(cn_array) {
1627 if (cn_array.length > 0) {
1628 for (var field in cn_array[0]) {
1629 cn.label( cn_array[0][field] );
1637 // If we are adding an empty vol,
1638 // this is ultimately just a placeholder copy
1639 // which gets removed before saving.
1640 // TODO: consider ways to remove this
1642 var cp = new itemSvc.generateNewCopy(
1644 proto.owner || cn.owning_lib(),
1649 if (proto.barcode) {
1650 cp.barcode( proto.barcode );
1651 cp.empty_barcode = false;
1659 angular.forEach(itemSvc.copies, function(c){
1660 var cn = c.call_number();
1661 var copy_id = c.id();
1663 cn.not_ephemeral = true;
1667 return $q.all(promises);
1670 if (data.copies && data.copies.length)
1671 return itemSvc.fetchIds(data.copies).then(fetchRaw);
1677 }).then( function() {
1679 return itemSvc.fetch_locations(
1680 itemSvc.copies.map(function(cp){
1681 return cp.location();
1682 }).filter(function(e,i,a){
1683 return a.lastIndexOf(e) === i;
1685 ).then(function(list){
1686 $scope.data = itemSvc;
1687 $scope.location_list = list;
1688 $scope.workingGridDataProvider.refresh();
1693 $scope.can_save = false;
1694 function check_saveable () {
1695 var can_save = true;
1700 if (!$scope.only_vols) {
1701 if (i.duplicate_barcode || i.empty_barcode || i.call_number().empty_label) {
1704 } else if (i.call_number().empty_label) {
1710 if (!$scope.only_vols && $scope.forms.myForm && $scope.forms.myForm.$invalid) {
1714 $scope.can_save = can_save;
1717 $scope.disableSave = function () {
1719 return !$scope.can_save;
1722 $scope.focusNextFirst = function(prev_lib,prev_bc) {
1725 angular.forEach(Object.keys($scope.data.tree).sort(), function (lib) {
1728 if (lib == prev_lib) {
1737 var first_cn = Object.keys($scope.data.tree[n])[0];
1738 var next = '#' + first_cn + '_' + $scope.data.tree[n][first_cn][0].id();
1741 if (!itemSvc.currently_generating) el.focus();
1742 if (prev_bc && itemSvc.auto_gen_barcode && el.val() == "") {
1743 itemSvc.nextBarcode(prev_bc).then(function(bc){
1746 el.trigger('change');
1749 itemSvc.currently_generating = false;
1755 $scope.in_item_select = false;
1756 $scope.afterItemSelect = function() { $scope.in_item_select = false };
1757 $scope.handleItemSelect = function (item_list) {
1758 if (item_list && item_list.length > 0) {
1759 $scope.in_item_select = true;
1761 angular.forEach(Object.keys($scope.defaults.attributes), function (attr) {
1763 var value_hash = {};
1764 var value_list = [];
1765 angular.forEach(item_list, function (item) {
1767 var v = item[attr]()
1768 if (angular.isObject(v)) {
1769 if (v.id) v = v.id();
1770 else if (v.code) v = v.code();
1777 $scope.working.MultiMap[attr] = value_list;
1779 if (Object.keys(value_hash).length == 1) {
1780 if (attr == 'circ_lib') {
1781 $scope.working[attr] = egCore.org.get(item_list[0][attr]());
1783 $scope.working[attr] = item_list[0][attr]();
1786 $scope.working[attr] = undefined;
1790 angular.forEach($scope.statcats, function (sc) {
1793 var value_hash = {};
1795 angular.forEach(item_list, function (item) {
1796 if (item.stat_cat_entries()) {
1797 if (item.stat_cat_entries().length > 0) {
1798 var right_sc = item.stat_cat_entries().filter(function (e) {
1799 return e.stat_cat() == sc.id() && !Boolean(e.isdeleted());
1802 if (right_sc.length > 0) {
1803 value_hash[right_sc[0].id()] = right_sc[0].id();
1815 if (!none && Object.keys(value_hash).length == 1) {
1816 $scope.working.statcats[sc.id()] = value_hash[Object.keys(value_hash)[0]];
1817 $scope.working.statcats_multi[sc.id()] = false;
1818 } else if (item_list.length > 1 && Object.keys(value_hash).length > 0) {
1819 $scope.working.statcats[sc.id()] = undefined;
1820 $scope.working.statcats_multi[sc.id()] = true;
1822 $scope.working.statcats[sc.id()] = undefined;
1823 $scope.working.statcats_multi[sc.id()] = false;
1829 $scope.clearWorking();
1834 $scope.$watch('data.copies.length', function () {
1835 if ($scope.data.copies) {
1836 var base_orgs = $scope.data.copies.map(function(cp){
1837 if (isNaN(cp.circ_lib())) return Number(cp.circ_lib().id());
1838 return Number(cp.circ_lib());
1840 $scope.data.copies.map(function(cp){
1841 if (isNaN(cp.call_number().owning_lib())) return Number(cp.call_number().owning_lib().id());
1842 return Number(cp.call_number().owning_lib());
1845 [egCore.auth.user().ws_ou()]
1846 ).filter(function(e,i,a){
1847 return a.lastIndexOf(e) === i;
1851 angular.forEach(base_orgs, function(o) {
1852 all_orgs = all_orgs.concat( egCore.org.fullPath(o, true) );
1855 var final_orgs = all_orgs.filter(function(e,i,a){
1856 return a.lastIndexOf(e) === i;
1857 }).sort(function(a, b){return a-b});
1859 if ($scope.location_orgs.toString() != final_orgs.toString()) {
1860 $scope.location_orgs = final_orgs;
1861 if ($scope.location_orgs.length) {
1862 itemSvc.get_locations_by_org($scope.location_orgs).then(function(list){
1863 angular.forEach(list, function(l) {
1864 $scope.location_cache[ ''+l.id() ] = l;
1866 $scope.location_list = list;
1867 }).then(function() {
1868 $scope.statcat_filter_list = [];
1869 angular.forEach($scope.location_orgs, function (o) {
1870 $scope.statcat_filter_list.push(egCore.org.get(o));
1873 itemSvc.get_statcats($scope.location_orgs).then(function(list){
1874 $scope.statcats = list;
1875 angular.forEach($scope.statcats, function (s) {
1877 if (!$scope.working)
1878 $scope.working = { statcats_multi: {}, statcats: {}, statcat_filter: undefined};
1879 if (!$scope.working.statcats_multi)
1880 $scope.working.statcats_multi = {};
1881 if (!$scope.working.statcats)
1882 $scope.working.statcats = {};
1884 if (!$scope.in_item_select) {
1885 $scope.working.statcats[s.id()] = undefined;
1887 createStatcatUpdateWatcher(s.id());
1889 $scope.in_item_select = false;
1890 // do a refresh here to work around a race
1891 // condition that can result in stat cats
1892 // not being selected.
1893 $scope.workingGridDataProvider.refresh();
1898 $scope.workingGridDataProvider.refresh();
1903 $scope.statcat_visible = function (sc_owner) {
1904 var visible = typeof $scope.working.statcat_filter === 'undefined' || !$scope.working.statcat_filter;
1905 angular.forEach(egCore.org.ancestors(sc_owner), function (ancestor_org) {
1906 if ($scope.working.statcat_filter == ancestor_org.id())
1912 $scope.suffix_list = [];
1913 itemSvc.get_suffixes(egCore.auth.user().ws_ou()).then(function(list){
1914 $scope.suffix_list = list;
1917 $scope.prefix_list = [];
1918 itemSvc.get_prefixes(egCore.auth.user().ws_ou()).then(function(list){
1919 $scope.prefix_list = list;
1922 $scope.classification_list = [];
1923 itemSvc.get_classifications().then(function(list){
1924 $scope.classification_list = list;
1927 $scope.$watch('completed_copies.length', function () {
1928 $scope.completedGridDataProvider.refresh();
1931 $scope.location_list = [];
1932 createSimpleUpdateWatcher('location');
1934 $scope.status_list = [];
1935 itemSvc.get_magic_statuses().then(function(list){
1936 $scope.magic_status_list = list;
1937 createSimpleUpdateWatcher('status',$scope.magic_status_list);
1939 itemSvc.get_statuses().then(function(list){
1940 $scope.status_list = list;
1943 $scope.circ_modifier_list = [];
1944 itemSvc.get_circ_mods().then(function(list){
1945 $scope.circ_modifier_list = list;
1947 createSimpleUpdateWatcher('circ_modifier');
1949 $scope.circ_type_list = [];
1950 itemSvc.get_circ_types().then(function(list){
1951 $scope.circ_type_list = list;
1953 createSimpleUpdateWatcher('circ_as_type');
1955 $scope.age_protect_list = [];
1956 itemSvc.get_age_protects().then(function(list){
1957 $scope.age_protect_list = list;
1959 createSimpleUpdateWatcher('age_protect');
1961 $scope.floating_list = [];
1962 itemSvc.get_floating_groups().then(function(list){
1963 $scope.floating_list = list;
1965 createSimpleUpdateWatcher('floating');
1967 createSimpleUpdateWatcher('circ_lib');
1968 createSimpleUpdateWatcher('circulate');
1969 createSimpleUpdateWatcher('holdable');
1970 createSimpleUpdateWatcher('fine_level');
1971 createSimpleUpdateWatcher('loan_duration');
1972 createSimpleUpdateWatcher('price');
1973 createSimpleUpdateWatcher('cost');
1974 createSimpleUpdateWatcher('deposit');
1975 createSimpleUpdateWatcher('deposit_amount');
1976 createSimpleUpdateWatcher('mint_condition');
1977 createSimpleUpdateWatcher('opac_visible');
1978 createSimpleUpdateWatcher('ref');
1980 $scope.saveCompletedCopies = function (and_exit) {
1982 var perCnCopies = {};
1983 angular.forEach( $scope.completed_copies, function (cp) {
1984 var cn = cp.call_number();
1985 var cn_cps = cp.call_number().copies();
1986 cp.call_number().copies([]);
1987 var cn_id = cp.call_number().id();
1988 cp.call_number(cn_id); // prevent loops in JSON-ification
1989 if (!cnHash[cn_id]) {
1990 cnHash[cn_id] = egCore.idl.Clone(cn);
1991 perCnCopies[cn_id] = [egCore.idl.Clone(cp)];
1993 perCnCopies[cn_id].push(egCore.idl.Clone(cp));
1995 cp.call_number(cn); // put the data back
1996 cp.call_number().copies(cn_cps);
1997 if (typeof cnHash[cn_id].prefix() == 'object')
1998 cnHash[cn_id].prefix(cnHash[cn_id].prefix().id()); // un-object-ize some fields
1999 if (typeof cnHash[cn_id].suffix() == 'object')
2000 cnHash[cn_id].suffix(cnHash[cn_id].suffix().id()); // un-object-ize some fields
2003 if ($scope.only_vols) { // strip off copies when we're in vol-only mode
2004 angular.forEach(cnHash, function (v, k) {
2005 cnHash[k].copies([]);
2008 angular.forEach(perCnCopies, function (v, k) {
2009 cnHash[k].copies(v);
2014 angular.forEach(cnHash, function (v, k) {
2020 'open-ils.cat.asset.volume.fleshed.batch.update.override',
2021 egCore.auth.token(), cnList, 1, { auto_merge_vols : 1, create_parts : 1, return_copy_ids : 1 }
2022 ).then(function(copy_ids) {
2024 $scope.dirty = false;
2025 if ($scope.defaults.print_item_labels) {
2028 'open-ils.actor.anon_cache.set_value',
2029 null, 'print-labels-these-copies', {
2032 ).then(function(key) {
2034 var url = egCore.env.basePath + 'cat/printlabels/' + key;
2035 $timeout(function() { $window.open(url, '_blank') }).then(
2036 function() { $timeout(function(){$window.close()}); }
2039 alert('Could not create anonymous cache key!');
2043 $timeout(function(){
2044 if (typeof BroadcastChannel != 'undefined') {
2045 var bChannel = new BroadcastChannel("eg.holdings.update");
2046 var bre_ids = cnList && cnList.length > 0 ? cnList.map(function(cn){ return Number(cn.record()) }) : [];
2047 var cn_ids = cnList && cnList.length > 0 ? cnList.map(function(cn){ return cn.id() }) : [];
2048 bChannel.postMessage({
2062 $scope.saveAndContinue = function () {
2063 $scope.saveCompletedCopies(false);
2066 $scope.workingSaveAndExit = function () {
2067 $scope.workingToComplete();
2068 $scope.saveAndExit();
2071 $scope.saveAndExit = function () {
2072 $scope.saveCompletedCopies(true);
2077 $scope.copy_notes_dialog = function(copy_list) {
2078 var default_pub = Boolean($scope.defaults.copy_notes_pub);
2079 if (!angular.isArray(copy_list)) copy_list = [copy_list];
2081 return $uibModal.open({
2082 templateUrl: './cat/volcopy/t_copy_notes',
2086 ['$scope','$uibModalInstance',
2087 function($scope , $uibModalInstance) {
2088 $scope.focusNote = true;
2090 creator : egCore.auth.user().id(),
2096 $scope.require_initials = false;
2097 egCore.org.settings([
2098 'ui.staff.require_initials.copy_notes'
2099 ]).then(function(set) {
2100 $scope.require_initials_ous = Boolean(set['ui.staff.require_initials.copy_notes']);
2103 $scope.are_initials_required = function() {
2104 $scope.require_initials = $scope.require_initials_ous && ($scope.note.value.length > 0 || $scope.note.title.length > 0);
2107 $scope.$watch('note.value.length', $scope.are_initials_required);
2108 $scope.$watch('note.title.length', $scope.are_initials_required);
2110 $scope.note_list = [];
2111 if (copy_list.length == 1) {
2112 $scope.note_list = copy_list[0].notes();
2115 $scope.ok = function(note) {
2117 if (note.value.length > 0 || note.title.length > 0) {
2118 if ($scope.initials) {
2119 note.value = egCore.strings.$replace(
2120 egCore.strings.COPY_NOTE_INITIALS, {
2122 initials : $scope.initials,
2123 ws_ou : egCore.org.get(
2124 egCore.auth.user().ws_ou()).shortname()
2128 angular.forEach(copy_list, function (cp) {
2129 if (!angular.isArray(cp.notes())) cp.notes([]);
2130 var n = new egCore.idl.acpn();
2132 n.creator(note.creator);
2133 n.pub(note.pub ? 't' : 'f');
2134 n.title(note.title);
2135 n.value(note.value);
2136 n.owning_copy(cp.id());
2137 cp.notes().push( n );
2141 $uibModalInstance.close();
2144 $scope.cancel = function($event) {
2145 $uibModalInstance.dismiss();
2146 $event.preventDefault();
2152 $scope.copy_tags_dialog = function(copy_list) {
2153 if (!angular.isArray(copy_list)) copy_list = [copy_list];
2155 return $uibModal.open({
2156 templateUrl: './cat/volcopy/t_copy_tags',
2160 ['$scope','$uibModalInstance',
2161 function($scope , $uibModalInstance) {
2163 $scope.tag_map = [];
2165 var shared_tags = {};
2166 angular.forEach(copy_list, function (cp) {
2167 angular.forEach(cp.tags(), function(tag) {
2168 if (!(tag.tag().id() in shared_tags)) {
2169 shared_tags[tag.tag().id()] = 1;
2171 shared_tags[tag.tag().id()]++;
2173 if (!(tag.tag().id() in tag_hash)) {
2174 tag_hash[tag.tag().id()] = tag;
2178 angular.forEach(tag_hash, function(value, key) {
2179 if (shared_tags[key] == copy_list.length) {
2180 $scope.tag_map.push(value);
2184 $scope.tag_types = [];
2185 egCore.pcrud.retrieveAll('cctt', {order_by : { cctt : 'label' }}, {atomic : true}).then(function(list) {
2186 $scope.tag_types = list;
2187 $scope.tag_type = $scope.tag_types[0].code(); // just pick a default
2190 $scope.getTags = function(val) {
2191 return egCore.pcrud.search('acpt',
2193 owner : egCore.org.fullPath(egCore.auth.user().ws_ou(), true),
2194 label : { 'startwith' : {
2195 transform: 'evergreen.lowercase',
2196 value : [ 'evergreen.lowercase', val ]
2198 tag_type : $scope.tag_type
2200 { order_by : { 'acpt' : ['label'] } }, { atomic: true }
2201 ).then(function(list) {
2202 return list.map(function(item) {
2203 return { value: item.label(), display: item.label() + " (" + egCore.org.get(item.owner()).shortname() + ")" };
2208 $scope.addTag = function() {
2209 var tagLabel = $scope.selectedLabel;
2210 // clear the typeahead
2211 $scope.selectedLabel = "";
2213 // first, check tags already associated with the copy
2214 var foundMatch = false;
2215 angular.forEach($scope.tag_map, function(tag) {
2216 if (tag.tag().label() == tagLabel && tag.tag().tag_type() == $scope.tag_type) {
2218 if (tag.isdeleted()) tag.isdeleted(0); // just deleting the mapping
2222 egCore.pcrud.search('acpt',
2224 owner : egCore.org.fullPath(egCore.auth.user().ws_ou(), true),
2226 tag_type : $scope.tag_type
2228 { order_by : { 'acpt' : ['label'] } }, { atomic: true }
2229 ).then(function(list) {
2230 if (list.length > 0) {
2231 var newMap = new egCore.idl.acptcm();
2233 newMap.copy(copy_list[0].id());
2234 newMap.tag(egCore.idl.Clone(list[0]));
2235 $scope.tag_map.push(newMap);
2237 var newTag = new egCore.idl.acpt();
2239 newTag.owner(egCore.auth.user().ws_ou());
2240 newTag.label(tagLabel);
2242 newTag.tag_type($scope.tag_type);
2244 var newMap = new egCore.idl.acptcm();
2246 newMap.copy(copy_list[0].id());
2248 $scope.tag_map.push(newMap);
2254 $scope.ok = function(note) {
2255 // in the multi-item case, this works OK for
2256 // adding new maps to existing tags, but doesn't handle
2257 // all possibilities
2258 angular.forEach(copy_list, function (cp) {
2259 cp.tags($scope.tag_map);
2261 $uibModalInstance.close();
2264 $scope.cancel = function($event) {
2265 $uibModalInstance.dismiss();
2266 $event.preventDefault();
2272 $scope.copy_alerts_dialog = function(copy_list) {
2273 if (!angular.isArray(copy_list)) copy_list = [copy_list];
2275 return $uibModal.open({
2276 templateUrl: './cat/volcopy/t_copy_alerts',
2279 ['$scope','$uibModalInstance',
2280 function($scope , $uibModalInstance) {
2282 itemSvc.get_copy_alert_types().then(function(ccat) {
2283 $scope.alert_types = ccat;
2286 $scope.focusNote = true;
2287 $scope.copy_alert = {
2288 create_staff : egCore.auth.user().id(),
2293 egCore.hatch.getItem('cat.copy.alerts.last_type').then(function(t) {
2294 if (t) $scope.copy_alert.alert_type = t;
2297 if (copy_list.length == 1) {
2298 $scope.copy_alert_list = copy_list[0].copy_alerts();
2301 $scope.ok = function(copy_alert) {
2303 if (typeof(copy_alert.note) != 'undefined' &&
2304 copy_alert.note != '') {
2305 angular.forEach(copy_list, function (cp) {
2306 if (!angular.isArray(cp.copy_alerts())) cp.copy_alerts([]);
2307 var a = new egCore.idl.aca();
2309 a.create_staff(copy_alert.create_staff);
2310 a.note(copy_alert.note);
2311 a.temp(copy_alert.temp ? 't' : 'f');
2315 $scope.alert_types.filter(function(at) {
2316 return at.id() == copy_alert.alert_type;
2319 cp.copy_alerts().push( a );
2322 if (copy_alert.alert_type) {
2323 egCore.hatch.setItem(
2324 'cat.copy.alerts.last_type',
2325 copy_alert.alert_type
2331 $uibModalInstance.close();
2334 $scope.cancel = function($event) {
2335 $uibModalInstance.dismiss();
2336 $event.preventDefault();
2344 .directive("egVolTemplate", function () {
2348 template: '<div ng-include="'+"'/eg/staff/cat/volcopy/t_attr_edit'"+'"></div>',
2352 controller : ['$scope','$window','itemSvc','egCore','ngToast','$uibModal',
2353 function ( $scope , $window , itemSvc , egCore , ngToast , $uibModal) {
2355 $scope.i18n = egCore.i18n;
2357 $scope.defaults = { // If defaults are not set at all, allow everything
2358 barcode_checkdigit : false,
2359 auto_gen_barcode : false,
2366 loan_duration : true,
2371 deposit_amount : true,
2372 opac_visible : true,
2375 mint_condition : true,
2378 circ_modifier : true,
2379 circ_as_type : true,
2387 $scope.fetchDefaults = function () {
2388 egCore.hatch.getItem('cat.copy.defaults').then(function(t) {
2390 $scope.defaults = t;
2391 $scope.working.statcat_filter = $scope.defaults.statcat_filter;
2393 typeof $scope.defaults.statcat_filter == 'object' &&
2394 Object.keys($scope.defaults.statcat_filter).length > 0
2396 // want fieldmapper object here...
2397 $scope.defaults.statcat_filter =
2398 egCore.idl.Clone($scope.defaults.statcat_filter);
2400 $scope.working.statcat_filter = $scope.defaults.statcat_filter.id();
2405 $scope.fetchDefaults();
2407 $scope.dirty = false;
2408 $scope.$watch('dirty',
2409 function(newVal, oldVal) {
2410 if (newVal && newVal != oldVal) {
2411 $($window).on('beforeunload.template', function(){
2412 return 'There is unsaved template data!'
2415 $($window).off('beforeunload.template');
2420 $scope.template_controls = true;
2422 $scope.fetchTemplates = function () {
2423 itemSvc.get_acp_templates().then(function(t) {
2425 $scope.templates = t;
2426 $scope.template_name_list = Object.keys(t).sort();
2430 $scope.fetchTemplates();
2432 $scope.applyTemplate = function (n) {
2433 angular.forEach($scope.templates[n], function (v,k) {
2434 if (k == 'circ_lib') {
2435 $scope.working[k] = egCore.org.get(v);
2436 } else if (angular.isArray(v) || !angular.isObject(v)) {
2437 $scope.working[k] = angular.copy(v);
2439 angular.forEach(v, function (sv,sk) {
2440 if (!(k in $scope.working))
2441 $scope.working[k] = {};
2442 $scope.working[k][sk] = angular.copy(sv);
2446 $scope.template_name = '';
2449 $scope.deleteTemplate = function (n) {
2451 delete $scope.templates[n]
2452 $scope.template_name_list = Object.keys($scope.templates).sort();
2453 $scope.template_name = '';
2454 itemSvc.save_acp_templates($scope.templates);
2455 $scope.$parent.fetchTemplates();
2456 ngToast.create(egCore.strings.VOL_COPY_TEMPLATE_SUCCESS_DELETE);
2460 $scope.saveTemplate = function (n) {
2464 angular.forEach($scope.working, function (v,k) {
2465 if (angular.isObject(v)) { // we'll use the pkey
2466 if (v.id) v = v.id();
2467 else if (v.code) v = v.code();
2468 else v = angular.copy(v); // Should only be statcats and callnumbers currently
2474 $scope.templates[n] = tmpl;
2475 $scope.template_name_list = Object.keys($scope.templates).sort();
2477 itemSvc.save_acp_templates($scope.templates);
2478 $scope.$parent.fetchTemplates();
2480 $scope.dirty = false;
2482 // save all templates, as we might do after an import
2483 itemSvc.save_acp_templates($scope.templates);
2484 $scope.$parent.fetchTemplates();
2486 ngToast.create(egCore.strings.VOL_COPY_TEMPLATE_SUCCESS_SAVE);
2489 $scope.templates = {};
2490 $scope.imported_templates = { data : '' };
2491 $scope.template_name = '';
2492 $scope.template_name_list = [];
2494 $scope.$watch('imported_templates.data', function(newVal, oldVal) {
2495 if (newVal && newVal != oldVal) {
2497 var newTemplates = JSON.parse(newVal);
2498 if (!Object.keys(newTemplates).length) return;
2499 angular.forEach(Object.keys(newTemplates), function (k) {
2500 $scope.templates[k] = newTemplates[k];
2502 itemSvc.save_acp_templates($scope.templates);
2503 $scope.fetchTemplates();
2505 console.log('tried to import an invalid copy template file');
2510 $scope.tracker = function (x,f) { if (x) return x[f]() };
2511 $scope.idTracker = function (x) { if (x) return $scope.tracker(x,'id') };
2512 $scope.cant_have_vols = function (id) { return !egCore.org.CanHaveVolumes(id); };
2514 $scope.orgById = function (id) { return egCore.org.get(id) }
2515 $scope.statusById = function (id) {
2516 return $scope.status_list.filter( function (s) { return s.id() == id } )[0];
2518 $scope.locationById = function (id) {
2519 return $scope.location_cache[''+id];
2522 createSimpleUpdateWatcher = function (field) {
2523 $scope.$watch('working.' + field, function () {
2524 var newval = $scope.working[field];
2526 if (typeof newval != 'undefined') {
2527 $scope.dirty = true;
2528 if (angular.isObject(newval)) { // we'll use the pkey
2529 if (newval.id) $scope.working[field] = newval.id();
2530 else if (newval.code) $scope.working[field] = newval.code();
2533 if (""+newval == "" || newval == null) {
2534 $scope.working[field] = undefined;
2545 statcat_filter: undefined
2548 $scope.statcat_visible = function (sc_owner) {
2549 var visible = typeof $scope.working.statcat_filter === 'undefined' || !$scope.working.statcat_filter;
2550 angular.forEach(egCore.org.ancestors(sc_owner), function (ancestor_org) {
2551 if ($scope.working.statcat_filter == ancestor_org.id())
2557 createStatcatUpdateWatcher = function (id) {
2558 return $scope.$watch('working.statcats[' + id + ']', function () {
2559 if ($scope.working.statcats) {
2560 var newval = $scope.working.statcats[id];
2562 if (typeof newval != 'undefined') {
2563 $scope.dirty = true;
2564 if (angular.isObject(newval)) { // we'll use the pkey
2565 newval = newval.id();
2568 if (""+newval == "" || newval == null) {
2569 $scope.working.statcats[id] = undefined;
2578 $scope.clearWorking = function () {
2579 angular.forEach($scope.working, function (v,k,o) {
2580 if (!angular.isObject(v)) {
2581 if (typeof v != 'undefined')
2582 $scope.working[k] = undefined;
2583 } else if (k != 'circ_lib' && k != 'MultiMap') {
2584 angular.forEach(v, function (sv,sk) {
2585 $scope.working[k][sk] = undefined;
2589 $scope.working.circ_lib = undefined; // special
2590 $scope.dirty = false;
2593 $scope.working = {};
2594 $scope.location_orgs = [];
2595 $scope.location_cache = {};
2597 $scope.location_list = [];
2598 itemSvc.get_locations_by_org(
2599 egCore.org.fullPath( egCore.auth.user().ws_ou(), true )
2600 ).then(function(list){
2601 $scope.location_list = list;
2603 createSimpleUpdateWatcher('location');
2605 $scope.statcat_filter_list = egCore.org.fullPath( egCore.auth.user().ws_ou() );
2607 $scope.statcats = [];
2608 itemSvc.get_statcats(
2609 egCore.org.fullPath( egCore.auth.user().ws_ou(), true )
2610 ).then(function(list){
2611 $scope.statcats = list;
2612 angular.forEach($scope.statcats, function (s) {
2614 if (!$scope.working)
2615 $scope.working = { statcats: {}, statcat_filter: undefined};
2616 if (!$scope.working.statcats)
2617 $scope.working.statcats = {};
2619 $scope.working.statcats[s.id()] = undefined;
2620 createStatcatUpdateWatcher(s.id());
2624 $scope.copy_notes_dialog = function() {
2625 var default_pub = Boolean($scope.defaults.copy_notes_pub);
2626 var working = $scope.working;
2628 return $uibModal.open({
2629 templateUrl: './cat/volcopy/t_copy_notes',
2632 ['$scope','$uibModalInstance',
2633 function($scope , $uibModalInstance) {
2634 $scope.focusNote = true;
2641 $scope.require_initials = false;
2642 egCore.org.settings([
2643 'ui.staff.require_initials.copy_notes'
2644 ]).then(function(set) {
2645 $scope.require_initials = Boolean(set['ui.staff.require_initials.copy_notes']);
2648 $scope.note_list = [];
2649 angular.forEach(working.copy_notes, function(note) {
2650 var acpn = egCore.idl.fromHash('acpn', note);
2651 $scope.note_list.push(acpn);
2654 $scope.ok = function(note) {
2656 if (!working.copy_notes) {
2657 working.copy_notes = [];
2661 working.copy_notes.length = 0;
2662 angular.forEach($scope.note_list, function(existing_note) {
2663 if (!existing_note.isdeleted()) {
2664 working.copy_notes.push({
2665 pub : existing_note.pub() ? 't' : 'f',
2666 title : existing_note.title(),
2667 value : existing_note.value()
2672 // add new note, if any
2673 if (note.initials) note.value += ' [' + note.initials + ']';
2674 note.pub = note.pub ? 't' : 'f';
2675 if (note.title.length && note.value.length) {
2676 working.copy_notes.push(note);
2679 $uibModalInstance.close();
2682 $scope.cancel = function($event) {
2683 $uibModalInstance.dismiss();
2684 $event.preventDefault();
2690 $scope.copy_alerts_dialog = function() {
2691 var working = $scope.working;
2693 return $uibModal.open({
2694 templateUrl: './cat/volcopy/t_copy_alerts',
2697 ['$scope','$uibModalInstance',
2698 function($scope , $uibModalInstance) {
2700 itemSvc.get_copy_alert_types().then(function(ccat) {
2702 $scope.alert_types = ccat;
2703 angular.forEach(ccat, function(t) {
2704 ccat_map[t.id()] = t;
2706 $scope.copy_alert_list = [];
2707 angular.forEach(working.copy_alerts, function (alrt) {
2708 var aca = egCore.idl.fromHash('aca', alrt);
2709 aca.alert_type(ccat_map[alrt.alert_type]);
2711 $scope.copy_alert_list.push(aca);
2715 $scope.focusNote = true;
2716 $scope.copy_alert = {
2721 $scope.ok = function(copy_alert) {
2723 if (!working.copy_alerts) {
2724 working.copy_alerts = [];
2727 working.copy_alerts.length = 0;
2729 angular.forEach($scope.copy_alert_list, function(alrt) {
2730 if (alrt.ack_time() == null) {
2731 working.copy_alerts.push({
2734 alert_type : alrt.alert_type().id()
2739 if (typeof(copy_alert.note) != 'undefined' &&
2740 copy_alert.note != '') {
2741 working.copy_alerts.push({
2742 note : copy_alert.note,
2743 temp : copy_alert.temp ? 't' : 'f',
2744 alert_type : copy_alert.alert_type
2748 $uibModalInstance.close();
2751 $scope.cancel = function($event) {
2752 $uibModalInstance.dismiss();
2753 $event.preventDefault();
2759 $scope.status_list = [];
2760 itemSvc.get_magic_statuses().then(function(list){
2761 $scope.magic_status_list = list;
2763 itemSvc.get_statuses().then(function(list){
2764 $scope.status_list = list;
2766 createSimpleUpdateWatcher('status');
2768 $scope.circ_modifier_list = [];
2769 itemSvc.get_circ_mods().then(function(list){
2770 $scope.circ_modifier_list = list;
2772 createSimpleUpdateWatcher('circ_modifier');
2774 $scope.circ_type_list = [];
2775 itemSvc.get_circ_types().then(function(list){
2776 $scope.circ_type_list = list;
2778 createSimpleUpdateWatcher('circ_as_type');
2780 $scope.age_protect_list = [];
2781 itemSvc.get_age_protects().then(function(list){
2782 $scope.age_protect_list = list;
2784 createSimpleUpdateWatcher('age_protect');
2786 $scope.floating_list = [];
2787 itemSvc.get_floating_groups().then(function(list){
2788 $scope.floating_list = list;
2790 createSimpleUpdateWatcher('floating');
2792 createSimpleUpdateWatcher('circulate');
2793 createSimpleUpdateWatcher('holdable');
2794 createSimpleUpdateWatcher('fine_level');
2795 createSimpleUpdateWatcher('loan_duration');
2796 createSimpleUpdateWatcher('cost');
2797 createSimpleUpdateWatcher('deposit');
2798 createSimpleUpdateWatcher('deposit_amount');
2799 createSimpleUpdateWatcher('mint_condition');
2800 createSimpleUpdateWatcher('opac_visible');
2801 createSimpleUpdateWatcher('ref');
2803 $scope.suffix_list = [];
2804 itemSvc.get_suffixes(egCore.auth.user().ws_ou()).then(function(list){
2805 $scope.suffix_list = list;
2808 $scope.prefix_list = [];
2809 itemSvc.get_prefixes(egCore.auth.user().ws_ou()).then(function(list){
2810 $scope.prefix_list = list;
2813 $scope.classification_list = [];
2814 itemSvc.get_classifications().then(function(list){
2815 $scope.classification_list = list;
2818 createSimpleUpdateWatcher('working.callnumber.classification');
2819 createSimpleUpdateWatcher('working.callnumber.prefix');
2820 createSimpleUpdateWatcher('working.callnumber.suffix');