5 angular.module('egVolCopy',
6 ['ngRoute', 'ui.bootstrap', 'egCoreMod', 'egUiMod', 'egGridMod'])
8 .filter('boolText', function(){
14 .config(['ngToastProvider', function(ngToastProvider) {
15 ngToastProvider.configure({
16 verticalPosition: 'bottom',
21 .config(function($routeProvider, $locationProvider, $compileProvider) {
22 $locationProvider.html5Mode(true);
23 $compileProvider.aHrefSanitizationWhitelist(/^\s*(https?|mailto|blob):/); // grid export
26 delay : ['egStartup', function(egStartup) { return egStartup.go(); }]
29 $routeProvider.when('/cat/volcopy/edit_templates', {
30 templateUrl: './cat/volcopy/t_view',
31 controller: 'EditCtrl',
35 $routeProvider.when('/cat/volcopy/:dataKey', {
36 templateUrl: './cat/volcopy/t_view',
37 controller: 'EditCtrl',
41 $routeProvider.when('/cat/volcopy/:dataKey/:mode', {
42 templateUrl: './cat/volcopy/t_view',
43 controller: 'EditCtrl',
50 function(egCore , $q) {
53 currently_generating : false,
54 auto_gen_barcode : false,
55 barcode_checkdigit : false,
58 tree : {}, // holds lib->cn->copy hash stack
59 copies : [] // raw copy list
62 service.nextBarcode = function(bc) {
63 service.currently_generating = true;
64 return egCore.net.request(
66 'open-ils.cat.item.barcode.autogen',
68 bc, 1, { checkdigit: service.barcode_checkdigit }
69 ).then(function(resp) { // get_barcodes
70 var evt = egCore.evt.parse(resp);
71 if (!evt) return resp[0];
76 service.checkBarcode = function(bc) {
77 if (!service.barcode_checkdigit) return true;
78 if (bc != Number(bc)) return false;
80 // "16.00" == Number("16.00"), but the . is bad.
81 // Throw out any barcode that isn't just digits
82 if (bc.search(/\D/) != -1) return false;
83 var last_digit = bc.substr(bc.length-1);
84 var stripped_barcode = bc.substr(0,bc.length-1);
85 return service.barcodeCheckdigit(stripped_barcode).toString() == last_digit;
88 service.barcodeCheckdigit = function(bc) {
89 var reverse_barcode = bc.toString().split('').reverse();
90 var check_sum = 0; var multiplier = 2;
91 for (var i = 0; i < reverse_barcode.length; i++) {
92 var digit = reverse_barcode[i];
93 var product = digit * multiplier; product = product.toString();
95 for (var j = 0; j < product.length; j++) {
96 temp_sum += Number( product[j] );
98 check_sum += Number( temp_sum );
99 multiplier = ( multiplier == 2 ? 1 : 2 );
101 check_sum = check_sum.toString();
102 var next_multiple_of_10 = (check_sum.match(/(\d*)\d$/)[1] * 10) + 10;
103 var check_digit = next_multiple_of_10 - Number(check_sum); if (check_digit == 10) check_digit = 0;
107 // returns a promise resolved with the list of circ mods
108 service.get_classifications = function() {
110 return $q.when(egCore.env.acnc.list);
112 return egCore.pcrud.retrieveAll('acnc', null, {atomic : true})
113 .then(function(list) {
114 egCore.env.absorbList(list, 'acnc');
119 service.get_prefixes = function(org) {
120 return egCore.pcrud.search('acnp',
121 {owning_lib : egCore.org.fullPath(org, true)},
122 {order_by : { acnp : 'label_sortkey' }}, {atomic : true}
127 service.get_statcats = function(orgs) {
128 return egCore.pcrud.search('asc',
132 asc : ['owner','entries']
139 service.get_locations = function(orgs) {
140 return egCore.pcrud.search('acpl',
141 {owning_lib : orgs, deleted : 'f'},
145 acpl : ['owning_lib']
147 order_by : { acpl : 'name' }
153 service.get_suffixes = function(org) {
154 return egCore.pcrud.search('acns',
155 {owning_lib : egCore.org.fullPath(org, true)},
156 {order_by : { acns : 'label_sortkey' }}, {atomic : true}
161 service.get_magic_statuses = function() {
162 /* TODO: make these more configurable per lp1616170 */
167 ,8 /* On holds shelf */
168 ,16 /* Long overdue */
169 ,18 /* Canceled Transit */
173 service.get_statuses = function() {
175 return $q.when(egCore.env.ccs.list);
177 return egCore.pcrud.retrieveAll('ccs', {order_by : { ccs : 'name' }}, {atomic : true}).then(
179 egCore.env.absorbList(list, 'ccs');
186 service.get_circ_mods = function() {
188 return $q.when(egCore.env.ccm.list);
190 return egCore.pcrud.retrieveAll('ccm', {}, {atomic : true}).then(
192 egCore.env.absorbList(list, 'ccm');
199 service.get_circ_types = function() {
201 return $q.when(egCore.env.citm.list);
203 return egCore.pcrud.retrieveAll('citm', {}, {atomic : true}).then(
205 egCore.env.absorbList(list, 'citm');
212 service.get_age_protects = function() {
213 if (egCore.env.crahp)
214 return $q.when(egCore.env.crahp.list);
216 return egCore.pcrud.retrieveAll('crahp', {}, {atomic : true}).then(
218 egCore.env.absorbList(list, 'crahp');
225 service.get_floating_groups = function() {
227 return $q.when(egCore.env.cfg.list);
229 return egCore.pcrud.retrieveAll('cfg', {}, {atomic : true}).then(
231 egCore.env.absorbList(list, 'cfg');
238 service.bmp_parts = {};
239 service.get_parts = function(rec) {
240 if (service.bmp_parts[rec])
241 return $q.when(service.bmp_parts[rec]);
243 return egCore.pcrud.search('bmp',
244 {record : rec, deleted : 'f'},
245 null, {atomic : true}
246 ).then(function(list) {
247 service.bmp_parts[rec] = list;
253 service.get_acp_templates = function() {
254 // Already downloaded for this user? Return local copy. Changing users or logging out causes another download
255 // so users always have their own templates, and any changes made on other machines appear as expected.
256 if (egCore.hatch.getSessionItem('cat.copy.templates.usr') == egCore.auth.user().id()) {
257 return egCore.hatch.getItem('cat.copy.templates').then(function(templ) {
261 // this can be disabled for debugging to force a re-download and translation of test templates
262 egCore.hatch.setSessionItem('cat.copy.templates.usr', egCore.auth.user().id());
263 return service.load_remote_acp_templates();
268 service.save_acp_templates = function(t) {
269 egCore.hatch.setItem('cat.copy.templates', t);
270 egCore.net.request('open-ils.actor', 'open-ils.actor.patron.settings.update',
271 egCore.auth.token(), egCore.auth.user().id(), { "webstaff.cat.copy.templates": t });
272 // console.warn('Saved ' + JSON.stringify({"webstaff.cat.copy.templates": t}));
275 service.load_remote_acp_templates = function() {
276 // After the XUL Client is completely removed everything related to staff_client.copy_editor.templates and convert_xul_templates can be thrown away.
277 return egCore.net.request('open-ils.actor', 'open-ils.actor.patron.settings.retrieve.authoritative',
278 egCore.auth.token(), egCore.auth.user().id(),
279 ['webstaff.cat.copy.templates','staff_client.copy_editor.templates']).then(function(settings) {
280 if (settings['webstaff.cat.copy.templates']) {
281 egCore.hatch.setItem('cat.copy.templates', settings['webstaff.cat.copy.templates']);
282 return settings['webstaff.cat.copy.templates'];
284 if (settings['staff_client.copy_editor.templates']) {
285 var new_templ = service.convert_xul_templates(settings['staff_client.copy_editor.templates']);
286 egCore.hatch.setItem('cat.copy.templates', new_templ);
287 // console.warn('Saving: ' + JSON.stringify({'webstaff.cat.copy.templates' : new_templ}));
288 egCore.net.request('open-ils.actor', 'open-ils.actor.patron.settings.update',
289 egCore.auth.token(), egCore.auth.user().id(), {'webstaff.cat.copy.templates' : new_templ});
297 service.convert_xul_templates = function(xultempl) {
299 var templ_names = Object.keys(xultempl);
311 for (i=0; i < templ_names.length; i++) {
312 name = templ_names[i];
315 xul_t = xultempl[name];
316 fields = Object.keys(xul_t);
318 if (fields.length > 0) {
319 for (j=0; j < fields.length; j++) {
320 field_name = fields[j];
321 curr_field = xul_t[field_name];
323 if ( curr_field["field"] == null ) { continue; }
324 if ( curr_field["value"] == "<HACK:KLUDGE:NULL>" ) { continue; }
326 // floating changed from a boolean to an integer at one point; take this opportunity to remove the boolean from any old templates
327 if ( curr_field["type"] === "attribute" && curr_field["field"] === "floating" ) {
328 if ( curr_field["value"].match(/[tf]/) ) { continue; }
331 if ( curr_field["type"] === "stat_cat" ) {
332 stat_cats[curr_field["field"]] = parseInt(curr_field["value"]);
335 tmp_val = curr_field['value']; // so... some of the number fields are actually strings. Groovy.
336 if ( tmp_val.match(/^[-0-9.]+$/) && !(curr_field["field"].match(/(?:loan_duration|fine_level)/))) { tmp_val = parseFloat(tmp_val); }
337 curr_templ[curr_field["field"]] = tmp_val;
341 if ( (Object.keys(stat_cats)).length > 0 ){
342 curr_templ["statcats"] = stat_cats;
345 conv_templ[name] = curr_templ;
355 acp : ['call_number','parts','stat_cat_entries', 'notes', 'tags'],
356 acn : ['label_class','prefix','suffix'],
361 service.addCopy = function (cp) {
363 if (!cp.parts()) cp.parts([]); // just in case...
365 var lib = cp.call_number().owning_lib();
366 var cn = cp.call_number().id();
368 if (!service.tree[lib]) service.tree[lib] = {};
369 if (!service.tree[lib][cn]) service.tree[lib][cn] = [];
371 service.tree[lib][cn].push(cp);
372 service.copies.push(cp);
375 service.checkDuplicateBarcode = function(bc, id) {
377 return egCore.pcrud.search('acp', { deleted : 'f', 'barcode' : bc, id : { '!=' : id } })
379 function () { return final },
380 function () { return final },
381 function () { final = true; }
385 service.fetchIds = function(idList) {
386 service.tree = {}; // clear the tree on fetch
387 service.copies = []; // clear the copy list on fetch
388 return egCore.pcrud.search('acp', { 'id' : idList }, service.flesh).then(null,null,
390 service.addCopy(copy);
395 // create a new acp object with default values
396 // (both hard-coded and coming from OU settings)
397 service.generateNewCopy = function(callNumber, owningLib, isFastAdd, isNew) {
398 var cp = new egCore.idl.acp();
399 cp.id( --service.new_cp_id );
403 cp.circ_lib( owningLib );
404 cp.call_number( callNumber );
407 cp.deposit_amount(0);
408 cp.fine_level(2); // Normal
409 cp.loan_duration(2); // Normal
410 cp.location(1); // Stacks
413 cp.opac_visible('t');
415 cp.mint_condition('t');
416 cp.empty_barcode = true;
418 var status_setting = isFastAdd ?
419 'cat.default_copy_status_fast' :
420 'cat.default_copy_status_normal';
424 ).then(function(set) {
425 var default_ccs = parseInt(set[status_setting]);
426 if (isNaN(default_ccs))
427 default_ccs = (isFastAdd ? 0 : 5); // 0 is Available, 5 is In Process
428 cp.status(default_ccs);
437 .directive('stringToNumber', function() {
440 link: function(scope, element, attrs, ngModel) {
441 var precision = attrs.precision || 0;
442 ngModel.$parsers.push(function(value) {
446 function updateDisplay() {
447 var value = parseFloat(ngModel.$viewValue);
448 if ( isNaN(value) ) { return; }
449 element.val(value.toFixed(precision));
452 ngModel.$formatters.push(function(value) {
453 return parseFloat(value);
456 ngModel.$viewChangeListeners.push(updateDisplay);
458 ngModel.$render = function() {
465 .directive("egVolCopyEdit", function () {
471 '<div class="col-xs-5" ng-class="{'+"'has-error'"+':barcode_has_error}">'+
472 '<input id="{{callNumber.id()}}_{{copy.id()}}"'+
473 ' eg-enter="nextBarcode(copy.id())" class="form-control"'+
474 ' type="text" ng-model="barcode" ng-change="updateBarcode()"/>'+
475 '<div class="label label-danger" ng-if="duplicate_barcode">{{duplicate_barcode_string}}</div>'+
476 '<div class="label label-danger" ng-if="empty_barcode">{{empty_barcode_string}}</div>'+
478 '<div class="col-xs-3"><input class="form-control" type="number" min="1" ng-model="copy_number" ng-change="updateCopyNo()"/></div>'+
479 '<div class="col-xs-4"><eg-basic-combo-box eg-disabled="record == 0" list="parts" selected="part"></eg-basic-combo-box></div>'+
482 scope: { focusNext: "=", copy: "=", callNumber: "=", index: "@", record: "@" },
483 controller : ['$scope','itemSvc','egCore',
484 function ( $scope , itemSvc , egCore ) {
485 $scope.new_part_id = 0;
486 $scope.barcode_has_error = false;
487 $scope.duplicate_barcode = false;
488 $scope.empty_barcode = false;
489 $scope.duplicate_barcode_string = window.duplicate_barcode_string;
490 $scope.empty_barcode_string = window.empty_barcode_string;
492 if (!$scope.copy.barcode()) $scope.copy.empty_barcode = true;
494 $scope.nextBarcode = function (i) {
495 $scope.focusNext(i, $scope.barcode);
498 $scope.updateBarcode = function () {
499 if ($scope.barcode != '') {
500 $scope.copy.empty_barcode = $scope.empty_barcode = false;
501 $scope.barcode_has_error = !Boolean(itemSvc.checkBarcode($scope.barcode));
502 itemSvc.checkDuplicateBarcode($scope.barcode, $scope.copy.id())
503 .then(function (state) { $scope.copy.duplicate_barcode = $scope.duplicate_barcode = state });
505 $scope.copy.empty_barcode = $scope.empty_barcode = true;
508 $scope.copy.barcode($scope.barcode);
509 $scope.copy.ischanged(1);
510 if (itemSvc.currently_generating)
511 $scope.focusNext($scope.copy.id(), $scope.barcode);
514 $scope.updateCopyNo = function () { $scope.copy.copy_number($scope.copy_number); $scope.copy.ischanged(1); };
515 $scope.updatePart = function () {
517 var p = $scope.part_list.filter(function (x) {
518 return x.label() == $scope.part
520 if (p.length > 0) { // preexisting part
522 } else { // create one...
523 var part = new egCore.idl.bmp();
524 part.id( --$scope.new_part_id );
526 part.label( $scope.part );
527 part.record( $scope.callNumber.record() );
528 $scope.copy.parts([part]);
529 $scope.copy.ischanged(1);
532 $scope.copy.parts([]);
534 $scope.copy.ischanged(1);
536 $scope.$watch('part', $scope.updatePart);
538 $scope.barcode = $scope.copy.barcode();
539 $scope.copy_number = $scope.copy.copy_number();
541 if ($scope.copy.parts()) {
542 $scope.part = $scope.copy.parts()[0];
543 if ($scope.part) $scope.part = $scope.part.label();
547 $scope.part_list = [];
549 itemSvc.get_parts($scope.callNumber.record()).then(function(list){
550 $scope.part_list = list;
551 angular.forEach(list, function(p){ $scope.parts.push(p.label()) });
552 $scope.parts = angular.copy($scope.parts);
561 .directive("egVolRow", function () {
568 '<div class="col-xs-2">'+
569 '<select ng-disabled="record == 0" class="form-control" ng-model="classification" ng-change="updateClassification()" ng-options="cl.name() for cl in classification_list"/>'+
571 '<div class="col-xs-1">'+
572 '<select ng-disabled="record == 0" class="form-control" ng-model="prefix" ng-change="updatePrefix()" ng-options="p.label() for p in prefix_list"/>'+
574 '<div class="col-xs-2">'+
575 '<input ng-disabled="record == 0" class="form-control" type="text" ng-change="updateLabel()" ng-model="label"/>'+
576 '<div class="label label-danger" ng-if="empty_label">{{empty_label_string}}</div>'+
578 '<div class="col-xs-1">'+
579 '<select ng-disabled="record == 0" class="form-control" ng-model="suffix" ng-change="updateSuffix()" ng-options="s.label() for s in suffix_list"/>'+
581 '<div ng-hide="onlyVols" class="col-xs-1"><input ng-disabled="record == 0" class="form-control" type="number" ng-model="copy_count" min="{{orig_copy_count}}" ng-change="changeCPCount()"></div>'+
582 '<div ng-hide="onlyVols" class="col-xs-5">'+
583 '<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>'+
587 scope: {focusNext: "=", allcopies: "=", copies: "=", onlyVols: "=", record: "@" },
588 controller : ['$scope','itemSvc','egCore',
589 function ( $scope , itemSvc , egCore ) {
590 $scope.callNumber = $scope.copies[0].call_number();
591 if (!$scope.callNumber.label()) $scope.callNumber.emtpy_label = true;
593 $scope.empty_label = false;
594 $scope.empty_label_string = window.empty_label_string;
596 $scope.idTracker = function (x) { if (x && x.id) return x.id() };
598 // XXX $() is not working! arg
599 $scope.focusNextBarcode = function (i, prev_bc) {
602 angular.forEach($scope.copies, function (cp) {
610 if (yep) n = cp.id();
614 var next = '#' + $scope.callNumber.id() + '_' + n;
617 if (!itemSvc.currently_generating) el.focus();
618 if (prev_bc && itemSvc.auto_gen_barcode && el.val() == "") {
619 itemSvc.nextBarcode(prev_bc).then(function(bc){
622 el.trigger('change');
625 itemSvc.currently_generating = false;
629 $scope.focusNext($scope.callNumber.id(),prev_bc)
633 $scope.suffix_list = [];
634 itemSvc.get_suffixes($scope.callNumber.owning_lib()).then(function(list){
635 $scope.suffix_list = list;
636 $scope.$watch('callNumber.suffix()', function (v) {
637 if (angular.isObject(v)) v = v.id();
638 $scope.suffix = $scope.suffix_list.filter( function (s) {
644 $scope.updateSuffix = function () {
645 angular.forEach($scope.copies, function(cp) {
646 cp.call_number().suffix($scope.suffix);
647 cp.call_number().ischanged(1);
651 $scope.prefix_list = [];
652 itemSvc.get_prefixes($scope.callNumber.owning_lib()).then(function(list){
653 $scope.prefix_list = list;
654 $scope.$watch('callNumber.prefix()', function (v) {
655 if (angular.isObject(v)) v = v.id();
656 $scope.prefix = $scope.prefix_list.filter(function (p) {
662 $scope.updatePrefix = function () {
663 angular.forEach($scope.copies, function(cp) {
664 cp.call_number().prefix($scope.prefix);
665 cp.call_number().ischanged(1);
668 $scope.$watch('callNumber.owning_lib()', function(oldLib, newLib) {
669 if (oldLib == newLib) return;
670 var currentPrefix = $scope.callNumber.prefix();
671 if (angular.isObject(currentPrefix)) currentPrefix = currentPrefix.id();
672 itemSvc.get_prefixes($scope.callNumber.owning_lib()).then(function(list){
673 $scope.prefix_list = list;
674 var newPrefixId = $scope.prefix_list.filter(function (p) {
675 return p.id() == currentPrefix;
677 if (newPrefixId.id) newPrefixId = newPrefixId.id();
678 $scope.prefix = $scope.prefix_list.filter(function (p) {
679 return p.id() == newPrefixId;
681 if ($scope.newPrefixId != currentPrefix) {
682 $scope.callNumber.prefix($scope.prefix);
685 var currentSuffix = $scope.callNumber.suffix();
686 if (angular.isObject(currentSuffix)) currentSuffix = currentSuffix.id();
687 itemSvc.get_suffixes($scope.callNumber.owning_lib()).then(function(list){
688 $scope.suffix_list = list;
689 var newSuffixId = $scope.suffix_list.filter(function (s) {
690 return s.id() == currentSuffix;
692 if (newSuffixId.id) newSuffixId = newSuffixId.id();
693 $scope.suffix = $scope.suffix_list.filter(function (s) {
694 return s.id() == newSuffixId;
696 if ($scope.newSuffixId != currentSuffix) {
697 $scope.callNumber.suffix($scope.suffix);
702 $scope.classification_list = [];
703 itemSvc.get_classifications().then(function(list){
704 $scope.classification_list = list;
705 $scope.$watch('callNumber.label_class()', function (v) {
706 if (angular.isObject(v)) v = v.id();
707 $scope.classification = $scope.classification_list.filter(function (c) {
713 $scope.updateClassification = function () {
714 angular.forEach($scope.copies, function(cp) {
715 cp.call_number().label_class($scope.classification);
716 cp.call_number().ischanged(1);
720 $scope.updateLabel = function () {
721 if ($scope.label == '') {
722 $scope.callNumber.empty_label = $scope.empty_label = true;
724 $scope.callNumber.empty_label = $scope.empty_label = false;
726 angular.forEach($scope.copies, function(cp) {
727 cp.call_number().label($scope.label);
728 cp.call_number().ischanged(1);
732 $scope.$watch('callNumber.label()', function (v) {
736 $scope.prefix = $scope.callNumber.prefix();
737 $scope.suffix = $scope.callNumber.suffix();
738 $scope.classification = $scope.callNumber.label_class();
739 $scope.label = $scope.callNumber.label();
741 $scope.copy_count = $scope.copies.length;
742 $scope.orig_copy_count = $scope.copy_count;
744 $scope.changeCPCount = function () {
745 while ($scope.copy_count > $scope.copies.length) {
746 var cp = itemSvc.generateNewCopy(
748 $scope.callNumber.owning_lib(),
752 $scope.copies.push( cp );
753 $scope.allcopies.push( cp );
757 if ($scope.copy_count >= $scope.orig_copy_count) {
758 var how_many = $scope.copies.length - $scope.copy_count;
760 var dead = $scope.copies.splice($scope.copy_count,how_many);
761 $scope.callNumber.copies($scope.copies);
763 // Trimming the global list is a bit more tricky
764 angular.forEach( dead, function (d) {
765 angular.forEach( $scope.allcopies, function (l, i) {
766 if (l === d) $scope.allcopies.splice(i,1);
779 .directive("egVolEdit", function () {
785 '<div class="col-xs-1"><eg-org-selector alldisabled="{{record == 0}}" selected="owning_lib" disable-test="cant_have_vols"></eg-org-selector></div>'+
786 '<div class="col-xs-1"><input ng-disabled="record == 0" class="form-control" type="number" min="{{orig_cn_count}}" ng-model="cn_count" ng-change="changeCNCount()"/></div>'+
787 '<div class="col-xs-10">'+
788 '<eg-vol-row only-vols="onlyVols" record="{{record}}"'+
789 'ng-repeat="(cn,copies) in struct" '+
790 'focus-next="focusNextFirst" copies="copies" allcopies="allcopies">'+
795 scope: { focusNext: "=", allcopies: "=", struct: "=", lib: "@", record: "@", onlyVols: "=" },
796 controller : ['$scope','itemSvc','egCore',
797 function ( $scope , itemSvc , egCore ) {
798 $scope.first_cn = Object.keys($scope.struct)[0];
799 $scope.full_cn = $scope.struct[$scope.first_cn][0].call_number();
801 $scope.defaults = {};
802 egCore.hatch.getItem('cat.copy.defaults').then(function(t) {
808 $scope.focusNextFirst = function(prev_cn,prev_bc) {
811 angular.forEach(Object.keys($scope.struct).sort(), function (cn) {
823 var next = '#' + n + '_' + $scope.struct[n][0].id();
826 if (!itemSvc.currently_generating) el.focus();
827 if (prev_bc && itemSvc.auto_gen_barcode && el.val() == "") {
828 itemSvc.nextBarcode(prev_bc).then(function(bc){
831 el.trigger('change');
834 itemSvc.currently_generating = false;
838 $scope.focusNext($scope.lib, prev_bc);
842 $scope.cn_count = Object.keys($scope.struct).length;
843 $scope.orig_cn_count = $scope.cn_count;
845 $scope.owning_lib = egCore.org.get($scope.lib);
846 $scope.$watch('owning_lib', function (oldLib, newLib) {
847 if (oldLib == newLib) return;
848 angular.forEach( Object.keys($scope.struct), function (cn) {
849 $scope.struct[cn][0].call_number().owning_lib( $scope.owning_lib.id() );
850 $scope.struct[cn][0].call_number().ischanged(1);
854 $scope.cant_have_vols = function (id) { return !egCore.org.CanHaveVolumes(id); };
856 $scope.$watch('cn_count', function (n) {
857 var o = Object.keys($scope.struct).length;
858 if (n > o) { // adding
859 for (var i = o; o < n; o++) {
860 var cn = new egCore.idl.acn();
861 cn.id( --itemSvc.new_cn_id );
863 cn.prefix( $scope.defaults.prefix || -1 );
864 cn.suffix( $scope.defaults.suffix || -1 );
865 cn.label_class( $scope.defaults.classification || 1 );
866 cn.owning_lib( $scope.owning_lib.id() );
867 cn.record( $scope.full_cn.record() );
869 var cp = itemSvc.generateNewCopy(
871 $scope.owning_lib.id(),
876 $scope.struct[cn.id()] = [cp];
877 $scope.allcopies.push(cp);
878 if (!$scope.defaults.classification) {
880 ['cat.default_classification_scheme'],
882 ).then(function (val) {
883 cn.label_class(val['cat.default_classification_scheme']);
887 } else if (n < o && n >= $scope.orig_cn_count) { // removing
888 var how_many = o - n;
891 .sort(function(a, b){return parseInt(a)-parseInt(b)})
892 .filter(function(x){ return parseInt(x) <= 0 });
893 for (var i = 0; i < how_many; i++) {
894 // Trimming the global list is a bit more tricky
895 angular.forEach($scope.struct[list[i]], function (d) {
896 angular.forEach( $scope.allcopies, function (l, j) {
897 if (l === d) $scope.allcopies.splice(j,1);
900 delete $scope.struct[list[i]];
913 .controller('EditCtrl',
914 ['$scope','$q','$window','$routeParams','$location','$timeout','egCore','egNet','egGridDataProvider','itemSvc','$uibModal',
915 function($scope , $q , $window , $routeParams , $location , $timeout , egCore , egNet , egGridDataProvider , itemSvc , $uibModal) {
917 $scope.forms = {}; // Accessed by t_attr_edit.tt2
918 $scope.i18n = egCore.i18n;
920 $scope.defaults = { // If defaults are not set at all, allow everything
921 barcode_checkdigit : false,
922 auto_gen_barcode : false,
928 loan_duration : true,
933 deposit_amount : true,
937 mint_condition : true,
940 circ_modifier : true,
950 $scope.new_lib_to_add = egCore.org.get(egCore.auth.user().ws_ou());
951 $scope.changeNewLib = function (org) {
952 $scope.new_lib_to_add = org;
954 $scope.addLibToStruct = function () {
955 var newLib = $scope.new_lib_to_add;
956 var cn = new egCore.idl.acn();
957 cn.id( --itemSvc.new_cn_id );
959 cn.prefix( $scope.defaults.prefix || -1 );
960 cn.suffix( $scope.defaults.suffix || -1 );
961 cn.label_class( $scope.defaults.classification || 1 );
962 cn.owning_lib( newLib.id() );
963 cn.record( $scope.record_id );
965 var cp = itemSvc.generateNewCopy(
972 $scope.data.addCopy(cp);
974 if (!$scope.defaults.classification) {
976 ['cat.default_classification_scheme'],
978 ).then(function (val) {
979 cn.label_class(val['cat.default_classification_scheme']);
984 $scope.embedded = ($routeParams.mode && $routeParams.mode == 'embedded') ? true : false;
985 $scope.edit_templates = ($location.path().match(/edit_template/)) ? true : false;
987 $scope.saveDefaults = function () {
988 egCore.hatch.setItem('cat.copy.defaults', $scope.defaults);
991 $scope.fetchDefaults = function () {
992 egCore.hatch.getItem('cat.copy.defaults').then(function(t) {
995 if (!$scope.batch) $scope.batch = {};
996 $scope.batch.classification = $scope.defaults.classification;
997 $scope.batch.prefix = $scope.defaults.prefix;
998 $scope.batch.suffix = $scope.defaults.suffix;
999 $scope.working.statcat_filter = $scope.defaults.statcat_filter;
1001 typeof $scope.defaults.statcat_filter == 'object' &&
1002 Object.keys($scope.defaults.statcat_filter).length > 0
1004 // want fieldmapper object here...
1005 $scope.defaults.statcat_filter =
1006 egCore.idl.Clone($scope.defaults.statcat_filter);
1008 $scope.working.statcat_filter = $scope.defaults.statcat_filter.id();
1010 if ($scope.defaults.always_volumes) $scope.show_vols = true;
1011 if ($scope.defaults.barcode_checkdigit) itemSvc.barcode_checkdigit = true;
1012 if ($scope.defaults.auto_gen_barcode) itemSvc.auto_gen_barcode = true;
1016 $scope.fetchDefaults();
1018 $scope.$watch('defaults.statcat_filter', function() {
1019 $scope.saveDefaults();
1021 $scope.$watch('defaults.auto_gen_barcode', function (n,o) {
1022 itemSvc.auto_gen_barcode = n
1025 $scope.$watch('defaults.barcode_checkdigit', function (n,o) {
1026 itemSvc.barcode_checkdigit = n
1029 $scope.dirty = false;
1030 $scope.$watch('dirty',
1031 function(newVal, oldVal) {
1032 if (newVal && newVal != oldVal) {
1033 $($window).on('beforeunload.edit', function(){
1034 return 'There is unsaved data!'
1037 $($window).off('beforeunload.edit');
1042 $scope.only_vols = false;
1043 $scope.show_vols = true;
1044 $scope.show_copies = true;
1046 $scope.tracker = function (x,f) { if (x) return x[f]() };
1047 $scope.idTracker = function (x) { if (x) return $scope.tracker(x,'id') };
1048 $scope.cant_have_vols = function (id) { return !egCore.org.CanHaveVolumes(id); };
1050 $scope.orgById = function (id) { return egCore.org.get(id) }
1051 $scope.statusById = function (id) {
1052 return $scope.status_list.filter( function (s) { return s.id() == id } )[0];
1054 $scope.locationById = function (id) {
1055 return $scope.location_cache[''+id];
1058 $scope.workingToComplete = function () {
1059 angular.forEach( $scope.workingGridControls.selectedItems(), function (c) {
1060 angular.forEach( itemSvc.copies, function (w, i) {
1062 $scope.completed_copies = $scope.completed_copies.concat(itemSvc.copies.splice(i,1));
1069 $scope.completeToWorking = function () {
1070 angular.forEach( $scope.completedGridControls.selectedItems(), function (c) {
1071 angular.forEach( $scope.completed_copies, function (w, i) {
1073 itemSvc.copies = itemSvc.copies.concat($scope.completed_copies.splice(i,1));
1080 createSimpleUpdateWatcher = function (field,exclude_copies_with_one_of_these_values) {
1081 return $scope.$watch('working.' + field, function () {
1082 var newval = $scope.working[field];
1084 if (typeof newval != 'undefined') {
1085 if (angular.isObject(newval)) { // we'll use the pkey
1086 if (newval.id) newval = newval.id();
1087 else if (newval.code) newval = newval.code();
1090 if (""+newval == "" || newval == null) {
1091 $scope.working[field] = undefined;
1095 if ($scope.workingGridControls && $scope.workingGridControls.selectedItems) {
1097 $scope.workingGridControls.selectedItems(),
1099 if (exclude_copies_with_one_of_these_values
1100 && exclude_copies_with_one_of_these_values.indexOf(cp[field](),0) > -1) {
1103 if (cp[field]() !== newval) {
1106 $scope.dirty = true;
1117 statcat_filter: undefined
1120 $scope.statcatUpdate = function (id) {
1121 var newval = $scope.working.statcats[id];
1123 if (typeof newval != 'undefined') {
1124 if (angular.isObject(newval)) { // we'll use the pkey
1125 newval = newval.id();
1128 if (""+newval == "" || newval == null) {
1129 $scope.working.statcats[id] = undefined;
1133 if (!$scope.in_item_select && $scope.workingGridControls && $scope.workingGridControls.selectedItems) {
1135 $scope.workingGridControls.selectedItems(),
1137 $scope.dirty = true;
1139 cp.stat_cat_entries(
1140 angular.forEach( cp.stat_cat_entries(), function (e) {
1141 if (e.stat_cat() == id) { // mark deleted
1148 var e = new egCore.idl.asce();
1153 cp.stat_cat_entries(
1154 cp.stat_cat_entries() ?
1155 cp.stat_cat_entries().concat([ e ]) :
1161 // trim out all deleted ones; the API used to
1162 // do the update doesn't actually consult
1163 // isdeleted for stat cat entries
1164 cp.stat_cat_entries(
1165 cp.stat_cat_entries().filter(function (e) {
1166 return !Boolean(e.isdeleted());
1177 var dataKey = $routeParams.dataKey;
1178 console.debug('dataKey: ' + dataKey);
1180 if ((dataKey && dataKey.length > 0) || $scope.edit_templates) {
1182 $scope.templates = {};
1183 $scope.template_name = '';
1184 $scope.template_name_list = [];
1186 $scope.fetchTemplates = function () {
1187 itemSvc.get_acp_templates().then(function(t) {
1189 $scope.templates = t;
1190 $scope.template_name_list = Object.keys(t).sort();
1193 egCore.hatch.getItem('cat.copy.last_template').then(function(t) {
1194 if (t) $scope.template_name = t;
1197 $scope.fetchTemplates();
1199 $scope.applyTemplate = function (n) {
1200 angular.forEach($scope.templates[n], function (v,k) {
1201 if (k == 'circ_lib') {
1202 $scope.working[k] = egCore.org.get(v);
1203 } else if (!angular.isObject(v)) {
1204 $scope.working[k] = angular.copy(v);
1206 angular.forEach(v, function (sv,sk) {
1207 if (k == 'callnumber') {
1208 angular.forEach(v, function (cnv,cnk) {
1209 $scope.batch[cnk] = cnv;
1211 $scope.applyBatchCNValues();
1213 $scope.working[k][sk] = angular.copy(sv);
1214 if (k == 'statcats') $scope.statcatUpdate(sk);
1219 egCore.hatch.setItem('cat.copy.last_template', n);
1222 $scope.copytab = 'working';
1223 $scope.tab = 'edit';
1224 $scope.summaryRecord = null;
1225 $scope.record_id = null;
1227 $scope.completed_copies = [];
1228 $scope.location_orgs = [];
1229 $scope.location_cache = {};
1230 $scope.statcats = [];
1231 if (!$scope.batch) $scope.batch = {};
1233 $scope.applyBatchCNValues = function () {
1234 if ($scope.data.tree) {
1235 angular.forEach($scope.data.tree, function(cn_hash) {
1236 angular.forEach(cn_hash, function(copies) {
1237 angular.forEach(copies, function(cp) {
1238 if (typeof $scope.batch.classification != 'undefined' && $scope.batch.classification != '') {
1239 var label_class = $scope.classification_list.filter(function(p){ return p.id() == $scope.batch.classification })[0];
1240 cp.call_number().label_class(label_class);
1241 cp.call_number().ischanged(1);
1242 $scope.dirty = true;
1244 if (typeof $scope.batch.prefix != 'undefined' && $scope.batch.prefix != '') {
1245 var prefix = $scope.prefix_list.filter(function(p){ return p.id() == $scope.batch.prefix })[0];
1246 cp.call_number().prefix(prefix);
1247 cp.call_number().ischanged(1);
1248 $scope.dirty = true;
1250 if (typeof $scope.batch.label != 'undefined' && $scope.batch.label != '') {
1251 cp.call_number().label($scope.batch.label);
1252 cp.call_number().ischanged(1);
1253 $scope.dirty = true;
1255 if (typeof $scope.batch.suffix != 'undefined' && $scope.batch.suffix != '') {
1256 var suffix = $scope.suffix_list.filter(function(p){ return p.id() == $scope.batch.suffix })[0];
1257 cp.call_number().suffix(suffix);
1258 cp.call_number().ischanged(1);
1259 $scope.dirty = true;
1267 $scope.clearWorking = function () {
1268 angular.forEach($scope.working, function (v,k,o) {
1269 if (!angular.isObject(v)) {
1270 if (typeof v != 'undefined')
1271 $scope.working[k] = undefined;
1272 } else if (k != 'circ_lib') {
1273 angular.forEach(v, function (sv,sk) {
1274 if (typeof v != 'undefined')
1275 $scope.working[k][sk] = undefined;
1279 $scope.working.circ_lib = undefined; // special
1282 $scope.completedGridDataProvider = egGridDataProvider.instance({
1283 get : function(offset, count) {
1284 //return provider.arrayNotifier(itemSvc.copies, offset, count);
1285 return this.arrayNotifier($scope.completed_copies, offset, count);
1289 $scope.completedGridControls = {};
1291 $scope.workingGridDataProvider = egGridDataProvider.instance({
1292 get : function(offset, count) {
1293 //return provider.arrayNotifier(itemSvc.copies, offset, count);
1294 return this.arrayNotifier(itemSvc.copies, offset, count);
1298 $scope.workingGridControls = {};
1299 $scope.add_vols_copies = false;
1300 $scope.is_fast_add = false;
1304 'open-ils.actor.anon_cache.get_value',
1305 dataKey, 'edit-these-copies'
1306 ).then(function (data) {
1309 if (data.hide_vols && !$scope.defaults.always_volumes) $scope.show_vols = false;
1310 if (data.hide_copies) {
1311 $scope.show_copies = false;
1312 $scope.only_vols = true;
1315 $scope.record_id = data.record_id;
1317 function fetchRaw () {
1318 if (!$scope.only_vols) $scope.dirty = true;
1319 $scope.add_vols_copies = true;
1321 /* data.raw data structure looks like this:
1323 * callnumber : $cn_id, // optional, to add a copy to a cn
1324 * owner : $org, // optional, defaults to ws_ou
1325 * label : $cn_label, // optional, to supply a label on a new cn
1326 * barcode : $cp_barcode // optional, to supply a barcode on a new cp
1327 * fast_add : boolean // optional, to specify whether this came
1331 * All can be left out and a completely empty vol/copy combo will be vivicated.
1337 if (proto.fast_add) $scope.is_fast_add = true;
1338 if (proto.callnumber) {
1339 return egCore.pcrud.retrieve('acn', proto.callnumber)
1340 .then(function(cn) {
1341 var cp = new itemSvc.generateNewCopy(
1343 proto.owner || egCore.auth.user().ws_ou(),
1345 ((!$scope.only_vols) ? true : false)
1348 if (proto.barcode) {
1349 cp.barcode( proto.barcode );
1350 cp.empty_barcode = false;
1356 var cn = new egCore.idl.acn();
1357 cn.id( --itemSvc.new_cn_id );
1359 cn.prefix( $scope.defaults.prefix || -1 );
1360 cn.suffix( $scope.defaults.suffix || -1 );
1361 cn.owning_lib( proto.owner || egCore.auth.user().ws_ou() );
1362 cn.record( $scope.record_id );
1363 egCore.org.settings(
1364 ['cat.default_classification_scheme'],
1366 ).then(function (val) {
1368 $scope.defaults.classification ||
1369 val['cat.default_classification_scheme'] ||
1373 cn.label( proto.label );
1377 'open-ils.cat.biblio.record.marc_cn.retrieve',
1380 ).then(function(cn_array) {
1381 if (cn_array.length > 0) {
1382 for (var field in cn_array[0]) {
1383 cn.label( cn_array[0][field] );
1391 var cp = new itemSvc.generateNewCopy(
1393 proto.owner || egCore.auth.user().ws_ou(),
1398 if (proto.barcode) {
1399 cp.barcode( proto.barcode );
1400 cp.empty_barcode = false;
1409 return itemSvc.copies;
1412 if (data.copies && data.copies.length)
1413 return itemSvc.fetchIds(data.copies).then(fetchRaw);
1419 }).then( function() {
1420 $scope.data = itemSvc;
1421 $scope.workingGridDataProvider.refresh();
1424 $scope.can_save = false;
1425 function check_saveable () {
1426 var can_save = true;
1430 if (i.duplicate_barcode || i.empty_barcode || i.call_number().empty_label)
1434 if ($scope.forms.myForm && $scope.forms.myForm.$invalid) {
1437 $scope.can_save = can_save;
1440 $scope.disableSave = function () {
1442 return !$scope.can_save;
1445 $scope.focusNextFirst = function(prev_lib,prev_bc) {
1448 angular.forEach(Object.keys($scope.data.tree).sort(), function (lib) {
1451 if (lib == prev_lib) {
1460 var first_cn = Object.keys($scope.data.tree[n])[0];
1461 var next = '#' + first_cn + '_' + $scope.data.tree[n][first_cn][0].id();
1464 if (!itemSvc.currently_generating) el.focus();
1465 if (prev_bc && itemSvc.auto_gen_barcode && el.val() == "") {
1466 itemSvc.nextBarcode(prev_bc).then(function(bc){
1469 el.trigger('change');
1472 itemSvc.currently_generating = false;
1478 $scope.in_item_select = false;
1479 $scope.afterItemSelect = function() { $scope.in_item_select = false };
1480 $scope.handleItemSelect = function (item_list) {
1481 if (item_list && item_list.length > 0) {
1482 $scope.in_item_select = true;
1484 angular.forEach(Object.keys($scope.defaults.attributes), function (attr) {
1486 var value_hash = {};
1487 angular.forEach(item_list, function (item) {
1489 var v = item[attr]()
1490 if (angular.isObject(v)) {
1491 if (v.id) v = v.id();
1492 else if (v.code) v = v.code();
1498 if (Object.keys(value_hash).length == 1) {
1499 if (attr == 'circ_lib') {
1500 $scope.working[attr] = egCore.org.get(item_list[0][attr]());
1502 $scope.working[attr] = item_list[0][attr]();
1505 $scope.working[attr] = undefined;
1509 angular.forEach($scope.statcats, function (sc) {
1512 var value_hash = {};
1514 angular.forEach(item_list, function (item) {
1515 if (item.stat_cat_entries()) {
1516 if (item.stat_cat_entries().length > 0) {
1517 var right_sc = item.stat_cat_entries().filter(function (e) {
1518 return e.stat_cat() == sc.id() && !Boolean(e.isdeleted());
1521 if (right_sc.length > 0) {
1522 value_hash[right_sc[0].id()] = right_sc[0].id();
1532 if (!none && Object.keys(value_hash).length == 1) {
1533 $scope.working.statcats[sc.id()] = value_hash[Object.keys(value_hash)[0]];
1535 $scope.working.statcats[sc.id()] = undefined;
1540 $scope.clearWorking();
1545 $scope.$watch('data.copies.length', function () {
1546 if ($scope.data.copies) {
1547 var base_orgs = $scope.data.copies.map(function(cp){
1548 return cp.circ_lib()
1550 $scope.data.copies.map(function(cp){
1551 return cp.call_number().owning_lib()
1554 [egCore.auth.user().ws_ou()]
1555 ).filter(function(e,i,a){
1556 return a.lastIndexOf(e) === i;
1560 angular.forEach(base_orgs, function(o) {
1561 all_orgs = all_orgs.concat( egCore.org.fullPath(o, true) );
1564 var final_orgs = all_orgs.filter(function(e,i,a){
1565 return a.lastIndexOf(e) === i;
1566 }).sort(function(a, b){return parseInt(a)-parseInt(b)});
1568 if ($scope.location_orgs.toString() != final_orgs.toString()) {
1569 $scope.location_orgs = final_orgs;
1570 if ($scope.location_orgs.length) {
1571 itemSvc.get_locations($scope.location_orgs).then(function(list){
1572 angular.forEach(list, function(l) {
1573 $scope.location_cache[ ''+l.id() ] = l;
1575 $scope.location_list = list;
1578 $scope.statcat_filter_list = [];
1579 angular.forEach($scope.location_orgs, function (o) {
1580 $scope.statcat_filter_list.push(egCore.org.get(o));
1583 itemSvc.get_statcats($scope.location_orgs).then(function(list){
1584 $scope.statcats = list;
1585 angular.forEach($scope.statcats, function (s) {
1587 if (!$scope.working)
1588 $scope.working = { statcats: {}, statcat_filter: undefined};
1589 if (!$scope.working.statcats)
1590 $scope.working.statcats = {};
1592 if (!$scope.in_item_select) {
1593 $scope.working.statcats[s.id()] = undefined;
1595 createStatcatUpdateWatcher(s.id());
1597 $scope.in_item_select = false;
1598 // do a refresh here to work around a race
1599 // condition that can result in stat cats
1600 // not being selected.
1601 $scope.workingGridDataProvider.refresh();
1607 $scope.workingGridDataProvider.refresh();
1610 $scope.statcat_visible = function (sc_owner) {
1611 var visible = typeof $scope.working.statcat_filter === 'undefined' || !$scope.working.statcat_filter;
1612 angular.forEach(egCore.org.ancestors(sc_owner), function (ancestor_org) {
1613 if ($scope.working.statcat_filter == ancestor_org.id())
1619 $scope.suffix_list = [];
1620 itemSvc.get_suffixes(egCore.auth.user().ws_ou()).then(function(list){
1621 $scope.suffix_list = list;
1624 $scope.prefix_list = [];
1625 itemSvc.get_prefixes(egCore.auth.user().ws_ou()).then(function(list){
1626 $scope.prefix_list = list;
1629 $scope.classification_list = [];
1630 itemSvc.get_classifications().then(function(list){
1631 $scope.classification_list = list;
1634 $scope.$watch('completed_copies.length', function () {
1635 $scope.completedGridDataProvider.refresh();
1638 $scope.location_list = [];
1639 itemSvc.get_locations().then(function(list){
1640 $scope.location_list = list;
1642 createSimpleUpdateWatcher('location');
1644 $scope.status_list = [];
1645 itemSvc.get_magic_statuses().then(function(list){
1646 $scope.magic_status_list = list;
1647 createSimpleUpdateWatcher('status',$scope.magic_status_list);
1649 itemSvc.get_statuses().then(function(list){
1650 $scope.status_list = list;
1653 $scope.circ_modifier_list = [];
1654 itemSvc.get_circ_mods().then(function(list){
1655 $scope.circ_modifier_list = list;
1657 createSimpleUpdateWatcher('circ_modifier');
1659 $scope.circ_type_list = [];
1660 itemSvc.get_circ_types().then(function(list){
1661 $scope.circ_type_list = list;
1663 createSimpleUpdateWatcher('circ_as_type');
1665 $scope.age_protect_list = [];
1666 itemSvc.get_age_protects().then(function(list){
1667 $scope.age_protect_list = list;
1669 createSimpleUpdateWatcher('age_protect');
1671 $scope.floating_list = [];
1672 itemSvc.get_floating_groups().then(function(list){
1673 $scope.floating_list = list;
1675 createSimpleUpdateWatcher('floating');
1677 createSimpleUpdateWatcher('circ_lib');
1678 createSimpleUpdateWatcher('circulate');
1679 createSimpleUpdateWatcher('holdable');
1680 createSimpleUpdateWatcher('fine_level');
1681 createSimpleUpdateWatcher('loan_duration');
1682 createSimpleUpdateWatcher('price');
1683 createSimpleUpdateWatcher('cost');
1684 createSimpleUpdateWatcher('deposit');
1685 createSimpleUpdateWatcher('deposit_amount');
1686 createSimpleUpdateWatcher('mint_condition');
1687 createSimpleUpdateWatcher('opac_visible');
1688 createSimpleUpdateWatcher('ref');
1689 createSimpleUpdateWatcher('alert_message');
1691 $scope.saveCompletedCopies = function (and_exit) {
1693 var perCnCopies = {};
1694 angular.forEach( $scope.completed_copies, function (cp) {
1695 var cn = cp.call_number();
1696 var cn_cps = cp.call_number().copies();
1697 cp.call_number().copies([]);
1698 var cn_id = cp.call_number().id();
1699 cp.call_number(cn_id); // prevent loops in JSON-ification
1700 if (!cnHash[cn_id]) {
1701 cnHash[cn_id] = egCore.idl.Clone(cn);
1702 perCnCopies[cn_id] = [egCore.idl.Clone(cp)];
1704 perCnCopies[cn_id].push(egCore.idl.Clone(cp));
1706 cp.call_number(cn); // put the data back
1707 cp.call_number().copies(cn_cps);
1708 if (typeof cnHash[cn_id].prefix() == 'object')
1709 cnHash[cn_id].prefix(cnHash[cn_id].prefix().id()); // un-object-ize some fields
1710 if (typeof cnHash[cn_id].suffix() == 'object')
1711 cnHash[cn_id].suffix(cnHash[cn_id].suffix().id()); // un-object-ize some fields
1714 angular.forEach(perCnCopies, function (v, k) {
1715 cnHash[k].copies(v);
1719 angular.forEach(cnHash, function (v, k) {
1725 'open-ils.cat.asset.volume.fleshed.batch.update.override',
1726 egCore.auth.token(), cnList, 1, { auto_merge_vols : 1, create_parts : 1, return_copy_ids : 1 }
1727 ).then(function(copy_ids) {
1729 $scope.dirty = false;
1730 if ($scope.defaults.print_item_labels) {
1733 'open-ils.actor.anon_cache.set_value',
1734 null, 'print-labels-these-copies', {
1737 ).then(function(key) {
1739 var url = egCore.env.basePath + 'cat/printlabels/' + key;
1740 $timeout(function() { $window.open(url, '_blank') }).then(
1741 function() { $timeout(function(){$window.close()}); }
1744 alert('Could not create anonymous cache key!');
1748 $timeout(function(){$window.close()});
1754 $scope.saveAndContinue = function () {
1755 $scope.saveCompletedCopies(false);
1758 $scope.workingSaveAndExit = function () {
1759 $scope.workingToComplete();
1760 $scope.saveAndExit();
1763 $scope.saveAndExit = function () {
1764 $scope.saveCompletedCopies(true);
1769 $scope.copy_notes_dialog = function(copy_list) {
1770 var default_pub = Boolean($scope.defaults.copy_notes_pub);
1771 if (!angular.isArray(copy_list)) copy_list = [copy_list];
1773 return $uibModal.open({
1774 templateUrl: './cat/volcopy/t_copy_notes',
1778 ['$scope','$uibModalInstance',
1779 function($scope , $uibModalInstance) {
1780 $scope.focusNote = true;
1782 creator : egCore.auth.user().id(),
1788 $scope.require_initials = false;
1789 egCore.org.settings([
1790 'ui.staff.require_initials.copy_notes'
1791 ]).then(function(set) {
1792 $scope.require_initials = Boolean(set['ui.staff.require_initials.copy_notes']);
1795 $scope.note_list = [];
1796 if (copy_list.length == 1) {
1797 $scope.note_list = copy_list[0].notes();
1800 $scope.ok = function(note) {
1802 if ($scope.initials) {
1803 note.value = egCore.strings.$replace(
1804 egCore.strings.COPY_NOTE_INITIALS, {
1806 initials : $scope.initials,
1807 ws_ou : egCore.org.get(
1808 egCore.auth.user().ws_ou()).shortname()
1812 angular.forEach(copy_list, function (cp) {
1813 if (!angular.isArray(cp.notes())) cp.notes([]);
1814 var n = new egCore.idl.acpn();
1816 n.creator(note.creator);
1818 n.title(note.title);
1819 n.value(note.value);
1820 n.owning_copy(cp.id());
1821 cp.notes().push( n );
1824 $uibModalInstance.close();
1827 $scope.cancel = function($event) {
1828 $uibModalInstance.dismiss();
1829 $event.preventDefault();
1835 $scope.copy_tags_dialog = function(copy_list) {
1836 if (!angular.isArray(copy_list)) copy_list = [copy_list];
1838 return $uibModal.open({
1839 templateUrl: './cat/volcopy/t_copy_tags',
1843 ['$scope','$uibModalInstance',
1844 function($scope , $uibModalInstance) {
1846 $scope.tag_map = [];
1848 var shared_tags = {};
1849 angular.forEach(copy_list, function (cp) {
1850 angular.forEach(cp.tags(), function(tag) {
1851 if (!(tag.tag().id() in shared_tags)) {
1852 shared_tags[tag.tag().id()] = 1;
1854 shared_tags[tag.tag().id()]++;
1856 if (!(tag.tag().id() in tag_hash)) {
1857 tag_hash[tag.tag().id()] = tag;
1861 angular.forEach(tag_hash, function(value, key) {
1862 if (shared_tags[key] == copy_list.length) {
1863 $scope.tag_map.push(value);
1867 $scope.tag_types = [];
1868 egCore.pcrud.retrieveAll('cctt', {order_by : { cctt : 'label' }}, {atomic : true}).then(function(list) {
1869 $scope.tag_types = list;
1870 $scope.tag_type = $scope.tag_types[0].code(); // just pick a default
1873 $scope.getTags = function(val) {
1874 return egCore.pcrud.search('acpt',
1876 owner : egCore.org.fullPath(egCore.auth.user().ws_ou(), true),
1877 label : { 'startwith' : {
1878 transform: 'evergreen.lowercase',
1879 value : [ 'evergreen.lowercase', val ]
1881 tag_type : $scope.tag_type
1883 { order_by : { 'acpt' : ['label'] } }, { atomic: true }
1884 ).then(function(list) {
1885 return list.map(function(item) {
1886 return item.label();
1891 $scope.addTag = function() {
1892 var tagLabel = $scope.selectedLabel;
1893 // clear the typeahead
1894 $scope.selectedLabel = "";
1896 // first, check tags already associated with the copy
1897 var foundMatch = false;
1898 angular.forEach($scope.tag_map, function(tag) {
1899 if (tag.tag().label() == tagLabel && tag.tag().tag_type() == $scope.tag_type) {
1901 if (tag.isdeleted()) tag.isdeleted(0); // just deleting the mapping
1905 egCore.pcrud.search('acpt',
1907 owner : egCore.org.fullPath(egCore.auth.user().ws_ou(), true),
1909 tag_type : $scope.tag_type
1911 { order_by : { 'acpt' : ['label'] } }, { atomic: true }
1912 ).then(function(list) {
1913 if (list.length > 0) {
1914 var newMap = new egCore.idl.acptcm();
1916 newMap.copy(copy_list[0].id());
1917 newMap.tag(egCore.idl.Clone(list[0]));
1918 $scope.tag_map.push(newMap);
1920 var newTag = new egCore.idl.acpt();
1922 newTag.owner(egCore.auth.user().ws_ou());
1923 newTag.label(tagLabel);
1925 newTag.tag_type($scope.tag_type);
1927 var newMap = new egCore.idl.acptcm();
1929 newMap.copy(copy_list[0].id());
1931 $scope.tag_map.push(newMap);
1937 $scope.ok = function(note) {
1938 // in the multi-item case, this works OK for
1939 // adding new maps to existing tags, but doesn't handle
1940 // all possibilities
1941 angular.forEach(copy_list, function (cp) {
1942 cp.tags($scope.tag_map);
1944 $uibModalInstance.close();
1947 $scope.cancel = function($event) {
1948 $uibModalInstance.dismiss();
1949 $event.preventDefault();
1957 .directive("egVolTemplate", function () {
1961 template: '<div ng-include="'+"'/eg/staff/cat/volcopy/t_attr_edit'"+'"></div>',
1965 controller : ['$scope','$window','itemSvc','egCore','ngToast',
1966 function ( $scope , $window , itemSvc , egCore , ngToast) {
1968 $scope.i18n = egCore.i18n;
1970 $scope.defaults = { // If defaults are not set at all, allow everything
1971 barcode_checkdigit : false,
1972 auto_gen_barcode : false,
1978 loan_duration : true,
1983 deposit_amount : true,
1984 opac_visible : true,
1987 mint_condition : true,
1990 circ_modifier : true,
1991 circ_as_type : true,
1999 $scope.fetchDefaults = function () {
2000 egCore.hatch.getItem('cat.copy.defaults').then(function(t) {
2002 $scope.defaults = t;
2003 $scope.working.statcat_filter = $scope.defaults.statcat_filter;
2005 typeof $scope.defaults.statcat_filter == 'object' &&
2006 Object.keys($scope.defaults.statcat_filter).length > 0
2008 // want fieldmapper object here...
2009 $scope.defaults.statcat_filter =
2010 egCore.idl.Clone($scope.defaults.statcat_filter);
2012 $scope.working.statcat_filter = $scope.defaults.statcat_filter.id();
2017 $scope.fetchDefaults();
2019 $scope.dirty = false;
2020 $scope.$watch('dirty',
2021 function(newVal, oldVal) {
2022 if (newVal && newVal != oldVal) {
2023 $($window).on('beforeunload.template', function(){
2024 return 'There is unsaved template data!'
2027 $($window).off('beforeunload.template');
2032 $scope.template_controls = true;
2034 $scope.fetchTemplates = function () {
2035 itemSvc.get_acp_templates().then(function(t) {
2037 $scope.templates = t;
2038 $scope.template_name_list = Object.keys(t).sort();
2042 $scope.fetchTemplates();
2044 $scope.applyTemplate = function (n) {
2045 angular.forEach($scope.templates[n], function (v,k) {
2046 if (k == 'circ_lib') {
2047 $scope.working[k] = egCore.org.get(v);
2048 } else if (!angular.isObject(v)) {
2049 $scope.working[k] = angular.copy(v);
2051 angular.forEach(v, function (sv,sk) {
2052 if (!(k in $scope.working))
2053 $scope.working[k] = {};
2054 $scope.working[k][sk] = angular.copy(sv);
2058 $scope.template_name = '';
2061 $scope.deleteTemplate = function (n) {
2063 delete $scope.templates[n]
2064 $scope.template_name_list = Object.keys($scope.templates).sort();
2065 $scope.template_name = '';
2066 itemSvc.save_acp_templates($scope.templates);
2067 $scope.$parent.fetchTemplates();
2068 ngToast.create(egCore.strings.VOL_COPY_TEMPLATE_SUCCESS_DELETE);
2072 $scope.saveTemplate = function (n) {
2076 angular.forEach($scope.working, function (v,k) {
2077 if (angular.isObject(v)) { // we'll use the pkey
2078 if (v.id) v = v.id();
2079 else if (v.code) v = v.code();
2085 $scope.templates[n] = tmpl;
2086 $scope.template_name_list = Object.keys($scope.templates).sort();
2088 itemSvc.save_acp_templates($scope.templates);
2089 $scope.$parent.fetchTemplates();
2091 $scope.dirty = false;
2093 // save all templates, as we might do after an import
2094 itemSvc.save_acp_templates($scope.templates);
2095 $scope.$parent.fetchTemplates();
2097 ngToast.create(egCore.strings.VOL_COPY_TEMPLATE_SUCCESS_SAVE);
2100 $scope.templates = {};
2101 $scope.imported_templates = { data : '' };
2102 $scope.template_name = '';
2103 $scope.template_name_list = [];
2105 $scope.$watch('imported_templates.data', function(newVal, oldVal) {
2106 if (newVal && newVal != oldVal) {
2108 var newTemplates = JSON.parse(newVal);
2109 if (!Object.keys(newTemplates).length) return;
2110 angular.forEach(Object.keys(newTemplates), function (k) {
2111 $scope.templates[k] = newTemplates[k];
2113 itemSvc.save_acp_templates($scope.templates);
2114 $scope.fetchTemplates();
2116 console.log('tried to import an invalid copy template file');
2121 $scope.tracker = function (x,f) { if (x) return x[f]() };
2122 $scope.idTracker = function (x) { if (x) return $scope.tracker(x,'id') };
2123 $scope.cant_have_vols = function (id) { return !egCore.org.CanHaveVolumes(id); };
2125 $scope.orgById = function (id) { return egCore.org.get(id) }
2126 $scope.statusById = function (id) {
2127 return $scope.status_list.filter( function (s) { return s.id() == id } )[0];
2129 $scope.locationById = function (id) {
2130 return $scope.location_cache[''+id];
2133 createSimpleUpdateWatcher = function (field) {
2134 $scope.$watch('working.' + field, function () {
2135 var newval = $scope.working[field];
2137 if (typeof newval != 'undefined') {
2138 $scope.dirty = true;
2139 if (angular.isObject(newval)) { // we'll use the pkey
2140 if (newval.id) $scope.working[field] = newval.id();
2141 else if (newval.code) $scope.working[field] = newval.code();
2144 if (""+newval == "" || newval == null) {
2145 $scope.working[field] = undefined;
2154 statcat_filter: undefined
2157 $scope.statcat_visible = function (sc_owner) {
2158 var visible = typeof $scope.working.statcat_filter === 'undefined' || !$scope.working.statcat_filter;
2159 angular.forEach(egCore.org.ancestors(sc_owner), function (ancestor_org) {
2160 if ($scope.working.statcat_filter == ancestor_org.id())
2166 createStatcatUpdateWatcher = function (id) {
2167 return $scope.$watch('working.statcats[' + id + ']', function () {
2168 if ($scope.working.statcats) {
2169 var newval = $scope.working.statcats[id];
2171 if (typeof newval != 'undefined') {
2172 $scope.dirty = true;
2173 if (angular.isObject(newval)) { // we'll use the pkey
2174 newval = newval.id();
2177 if (""+newval == "" || newval == null) {
2178 $scope.working.statcats[id] = undefined;
2187 $scope.clearWorking = function () {
2188 angular.forEach($scope.working, function (v,k,o) {
2189 if (!angular.isObject(v)) {
2190 if (typeof v != 'undefined')
2191 $scope.working[k] = undefined;
2192 } else if (k != 'circ_lib') {
2193 angular.forEach(v, function (sv,sk) {
2194 $scope.working[k][sk] = undefined;
2198 $scope.working.circ_lib = undefined; // special
2199 $scope.dirty = false;
2202 $scope.working = {};
2203 $scope.location_orgs = [];
2204 $scope.location_cache = {};
2206 $scope.location_list = [];
2207 itemSvc.get_locations(
2208 egCore.org.fullPath( egCore.auth.user().ws_ou(), true )
2209 ).then(function(list){
2210 $scope.location_list = list;
2212 createSimpleUpdateWatcher('location');
2214 $scope.statcat_filter_list = egCore.org.fullPath( egCore.auth.user().ws_ou() );
2216 $scope.statcats = [];
2217 itemSvc.get_statcats(
2218 egCore.org.fullPath( egCore.auth.user().ws_ou(), true )
2219 ).then(function(list){
2220 $scope.statcats = list;
2221 angular.forEach($scope.statcats, function (s) {
2223 if (!$scope.working)
2224 $scope.working = { statcats: {}, statcat_filter: undefined};
2225 if (!$scope.working.statcats)
2226 $scope.working.statcats = {};
2228 $scope.working.statcats[s.id()] = undefined;
2229 createStatcatUpdateWatcher(s.id());
2233 $scope.status_list = [];
2234 itemSvc.get_magic_statuses().then(function(list){
2235 $scope.magic_status_list = list;
2237 itemSvc.get_statuses().then(function(list){
2238 $scope.status_list = list;
2240 createSimpleUpdateWatcher('status');
2242 $scope.circ_modifier_list = [];
2243 itemSvc.get_circ_mods().then(function(list){
2244 $scope.circ_modifier_list = list;
2246 createSimpleUpdateWatcher('circ_modifier');
2248 $scope.circ_type_list = [];
2249 itemSvc.get_circ_types().then(function(list){
2250 $scope.circ_type_list = list;
2252 createSimpleUpdateWatcher('circ_as_type');
2254 $scope.age_protect_list = [];
2255 itemSvc.get_age_protects().then(function(list){
2256 $scope.age_protect_list = list;
2258 createSimpleUpdateWatcher('age_protect');
2260 createSimpleUpdateWatcher('circulate');
2261 createSimpleUpdateWatcher('holdable');
2262 createSimpleUpdateWatcher('fine_level');
2263 createSimpleUpdateWatcher('loan_duration');
2264 createSimpleUpdateWatcher('cost');
2265 createSimpleUpdateWatcher('deposit');
2266 createSimpleUpdateWatcher('deposit_amount');
2267 createSimpleUpdateWatcher('mint_condition');
2268 createSimpleUpdateWatcher('opac_visible');
2269 createSimpleUpdateWatcher('ref');
2270 createSimpleUpdateWatcher('alert_message');
2272 $scope.suffix_list = [];
2273 itemSvc.get_suffixes(egCore.auth.user().ws_ou()).then(function(list){
2274 $scope.suffix_list = list;
2277 $scope.prefix_list = [];
2278 itemSvc.get_prefixes(egCore.auth.user().ws_ou()).then(function(list){
2279 $scope.prefix_list = list;
2282 $scope.classification_list = [];
2283 itemSvc.get_classifications().then(function(list){
2284 $scope.classification_list = list;
2287 createSimpleUpdateWatcher('working.callnumber.classification');
2288 createSimpleUpdateWatcher('working.callnumber.prefix');
2289 createSimpleUpdateWatcher('working.callnumber.suffix');