5 angular.module('egVolCopy',
6 ['ngRoute', 'ui.bootstrap', 'egCoreMod', 'egUiMod', 'egGridMod'])
8 .filter('boolText', function(){
14 .config(function($routeProvider, $locationProvider, $compileProvider) {
15 $locationProvider.html5Mode(true);
16 $compileProvider.aHrefSanitizationWhitelist(/^\s*(https?|blob):/); // grid export
19 delay : ['egStartup', function(egStartup) { return egStartup.go(); }]
22 $routeProvider.when('/cat/volcopy/:dataKey', {
23 templateUrl: './cat/volcopy/t_view',
24 controller: 'EditCtrl',
32 function(egCore , $q) {
37 tree : {}, // holds lib->cn->copy hash stack
38 copies : [] // raw copy list
41 // returns a promise resolved with the list of circ mods
42 service.get_classifications = function() {
44 return $q.when(egCore.env.acnc.list);
46 return egCore.pcrud.retrieveAll('acnc', null, {atomic : true})
47 .then(function(list) {
48 egCore.env.absorbList(list, 'acnc');
53 service.get_prefixes = function(org) {
54 return egCore.pcrud.search('acnp',
55 {owning_lib : egCore.org.fullPath(org, true)},
61 service.get_statcats = function(orgs) {
62 return egCore.pcrud.search('asc',
66 asc : ['owner','entries']
73 service.get_locations = function(orgs) {
74 return egCore.pcrud.search('acpl',
80 service.get_suffixes = function(org) {
81 return egCore.pcrud.search('acns',
82 {owning_lib : egCore.org.fullPath(org, true)},
88 service.get_statuses = function() {
90 return $q.when(egCore.env.ccs.list);
92 return egCore.pcrud.retrieveAll('ccs', {}, {atomic : true}).then(
94 egCore.env.absorbList(list, 'ccs');
101 service.get_circ_mods = function() {
103 return $q.when(egCore.env.ccm.list);
105 return egCore.pcrud.retrieveAll('ccm', {}, {atomic : true}).then(
107 egCore.env.absorbList(list, 'ccm');
114 service.get_circ_types = function() {
116 return $q.when(egCore.env.citm.list);
118 return egCore.pcrud.retrieveAll('citm', {}, {atomic : true}).then(
120 egCore.env.absorbList(list, 'citm');
127 service.get_age_protects = function() {
128 if (egCore.env.crahp)
129 return $q.when(egCore.env.crahp.list);
131 return egCore.pcrud.retrieveAll('crahp', {}, {atomic : true}).then(
133 egCore.env.absorbList(list, 'crahp');
140 service.bmp_parts = {};
141 service.get_parts = function(rec) {
142 if (service.bmp_parts[rec])
143 return $q.when(service.bmp_parts[rec]);
145 return egCore.pcrud.search('bmp',
147 null, {atomic : true}
148 ).then(function(list) {
149 service.bmp_parts[rec] = list;
158 acp : ['call_number','parts','stat_cat_entries', 'notes'],
159 acn : ['label_class','prefix','suffix']
163 service.addCopy = function (cp) {
165 if (!cp.parts()) cp.parts([]); // just in case...
167 var lib = cp.call_number().owning_lib();
168 var cn = cp.call_number().id();
170 if (!service.tree[lib]) service.tree[lib] = {};
171 if (!service.tree[lib][cn]) service.tree[lib][cn] = [];
173 service.tree[lib][cn].push(cp);
174 service.copies.push(cp);
177 service.fetchIds = function(idList) {
178 service.tree = {}; // clear the tree on fetch
179 service.copies = []; // clear the copy list on fetch
180 return egCore.pcrud.search('acp', { 'id' : idList }, service.flesh).then(null,null,
182 service.addCopy(copy);
190 .directive("egVolCopyEdit", function () {
196 '<div class="col-xs-5">'+
197 '<input id="{{callNumber.id()}}_{{copy.id()}}"'+
198 ' eg-enter="nextBarcode(copy.id())" class="form-control"'+
199 ' type="text" ng-model="barcode" ng-change="updateBarcode()"/>'+
201 '<div class="col-xs-3"><input class="form-control" type="number" ng-model="copy_number" ng-change="updateCopyNo()"/></div>'+
202 '<div class="col-xs-4"><eg-basic-combo-box list="parts" selected="part"></eg-basic-combo-box></div>'+
205 scope: { focusNext: "=", copy: "=", callNumber: "=", index: "@" },
206 controller : ['$scope','itemSvc','egCore',
207 function ( $scope , itemSvc , egCore ) {
208 $scope.new_part_id = 0;
210 $scope.nextBarcode = function (i) {
214 $scope.updateBarcode = function () { $scope.copy.barcode($scope.barcode); $scope.copy.ischanged(1); };
215 $scope.updateCopyNo = function () { $scope.copy.copy_number($scope.copy_number); $scope.copy.ischanged(1); };
216 $scope.updatePart = function () {
218 var p = $scope.part_list.filter(function (x) {
219 return x.label() == $scope.part
221 if (p.length > 0) { // preexisting part
223 } else { // create one...
224 var part = new egCore.idl.bmp();
225 part.id( --$scope.new_part_id );
227 part.label( $scope.part );
228 part.record( $scope.callNumber.owning_lib() );
229 $scope.copy.parts([part]);
230 $scope.copy.ischanged(1);
233 $scope.copy.parts([]);
236 $scope.$watch('part', $scope.updatePart);
238 $scope.barcode = $scope.copy.barcode();
239 $scope.copy_number = $scope.copy.copy_number();
241 if ($scope.copy.parts()) {
242 $scope.part = $scope.copy.parts()[0];
243 if ($scope.part) $scope.part = $scope.part.label();
247 $scope.part_list = [];
249 itemSvc.get_parts($scope.callNumber.record()).then(function(list){
250 $scope.part_list = list;
251 angular.forEach(list, function(p){ $scope.parts.push(p.label()) });
252 $scope.parts = angular.copy($scope.parts);
261 .directive("egVolRow", function () {
268 '<div class="col-xs-2">'+
269 '<select class="form-control" ng-model="classification" ng-options="cl.name() for cl in classification_list track by idTracker(cl)"/>'+
271 '<div class="col-xs-1">'+
272 '<select class="form-control" ng-model="prefix" ng-change="updatePrefix()" ng-options="p.label() for p in prefix_list track by idTracker(p)"/>'+
274 '<div class="col-xs-2"><input class="form-control" type="text" ng-change="updateLabel()" ng-model="label"/></div>'+
275 '<div class="col-xs-1">'+
276 '<select class="form-control" ng-model="suffix" ng-change="updateSuffix()" ng-options="s.label() for s in suffix_list track by idTracker(s)"/>'+
278 '<div class="col-xs-1"><input class="form-control" type="number" ng-model="copy_count" min="{{orig_copy_count}}" ng-change="changeCPCount()"></div>'+
279 '<div class="col-xs-5">'+
280 '<eg-vol-copy-edit ng-repeat="cp in copies track by idTracker(cp)" focus-next="focusNextBarcode" copy="cp" call-number="callNumber"></eg-vol-copy-edit>'+
284 scope: {focusNext: "=", allcopies: "=", copies: "=" },
285 controller : ['$scope','itemSvc','egCore',
286 function ( $scope , itemSvc , egCore ) {
287 $scope.callNumber = $scope.copies[0].call_number();
289 $scope.idTracker = function (x) { if (x && x.id) return x.id() };
291 // XXX $() is not working! arg
292 $scope.focusNextBarcode = function (i) {
295 angular.forEach($scope.copies, function (cp) {
303 if (yep) n = cp.id();
307 var next = '#' + $scope.callNumber.id() + '_' + n;
311 $scope.focusNext($scope.callNumber.id())
315 $scope.suffix_list = [];
316 itemSvc.get_suffixes($scope.callNumber.owning_lib()).then(function(list){
317 $scope.suffix_list = list;
318 $scope.$watch('callNumber.suffix()', function (v) {
319 $scope.suffix = $scope.suffix_list.filter( function (s) {
325 $scope.updateSuffix = function () {
326 angular.forEach($scope.copies, function(cp) {
327 cp.call_number().suffix($scope.suffix.id());
328 cp.call_number().ischanged(1);
332 $scope.prefix_list = [];
333 itemSvc.get_prefixes($scope.callNumber.owning_lib()).then(function(list){
334 $scope.prefix_list = list;
335 $scope.$watch('callNumber.prefix()', function (v) {
336 $scope.prefix = $scope.prefix_list.filter(function (p) {
342 $scope.updatePrefix = function () {
343 angular.forEach($scope.copies, function(cp) {
344 cp.call_number().prefix($scope.prefix.id());
345 cp.call_number().ischanged(1);
349 $scope.classification_list = [];
350 itemSvc.get_classifications().then(function(list){
351 $scope.classification_list = list;
352 $scope.$watch('callNumber.label_class()', function (v) {
353 $scope.classification = $scope.classification_list.filter(function (c) {
359 $scope.updateClassification = function () {
360 angular.forEach($scope.copies, function(cp) {
361 cp.call_number().label_class($scope.classification.id());
362 cp.call_number().ischanged(1);
366 $scope.updateLabel = function () {
367 angular.forEach($scope.copies, function(cp) {
368 cp.call_number().label($scope.label);
369 cp.call_number().ischanged(1);
373 $scope.$watch('callNumber.label()', function (v) {
377 $scope.prefix = $scope.callNumber.prefix();
378 $scope.suffix = $scope.callNumber.suffix();
379 $scope.classification = $scope.callNumber.label_class();
380 $scope.label = $scope.callNumber.label();
382 $scope.copy_count = $scope.copies.length;
383 $scope.orig_copy_count = $scope.copy_count;
385 $scope.changeCPCount = function () {
386 while ($scope.copy_count > $scope.copies.length) {
387 var cp = new egCore.idl.acp();
388 cp.id( --itemSvc.new_cp_id );
390 cp.circ_lib( $scope.lib );
391 cp.call_number( $scope.callNumber );
392 $scope.copies.push( cp );
393 $scope.allcopies.push( cp );
396 if ($scope.copy_count >= $scope.orig_copy_count) {
397 var how_many = $scope.copies.length - $scope.copy_count;
399 var dead = $scope.copies.splice($scope.copy_count,how_many);
400 $scope.callNumber.copies($scope.copies);
402 // Trimming the global list is a bit more tricky
403 angular.forEach( dead, function (d) {
404 angular.forEach( $scope.allcopies, function (l, i) {
405 if (l === d) $scope.allcopies.splice(i,1);
418 .directive("egVolEdit", function () {
424 '<div class="col-xs-1"><eg-org-selector selected="owning_lib" disableTest="cant_have_vols"></eg-org-selector></div>'+
425 '<div class="col-xs-1"><input class="form-control" type="number" min="{{orig_cn_count}}" ng-model="cn_count" ng-change="changeCNCount()"/></div>'+
426 '<div class="col-xs-10">'+
427 '<eg-vol-row ng-repeat="(cn,copies) in struct | orderBy:cn track by cn" focus-next="focusNextFirst" copies="copies" allcopies="allcopies"></eg-vol-row>'+
431 scope: { focusNext: "=", allcopies: "=", struct: "=", lib: "@", record: "@" },
432 controller : ['$scope','itemSvc','egCore',
433 function ( $scope , itemSvc , egCore ) {
434 $scope.first_cn = Object.keys($scope.struct)[0];
435 $scope.full_cn = $scope.struct[$scope.first_cn][0].call_number();
437 $scope.defaults = {};
438 egCore.hatch.getItem('cat.copy.defaults').then(function(t) {
444 $scope.focusNextFirst = function(prev_cn) {
447 angular.forEach(Object.keys($scope.struct).sort(), function (cn) {
448 console.log('checking '+cn);
452 console.log('prev is '+cn);
456 console.log('prev is not '+cn);
461 console.log('found '+n);
463 var next = '#' + n + '_' + $scope.struct[n][0].id();
467 $scope.focusNext($scope.lib);
471 $scope.cn_count = Object.keys($scope.struct).length;
472 $scope.orig_cn_count = $scope.cn_count;
474 $scope.owning_lib = egCore.org.get($scope.lib);
475 $scope.$watch('owning_lib', function (l) {
476 angular.forEach( $scope.struct[$scope.first_cn], function (cp) {
477 cp.call_number().owning_lib( $scope.owning_lib.id() );
481 $scope.cant_have_vols = function (id) { return !egCore.org.CanHaveVolumes(id); };
483 $scope.$watch('cn_count', function (n) {
484 var o = Object.keys($scope.struct).length;
485 if (n > o) { // adding
486 for (var i = o; o < n; o++) {
487 var cn = new egCore.idl.acn();
488 cn.id( --itemSvc.new_cn_id );
490 cn.prefix( $scope.defaults.prefix || -1 );
491 cn.suffix( $scope.defaults.suffix || -1 );
492 cn.label_class( $scope.defaults.classification || 1 );
493 cn.owning_lib( $scope.owning_lib.id() );
494 cn.record( $scope.full_cn.record() );
496 var cp = new egCore.idl.acp();
497 cp.id( --itemSvc.new_cp_id );
499 cp.circ_lib( $scope.owning_lib.id() );
500 cp.call_number( cn );
502 $scope.struct[cn.id()] = [cp];
503 $scope.allcopies.push(cp);
505 } else if (n < o && n >= $scope.orig_cn_count) { // removing
506 var how_many = o - n;
509 .sort(function(a, b){return parseInt(a)-parseInt(b)})
510 .filter(function(x){ return parseInt(x) <= 0 });
511 for (var i = 0; i < how_many; i++) {
512 // Trimming the global list is a bit more tricky
513 console.log('trying to trim ' + i);
514 angular.forEach($scope.struct[list[i]], function (d) {
515 angular.forEach( $scope.allcopies, function (l, j) {
516 if (l === d) $scope.allcopies.splice(j,1);
519 delete $scope.struct[list[i]];
532 .controller('EditCtrl',
533 ['$scope','$q','$window','$routeParams','$location','$timeout','egCore','egNet','egGridDataProvider','itemSvc','$modal',
534 function($scope , $q , $window , $routeParams , $location , $timeout , egCore , egNet , egGridDataProvider , itemSvc , $modal) {
536 $scope.defaults = { // If defaults are not set at all, allow everything
541 loan_duration : true,
546 deposit_amount : true,
550 mint_condition : true,
553 circ_modifier : true,
561 $scope.saveDefaults = function () {
562 egCore.hatch.setItem('cat.copy.defaults', $scope.defaults);
565 $scope.fetchDefaults = function () {
566 egCore.hatch.getItem('cat.copy.defaults').then(function(t) {
569 if (!$scope.batch) $scope.batch = {};
570 $scope.batch.classification = $scope.defaults.classification;
571 $scope.batch.prefix = $scope.defaults.prefix;
572 $scope.batch.suffix = $scope.defaults.suffix;
573 $scope.working.statcat_filter = $scope.defaults.statcat_filter;
574 if ($scope.defaults.always_vols) $scope.show_vols = true;
578 $scope.fetchDefaults();
580 $scope.dirty = false;
581 $scope.$watch('dirty',
582 function(newVal, oldVal) {
583 if (newVal && newVal != oldVal) {
584 $($window).on('beforeunload.edit', function(){
585 return 'There is unsaved data!'
588 $($window).off('beforeunload.edit');
593 $scope.show_vols = true;
594 $scope.show_copies = true;
596 $scope.tracker = function (x,f) { if (x) return x[f]() };
597 $scope.idTracker = function (x) { if (x) return $scope.tracker(x,'id') };
598 $scope.cant_have_vols = function (id) { return !egCore.org.CanHaveVolumes(id); };
600 $scope.orgById = function (id) { return egCore.org.get(id) }
601 $scope.statusById = function (id) {
602 return $scope.status_list.filter( function (s) { return s.id() == id } )[0];
604 $scope.locationById = function (id) {
605 return $scope.location_cache[''+id];
608 $scope.workingToComplete = function () {
609 angular.forEach( $scope.workingGridControls.selectedItems(), function (c) {
610 angular.forEach( itemSvc.copies, function (w, i) {
612 $scope.completed_copies = $scope.completed_copies.concat(itemSvc.copies.splice(i,1));
617 $scope.completeToWorking = function () {
618 angular.forEach( $scope.completedGridControls.selectedItems(), function (c) {
619 angular.forEach( $scope.completed_copies, function (w, i) {
621 itemSvc.copies = itemSvc.copies.concat($scope.completed_copies.splice(i,1));
626 createSimpleUpdateWatcher = function (field) {
627 return $scope.$watch('working.' + field, function () {
628 var newval = $scope.working[field];
630 if (typeof newval != 'undefined') {
631 if (angular.isObject(newval)) { // we'll use the pkey
632 if (newval.id) newval = newval.id();
633 else if (newval.code) newval = newval.code();
636 if (""+newval == "" || newval == null) {
637 $scope.working[field] = undefined;
641 if ($scope.workingGridControls && $scope.workingGridControls.selectedItems) {
643 $scope.workingGridControls.selectedItems(),
645 if (cp[field]() !== newval) {
659 statcat_filter: undefined
662 $scope.statcatUpdate = function (id) {
663 var newval = $scope.working.statcats[id];
665 if (typeof newval != 'undefined') {
666 if (angular.isObject(newval)) { // we'll use the pkey
667 newval = newval.id();
670 if (""+newval == "" || newval == null) {
671 $scope.working.statcats[id] = undefined;
675 if (!$scope.in_item_select && $scope.workingGridControls && $scope.workingGridControls.selectedItems) {
677 $scope.workingGridControls.selectedItems(),
682 angular.forEach( cp.stat_cat_entries(), function (e) {
683 if (e.stat_cat() == id) { // mark deleted
690 var e = new egCore.idl.ascecm();
692 e.owning_copy( cp.id() );
694 e.stat_cat_entry( newval );
697 cp.stat_cat_entries().concat([ e ])
702 cp.stat_cat_entries( // trim out ephemeral deleted ones
703 cp.stat_cat_entries().filter(function (e) {
704 if (Boolean(e.isnew())) {
705 if (Boolean(e.isdeleted())) {
720 var dataKey = $routeParams.dataKey;
721 console.debug('dataKey: ' + dataKey);
723 if (dataKey && dataKey.length > 0) {
725 $scope.templates = {};
726 $scope.template_name = '';
727 $scope.template_name_list = [];
729 $scope.fetchTemplates = function () {
730 egCore.hatch.getItem('cat.copy.templates').then(function(t) {
732 $scope.templates = t;
733 $scope.template_name_list = Object.keys(t);
737 $scope.fetchTemplates();
739 $scope.applyTemplate = function (n) {
740 angular.forEach($scope.templates[n], function (v,k) {
741 if (!angular.isObject(v)) {
742 $scope.working[k] = angular.copy(v);
744 angular.forEach(v, function (sv,sk) {
745 if (k == 'callnumber') {
746 angular.forEach(v, function (cnv,cnk) {
747 $scope.batch[cnk] = cnv;
749 $scope.applyBatchCNValues();
751 $scope.working[k][sk] = angular.copy(sv);
752 if (k == 'statcats') $scope.statcatUpdate(sk);
757 $scope.template_name = '';
760 $scope.copytab = 'working';
762 $scope.summaryRecord = null;
763 $scope.record_id = null;
765 $scope.completed_copies = [];
766 $scope.location_orgs = [];
767 $scope.location_cache = {};
768 $scope.statcats = [];
769 if (!$scope.batch) $scope.batch = {};
771 $scope.applyBatchCNValues = function () {
772 if ($scope.data.tree) {
773 angular.forEach($scope.data.tree, function(cn_hash) {
774 angular.forEach(cn_hash, function(copies) {
775 angular.forEach(copies, function(cp) {
776 if (typeof $scope.batch.classification != 'undefined' && $scope.batch.classification != '')
777 cp.call_number().label_class($scope.batch.classification);
779 if (typeof $scope.batch.prefix != 'undefined' && $scope.batch.prefix != '')
780 cp.call_number().prefix($scope.batch.prefix);
782 if (typeof $scope.batch.label != 'undefined' && $scope.batch.label != '')
783 cp.call_number().label($scope.batch.label);
785 if (typeof $scope.batch.suffix != 'undefined' && $scope.batch.suffix != '')
786 cp.call_number().suffix($scope.batch.suffix);
794 $scope.clearWorking = function () {
795 angular.forEach($scope.working, function (v,k,o) {
796 if (!angular.isObject(v)) {
797 if (typeof v != 'undefined')
798 $scope.working[k] = undefined;
799 } else if (k != 'circ_lib') {
800 angular.forEach(v, function (sv,sk) {
801 if (typeof v != 'undefined')
802 $scope.working[k][sk] = undefined;
806 $scope.working.circ_lib = undefined; // special
809 $scope.completedGridDataProvider = egGridDataProvider.instance({
810 get : function(offset, count) {
811 //return provider.arrayNotifier(itemSvc.copies, offset, count);
812 return this.arrayNotifier($scope.completed_copies, offset, count);
816 $scope.completedGridControls = {};
818 $scope.workingGridDataProvider = egGridDataProvider.instance({
819 get : function(offset, count) {
820 //return provider.arrayNotifier(itemSvc.copies, offset, count);
821 return this.arrayNotifier(itemSvc.copies, offset, count);
825 $scope.workingGridControls = {};
829 'open-ils.actor.anon_cache.get_value',
830 dataKey, 'edit-these-copies'
831 ).then(function (data) {
834 if (data.hide_vols && !$scope.defaults.always_vols) $scope.show_vols = false;
835 if (data.hide_copies) $scope.show_copies = false;
837 $scope.record_id = data.record_id;
839 if (data.copies && data.copies.length)
840 return itemSvc.fetchIds(data.copies);
842 if (data.raw && data.raw.length) {
845 /* data.raw data structure looks like this:
847 * callnumber : $cn_id, // optional, to add a copy to a cn
848 * owner : $org, // optional, defaults to ws_ou
849 * label : $cn_label, // optional, to supply a label on a new cn
850 * barcode : $cp_barcode // optional, to supply a barcode on a new cp
853 * All can be left out and a completely empty vol/copy combo will be vivicated.
859 if (proto.callnumber) {
860 return egCore.pcrud.retrieve('acn', proto.callnumber)
862 var cp = new egCore.idl.acp();
863 cp.call_number( cn );
864 cp.id( --itemSvc.new_cp_id );
866 cp.circ_lib( $scope.record_id );
867 if (proto.barcode) cp.barcode( proto.barcode );
872 var cn = new egCore.idl.acn();
873 cn.id( --itemSvc.new_cn_id );
875 cn.prefix( $scope.defaults.prefix || -1 );
876 cn.suffix( $scope.defaults.suffix || -1 );
877 cn.label_class( $scope.defaults.classification || 1 );
878 cn.owning_lib( proto.owner || egCore.auth.user().ws_ou() );
879 cn.record( $scope.record_id );
880 if (proto.label) cn.label( proto.label );
882 var cp = new egCore.idl.acp();
883 cp.call_number( cn );
884 cp.id( --itemSvc.new_cp_id );
886 cp.circ_lib( $scope.record_id );
887 if (proto.barcode) cp.barcode( proto.barcode );
895 return itemSvc.copies;
899 }).then( function() {
900 $scope.data = itemSvc;
901 $scope.workingGridDataProvider.refresh();
904 $scope.focusNextFirst = function(prev_lib) {
907 angular.forEach(Object.keys($scope.data.tree).sort(), function (lib) {
908 console.log('checking lib '+lib);
911 if (lib == prev_lib) {
912 console.log('prev is '+lib);
916 console.log('prev is not '+lib);
921 console.log('found '+n);
923 var first_cn = Object.keys($scope.data.tree[n])[0];
924 var next = '#' + first_cn + '_' + $scope.data.tree[n][first_cn][0].id();
928 $scope.focusNext($scope.lib);
932 $scope.in_item_select = false;
933 $scope.afterItemSelect = function() { $scope.in_item_select = false };
934 $scope.handleItemSelect = function (item_list) {
935 if (item_list && item_list.length > 0) {
936 $scope.in_item_select = true;
938 angular.forEach(Object.keys($scope.defaults.attributes), function (attr) {
941 angular.forEach(item_list, function (item) {
944 if (angular.isObject(v)) {
945 if (v.id) v = v.id();
946 else if (v.code) v = v.code();
952 if (Object.keys(value_hash).length == 1) {
953 if (attr == 'circ_lib') {
954 $scope.working[attr] = egCore.org.get(item_list[0][attr]());
956 $scope.working[attr] = item_list[0][attr]();
959 $scope.working[attr] = undefined;
963 angular.forEach($scope.statcats, function (sc) {
968 angular.forEach(item_list, function (item) {
969 if (item.stat_cat_entries()) {
970 if (item.stat_cat_entries().length > 0) {
971 var right_sc = item.stat_cat_entries().filter(function (e) {
972 return e.stat_cat() == sc.id() && !Boolean(e.isdeleted());
975 if (right_sc.length > 0) {
976 value_hash[right_sc[0].stat_cat_entry()] = right_sc[0].stat_cat_entry();
986 if (!none && Object.keys(value_hash).length == 1) {
987 $scope.working.statcats[sc.id()] = value_hash[Object.keys(value_hash)[0]];
989 $scope.working.statcats[sc.id()] = undefined;
994 $scope.clearWorking();
999 $scope.$watch('data.copies.length', function () {
1000 if ($scope.data.copies) {
1001 var base_orgs = $scope.data.copies.map(function(cp){
1002 return cp.circ_lib()
1004 $scope.data.copies.map(function(cp){
1005 return cp.call_number().owning_lib()
1008 [egCore.auth.user().ws_ou()]
1009 ).filter(function(e,i,a){
1010 return a.lastIndexOf(e) === i;
1014 angular.forEach(base_orgs, function(o) {
1015 all_orgs = all_orgs.concat( egCore.org.fullPath(o, true) );
1018 var final_orgs = all_orgs.filter(function(e,i,a){
1019 return a.lastIndexOf(e) === i;
1020 }).sort(function(a, b){return parseInt(a)-parseInt(b)});
1022 if ($scope.location_orgs.toString() != final_orgs.toString()) {
1023 $scope.location_orgs = final_orgs;
1024 if ($scope.location_orgs.length) {
1025 itemSvc.get_locations($scope.location_orgs).then(function(list){
1026 angular.forEach(list, function(l) {
1027 $scope.location_cache[ ''+l.id() ] = l;
1029 $scope.location_list = list;
1032 $scope.statcat_filter_list = [];
1033 angular.forEach($scope.location_orgs, function (o) {
1034 $scope.statcat_filter_list.push(egCore.org.get(o));
1037 itemSvc.get_statcats($scope.location_orgs).then(function(list){
1038 $scope.statcats = list;
1039 angular.forEach($scope.statcats, function (s) {
1041 if (!$scope.working)
1042 $scope.working = { statcats: {}, statcat_filter: undefined};
1043 if (!$scope.working.statcats)
1044 $scope.working.statcats = {};
1046 if (!$scope.in_item_select) {
1047 $scope.working.statcats[s.id()] = undefined;
1049 createStatcatUpdateWatcher(s.id());
1051 $scope.in_item_select = false;
1057 $scope.workingGridDataProvider.refresh();
1060 $scope.suffix_list = [];
1061 itemSvc.get_suffixes(egCore.auth.user().ws_ou()).then(function(list){
1062 $scope.suffix_list = list;
1065 $scope.prefix_list = [];
1066 itemSvc.get_prefixes(egCore.auth.user().ws_ou()).then(function(list){
1067 $scope.prefix_list = list;
1070 $scope.classification_list = [];
1071 itemSvc.get_classifications().then(function(list){
1072 $scope.classification_list = list;
1075 $scope.$watch('completed_copies.length', function () {
1076 $scope.completedGridDataProvider.refresh();
1079 $scope.location_list = [];
1080 itemSvc.get_locations().then(function(list){
1081 $scope.location_list = list;
1083 createSimpleUpdateWatcher('location');
1085 $scope.status_list = [];
1086 itemSvc.get_statuses().then(function(list){
1087 $scope.status_list = list;
1089 createSimpleUpdateWatcher('status');
1091 $scope.circ_modifier_list = [];
1092 itemSvc.get_circ_mods().then(function(list){
1093 $scope.circ_modifier_list = list;
1095 createSimpleUpdateWatcher('circ_modifier');
1097 $scope.circ_type_list = [];
1098 itemSvc.get_circ_types().then(function(list){
1099 $scope.circ_type_list = list;
1101 createSimpleUpdateWatcher('circ_as_type');
1103 $scope.age_protect_list = [];
1104 itemSvc.get_age_protects().then(function(list){
1105 $scope.age_protect_list = list;
1107 createSimpleUpdateWatcher('age_protect');
1109 createSimpleUpdateWatcher('circ_lib');
1110 createSimpleUpdateWatcher('circulate');
1111 createSimpleUpdateWatcher('holdable');
1112 createSimpleUpdateWatcher('fine_level');
1113 createSimpleUpdateWatcher('loan_duration');
1114 createSimpleUpdateWatcher('cost');
1115 createSimpleUpdateWatcher('deposit');
1116 createSimpleUpdateWatcher('deposit_amount');
1117 createSimpleUpdateWatcher('mint_condition');
1118 createSimpleUpdateWatcher('opac_visible');
1119 createSimpleUpdateWatcher('ref');
1121 $scope.saveCompletedCopies = function (and_exit) {
1123 var perCnCopies = {};
1124 angular.forEach( egCore.idl.Clone($scope.completed_copies), function (cp) {
1125 var cn_id = cp.call_number().id();
1126 if (!cnHash[cn_id]) {
1127 cnHash[cn_id] = cp.call_number();
1128 perCnCopies[cn_id] = [cp];
1130 perCnCopies[cn_id].push(cp);
1132 cp.call_number(cn_id); // prevent loops in JSON-ification
1135 angular.forEach(perCnCopies, function (v, k) {
1136 cnHash[k].copies(v);
1140 angular.forEach(cnHash, function (v, k) {
1146 'open-ils.cat.asset.volume.fleshed.batch.update.override',
1147 egCore.auth.token(), cnList, 1, { auto_merge_vols : 1, create_parts : 1 }
1148 ).then(function(update_count) {
1150 $scope.dirty = false;
1151 $timeout(function(){$window.close()});
1156 $scope.saveAndContinue = function () {
1157 $scope.saveCompletedCopies(false);
1160 $scope.saveAndExit = function () {
1161 $scope.saveCompletedCopies(true);
1166 $scope.copy_notes_dialog = function(copy_list) {
1167 var default_pub = Boolean($scope.defaults.copy_notes_pub);
1168 if (!angular.isArray(copy_list)) copy_list = [copy_list];
1170 return $modal.open({
1171 templateUrl: './cat/volcopy/t_copy_notes',
1174 ['$scope','$modalInstance',
1175 function($scope , $modalInstance) {
1176 $scope.focusNote = true;
1178 creator : egCore.auth.user().id(),
1184 $scope.require_initials = false;
1185 egCore.org.settings([
1186 'ui.staff.require_initials.copy_notes'
1187 ]).then(function(set) {
1188 $scope.require_initials = Boolean(set['ui.staff.require_initials.copy_notes']);
1191 $scope.note_list = [];
1192 if (copy_list.length == 1) {
1193 $scope.note_list = copy_list[0].notes();
1196 $scope.ok = function(note) {
1198 if (note.initials) note.value += ' [' + note.initials + ']';
1199 angular.forEach(copy_list, function (cp) {
1200 var n = new egCore.idl.acpn();
1201 n.creator(note.creator);
1203 n.title(note.title);
1204 n.value(note.value);
1205 n.owning_copy(cp.id());
1206 cp.notes().push( n );
1209 $modalInstance.close();
1212 $scope.cancel = function($event) {
1213 $modalInstance.dismiss();
1214 $event.preventDefault();
1222 .directive("egVolTemplate", function () {
1226 template: '<div ng-include="'+"'/eg/staff/cat/volcopy/t_attr_edit'"+'"></div>',
1228 controller : ['$scope','$window','itemSvc','egCore',
1229 function ( $scope , $window , itemSvc , egCore ) {
1231 $scope.defaults = { // If defaults are not set at all, allow everything
1236 loan_duration : true,
1241 deposit_amount : true,
1242 opac_visible : true,
1245 mint_condition : true,
1248 circ_modifier : true,
1249 circ_as_type : true,
1256 $scope.fetchDefaults = function () {
1257 egCore.hatch.getItem('cat.copy.defaults').then(function(t) {
1259 $scope.defaults = t;
1260 $scope.working.statcat_filter = $scope.defaults.statcat_filter;
1264 $scope.fetchDefaults();
1266 $scope.dirty = false;
1267 $scope.$watch('dirty',
1268 function(newVal, oldVal) {
1269 if (newVal && newVal != oldVal) {
1270 $($window).on('beforeunload.template', function(){
1271 return 'There is unsaved template data!'
1274 $($window).off('beforeunload.template');
1279 $scope.template_controls = true;
1281 $scope.fetchTemplates = function () {
1282 egCore.hatch.getItem('cat.copy.templates').then(function(t) {
1284 $scope.templates = t;
1285 $scope.template_name_list = Object.keys(t);
1289 $scope.fetchTemplates();
1291 $scope.applyTemplate = function (n) {
1292 angular.forEach($scope.templates[n], function (v,k) {
1293 if (!angular.isObject(v)) {
1294 $scope.working[k] = angular.copy(v);
1296 angular.forEach(v, function (sv,sk) {
1297 $scope.working[k][sk] = angular.copy(sv);
1301 $scope.template_name = '';
1304 $scope.deleteTemplate = function (n) {
1306 delete $scope.templates[n]
1307 $scope.template_name_list = Object.keys($scope.templates);
1308 $scope.template_name = '';
1309 egCore.hatch.setItem('cat.copy.templates', $scope.templates);
1310 $scope.$parent.fetchTemplates();
1314 $scope.saveTemplate = function (n) {
1318 angular.forEach($scope.working, function (v,k) {
1319 if (angular.isObject(v)) { // we'll use the pkey
1320 if (v.id) v = v.id();
1321 else if (v.code) v = v.code();
1327 $scope.templates[n] = tmpl;
1328 $scope.template_name_list = Object.keys($scope.templates);
1330 egCore.hatch.setItem('cat.copy.templates', $scope.templates);
1331 $scope.$parent.fetchTemplates();
1333 $scope.dirty = false;
1337 $scope.templates = {};
1338 $scope.template_name = '';
1339 $scope.template_name_list = [];
1341 $scope.tracker = function (x,f) { if (x) return x[f]() };
1342 $scope.idTracker = function (x) { if (x) return $scope.tracker(x,'id') };
1343 $scope.cant_have_vols = function (id) { return !egCore.org.CanHaveVolumes(id); };
1345 $scope.orgById = function (id) { return egCore.org.get(id) }
1346 $scope.statusById = function (id) {
1347 return $scope.status_list.filter( function (s) { return s.id() == id } )[0];
1349 $scope.locationById = function (id) {
1350 return $scope.location_cache[''+id];
1353 createSimpleUpdateWatcher = function (field) {
1354 $scope.$watch('working.' + field, function () {
1355 var newval = $scope.working[field];
1357 if (typeof newval != 'undefined') {
1358 $scope.dirty = true;
1359 if (angular.isObject(newval)) { // we'll use the pkey
1360 if (newval.id) $scope.working[field] = newval.id();
1361 else if (newval.code) $scope.working[field] = newval.code();
1364 if (""+newval == "" || newval == null) {
1365 $scope.working[field] = undefined;
1374 statcat_filter: undefined
1377 createStatcatUpdateWatcher = function (id) {
1378 return $scope.$watch('working.statcats[' + id + ']', function () {
1379 if ($scope.working.statcats) {
1380 var newval = $scope.working.statcats[id];
1382 if (typeof newval != 'undefined') {
1383 $scope.dirty = true;
1384 if (angular.isObject(newval)) { // we'll use the pkey
1385 newval = newval.id();
1388 if (""+newval == "" || newval == null) {
1389 $scope.working.statcats[id] = undefined;
1398 $scope.clearWorking = function () {
1399 angular.forEach($scope.working, function (v,k,o) {
1400 if (!angular.isObject(v)) {
1401 if (typeof v != 'undefined')
1402 $scope.working[k] = undefined;
1403 } else if (k != 'circ_lib') {
1404 angular.forEach(v, function (sv,sk) {
1405 $scope.working[k][sk] = undefined;
1409 $scope.working.circ_lib = undefined; // special
1410 $scope.dirty = false;
1413 $scope.working = {};
1414 $scope.location_orgs = [];
1415 $scope.location_cache = {};
1417 $scope.location_list = [];
1418 itemSvc.get_locations(
1419 egCore.org.fullPath( egCore.auth.user().ws_ou(), true )
1420 ).then(function(list){
1421 $scope.location_list = list;
1423 createSimpleUpdateWatcher('location');
1425 $scope.statcat_filter_list = egCore.org.fullPath( egCore.auth.user().ws_ou() );
1427 $scope.statcats = [];
1428 itemSvc.get_statcats(
1429 egCore.org.fullPath( egCore.auth.user().ws_ou(), true )
1430 ).then(function(list){
1431 $scope.statcats = list;
1432 angular.forEach($scope.statcats, function (s) {
1434 if (!$scope.working)
1435 $scope.working = { statcats: {}, statcat_filter: undefined};
1436 if (!$scope.working.statcats)
1437 $scope.working.statcats = {};
1439 $scope.working.statcats[s.id()] = undefined;
1440 createStatcatUpdateWatcher(s.id());
1444 $scope.status_list = [];
1445 itemSvc.get_statuses().then(function(list){
1446 $scope.status_list = list;
1448 createSimpleUpdateWatcher('status');
1450 $scope.circ_modifier_list = [];
1451 itemSvc.get_circ_mods().then(function(list){
1452 $scope.circ_modifier_list = list;
1454 createSimpleUpdateWatcher('circ_modifier');
1456 $scope.circ_type_list = [];
1457 itemSvc.get_circ_types().then(function(list){
1458 $scope.circ_type_list = list;
1460 createSimpleUpdateWatcher('circ_as_type');
1462 $scope.age_protect_list = [];
1463 itemSvc.get_age_protects().then(function(list){
1464 $scope.age_protect_list = list;
1466 createSimpleUpdateWatcher('age_protect');
1468 createSimpleUpdateWatcher('circ_lib');
1469 createSimpleUpdateWatcher('circulate');
1470 createSimpleUpdateWatcher('holdable');
1471 createSimpleUpdateWatcher('fine_level');
1472 createSimpleUpdateWatcher('loan_duration');
1473 createSimpleUpdateWatcher('cost');
1474 createSimpleUpdateWatcher('deposit');
1475 createSimpleUpdateWatcher('deposit_amount');
1476 createSimpleUpdateWatcher('mint_condition');
1477 createSimpleUpdateWatcher('opac_visible');
1478 createSimpleUpdateWatcher('ref');
1480 $scope.suffix_list = [];
1481 itemSvc.get_suffixes(egCore.auth.user().ws_ou()).then(function(list){
1482 $scope.suffix_list = list;
1485 $scope.prefix_list = [];
1486 itemSvc.get_prefixes(egCore.auth.user().ws_ou()).then(function(list){
1487 $scope.prefix_list = list;
1490 $scope.classification_list = [];
1491 itemSvc.get_classifications().then(function(list){
1492 $scope.classification_list = list;
1495 createSimpleUpdateWatcher('working.callnumber.classification');
1496 createSimpleUpdateWatcher('working.callnumber.prefix');
1497 createSimpleUpdateWatcher('working.callnumber.suffix');