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
277 // to staff_client.copy_editor.templates and convert_xul_templates
278 // can be thrown away.
279 return egCore.net.request('open-ils.actor', 'open-ils.actor.patron.settings.retrieve.authoritative',
280 egCore.auth.token(), egCore.auth.user().id(),
281 ['webstaff.cat.copy.templates','staff_client.copy_editor.templates']).then(function(settings) {
282 if (settings['webstaff.cat.copy.templates']) {
283 egCore.hatch.setItem('cat.copy.templates', settings['webstaff.cat.copy.templates']);
284 return settings['webstaff.cat.copy.templates'];
286 if (settings['staff_client.copy_editor.templates']) {
287 var new_templ = service.convert_xul_templates(settings['staff_client.copy_editor.templates']);
288 egCore.hatch.setItem('cat.copy.templates', new_templ);
289 // console.warn('Saving: ' + JSON.stringify({'webstaff.cat.copy.templates' : new_templ}));
290 egCore.net.request('open-ils.actor', 'open-ils.actor.patron.settings.update',
291 egCore.auth.token(), egCore.auth.user().id(), {'webstaff.cat.copy.templates' : new_templ});
299 service.convert_xul_templates = function(xultempl) {
301 var templ_names = Object.keys(xultempl);
312 for (i=0; i < templ_names.length; i++) {
313 name = templ_names[i];
316 xul_t = xultempl[name];
317 fields = Object.keys(xul_t);
319 if (fields.length > 0) {
320 for (j=0; j < fields.length; j++) {
321 curr_field = xul_t[fields[j]];
322 var field_name = curr_field["field"];
324 if ( field_name == null ) { continue; }
325 if ( curr_field["value"] == "<HACK:KLUDGE:NULL>" ) { continue; }
327 // floating changed from a boolean to an integer at one point;
328 // take this opportunity to remove the boolean from any old templates
329 if ( curr_field["type"] === "attribute" && field_name === "floating" ) {
330 if ( curr_field["value"].match(/[tf]/) ) { continue; }
333 if ( curr_field["type"] === "stat_cat" ) {
334 stat_cats[field_name] = parseInt(curr_field["value"]);
337 tmp_val = curr_field['value']; // so... some of the number fields are actually strings. Groovy.
338 if ( tmp_val.match(/^[-0-9.]+$/) && !(field_name.match(/(?:loan_duration|fine_level)/))) { tmp_val = parseFloat(tmp_val); }
340 if (field_name.match(/^batch_.*_menulist$/)) {
341 // special handling for volume fields
342 if (!("callnumber" in curr_templ)) curr_templ["callnumber"] = {};
343 if (field_name === "batch_class_menulist") curr_templ["callnumber"]["classification"] = tmp_val;
344 if (field_name === "batch_prefix_menulist") curr_templ["callnumber"]["prefix"] = tmp_val;
345 if (field_name === "batch_suffix_menulist") curr_templ["callnumber"]["suffix"] = tmp_val;
347 curr_templ[field_name] = tmp_val;
352 if ( (Object.keys(stat_cats)).length > 0 ){
353 curr_templ["statcats"] = stat_cats;
356 conv_templ[name] = curr_templ;
366 acp : ['call_number','parts','stat_cat_entries', 'notes', 'tags'],
367 acn : ['label_class','prefix','suffix'],
372 service.addCopy = function (cp) {
374 if (!cp.parts()) cp.parts([]); // just in case...
376 var lib = cp.call_number().owning_lib();
377 var cn = cp.call_number().id();
379 if (!service.tree[lib]) service.tree[lib] = {};
380 if (!service.tree[lib][cn]) service.tree[lib][cn] = [];
382 service.tree[lib][cn].push(cp);
383 service.copies.push(cp);
386 service.checkDuplicateBarcode = function(bc, id) {
388 return egCore.pcrud.search('acp', { deleted : 'f', 'barcode' : bc, id : { '!=' : id } })
390 function () { return final },
391 function () { return final },
392 function () { final = true; }
396 service.fetchIds = function(idList) {
397 service.tree = {}; // clear the tree on fetch
398 service.copies = []; // clear the copy list on fetch
399 return egCore.pcrud.search('acp', { 'id' : idList }, service.flesh).then(null,null,
401 service.addCopy(copy);
406 // create a new acp object with default values
407 // (both hard-coded and coming from OU settings)
408 service.generateNewCopy = function(callNumber, owningLib, isFastAdd, isNew) {
409 var cp = new egCore.idl.acp();
410 cp.id( --service.new_cp_id );
414 cp.circ_lib( owningLib );
415 cp.call_number( callNumber );
418 cp.deposit_amount(0);
419 cp.fine_level(2); // Normal
420 cp.loan_duration(2); // Normal
421 cp.location(1); // Stacks
424 cp.opac_visible('t');
426 cp.mint_condition('t');
427 cp.empty_barcode = true;
429 var status_setting = isFastAdd ?
430 'cat.default_copy_status_fast' :
431 'cat.default_copy_status_normal';
435 ).then(function(set) {
436 var default_ccs = parseInt(set[status_setting]);
437 if (isNaN(default_ccs))
438 default_ccs = (isFastAdd ? 0 : 5); // 0 is Available, 5 is In Process
439 cp.status(default_ccs);
448 .directive('stringToNumber', function() {
451 link: function(scope, element, attrs, ngModel) {
452 var precision = attrs.precision || 0;
453 ngModel.$parsers.push(function(value) {
457 function updateDisplay() {
458 var value = parseFloat(ngModel.$viewValue);
459 if ( isNaN(value) ) { return; }
460 element.val(value.toFixed(precision));
463 ngModel.$formatters.push(function(value) {
464 return parseFloat(value);
467 ngModel.$viewChangeListeners.push(updateDisplay);
469 ngModel.$render = function() {
476 .directive("egVolCopyEdit", function () {
482 '<div class="col-xs-5" ng-class="{'+"'has-error'"+':barcode_has_error}">'+
483 '<input id="{{callNumber.id()}}_{{copy.id()}}"'+
484 ' eg-enter="nextBarcode(copy.id())" class="form-control"'+
485 ' type="text" ng-model="barcode" ng-change="updateBarcode()"/>'+
486 '<div class="label label-danger" ng-if="duplicate_barcode">{{duplicate_barcode_string}}</div>'+
487 '<div class="label label-danger" ng-if="empty_barcode">{{empty_barcode_string}}</div>'+
489 '<div class="col-xs-3"><input class="form-control" type="number" min="1" ng-model="copy_number" ng-change="updateCopyNo()"/></div>'+
490 '<div class="col-xs-4"><eg-basic-combo-box eg-disabled="record == 0" list="parts" selected="part"></eg-basic-combo-box></div>'+
493 scope: { focusNext: "=", copy: "=", callNumber: "=", index: "@", record: "@" },
494 controller : ['$scope','itemSvc','egCore',
495 function ( $scope , itemSvc , egCore ) {
496 $scope.new_part_id = 0;
497 $scope.barcode_has_error = false;
498 $scope.duplicate_barcode = false;
499 $scope.empty_barcode = false;
500 $scope.duplicate_barcode_string = window.duplicate_barcode_string;
501 $scope.empty_barcode_string = window.empty_barcode_string;
503 if (!$scope.copy.barcode()) $scope.copy.empty_barcode = true;
505 $scope.nextBarcode = function (i) {
506 $scope.focusNext(i, $scope.barcode);
509 $scope.updateBarcode = function () {
510 if ($scope.barcode != '') {
511 $scope.copy.empty_barcode = $scope.empty_barcode = false;
512 $scope.barcode_has_error = !Boolean(itemSvc.checkBarcode($scope.barcode));
513 itemSvc.checkDuplicateBarcode($scope.barcode, $scope.copy.id())
514 .then(function (state) { $scope.copy.duplicate_barcode = $scope.duplicate_barcode = state });
516 $scope.copy.empty_barcode = $scope.empty_barcode = true;
519 $scope.copy.barcode($scope.barcode);
520 $scope.copy.ischanged(1);
521 if (itemSvc.currently_generating)
522 $scope.focusNext($scope.copy.id(), $scope.barcode);
525 $scope.updateCopyNo = function () { $scope.copy.copy_number($scope.copy_number); $scope.copy.ischanged(1); };
526 $scope.updatePart = function () {
528 var p = $scope.part_list.filter(function (x) {
529 return x.label() == $scope.part
531 if (p.length > 0) { // preexisting part
533 } else { // create one...
534 var part = new egCore.idl.bmp();
535 part.id( --$scope.new_part_id );
537 part.label( $scope.part );
538 part.record( $scope.callNumber.record() );
539 $scope.copy.parts([part]);
540 $scope.copy.ischanged(1);
543 $scope.copy.parts([]);
545 $scope.copy.ischanged(1);
547 $scope.$watch('part', $scope.updatePart);
549 $scope.barcode = $scope.copy.barcode();
550 $scope.copy_number = $scope.copy.copy_number();
552 if ($scope.copy.parts()) {
553 $scope.part = $scope.copy.parts()[0];
554 if ($scope.part) $scope.part = $scope.part.label();
558 $scope.part_list = [];
560 itemSvc.get_parts($scope.callNumber.record()).then(function(list){
561 $scope.part_list = list;
562 angular.forEach(list, function(p){ $scope.parts.push(p.label()) });
563 $scope.parts = angular.copy($scope.parts);
572 .directive("egVolRow", function () {
579 '<div class="col-xs-2">'+
580 '<select ng-disabled="record == 0" class="form-control" ng-model="classification" ng-change="updateClassification()" ng-options="cl.name() for cl in classification_list"/>'+
582 '<div class="col-xs-1">'+
583 '<select ng-disabled="record == 0" class="form-control" ng-model="prefix" ng-change="updatePrefix()" ng-options="p.label() for p in prefix_list"/>'+
585 '<div class="col-xs-2">'+
586 '<input ng-disabled="record == 0" class="form-control" type="text" ng-change="updateLabel()" ng-model="label"/>'+
587 '<div class="label label-danger" ng-if="empty_label">{{empty_label_string}}</div>'+
589 '<div class="col-xs-1">'+
590 '<select ng-disabled="record == 0" class="form-control" ng-model="suffix" ng-change="updateSuffix()" ng-options="s.label() for s in suffix_list"/>'+
592 '<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>'+
593 '<div ng-hide="onlyVols" class="col-xs-5">'+
594 '<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>'+
598 scope: {focusNext: "=", allcopies: "=", copies: "=", onlyVols: "=", record: "@" },
599 controller : ['$scope','itemSvc','egCore',
600 function ( $scope , itemSvc , egCore ) {
601 $scope.callNumber = $scope.copies[0].call_number();
602 if (!$scope.callNumber.label()) $scope.callNumber.emtpy_label = true;
604 $scope.empty_label = false;
605 $scope.empty_label_string = window.empty_label_string;
607 $scope.idTracker = function (x) { if (x && x.id) return x.id() };
609 // XXX $() is not working! arg
610 $scope.focusNextBarcode = function (i, prev_bc) {
613 angular.forEach($scope.copies, function (cp) {
621 if (yep) n = cp.id();
625 var next = '#' + $scope.callNumber.id() + '_' + n;
628 if (!itemSvc.currently_generating) el.focus();
629 if (prev_bc && itemSvc.auto_gen_barcode && el.val() == "") {
630 itemSvc.nextBarcode(prev_bc).then(function(bc){
633 el.trigger('change');
636 itemSvc.currently_generating = false;
640 $scope.focusNext($scope.callNumber.id(),prev_bc)
644 $scope.suffix_list = [];
645 itemSvc.get_suffixes($scope.callNumber.owning_lib()).then(function(list){
646 $scope.suffix_list = list;
647 $scope.$watch('callNumber.suffix()', function (v) {
648 if (angular.isObject(v)) v = v.id();
649 $scope.suffix = $scope.suffix_list.filter( function (s) {
655 $scope.updateSuffix = function () {
656 angular.forEach($scope.copies, function(cp) {
657 cp.call_number().suffix($scope.suffix);
658 cp.call_number().ischanged(1);
662 $scope.prefix_list = [];
663 itemSvc.get_prefixes($scope.callNumber.owning_lib()).then(function(list){
664 $scope.prefix_list = list;
665 $scope.$watch('callNumber.prefix()', function (v) {
666 if (angular.isObject(v)) v = v.id();
667 $scope.prefix = $scope.prefix_list.filter(function (p) {
673 $scope.updatePrefix = function () {
674 angular.forEach($scope.copies, function(cp) {
675 cp.call_number().prefix($scope.prefix);
676 cp.call_number().ischanged(1);
679 $scope.$watch('callNumber.owning_lib()', function(oldLib, newLib) {
680 if (oldLib == newLib) return;
681 var currentPrefix = $scope.callNumber.prefix();
682 if (angular.isObject(currentPrefix)) currentPrefix = currentPrefix.id();
683 itemSvc.get_prefixes($scope.callNumber.owning_lib()).then(function(list){
684 $scope.prefix_list = list;
685 var newPrefixId = $scope.prefix_list.filter(function (p) {
686 return p.id() == currentPrefix;
688 if (newPrefixId.id) newPrefixId = newPrefixId.id();
689 $scope.prefix = $scope.prefix_list.filter(function (p) {
690 return p.id() == newPrefixId;
692 if ($scope.newPrefixId != currentPrefix) {
693 $scope.callNumber.prefix($scope.prefix);
696 var currentSuffix = $scope.callNumber.suffix();
697 if (angular.isObject(currentSuffix)) currentSuffix = currentSuffix.id();
698 itemSvc.get_suffixes($scope.callNumber.owning_lib()).then(function(list){
699 $scope.suffix_list = list;
700 var newSuffixId = $scope.suffix_list.filter(function (s) {
701 return s.id() == currentSuffix;
703 if (newSuffixId.id) newSuffixId = newSuffixId.id();
704 $scope.suffix = $scope.suffix_list.filter(function (s) {
705 return s.id() == newSuffixId;
707 if ($scope.newSuffixId != currentSuffix) {
708 $scope.callNumber.suffix($scope.suffix);
713 $scope.classification_list = [];
714 itemSvc.get_classifications().then(function(list){
715 $scope.classification_list = list;
716 $scope.$watch('callNumber.label_class()', function (v) {
717 if (angular.isObject(v)) v = v.id();
718 $scope.classification = $scope.classification_list.filter(function (c) {
724 $scope.updateClassification = function () {
725 angular.forEach($scope.copies, function(cp) {
726 cp.call_number().label_class($scope.classification);
727 cp.call_number().ischanged(1);
731 $scope.updateLabel = function () {
732 if ($scope.label == '') {
733 $scope.callNumber.empty_label = $scope.empty_label = true;
735 $scope.callNumber.empty_label = $scope.empty_label = false;
737 angular.forEach($scope.copies, function(cp) {
738 cp.call_number().label($scope.label);
739 cp.call_number().ischanged(1);
743 $scope.$watch('callNumber.label()', function (v) {
747 $scope.prefix = $scope.callNumber.prefix();
748 $scope.suffix = $scope.callNumber.suffix();
749 $scope.classification = $scope.callNumber.label_class();
750 $scope.label = $scope.callNumber.label();
752 $scope.copy_count = $scope.copies.length;
753 $scope.orig_copy_count = $scope.copy_count;
755 $scope.changeCPCount = function () {
756 while ($scope.copy_count > $scope.copies.length) {
757 var cp = itemSvc.generateNewCopy(
759 $scope.callNumber.owning_lib(),
763 $scope.copies.push( cp );
764 $scope.allcopies.push( cp );
768 if ($scope.copy_count >= $scope.orig_copy_count) {
769 var how_many = $scope.copies.length - $scope.copy_count;
771 var dead = $scope.copies.splice($scope.copy_count,how_many);
772 $scope.callNumber.copies($scope.copies);
774 // Trimming the global list is a bit more tricky
775 angular.forEach( dead, function (d) {
776 angular.forEach( $scope.allcopies, function (l, i) {
777 if (l === d) $scope.allcopies.splice(i,1);
790 .directive("egVolEdit", function () {
796 '<div class="col-xs-1"><eg-org-selector alldisabled="{{record == 0}}" selected="owning_lib" disable-test="cant_have_vols"></eg-org-selector></div>'+
797 '<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>'+
798 '<div class="col-xs-10">'+
799 '<eg-vol-row only-vols="onlyVols" record="{{record}}"'+
800 'ng-repeat="(cn,copies) in struct" '+
801 'focus-next="focusNextFirst" copies="copies" allcopies="allcopies">'+
806 scope: { focusNext: "=", allcopies: "=", struct: "=", lib: "@", record: "@", onlyVols: "=" },
807 controller : ['$scope','itemSvc','egCore',
808 function ( $scope , itemSvc , egCore ) {
809 $scope.first_cn = Object.keys($scope.struct)[0];
810 $scope.full_cn = $scope.struct[$scope.first_cn][0].call_number();
812 $scope.defaults = {};
813 egCore.hatch.getItem('cat.copy.defaults').then(function(t) {
819 $scope.focusNextFirst = function(prev_cn,prev_bc) {
822 angular.forEach(Object.keys($scope.struct).sort(), function (cn) {
834 var next = '#' + n + '_' + $scope.struct[n][0].id();
837 if (!itemSvc.currently_generating) el.focus();
838 if (prev_bc && itemSvc.auto_gen_barcode && el.val() == "") {
839 itemSvc.nextBarcode(prev_bc).then(function(bc){
842 el.trigger('change');
845 itemSvc.currently_generating = false;
849 $scope.focusNext($scope.lib, prev_bc);
853 $scope.cn_count = Object.keys($scope.struct).length;
854 $scope.orig_cn_count = $scope.cn_count;
856 $scope.owning_lib = egCore.org.get($scope.lib);
857 $scope.$watch('owning_lib', function (oldLib, newLib) {
858 if (oldLib == newLib) return;
859 angular.forEach( Object.keys($scope.struct), function (cn) {
860 $scope.struct[cn][0].call_number().owning_lib( $scope.owning_lib.id() );
861 $scope.struct[cn][0].call_number().ischanged(1);
865 $scope.cant_have_vols = function (id) { return !egCore.org.CanHaveVolumes(id); };
867 $scope.$watch('cn_count', function (n) {
868 var o = Object.keys($scope.struct).length;
869 if (n > o) { // adding
870 for (var i = o; o < n; o++) {
871 var cn = new egCore.idl.acn();
872 cn.id( --itemSvc.new_cn_id );
874 cn.prefix( $scope.defaults.prefix || -1 );
875 cn.suffix( $scope.defaults.suffix || -1 );
876 cn.label_class( $scope.defaults.classification || 1 );
877 cn.owning_lib( $scope.owning_lib.id() );
878 cn.record( $scope.full_cn.record() );
880 var cp = itemSvc.generateNewCopy(
882 $scope.owning_lib.id(),
887 $scope.struct[cn.id()] = [cp];
888 $scope.allcopies.push(cp);
889 if (!$scope.defaults.classification) {
891 ['cat.default_classification_scheme'],
893 ).then(function (val) {
894 cn.label_class(val['cat.default_classification_scheme']);
898 } else if (n < o && n >= $scope.orig_cn_count) { // removing
899 var how_many = o - n;
902 .sort(function(a, b){return parseInt(a)-parseInt(b)})
903 .filter(function(x){ return parseInt(x) <= 0 });
904 for (var i = 0; i < how_many; i++) {
905 // Trimming the global list is a bit more tricky
906 angular.forEach($scope.struct[list[i]], function (d) {
907 angular.forEach( $scope.allcopies, function (l, j) {
908 if (l === d) $scope.allcopies.splice(j,1);
911 delete $scope.struct[list[i]];
924 .controller('EditCtrl',
925 ['$scope','$q','$window','$routeParams','$location','$timeout','egCore','egNet','egGridDataProvider','itemSvc','$uibModal',
926 function($scope , $q , $window , $routeParams , $location , $timeout , egCore , egNet , egGridDataProvider , itemSvc , $uibModal) {
928 $scope.forms = {}; // Accessed by t_attr_edit.tt2
929 $scope.i18n = egCore.i18n;
931 $scope.defaults = { // If defaults are not set at all, allow everything
932 barcode_checkdigit : false,
933 auto_gen_barcode : false,
939 loan_duration : true,
944 deposit_amount : true,
948 mint_condition : true,
951 circ_modifier : true,
961 $scope.new_lib_to_add = egCore.org.get(egCore.auth.user().ws_ou());
962 $scope.changeNewLib = function (org) {
963 $scope.new_lib_to_add = org;
965 $scope.addLibToStruct = function () {
966 var newLib = $scope.new_lib_to_add;
967 var cn = new egCore.idl.acn();
968 cn.id( --itemSvc.new_cn_id );
970 cn.prefix( $scope.defaults.prefix || -1 );
971 cn.suffix( $scope.defaults.suffix || -1 );
972 cn.label_class( $scope.defaults.classification || 1 );
973 cn.owning_lib( newLib.id() );
974 cn.record( $scope.record_id );
976 var cp = itemSvc.generateNewCopy(
983 $scope.data.addCopy(cp);
985 if (!$scope.defaults.classification) {
987 ['cat.default_classification_scheme'],
989 ).then(function (val) {
990 cn.label_class(val['cat.default_classification_scheme']);
995 $scope.embedded = ($routeParams.mode && $routeParams.mode == 'embedded') ? true : false;
996 $scope.edit_templates = ($location.path().match(/edit_template/)) ? true : false;
998 $scope.saveDefaults = function () {
999 egCore.hatch.setItem('cat.copy.defaults', $scope.defaults);
1002 $scope.fetchDefaults = function () {
1003 egCore.hatch.getItem('cat.copy.defaults').then(function(t) {
1005 $scope.defaults = t;
1006 if (!$scope.batch) $scope.batch = {};
1007 $scope.batch.classification = $scope.defaults.classification;
1008 $scope.batch.prefix = $scope.defaults.prefix;
1009 $scope.batch.suffix = $scope.defaults.suffix;
1010 $scope.working.statcat_filter = $scope.defaults.statcat_filter;
1012 typeof $scope.defaults.statcat_filter == 'object' &&
1013 Object.keys($scope.defaults.statcat_filter).length > 0
1015 // want fieldmapper object here...
1016 $scope.defaults.statcat_filter =
1017 egCore.idl.Clone($scope.defaults.statcat_filter);
1019 $scope.working.statcat_filter = $scope.defaults.statcat_filter.id();
1021 if ($scope.defaults.always_volumes) $scope.show_vols = true;
1022 if ($scope.defaults.barcode_checkdigit) itemSvc.barcode_checkdigit = true;
1023 if ($scope.defaults.auto_gen_barcode) itemSvc.auto_gen_barcode = true;
1027 $scope.fetchDefaults();
1029 $scope.$watch('defaults.statcat_filter', function() {
1030 $scope.saveDefaults();
1032 $scope.$watch('defaults.auto_gen_barcode', function (n,o) {
1033 itemSvc.auto_gen_barcode = n
1036 $scope.$watch('defaults.barcode_checkdigit', function (n,o) {
1037 itemSvc.barcode_checkdigit = n
1040 $scope.dirty = false;
1041 $scope.$watch('dirty',
1042 function(newVal, oldVal) {
1043 if (newVal && newVal != oldVal) {
1044 $($window).on('beforeunload.edit', function(){
1045 return 'There is unsaved data!'
1048 $($window).off('beforeunload.edit');
1053 $scope.only_vols = false;
1054 $scope.show_vols = true;
1055 $scope.show_copies = true;
1057 $scope.tracker = function (x,f) { if (x) return x[f]() };
1058 $scope.idTracker = function (x) { if (x) return $scope.tracker(x,'id') };
1059 $scope.cant_have_vols = function (id) { return !egCore.org.CanHaveVolumes(id); };
1061 $scope.orgById = function (id) { return egCore.org.get(id) }
1062 $scope.statusById = function (id) {
1063 return $scope.status_list.filter( function (s) { return s.id() == id } )[0];
1065 $scope.locationById = function (id) {
1066 return $scope.location_cache[''+id];
1069 $scope.workingToComplete = function () {
1070 angular.forEach( $scope.workingGridControls.selectedItems(), function (c) {
1071 angular.forEach( itemSvc.copies, function (w, i) {
1073 $scope.completed_copies = $scope.completed_copies.concat(itemSvc.copies.splice(i,1));
1080 $scope.completeToWorking = function () {
1081 angular.forEach( $scope.completedGridControls.selectedItems(), function (c) {
1082 angular.forEach( $scope.completed_copies, function (w, i) {
1084 itemSvc.copies = itemSvc.copies.concat($scope.completed_copies.splice(i,1));
1091 createSimpleUpdateWatcher = function (field,exclude_copies_with_one_of_these_values) {
1092 return $scope.$watch('working.' + field, function () {
1093 var newval = $scope.working[field];
1095 if (typeof newval != 'undefined') {
1096 if (angular.isObject(newval)) { // we'll use the pkey
1097 if (newval.id) newval = newval.id();
1098 else if (newval.code) newval = newval.code();
1101 if (""+newval == "" || newval == null) {
1102 $scope.working[field] = undefined;
1106 if ($scope.workingGridControls && $scope.workingGridControls.selectedItems) {
1108 $scope.workingGridControls.selectedItems(),
1110 if (exclude_copies_with_one_of_these_values
1111 && exclude_copies_with_one_of_these_values.indexOf(cp[field](),0) > -1) {
1114 if (cp[field]() !== newval) {
1117 $scope.dirty = true;
1128 statcat_filter: undefined
1131 $scope.statcatUpdate = function (id) {
1132 var newval = $scope.working.statcats[id];
1134 if (typeof newval != 'undefined') {
1135 if (angular.isObject(newval)) { // we'll use the pkey
1136 newval = newval.id();
1139 if (""+newval == "" || newval == null) {
1140 $scope.working.statcats[id] = undefined;
1144 if (!$scope.in_item_select && $scope.workingGridControls && $scope.workingGridControls.selectedItems) {
1146 $scope.workingGridControls.selectedItems(),
1148 $scope.dirty = true;
1150 cp.stat_cat_entries(
1151 angular.forEach( cp.stat_cat_entries(), function (e) {
1152 if (e.stat_cat() == id) { // mark deleted
1159 var e = new egCore.idl.asce();
1164 cp.stat_cat_entries(
1165 cp.stat_cat_entries() ?
1166 cp.stat_cat_entries().concat([ e ]) :
1172 // trim out all deleted ones; the API used to
1173 // do the update doesn't actually consult
1174 // isdeleted for stat cat entries
1175 cp.stat_cat_entries(
1176 cp.stat_cat_entries().filter(function (e) {
1177 return !Boolean(e.isdeleted());
1188 var dataKey = $routeParams.dataKey;
1189 console.debug('dataKey: ' + dataKey);
1191 if ((dataKey && dataKey.length > 0) || $scope.edit_templates) {
1193 $scope.templates = {};
1194 $scope.template_name = '';
1195 $scope.template_name_list = [];
1197 $scope.fetchTemplates = function () {
1198 itemSvc.get_acp_templates().then(function(t) {
1200 $scope.templates = t;
1201 $scope.template_name_list = Object.keys(t).sort();
1204 egCore.hatch.getItem('cat.copy.last_template').then(function(t) {
1205 if (t) $scope.template_name = t;
1208 $scope.fetchTemplates();
1210 $scope.applyTemplate = function (n) {
1211 angular.forEach($scope.templates[n], function (v,k) {
1212 if (k == 'circ_lib') {
1213 $scope.working[k] = egCore.org.get(v);
1214 } else if (!angular.isObject(v)) {
1215 $scope.working[k] = angular.copy(v);
1217 angular.forEach(v, function (sv,sk) {
1218 if (k == 'callnumber') {
1219 angular.forEach(v, function (cnv,cnk) {
1220 $scope.batch[cnk] = cnv;
1222 $scope.applyBatchCNValues();
1224 $scope.working[k][sk] = angular.copy(sv);
1225 if (k == 'statcats') $scope.statcatUpdate(sk);
1230 egCore.hatch.setItem('cat.copy.last_template', n);
1233 $scope.copytab = 'working';
1234 $scope.tab = 'edit';
1235 $scope.summaryRecord = null;
1236 $scope.record_id = null;
1238 $scope.completed_copies = [];
1239 $scope.location_orgs = [];
1240 $scope.location_cache = {};
1241 $scope.statcats = [];
1242 if (!$scope.batch) $scope.batch = {};
1244 $scope.applyBatchCNValues = function () {
1245 if ($scope.data.tree) {
1246 angular.forEach($scope.data.tree, function(cn_hash) {
1247 angular.forEach(cn_hash, function(copies) {
1248 angular.forEach(copies, function(cp) {
1249 if (typeof $scope.batch.classification != 'undefined' && $scope.batch.classification != '') {
1250 var label_class = $scope.classification_list.filter(function(p){ return p.id() == $scope.batch.classification })[0];
1251 cp.call_number().label_class(label_class);
1252 cp.call_number().ischanged(1);
1253 $scope.dirty = true;
1255 if (typeof $scope.batch.prefix != 'undefined' && $scope.batch.prefix != '') {
1256 var prefix = $scope.prefix_list.filter(function(p){ return p.id() == $scope.batch.prefix })[0];
1257 cp.call_number().prefix(prefix);
1258 cp.call_number().ischanged(1);
1259 $scope.dirty = true;
1261 if (typeof $scope.batch.label != 'undefined' && $scope.batch.label != '') {
1262 cp.call_number().label($scope.batch.label);
1263 cp.call_number().ischanged(1);
1264 $scope.dirty = true;
1266 if (typeof $scope.batch.suffix != 'undefined' && $scope.batch.suffix != '') {
1267 var suffix = $scope.suffix_list.filter(function(p){ return p.id() == $scope.batch.suffix })[0];
1268 cp.call_number().suffix(suffix);
1269 cp.call_number().ischanged(1);
1270 $scope.dirty = true;
1278 $scope.clearWorking = function () {
1279 angular.forEach($scope.working, function (v,k,o) {
1280 if (!angular.isObject(v)) {
1281 if (typeof v != 'undefined')
1282 $scope.working[k] = undefined;
1283 } else if (k != 'circ_lib') {
1284 angular.forEach(v, function (sv,sk) {
1285 if (typeof v != 'undefined')
1286 $scope.working[k][sk] = undefined;
1290 $scope.working.circ_lib = undefined; // special
1293 $scope.completedGridDataProvider = egGridDataProvider.instance({
1294 get : function(offset, count) {
1295 //return provider.arrayNotifier(itemSvc.copies, offset, count);
1296 return this.arrayNotifier($scope.completed_copies, offset, count);
1300 $scope.completedGridControls = {};
1302 $scope.workingGridDataProvider = egGridDataProvider.instance({
1303 get : function(offset, count) {
1304 //return provider.arrayNotifier(itemSvc.copies, offset, count);
1305 return this.arrayNotifier(itemSvc.copies, offset, count);
1309 $scope.workingGridControls = {};
1310 $scope.add_vols_copies = false;
1311 $scope.is_fast_add = false;
1315 'open-ils.actor.anon_cache.get_value',
1316 dataKey, 'edit-these-copies'
1317 ).then(function (data) {
1320 if (data.hide_vols && !$scope.defaults.always_volumes) $scope.show_vols = false;
1321 if (data.hide_copies) {
1322 $scope.show_copies = false;
1323 $scope.only_vols = true;
1326 $scope.record_id = data.record_id;
1328 function fetchRaw () {
1329 if (!$scope.only_vols) $scope.dirty = true;
1330 $scope.add_vols_copies = true;
1332 /* data.raw data structure looks like this:
1334 * callnumber : $cn_id, // optional, to add a copy to a cn
1335 * owner : $org, // optional, defaults to ws_ou
1336 * label : $cn_label, // optional, to supply a label on a new cn
1337 * barcode : $cp_barcode // optional, to supply a barcode on a new cp
1338 * fast_add : boolean // optional, to specify whether this came
1342 * All can be left out and a completely empty vol/copy combo will be vivicated.
1348 if (proto.fast_add) $scope.is_fast_add = true;
1349 if (proto.callnumber) {
1350 return egCore.pcrud.retrieve('acn', proto.callnumber)
1351 .then(function(cn) {
1352 var cp = new itemSvc.generateNewCopy(
1354 proto.owner || egCore.auth.user().ws_ou(),
1356 ((!$scope.only_vols) ? true : false)
1359 if (proto.barcode) {
1360 cp.barcode( proto.barcode );
1361 cp.empty_barcode = false;
1367 var cn = new egCore.idl.acn();
1368 cn.id( --itemSvc.new_cn_id );
1370 cn.prefix( $scope.defaults.prefix || -1 );
1371 cn.suffix( $scope.defaults.suffix || -1 );
1372 cn.owning_lib( proto.owner || egCore.auth.user().ws_ou() );
1373 cn.record( $scope.record_id );
1374 egCore.org.settings(
1375 ['cat.default_classification_scheme'],
1377 ).then(function (val) {
1379 $scope.defaults.classification ||
1380 val['cat.default_classification_scheme'] ||
1384 cn.label( proto.label );
1388 'open-ils.cat.biblio.record.marc_cn.retrieve',
1391 ).then(function(cn_array) {
1392 if (cn_array.length > 0) {
1393 for (var field in cn_array[0]) {
1394 cn.label( cn_array[0][field] );
1402 var cp = new itemSvc.generateNewCopy(
1404 proto.owner || egCore.auth.user().ws_ou(),
1409 if (proto.barcode) {
1410 cp.barcode( proto.barcode );
1411 cp.empty_barcode = false;
1420 return itemSvc.copies;
1423 if (data.copies && data.copies.length)
1424 return itemSvc.fetchIds(data.copies).then(fetchRaw);
1430 }).then( function() {
1431 $scope.data = itemSvc;
1432 $scope.workingGridDataProvider.refresh();
1435 $scope.can_save = false;
1436 function check_saveable () {
1437 var can_save = true;
1441 if (i.duplicate_barcode || i.empty_barcode || i.call_number().empty_label)
1445 if ($scope.forms.myForm && $scope.forms.myForm.$invalid) {
1448 $scope.can_save = can_save;
1451 $scope.disableSave = function () {
1453 return !$scope.can_save;
1456 $scope.focusNextFirst = function(prev_lib,prev_bc) {
1459 angular.forEach(Object.keys($scope.data.tree).sort(), function (lib) {
1462 if (lib == prev_lib) {
1471 var first_cn = Object.keys($scope.data.tree[n])[0];
1472 var next = '#' + first_cn + '_' + $scope.data.tree[n][first_cn][0].id();
1475 if (!itemSvc.currently_generating) el.focus();
1476 if (prev_bc && itemSvc.auto_gen_barcode && el.val() == "") {
1477 itemSvc.nextBarcode(prev_bc).then(function(bc){
1480 el.trigger('change');
1483 itemSvc.currently_generating = false;
1489 $scope.in_item_select = false;
1490 $scope.afterItemSelect = function() { $scope.in_item_select = false };
1491 $scope.handleItemSelect = function (item_list) {
1492 if (item_list && item_list.length > 0) {
1493 $scope.in_item_select = true;
1495 angular.forEach(Object.keys($scope.defaults.attributes), function (attr) {
1497 var value_hash = {};
1498 angular.forEach(item_list, function (item) {
1500 var v = item[attr]()
1501 if (angular.isObject(v)) {
1502 if (v.id) v = v.id();
1503 else if (v.code) v = v.code();
1509 if (Object.keys(value_hash).length == 1) {
1510 if (attr == 'circ_lib') {
1511 $scope.working[attr] = egCore.org.get(item_list[0][attr]());
1513 $scope.working[attr] = item_list[0][attr]();
1516 $scope.working[attr] = undefined;
1520 angular.forEach($scope.statcats, function (sc) {
1523 var value_hash = {};
1525 angular.forEach(item_list, function (item) {
1526 if (item.stat_cat_entries()) {
1527 if (item.stat_cat_entries().length > 0) {
1528 var right_sc = item.stat_cat_entries().filter(function (e) {
1529 return e.stat_cat() == sc.id() && !Boolean(e.isdeleted());
1532 if (right_sc.length > 0) {
1533 value_hash[right_sc[0].id()] = right_sc[0].id();
1543 if (!none && Object.keys(value_hash).length == 1) {
1544 $scope.working.statcats[sc.id()] = value_hash[Object.keys(value_hash)[0]];
1546 $scope.working.statcats[sc.id()] = undefined;
1551 $scope.clearWorking();
1556 $scope.$watch('data.copies.length', function () {
1557 if ($scope.data.copies) {
1558 var base_orgs = $scope.data.copies.map(function(cp){
1559 return cp.circ_lib()
1561 $scope.data.copies.map(function(cp){
1562 return cp.call_number().owning_lib()
1565 [egCore.auth.user().ws_ou()]
1566 ).filter(function(e,i,a){
1567 return a.lastIndexOf(e) === i;
1571 angular.forEach(base_orgs, function(o) {
1572 all_orgs = all_orgs.concat( egCore.org.fullPath(o, true) );
1575 var final_orgs = all_orgs.filter(function(e,i,a){
1576 return a.lastIndexOf(e) === i;
1577 }).sort(function(a, b){return parseInt(a)-parseInt(b)});
1579 if ($scope.location_orgs.toString() != final_orgs.toString()) {
1580 $scope.location_orgs = final_orgs;
1581 if ($scope.location_orgs.length) {
1582 itemSvc.get_locations($scope.location_orgs).then(function(list){
1583 angular.forEach(list, function(l) {
1584 $scope.location_cache[ ''+l.id() ] = l;
1586 $scope.location_list = list;
1589 $scope.statcat_filter_list = [];
1590 angular.forEach($scope.location_orgs, function (o) {
1591 $scope.statcat_filter_list.push(egCore.org.get(o));
1594 itemSvc.get_statcats($scope.location_orgs).then(function(list){
1595 $scope.statcats = list;
1596 angular.forEach($scope.statcats, function (s) {
1598 if (!$scope.working)
1599 $scope.working = { statcats: {}, statcat_filter: undefined};
1600 if (!$scope.working.statcats)
1601 $scope.working.statcats = {};
1603 if (!$scope.in_item_select) {
1604 $scope.working.statcats[s.id()] = undefined;
1606 createStatcatUpdateWatcher(s.id());
1608 $scope.in_item_select = false;
1609 // do a refresh here to work around a race
1610 // condition that can result in stat cats
1611 // not being selected.
1612 $scope.workingGridDataProvider.refresh();
1618 $scope.workingGridDataProvider.refresh();
1621 $scope.statcat_visible = function (sc_owner) {
1622 var visible = typeof $scope.working.statcat_filter === 'undefined' || !$scope.working.statcat_filter;
1623 angular.forEach(egCore.org.ancestors(sc_owner), function (ancestor_org) {
1624 if ($scope.working.statcat_filter == ancestor_org.id())
1630 $scope.suffix_list = [];
1631 itemSvc.get_suffixes(egCore.auth.user().ws_ou()).then(function(list){
1632 $scope.suffix_list = list;
1635 $scope.prefix_list = [];
1636 itemSvc.get_prefixes(egCore.auth.user().ws_ou()).then(function(list){
1637 $scope.prefix_list = list;
1640 $scope.classification_list = [];
1641 itemSvc.get_classifications().then(function(list){
1642 $scope.classification_list = list;
1645 $scope.$watch('completed_copies.length', function () {
1646 $scope.completedGridDataProvider.refresh();
1649 $scope.location_list = [];
1650 itemSvc.get_locations().then(function(list){
1651 $scope.location_list = list;
1653 createSimpleUpdateWatcher('location');
1655 $scope.status_list = [];
1656 itemSvc.get_magic_statuses().then(function(list){
1657 $scope.magic_status_list = list;
1658 createSimpleUpdateWatcher('status',$scope.magic_status_list);
1660 itemSvc.get_statuses().then(function(list){
1661 $scope.status_list = list;
1664 $scope.circ_modifier_list = [];
1665 itemSvc.get_circ_mods().then(function(list){
1666 $scope.circ_modifier_list = list;
1668 createSimpleUpdateWatcher('circ_modifier');
1670 $scope.circ_type_list = [];
1671 itemSvc.get_circ_types().then(function(list){
1672 $scope.circ_type_list = list;
1674 createSimpleUpdateWatcher('circ_as_type');
1676 $scope.age_protect_list = [];
1677 itemSvc.get_age_protects().then(function(list){
1678 $scope.age_protect_list = list;
1680 createSimpleUpdateWatcher('age_protect');
1682 $scope.floating_list = [];
1683 itemSvc.get_floating_groups().then(function(list){
1684 $scope.floating_list = list;
1686 createSimpleUpdateWatcher('floating');
1688 createSimpleUpdateWatcher('circ_lib');
1689 createSimpleUpdateWatcher('circulate');
1690 createSimpleUpdateWatcher('holdable');
1691 createSimpleUpdateWatcher('fine_level');
1692 createSimpleUpdateWatcher('loan_duration');
1693 createSimpleUpdateWatcher('price');
1694 createSimpleUpdateWatcher('cost');
1695 createSimpleUpdateWatcher('deposit');
1696 createSimpleUpdateWatcher('deposit_amount');
1697 createSimpleUpdateWatcher('mint_condition');
1698 createSimpleUpdateWatcher('opac_visible');
1699 createSimpleUpdateWatcher('ref');
1700 createSimpleUpdateWatcher('alert_message');
1702 $scope.saveCompletedCopies = function (and_exit) {
1704 var perCnCopies = {};
1705 angular.forEach( $scope.completed_copies, function (cp) {
1706 var cn = cp.call_number();
1707 var cn_cps = cp.call_number().copies();
1708 cp.call_number().copies([]);
1709 var cn_id = cp.call_number().id();
1710 cp.call_number(cn_id); // prevent loops in JSON-ification
1711 if (!cnHash[cn_id]) {
1712 cnHash[cn_id] = egCore.idl.Clone(cn);
1713 perCnCopies[cn_id] = [egCore.idl.Clone(cp)];
1715 perCnCopies[cn_id].push(egCore.idl.Clone(cp));
1717 cp.call_number(cn); // put the data back
1718 cp.call_number().copies(cn_cps);
1719 if (typeof cnHash[cn_id].prefix() == 'object')
1720 cnHash[cn_id].prefix(cnHash[cn_id].prefix().id()); // un-object-ize some fields
1721 if (typeof cnHash[cn_id].suffix() == 'object')
1722 cnHash[cn_id].suffix(cnHash[cn_id].suffix().id()); // un-object-ize some fields
1725 angular.forEach(perCnCopies, function (v, k) {
1726 cnHash[k].copies(v);
1730 angular.forEach(cnHash, function (v, k) {
1736 'open-ils.cat.asset.volume.fleshed.batch.update.override',
1737 egCore.auth.token(), cnList, 1, { auto_merge_vols : 1, create_parts : 1, return_copy_ids : 1 }
1738 ).then(function(copy_ids) {
1740 $scope.dirty = false;
1741 if ($scope.defaults.print_item_labels) {
1744 'open-ils.actor.anon_cache.set_value',
1745 null, 'print-labels-these-copies', {
1748 ).then(function(key) {
1750 var url = egCore.env.basePath + 'cat/printlabels/' + key;
1751 $timeout(function() { $window.open(url, '_blank') }).then(
1752 function() { $timeout(function(){$window.close()}); }
1755 alert('Could not create anonymous cache key!');
1759 $timeout(function(){$window.close()});
1765 $scope.saveAndContinue = function () {
1766 $scope.saveCompletedCopies(false);
1769 $scope.workingSaveAndExit = function () {
1770 $scope.workingToComplete();
1771 $scope.saveAndExit();
1774 $scope.saveAndExit = function () {
1775 $scope.saveCompletedCopies(true);
1780 $scope.copy_notes_dialog = function(copy_list) {
1781 var default_pub = Boolean($scope.defaults.copy_notes_pub);
1782 if (!angular.isArray(copy_list)) copy_list = [copy_list];
1784 return $uibModal.open({
1785 templateUrl: './cat/volcopy/t_copy_notes',
1789 ['$scope','$uibModalInstance',
1790 function($scope , $uibModalInstance) {
1791 $scope.focusNote = true;
1793 creator : egCore.auth.user().id(),
1799 $scope.require_initials = false;
1800 egCore.org.settings([
1801 'ui.staff.require_initials.copy_notes'
1802 ]).then(function(set) {
1803 $scope.require_initials = Boolean(set['ui.staff.require_initials.copy_notes']);
1806 $scope.note_list = [];
1807 if (copy_list.length == 1) {
1808 $scope.note_list = copy_list[0].notes();
1811 $scope.ok = function(note) {
1813 if ($scope.initials) {
1814 note.value = egCore.strings.$replace(
1815 egCore.strings.COPY_NOTE_INITIALS, {
1817 initials : $scope.initials,
1818 ws_ou : egCore.org.get(
1819 egCore.auth.user().ws_ou()).shortname()
1823 angular.forEach(copy_list, function (cp) {
1824 if (!angular.isArray(cp.notes())) cp.notes([]);
1825 var n = new egCore.idl.acpn();
1827 n.creator(note.creator);
1829 n.title(note.title);
1830 n.value(note.value);
1831 n.owning_copy(cp.id());
1832 cp.notes().push( n );
1835 $uibModalInstance.close();
1838 $scope.cancel = function($event) {
1839 $uibModalInstance.dismiss();
1840 $event.preventDefault();
1846 $scope.copy_tags_dialog = function(copy_list) {
1847 if (!angular.isArray(copy_list)) copy_list = [copy_list];
1849 return $uibModal.open({
1850 templateUrl: './cat/volcopy/t_copy_tags',
1854 ['$scope','$uibModalInstance',
1855 function($scope , $uibModalInstance) {
1857 $scope.tag_map = [];
1859 var shared_tags = {};
1860 angular.forEach(copy_list, function (cp) {
1861 angular.forEach(cp.tags(), function(tag) {
1862 if (!(tag.tag().id() in shared_tags)) {
1863 shared_tags[tag.tag().id()] = 1;
1865 shared_tags[tag.tag().id()]++;
1867 if (!(tag.tag().id() in tag_hash)) {
1868 tag_hash[tag.tag().id()] = tag;
1872 angular.forEach(tag_hash, function(value, key) {
1873 if (shared_tags[key] == copy_list.length) {
1874 $scope.tag_map.push(value);
1878 $scope.tag_types = [];
1879 egCore.pcrud.retrieveAll('cctt', {order_by : { cctt : 'label' }}, {atomic : true}).then(function(list) {
1880 $scope.tag_types = list;
1881 $scope.tag_type = $scope.tag_types[0].code(); // just pick a default
1884 $scope.getTags = function(val) {
1885 return egCore.pcrud.search('acpt',
1887 owner : egCore.org.fullPath(egCore.auth.user().ws_ou(), true),
1888 label : { 'startwith' : {
1889 transform: 'evergreen.lowercase',
1890 value : [ 'evergreen.lowercase', val ]
1892 tag_type : $scope.tag_type
1894 { order_by : { 'acpt' : ['label'] } }, { atomic: true }
1895 ).then(function(list) {
1896 return list.map(function(item) {
1897 return item.label();
1902 $scope.addTag = function() {
1903 var tagLabel = $scope.selectedLabel;
1904 // clear the typeahead
1905 $scope.selectedLabel = "";
1907 // first, check tags already associated with the copy
1908 var foundMatch = false;
1909 angular.forEach($scope.tag_map, function(tag) {
1910 if (tag.tag().label() == tagLabel && tag.tag().tag_type() == $scope.tag_type) {
1912 if (tag.isdeleted()) tag.isdeleted(0); // just deleting the mapping
1916 egCore.pcrud.search('acpt',
1918 owner : egCore.org.fullPath(egCore.auth.user().ws_ou(), true),
1920 tag_type : $scope.tag_type
1922 { order_by : { 'acpt' : ['label'] } }, { atomic: true }
1923 ).then(function(list) {
1924 if (list.length > 0) {
1925 var newMap = new egCore.idl.acptcm();
1927 newMap.copy(copy_list[0].id());
1928 newMap.tag(egCore.idl.Clone(list[0]));
1929 $scope.tag_map.push(newMap);
1931 var newTag = new egCore.idl.acpt();
1933 newTag.owner(egCore.auth.user().ws_ou());
1934 newTag.label(tagLabel);
1936 newTag.tag_type($scope.tag_type);
1938 var newMap = new egCore.idl.acptcm();
1940 newMap.copy(copy_list[0].id());
1942 $scope.tag_map.push(newMap);
1948 $scope.ok = function(note) {
1949 // in the multi-item case, this works OK for
1950 // adding new maps to existing tags, but doesn't handle
1951 // all possibilities
1952 angular.forEach(copy_list, function (cp) {
1953 cp.tags($scope.tag_map);
1955 $uibModalInstance.close();
1958 $scope.cancel = function($event) {
1959 $uibModalInstance.dismiss();
1960 $event.preventDefault();
1968 .directive("egVolTemplate", function () {
1972 template: '<div ng-include="'+"'/eg/staff/cat/volcopy/t_attr_edit'"+'"></div>',
1976 controller : ['$scope','$window','itemSvc','egCore','ngToast',
1977 function ( $scope , $window , itemSvc , egCore , ngToast) {
1979 $scope.i18n = egCore.i18n;
1981 $scope.defaults = { // If defaults are not set at all, allow everything
1982 barcode_checkdigit : false,
1983 auto_gen_barcode : false,
1989 loan_duration : true,
1994 deposit_amount : true,
1995 opac_visible : true,
1998 mint_condition : true,
2001 circ_modifier : true,
2002 circ_as_type : true,
2010 $scope.fetchDefaults = function () {
2011 egCore.hatch.getItem('cat.copy.defaults').then(function(t) {
2013 $scope.defaults = t;
2014 $scope.working.statcat_filter = $scope.defaults.statcat_filter;
2016 typeof $scope.defaults.statcat_filter == 'object' &&
2017 Object.keys($scope.defaults.statcat_filter).length > 0
2019 // want fieldmapper object here...
2020 $scope.defaults.statcat_filter =
2021 egCore.idl.Clone($scope.defaults.statcat_filter);
2023 $scope.working.statcat_filter = $scope.defaults.statcat_filter.id();
2028 $scope.fetchDefaults();
2030 $scope.dirty = false;
2031 $scope.$watch('dirty',
2032 function(newVal, oldVal) {
2033 if (newVal && newVal != oldVal) {
2034 $($window).on('beforeunload.template', function(){
2035 return 'There is unsaved template data!'
2038 $($window).off('beforeunload.template');
2043 $scope.template_controls = true;
2045 $scope.fetchTemplates = function () {
2046 itemSvc.get_acp_templates().then(function(t) {
2048 $scope.templates = t;
2049 $scope.template_name_list = Object.keys(t).sort();
2053 $scope.fetchTemplates();
2055 $scope.applyTemplate = function (n) {
2056 angular.forEach($scope.templates[n], function (v,k) {
2057 if (k == 'circ_lib') {
2058 $scope.working[k] = egCore.org.get(v);
2059 } else if (!angular.isObject(v)) {
2060 $scope.working[k] = angular.copy(v);
2062 angular.forEach(v, function (sv,sk) {
2063 if (!(k in $scope.working))
2064 $scope.working[k] = {};
2065 $scope.working[k][sk] = angular.copy(sv);
2069 $scope.template_name = '';
2072 $scope.deleteTemplate = function (n) {
2074 delete $scope.templates[n]
2075 $scope.template_name_list = Object.keys($scope.templates).sort();
2076 $scope.template_name = '';
2077 itemSvc.save_acp_templates($scope.templates);
2078 $scope.$parent.fetchTemplates();
2079 ngToast.create(egCore.strings.VOL_COPY_TEMPLATE_SUCCESS_DELETE);
2083 $scope.saveTemplate = function (n) {
2087 angular.forEach($scope.working, function (v,k) {
2088 if (angular.isObject(v)) { // we'll use the pkey
2089 if (v.id) v = v.id();
2090 else if (v.code) v = v.code();
2096 $scope.templates[n] = tmpl;
2097 $scope.template_name_list = Object.keys($scope.templates).sort();
2099 itemSvc.save_acp_templates($scope.templates);
2100 $scope.$parent.fetchTemplates();
2102 $scope.dirty = false;
2104 // save all templates, as we might do after an import
2105 itemSvc.save_acp_templates($scope.templates);
2106 $scope.$parent.fetchTemplates();
2108 ngToast.create(egCore.strings.VOL_COPY_TEMPLATE_SUCCESS_SAVE);
2111 $scope.templates = {};
2112 $scope.imported_templates = { data : '' };
2113 $scope.template_name = '';
2114 $scope.template_name_list = [];
2116 $scope.$watch('imported_templates.data', function(newVal, oldVal) {
2117 if (newVal && newVal != oldVal) {
2119 var newTemplates = JSON.parse(newVal);
2120 if (!Object.keys(newTemplates).length) return;
2121 angular.forEach(Object.keys(newTemplates), function (k) {
2122 $scope.templates[k] = newTemplates[k];
2124 itemSvc.save_acp_templates($scope.templates);
2125 $scope.fetchTemplates();
2127 console.log('tried to import an invalid copy template file');
2132 $scope.tracker = function (x,f) { if (x) return x[f]() };
2133 $scope.idTracker = function (x) { if (x) return $scope.tracker(x,'id') };
2134 $scope.cant_have_vols = function (id) { return !egCore.org.CanHaveVolumes(id); };
2136 $scope.orgById = function (id) { return egCore.org.get(id) }
2137 $scope.statusById = function (id) {
2138 return $scope.status_list.filter( function (s) { return s.id() == id } )[0];
2140 $scope.locationById = function (id) {
2141 return $scope.location_cache[''+id];
2144 createSimpleUpdateWatcher = function (field) {
2145 $scope.$watch('working.' + field, function () {
2146 var newval = $scope.working[field];
2148 if (typeof newval != 'undefined') {
2149 $scope.dirty = true;
2150 if (angular.isObject(newval)) { // we'll use the pkey
2151 if (newval.id) $scope.working[field] = newval.id();
2152 else if (newval.code) $scope.working[field] = newval.code();
2155 if (""+newval == "" || newval == null) {
2156 $scope.working[field] = undefined;
2165 statcat_filter: undefined
2168 $scope.statcat_visible = function (sc_owner) {
2169 var visible = typeof $scope.working.statcat_filter === 'undefined' || !$scope.working.statcat_filter;
2170 angular.forEach(egCore.org.ancestors(sc_owner), function (ancestor_org) {
2171 if ($scope.working.statcat_filter == ancestor_org.id())
2177 createStatcatUpdateWatcher = function (id) {
2178 return $scope.$watch('working.statcats[' + id + ']', function () {
2179 if ($scope.working.statcats) {
2180 var newval = $scope.working.statcats[id];
2182 if (typeof newval != 'undefined') {
2183 $scope.dirty = true;
2184 if (angular.isObject(newval)) { // we'll use the pkey
2185 newval = newval.id();
2188 if (""+newval == "" || newval == null) {
2189 $scope.working.statcats[id] = undefined;
2198 $scope.clearWorking = function () {
2199 angular.forEach($scope.working, function (v,k,o) {
2200 if (!angular.isObject(v)) {
2201 if (typeof v != 'undefined')
2202 $scope.working[k] = undefined;
2203 } else if (k != 'circ_lib') {
2204 angular.forEach(v, function (sv,sk) {
2205 $scope.working[k][sk] = undefined;
2209 $scope.working.circ_lib = undefined; // special
2210 $scope.dirty = false;
2213 $scope.working = {};
2214 $scope.location_orgs = [];
2215 $scope.location_cache = {};
2217 $scope.location_list = [];
2218 itemSvc.get_locations(
2219 egCore.org.fullPath( egCore.auth.user().ws_ou(), true )
2220 ).then(function(list){
2221 $scope.location_list = list;
2223 createSimpleUpdateWatcher('location');
2225 $scope.statcat_filter_list = egCore.org.fullPath( egCore.auth.user().ws_ou() );
2227 $scope.statcats = [];
2228 itemSvc.get_statcats(
2229 egCore.org.fullPath( egCore.auth.user().ws_ou(), true )
2230 ).then(function(list){
2231 $scope.statcats = list;
2232 angular.forEach($scope.statcats, function (s) {
2234 if (!$scope.working)
2235 $scope.working = { statcats: {}, statcat_filter: undefined};
2236 if (!$scope.working.statcats)
2237 $scope.working.statcats = {};
2239 $scope.working.statcats[s.id()] = undefined;
2240 createStatcatUpdateWatcher(s.id());
2244 $scope.status_list = [];
2245 itemSvc.get_magic_statuses().then(function(list){
2246 $scope.magic_status_list = list;
2248 itemSvc.get_statuses().then(function(list){
2249 $scope.status_list = list;
2251 createSimpleUpdateWatcher('status');
2253 $scope.circ_modifier_list = [];
2254 itemSvc.get_circ_mods().then(function(list){
2255 $scope.circ_modifier_list = list;
2257 createSimpleUpdateWatcher('circ_modifier');
2259 $scope.circ_type_list = [];
2260 itemSvc.get_circ_types().then(function(list){
2261 $scope.circ_type_list = list;
2263 createSimpleUpdateWatcher('circ_as_type');
2265 $scope.age_protect_list = [];
2266 itemSvc.get_age_protects().then(function(list){
2267 $scope.age_protect_list = list;
2269 createSimpleUpdateWatcher('age_protect');
2271 createSimpleUpdateWatcher('circulate');
2272 createSimpleUpdateWatcher('holdable');
2273 createSimpleUpdateWatcher('fine_level');
2274 createSimpleUpdateWatcher('loan_duration');
2275 createSimpleUpdateWatcher('cost');
2276 createSimpleUpdateWatcher('deposit');
2277 createSimpleUpdateWatcher('deposit_amount');
2278 createSimpleUpdateWatcher('mint_condition');
2279 createSimpleUpdateWatcher('opac_visible');
2280 createSimpleUpdateWatcher('ref');
2281 createSimpleUpdateWatcher('alert_message');
2283 $scope.suffix_list = [];
2284 itemSvc.get_suffixes(egCore.auth.user().ws_ou()).then(function(list){
2285 $scope.suffix_list = list;
2288 $scope.prefix_list = [];
2289 itemSvc.get_prefixes(egCore.auth.user().ws_ou()).then(function(list){
2290 $scope.prefix_list = list;
2293 $scope.classification_list = [];
2294 itemSvc.get_classifications().then(function(list){
2295 $scope.classification_list = list;
2298 createSimpleUpdateWatcher('working.callnumber.classification');
2299 createSimpleUpdateWatcher('working.callnumber.prefix');
2300 createSimpleUpdateWatcher('working.callnumber.suffix');