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) {
35 tree : {}, // holds lib->cn->copy hash stack
36 copies : [] // raw copy list
39 // returns a promise resolved with the list of circ mods
40 service.get_classifications = function() {
42 return $q.when(egCore.env.acnc.list);
44 return egCore.pcrud.retrieveAll('acnc', null, {atomic : true})
45 .then(function(list) {
46 egCore.env.absorbList(list, 'acnc');
51 service.get_prefixes = function(org) {
52 return egCore.pcrud.search('acnp',
53 {owning_lib : egCore.org.fullPath(org, true)},
59 service.get_statcats = function(orgs) {
60 return egCore.pcrud.search('asc',
64 asc : ['owner','entries']
71 service.get_locations = function(orgs) {
72 return egCore.pcrud.search('acpl',
78 service.get_suffixes = function(org) {
79 return egCore.pcrud.search('acns',
80 {owning_lib : egCore.org.fullPath(org, true)},
86 service.get_statuses = function() {
88 return $q.when(egCore.env.ccs.list);
90 return egCore.pcrud.retrieveAll('ccs', {}, {atomic : true}).then(
92 egCore.env.absorbList(list, 'ccs');
99 service.get_circ_mods = function() {
101 return $q.when(egCore.env.ccm.list);
103 return egCore.pcrud.retrieveAll('ccm', {}, {atomic : true}).then(
105 egCore.env.absorbList(list, 'ccm');
112 service.get_circ_types = function() {
114 return $q.when(egCore.env.citm.list);
116 return egCore.pcrud.retrieveAll('citm', {}, {atomic : true}).then(
118 egCore.env.absorbList(list, 'citm');
125 service.get_age_protects = function() {
126 if (egCore.env.crahp)
127 return $q.when(egCore.env.crahp.list);
129 return egCore.pcrud.retrieveAll('crahp', {}, {atomic : true}).then(
131 egCore.env.absorbList(list, 'crahp');
138 service.bmp_parts = {};
139 service.get_parts = function(rec) {
140 if (service.bmp_parts[rec])
141 return $q.when(service.bmp_parts[rec]);
143 return egCore.pcrud.search('bmp',
145 null, {atomic : true}
146 ).then(function(list) {
147 service.bmp_parts[rec] = list;
156 acp : ['call_number','parts','stat_cat_entries'],
157 acn : ['label_class','prefix','suffix']
161 service.addCopy = function (cp) {
163 if (!cp.parts()) cp.parts([]); // just in case...
165 var lib = cp.call_number().owning_lib();
166 var cn = cp.call_number().id();
168 if (!service.tree[lib]) service.tree[lib] = {};
169 if (!service.tree[lib][cn]) service.tree[lib][cn] = [];
171 service.tree[lib][cn].push(cp);
172 service.copies.push(cp);
175 service.fetchIds = function(idList) {
176 service.tree = {}; // clear the tree on fetch
177 service.copies = []; // clear the copy list on fetch
178 return egCore.pcrud.search('acp', { 'id' : idList }, service.flesh).then(null,null,
180 service.addCopy(copy);
188 .directive("egVolCopyEdit", function () {
194 '<div class="col-xs-5">'+
195 '<input id="{{callNumber.id()}}.{{copy.id()}}"'+
196 ' eg-enter="nextBarcode()" class="form-control"'+
197 ' type="text" ng-model="barcode" ng-change="updateBarcode()"/>'+
199 '<div class="col-xs-3"><input class="form-control" type="number" ng-model="copy_number" ng-change="updateCopyNo()"/></div>'+
200 '<div class="col-xs-4"><eg-basic-combo-box list="parts" selected="part"></eg-basic-combo-box></div>'+
203 scope: { copy: "=", callNumber: "=", index: "@" },
204 controller : ['$scope','itemSvc','egCore',
205 function ( $scope , itemSvc , egCore ) {
206 $scope.new_part_id = 0;
208 $scope.nextBarcode = function (i) {
209 $scope.$parent.focusNextBarcode($scope.copy.id());
212 $scope.updateBarcode = function () { $scope.copy.barcode($scope.barcode); $scope.copy.ischanged(1); };
213 $scope.updateCopyNo = function () { $scope.copy.copy_number($scope.copy_number); $scope.copy.ischanged(1); };
214 $scope.updatePart = function () {
216 var p = $scope.part_list.filter(function (x) {
217 return x.label() == $scope.part
219 if (p.length > 0) { // preexisting part
221 } else { // create one...
222 var part = new egCore.idl.bmp();
223 part.id( --$scope.new_part_id );
225 part.label( $scope.part );
226 part.record( $scope.callNumber.owning_lib() );
227 $scope.copy.parts([part]);
228 $scope.copy.ischanged(1);
231 $scope.copy.parts([]);
234 $scope.$watch('part', $scope.updatePart);
236 $scope.barcode = $scope.copy.barcode();
237 $scope.copy_number = $scope.copy.copy_number();
239 if ($scope.copy.parts()) {
240 $scope.part = $scope.copy.parts()[0];
241 if ($scope.part) $scope.part = $scope.part.label();
245 $scope.part_list = [];
247 itemSvc.get_parts($scope.callNumber.record()).then(function(list){
248 $scope.part_list = list;
249 angular.forEach(list, function(p){ $scope.parts.push(p.label()) });
250 $scope.parts = angular.copy($scope.parts);
259 .directive("egVolRow", function () {
266 '<div class="col-xs-2">'+
267 '<select class="form-control" ng-model="classification" ng-options="cl.name() for cl in classification_list track by idTracker(cl)"/>'+
269 '<div class="col-xs-1">'+
270 '<select class="form-control" ng-model="prefix" ng-change="updatePrefix()" ng-options="p.label() for p in prefix_list track by idTracker(p)"/>'+
272 '<div class="col-xs-2"><input class="form-control" type="text" ng-change="updateLabel()" ng-model="label"/></div>'+
273 '<div class="col-xs-1">'+
274 '<select class="form-control" ng-model="suffix" ng-change="updateSuffix()" ng-options="s.label() for s in suffix_list track by idTracker(s)"/>'+
276 '<div class="col-xs-1"><input class="form-control" type="number" ng-model="copy_count" min="{{orig_copy_count}}" ng-change="changeCPCount()"></div>'+
277 '<div class="col-xs-5">'+
278 '<eg-vol-copy-edit ng-repeat="cp in copies track by idTracker(cp)" copy="cp" call-number="callNumber"></eg-vol-copy-edit>'+
282 scope: {allcopies: "=", copies: "=" },
283 controller : ['$scope','itemSvc','egCore',
284 function ( $scope , itemSvc , egCore ) {
285 $scope.new_cp_id = 0;
286 $scope.callNumber = $scope.copies[0].call_number();
288 $scope.idTracker = function (x) { if (x) return x.id() };
290 // XXX $() is not working! arg
291 $scope.focusNextBarcode = function (i) {
294 angular.forEach($scope.copies, function (cp) {
302 if (yep) n = cp.id();
306 var next = '#' + $scope.callNumber.id() + '.' + n;
307 var el = $(next).get(0);
312 $scope.suffix_list = [];
313 itemSvc.get_suffixes($scope.callNumber.owning_lib()).then(function(list){
314 $scope.suffix_list = list;
316 $scope.updateSuffix = function () {
317 angular.forEach($scope.copies, function(cp) {
318 cp.call_number().suffix($scope.suffix);
319 cp.call_number().ischanged(1);
323 $scope.prefix_list = [];
324 itemSvc.get_prefixes($scope.callNumber.owning_lib()).then(function(list){
325 $scope.prefix_list = list;
327 $scope.updatePrefix = function () {
328 angular.forEach($scope.copies, function(cp) {
329 cp.call_number().prefix($scope.prefix);
330 cp.call_number().ischanged(1);
334 $scope.classification_list = [];
335 itemSvc.get_classifications().then(function(list){
336 $scope.classification_list = list;
338 $scope.updateClassification = function () {
339 angular.forEach($scope.copies, function(cp) {
340 cp.call_number().label_class($scope.classification);
341 cp.call_number().ischanged(1);
345 $scope.updateLabel = function () {
346 angular.forEach($scope.copies, function(cp) {
347 cp.call_number().label($scope.label);
348 cp.call_number().ischanged(1);
352 $scope.$watch('callNumber.prefix()', function (v) {
353 if (typeof v != 'object') {
354 $scope.prefix = $scope.prefix_list.filter(function (p) {
357 $scope.callNumber.prefix($scope.prefix);
361 $scope.$watch('callNumber.suffix()', function (v) {
362 if (typeof v != 'object') {
363 $scope.suffix = $scope.suffix_list.filter( function (s) {
366 $scope.callNumber.suffix($scope.suffix);
370 $scope.$watch('callNumber.label_class()', function (v) {
371 if (typeof v != 'object') {
372 $scope.classification = $scope.classification_list.filter(function (c) {
375 $scope.callNumber.label_class($scope.classification);
379 $scope.$watch('callNumber.label()', function (v) {
383 $scope.prefix = $scope.callNumber.prefix();
384 $scope.suffix = $scope.callNumber.suffix();
385 $scope.classification = $scope.callNumber.label_class();
386 $scope.label = $scope.callNumber.label();
388 $scope.copy_count = $scope.copies.length;
389 $scope.orig_copy_count = $scope.copy_count;
391 $scope.changeCPCount = function () {
392 while ($scope.copy_count > $scope.copies.length) {
393 var cp = new egCore.idl.acp();
394 cp.id( --$scope.new_cp_id );
396 cp.circ_lib( $scope.lib );
397 cp.call_number( $scope.callNumber );
398 $scope.copies.push( cp );
399 $scope.allcopies.push( cp );
402 if ($scope.copy_count >= $scope.orig_copy_count) {
403 var how_many = $scope.copies.length - $scope.copy_count;
405 var dead = $scope.copies.splice($scope.copy_count,how_many);
406 $scope.callNumber.copies($scope.copies);
408 // Trimming the global list is a bit more tricky
409 angular.forEach( dead, function (d) {
410 angular.forEach( $scope.allcopies, function (l, i) {
411 if (l === d) $scope.allcopies.splice(i,1);
424 .directive("egVolEdit", function () {
430 '<div class="col-xs-1"><eg-org-selector selected="owning_lib" disableTest="cant_have_vols"></eg-org-selector></div>'+
431 '<div class="col-xs-1"><input class="form-control" type="number" min="{{orig_cn_count}}" ng-model="cn_count" ng-change="changeCNCount()"/></div>'+
432 '<div class="col-xs-10">'+
433 '<eg-vol-row ng-repeat="(cn,copies) in struct track by cn" copies="copies" allcopies="allcopies"></eg-vol-row>'+
437 scope: { allcopies: "=", struct: "=", lib: "@", record: "@" },
438 controller : ['$scope','itemSvc','egCore',
439 function ( $scope , itemSvc , egCore ) {
440 $scope.new_cn_id = 0;
441 $scope.first_cn = Object.keys($scope.struct)[0];
442 $scope.full_cn = $scope.struct[$scope.first_cn][0].call_number();
444 $scope.cn_count = Object.keys($scope.struct).length;
445 $scope.orig_cn_count = $scope.cn_count;
447 $scope.owning_lib = egCore.org.get($scope.lib);
448 $scope.$watch('owning_lib', function (l) {
449 angular.forEach( $scope.struct[$scope.first_cn], function (cp) {
450 cp.call_number().owning_lib( $scope.owning_lib.id() );
454 $scope.cant_have_vols = function (id) { return !egCore.org.CanHaveVolumes(id); };
456 $scope.$watch('cn_count', function (n) {
457 var o = Object.keys($scope.struct).length;
458 if (n > o) { // adding
459 for (var i = o; o < n; o++) {
460 var cn = new egCore.idl.acn();
461 cn.id( --$scope.new_cn_id );
463 cn.owning_lib( $scope.owning_lib.id() );
464 cn.record( $scope.full_cn.record() );
466 var cp = new egCore.idl.acp();
467 cp.id( --$scope.new_cp_id );
469 cp.circ_lib( $scope.owning_lib.id() );
470 cp.call_number( cn );
472 $scope.struct[cn.id()] = [cp];
473 $scope.allcopies.push(cp);
475 } else if (n < o && n >= $scope.orig_cn_count) { // removing
476 var how_many = o - n;
479 .sort(function(a, b){return a-b})
481 for (var i = how_many; i > 0; i--) {
482 // Trimming the global list is a bit more tricky
483 angular.forEach($scope.struct[list[i]], function (d) {
484 angular.forEach( $scope.allcopies, function (l, j) {
485 if (l === d) $scope.allcopies.splice(j,1);
488 delete $scope.struct[list[i]];
501 .controller('EditCtrl',
502 ['$scope','$q','$window','$routeParams','$location','$timeout','egCore','egNet','egGridDataProvider','itemSvc',
503 function($scope , $q , $window , $routeParams , $location , $timeout , egCore , egNet , egGridDataProvider , itemSvc) {
505 $scope.defaults = { // If defaults are not set at all, allow everything
509 loan_duration : true,
514 deposit_amount : true,
518 mint_condition : true,
521 circ_modifier : true,
529 $scope.saveDefaults = function () {
530 egCore.hatch.setItem('cat.copy.defaults', $scope.defaults);
533 $scope.fetchDefaults = function () {
534 egCore.hatch.getItem('cat.copy.defaults').then(function(t) {
537 if (!$scope.batch) $scope.batch = {};
538 $scope.batch.classification = $scope.defaults.classification;
539 $scope.batch.prefix = $scope.defaults.prefix;
540 $scope.batch.suffix = $scope.defaults.suffix;
541 $scope.working.statcat_filter = $scope.defaults.statcat_filter;
542 if ($scope.defaults.always_vols) $scope.show_vols = true;
546 $scope.fetchDefaults();
548 $scope.dirty = false;
549 $scope.$watch('dirty',
550 function(newVal, oldVal) {
551 if (newVal && newVal != oldVal) {
552 $($window).on('beforeunload.edit', function(){
553 return 'There is unsaved data!'
556 $($window).off('beforeunload.edit');
561 $scope.show_vols = true;
562 $scope.show_copies = true;
564 $scope.tracker = function (x,f) { if (x) return x[f]() };
565 $scope.idTracker = function (x) { if (x) return $scope.tracker(x,'id') };
566 $scope.cant_have_vols = function (id) { return !egCore.org.CanHaveVolumes(id); };
568 $scope.orgById = function (id) { return egCore.org.get(id) }
569 $scope.statusById = function (id) {
570 return $scope.status_list.filter( function (s) { return s.id() == id } )[0];
572 $scope.locationById = function (id) {
573 return $scope.location_cache[''+id];
576 $scope.workingToComplete = function () {
577 angular.forEach( $scope.workingGridControls.selectedItems(), function (c) {
578 angular.forEach( itemSvc.copies, function (w, i) {
580 $scope.completed_copies = $scope.completed_copies.concat(itemSvc.copies.splice(i,1));
585 $scope.completeToWorking = function () {
586 angular.forEach( $scope.completedGridControls.selectedItems(), function (c) {
587 angular.forEach( $scope.completed_copies, function (w, i) {
589 itemSvc.copies = itemSvc.copies.concat($scope.completed_copies.splice(i,1));
594 createSimpleUpdateWatcher = function (field) {
595 return $scope.$watch('working.' + field, function () {
596 var newval = $scope.working[field];
598 if (typeof newval != 'undefined') {
599 if (angular.isObject(newval)) { // we'll use the pkey
600 if (newval.id) newval = newval.id();
601 else if (newval.code) newval = newval.code();
604 if (""+newval == "" || newval == null) {
605 $scope.working[field] = undefined;
609 if ($scope.workingGridControls && $scope.workingGridControls.selectedItems) {
611 $scope.workingGridControls.selectedItems(),
613 if (cp[field]() !== newval) {
627 statcat_filter: undefined
630 $scope.statcatUpdate = function (id) {
631 var newval = $scope.working.statcats[id];
633 if (typeof newval != 'undefined') {
634 if (angular.isObject(newval)) { // we'll use the pkey
635 newval = newval.id();
638 if (""+newval == "" || newval == null) {
639 $scope.working.statcats[id] = undefined;
643 if (!$scope.in_item_select && $scope.workingGridControls && $scope.workingGridControls.selectedItems) {
645 $scope.workingGridControls.selectedItems(),
650 angular.forEach( cp.stat_cat_entries(), function (e) {
651 if (e.stat_cat() == id) { // mark deleted
658 var e = new egCore.idl.ascecm();
660 e.owning_copy( cp.id() );
662 e.stat_cat_entry( newval );
665 cp.stat_cat_entries().concat([ e ])
670 cp.stat_cat_entries( // trim out ephemeral deleted ones
671 cp.stat_cat_entries().filter(function (e) {
672 if (Boolean(e.isnew())) {
673 if (Boolean(e.isdeleted())) {
688 var dataKey = $routeParams.dataKey;
689 console.debug('dataKey: ' + dataKey);
691 if (dataKey && dataKey.length > 0) {
693 $scope.templates = {};
694 $scope.template_name = '';
695 $scope.template_name_list = [];
697 $scope.fetchTemplates = function () {
698 egCore.hatch.getItem('cat.copy.templates').then(function(t) {
700 $scope.templates = t;
701 $scope.template_name_list = Object.keys(t);
705 $scope.fetchTemplates();
707 $scope.applyTemplate = function (n) {
708 angular.forEach($scope.templates[n], function (v,k) {
709 if (!angular.isObject(v)) {
710 $scope.working[k] = angular.copy(v);
712 angular.forEach(v, function (sv,sk) {
713 if (k == 'callnumber') {
714 angular.forEach(v, function (cnv,cnk) {
715 $scope.batch[cnk] = cnv;
717 $scope.applyBatchCNValues();
719 $scope.working[k][sk] = angular.copy(sv);
720 if (k == 'statcats') $scope.statcatUpdate(sk);
725 $scope.template_name = '';
728 $scope.copytab = 'working';
730 $scope.summaryRecord = null;
731 $scope.record_id = null;
733 $scope.completed_copies = [];
734 $scope.location_orgs = [];
735 $scope.location_cache = {};
736 $scope.statcats = [];
737 if (!$scope.batch) $scope.batch = {};
739 $scope.applyBatchCNValues = function () {
740 if ($scope.data.tree) {
741 angular.forEach($scope.data.tree, function(cn_hash) {
742 angular.forEach(cn_hash, function(copies) {
743 angular.forEach(copies, function(cp) {
744 if (typeof $scope.batch.classification != 'undefined' && $scope.batch.classification != '')
745 cp.call_number().label_class($scope.batch.classification);
747 if (typeof $scope.batch.prefix != 'undefined' && $scope.batch.prefix != '')
748 cp.call_number().prefix($scope.batch.prefix);
750 if (typeof $scope.batch.label != 'undefined' && $scope.batch.label != '')
751 cp.call_number().label($scope.batch.label);
753 if (typeof $scope.batch.suffix != 'undefined' && $scope.batch.suffix != '')
754 cp.call_number().suffix($scope.batch.suffix);
762 $scope.clearWorking = function () {
763 angular.forEach($scope.working, function (v,k,o) {
764 if (!angular.isObject(v)) {
765 if (typeof v != 'undefined')
766 $scope.working[k] = undefined;
767 } else if (k != 'circ_lib') {
768 angular.forEach(v, function (sv,sk) {
769 if (typeof v != 'undefined')
770 $scope.working[k][sk] = undefined;
774 $scope.working.circ_lib = undefined; // special
777 $scope.completedGridDataProvider = egGridDataProvider.instance({
778 get : function(offset, count) {
779 //return provider.arrayNotifier(itemSvc.copies, offset, count);
780 return this.arrayNotifier($scope.completed_copies, offset, count);
784 $scope.completedGridControls = {};
786 $scope.workingGridDataProvider = egGridDataProvider.instance({
787 get : function(offset, count) {
788 //return provider.arrayNotifier(itemSvc.copies, offset, count);
789 return this.arrayNotifier(itemSvc.copies, offset, count);
793 $scope.workingGridControls = {};
797 'open-ils.actor.anon_cache.get_value',
798 dataKey, 'edit-these-copies'
799 ).then(function (data) {
802 if (data.hide_vols && !$scope.defaults.always_vols) $scope.show_vols = false;
803 if (data.hide_copies) $scope.show_copies = false;
805 $scope.record_id = data.record_id;
807 if (data.copies && data.copies.length)
808 return itemSvc.fetchIds(data.copies);
810 if (data.raw && data.raw.length) {
812 /* data.raw must be an array of copies with (at least)
813 * the call number fleshed on each. For new copies
814 * create from whole cloth, the id for each should
815 * probably be negative and isnew() should return true.
816 * Each /distinct/ call number must have a distinct id
817 * as well, probably negative also if they're new. Clear?
822 function (cp) { itemSvc.addCopy(cp) }
825 return itemSvc.copies;
829 }).then( function() {
830 $scope.data = itemSvc;
831 $scope.workingGridDataProvider.refresh();
834 $scope.in_item_select = false;
835 $scope.afterItemSelect = function() { $scope.in_item_select = false };
836 $scope.handleItemSelect = function (item_list) {
837 if (item_list && item_list.length > 0) {
838 $scope.in_item_select = true;
840 angular.forEach(Object.keys($scope.defaults.attributes), function (attr) {
843 angular.forEach(item_list, function (item) {
846 if (angular.isObject(v)) {
847 if (v.id) v = v.id();
848 else if (v.code) v = v.code();
854 if (Object.keys(value_hash).length == 1) {
855 if (attr == 'circ_lib') {
856 $scope.working[attr] = egCore.org.get(item_list[0][attr]());
858 $scope.working[attr] = item_list[0][attr]();
861 $scope.working[attr] = undefined;
865 angular.forEach($scope.statcats, function (sc) {
870 angular.forEach(item_list, function (item) {
871 if (item.stat_cat_entries()) {
872 if (item.stat_cat_entries().length > 0) {
873 var right_sc = item.stat_cat_entries().filter(function (e) {
874 return e.stat_cat() == sc.id() && !Boolean(e.isdeleted());
877 if (right_sc.length > 0) {
878 value_hash[right_sc[0].stat_cat_entry()] = right_sc[0].stat_cat_entry();
888 if (!none && Object.keys(value_hash).length == 1) {
889 $scope.working.statcats[sc.id()] = value_hash[Object.keys(value_hash)[0]];
891 $scope.working.statcats[sc.id()] = undefined;
896 $scope.clearWorking();
901 $scope.$watch('data.copies.length', function () {
902 if ($scope.data.copies) {
903 var base_orgs = $scope.data.copies.map(function(cp){
906 $scope.data.copies.map(function(cp){
907 return cp.call_number().owning_lib()
910 [egCore.auth.user().ws_ou()]
911 ).filter(function(e,i,a){
912 return a.lastIndexOf(e) === i;
916 angular.forEach(base_orgs, function(o) {
917 all_orgs = all_orgs.concat( egCore.org.fullPath(o, true) );
920 var final_orgs = all_orgs.filter(function(e,i,a){
921 return a.lastIndexOf(e) === i;
922 }).sort(function(a,b){return b-a});
924 if ($scope.location_orgs.toString() != final_orgs.toString()) {
925 $scope.location_orgs = final_orgs;
926 if ($scope.location_orgs.length) {
927 itemSvc.get_locations($scope.location_orgs).then(function(list){
928 angular.forEach(list, function(l) {
929 $scope.location_cache[ ''+l.id() ] = l;
931 $scope.location_list = list;
934 $scope.statcat_filter_list = [];
935 angular.forEach($scope.location_orgs, function (o) {
936 $scope.statcat_filter_list.push(egCore.org.get(o));
939 itemSvc.get_statcats($scope.location_orgs).then(function(list){
940 $scope.statcats = list;
941 angular.forEach($scope.statcats, function (s) {
944 $scope.working = { statcats: {}, statcat_filter: undefined};
945 if (!$scope.working.statcats)
946 $scope.working.statcats = {};
948 if (!$scope.in_item_select) {
949 $scope.working.statcats[s.id()] = undefined;
951 createStatcatUpdateWatcher(s.id());
953 $scope.in_item_select = false;
959 $scope.workingGridDataProvider.refresh();
962 $scope.suffix_list = [];
963 itemSvc.get_suffixes(egCore.auth.user().ws_ou()).then(function(list){
964 $scope.suffix_list = list;
967 $scope.prefix_list = [];
968 itemSvc.get_prefixes(egCore.auth.user().ws_ou()).then(function(list){
969 $scope.prefix_list = list;
972 $scope.classification_list = [];
973 itemSvc.get_classifications().then(function(list){
974 $scope.classification_list = list;
977 $scope.$watch('completed_copies.length', function () {
978 $scope.completedGridDataProvider.refresh();
981 $scope.location_list = [];
982 itemSvc.get_locations().then(function(list){
983 $scope.location_list = list;
985 createSimpleUpdateWatcher('location');
987 $scope.status_list = [];
988 itemSvc.get_statuses().then(function(list){
989 $scope.status_list = list;
991 createSimpleUpdateWatcher('status');
993 $scope.circ_modifier_list = [];
994 itemSvc.get_circ_mods().then(function(list){
995 $scope.circ_modifier_list = list;
997 createSimpleUpdateWatcher('circ_modifier');
999 $scope.circ_type_list = [];
1000 itemSvc.get_circ_types().then(function(list){
1001 $scope.circ_type_list = list;
1003 createSimpleUpdateWatcher('circ_as_type');
1005 $scope.age_protect_list = [];
1006 itemSvc.get_age_protects().then(function(list){
1007 $scope.age_protect_list = list;
1009 createSimpleUpdateWatcher('age_protect');
1011 createSimpleUpdateWatcher('circ_lib');
1012 createSimpleUpdateWatcher('circulate');
1013 createSimpleUpdateWatcher('holdable');
1014 createSimpleUpdateWatcher('fine_level');
1015 createSimpleUpdateWatcher('loan_duration');
1016 createSimpleUpdateWatcher('cost');
1017 createSimpleUpdateWatcher('deposit');
1018 createSimpleUpdateWatcher('deposit_amount');
1019 createSimpleUpdateWatcher('mint_condition');
1020 createSimpleUpdateWatcher('opac_visible');
1021 createSimpleUpdateWatcher('ref');
1023 $scope.saveCompletedCopies = function (and_exit) {
1025 var perCnCopies = {};
1026 angular.forEach( $scope.completed_copies, function (cp) {
1027 var cn_id = cp.call_number().id();
1028 if (!cnHash[cn_id]) {
1029 cnHash[cn_id] = cp.call_number();
1030 perCnCopies[cn_id] = [cp];
1032 perCnCopies[cn_id].push(cp);
1034 cp.call_number(cn_id); // prevent loops in JSON-ification
1037 angular.forEach(perCnCopies, function (v, k) {
1038 cnHash[k].copies(v);
1042 angular.forEach(cnHash, function (v, k) {
1048 'open-ils.cat.asset.volume.fleshed.batch.update.override',
1049 egCore.auth.token(), cnList, 1, { auto_merge_vols : 1, create_parts : 1 }
1050 ).then(function(update_count) {
1051 alert(update_count + ' call numbers updated');
1053 $scope.dirty = false;
1054 $timeout(function(){$window.close()});
1059 $scope.saveAndExit = function () {
1060 $scope.saveCompletedCopies(true);
1067 .directive("egVolTemplate", function () {
1071 template: '<div ng-include="'+"'/eg/staff/cat/volcopy/t_attr_edit'"+'"></div>',
1073 controller : ['$scope','$window','itemSvc','egCore',
1074 function ( $scope , $window , itemSvc , egCore ) {
1076 $scope.defaults = { // If defaults are not set at all, allow everything
1080 loan_duration : true,
1085 deposit_amount : true,
1086 opac_visible : true,
1089 mint_condition : true,
1092 circ_modifier : true,
1093 circ_as_type : true,
1100 $scope.fetchDefaults = function () {
1101 egCore.hatch.getItem('cat.copy.defaults').then(function(t) {
1103 $scope.defaults = t;
1104 $scope.working.statcat_filter = $scope.defaults.statcat_filter;
1108 $scope.fetchDefaults();
1110 $scope.dirty = false;
1111 $scope.$watch('dirty',
1112 function(newVal, oldVal) {
1113 if (newVal && newVal != oldVal) {
1114 $($window).on('beforeunload.template', function(){
1115 return 'There is unsaved template data!'
1118 $($window).off('beforeunload.template');
1123 $scope.template_controls = true;
1125 $scope.fetchTemplates = function () {
1126 egCore.hatch.getItem('cat.copy.templates').then(function(t) {
1128 $scope.templates = t;
1129 $scope.template_name_list = Object.keys(t);
1133 $scope.fetchTemplates();
1135 $scope.applyTemplate = function (n) {
1136 angular.forEach($scope.templates[n], function (v,k) {
1137 if (!angular.isObject(v)) {
1138 $scope.working[k] = angular.copy(v);
1140 angular.forEach(v, function (sv,sk) {
1141 $scope.working[k][sk] = angular.copy(sv);
1145 $scope.template_name = '';
1148 $scope.deleteTemplate = function (n) {
1150 delete $scope.templates[n]
1151 $scope.template_name_list = Object.keys($scope.templates);
1152 $scope.template_name = '';
1153 egCore.hatch.setItem('cat.copy.templates', $scope.templates);
1154 $scope.$parent.fetchTemplates();
1158 $scope.saveTemplate = function (n) {
1162 angular.forEach($scope.working, function (v,k) {
1163 if (angular.isObject(v)) { // we'll use the pkey
1164 if (v.id) v = v.id();
1165 else if (v.code) v = v.code();
1171 $scope.templates[n] = tmpl;
1172 $scope.template_name_list = Object.keys($scope.templates);
1174 egCore.hatch.setItem('cat.copy.templates', $scope.templates);
1175 $scope.$parent.fetchTemplates();
1177 $scope.dirty = false;
1181 $scope.templates = {};
1182 $scope.template_name = '';
1183 $scope.template_name_list = [];
1185 $scope.tracker = function (x,f) { if (x) return x[f]() };
1186 $scope.idTracker = function (x) { if (x) return $scope.tracker(x,'id') };
1187 $scope.cant_have_vols = function (id) { return !egCore.org.CanHaveVolumes(id); };
1189 $scope.orgById = function (id) { return egCore.org.get(id) }
1190 $scope.statusById = function (id) {
1191 return $scope.status_list.filter( function (s) { return s.id() == id } )[0];
1193 $scope.locationById = function (id) {
1194 return $scope.location_cache[''+id];
1197 createSimpleUpdateWatcher = function (field) {
1198 $scope.$watch('working.' + field, function () {
1199 var newval = $scope.working[field];
1201 if (typeof newval != 'undefined') {
1202 $scope.dirty = true;
1203 if (angular.isObject(newval)) { // we'll use the pkey
1204 if (newval.id) $scope.working[field] = newval.id();
1205 else if (newval.code) $scope.working[field] = newval.code();
1208 if (""+newval == "" || newval == null) {
1209 $scope.working[field] = undefined;
1218 statcat_filter: undefined
1221 createStatcatUpdateWatcher = function (id) {
1222 return $scope.$watch('working.statcats[' + id + ']', function () {
1223 if ($scope.working.statcats) {
1224 var newval = $scope.working.statcats[id];
1226 if (typeof newval != 'undefined') {
1227 $scope.dirty = true;
1228 if (angular.isObject(newval)) { // we'll use the pkey
1229 newval = newval.id();
1232 if (""+newval == "" || newval == null) {
1233 $scope.working.statcats[id] = undefined;
1242 $scope.clearWorking = function () {
1243 angular.forEach($scope.working, function (v,k,o) {
1244 if (!angular.isObject(v)) {
1245 if (typeof v != 'undefined')
1246 $scope.working[k] = undefined;
1247 } else if (k != 'circ_lib') {
1248 angular.forEach(v, function (sv,sk) {
1249 $scope.working[k][sk] = undefined;
1253 $scope.working.circ_lib = undefined; // special
1254 $scope.dirty = false;
1257 $scope.working = {};
1258 $scope.location_orgs = [];
1259 $scope.location_cache = {};
1261 $scope.location_list = [];
1262 itemSvc.get_locations(
1263 egCore.org.fullPath( egCore.auth.user().ws_ou(), true )
1264 ).then(function(list){
1265 $scope.location_list = list;
1267 createSimpleUpdateWatcher('location');
1269 $scope.statcat_filter_list = egCore.org.fullPath( egCore.auth.user().ws_ou() );
1271 $scope.statcats = [];
1272 itemSvc.get_statcats(
1273 egCore.org.fullPath( egCore.auth.user().ws_ou(), true )
1274 ).then(function(list){
1275 $scope.statcats = list;
1276 angular.forEach($scope.statcats, function (s) {
1278 if (!$scope.working)
1279 $scope.working = { statcats: {}, statcat_filter: undefined};
1280 if (!$scope.working.statcats)
1281 $scope.working.statcats = {};
1283 $scope.working.statcats[s.id()] = undefined;
1284 createStatcatUpdateWatcher(s.id());
1288 $scope.status_list = [];
1289 itemSvc.get_statuses().then(function(list){
1290 $scope.status_list = list;
1292 createSimpleUpdateWatcher('status');
1294 $scope.circ_modifier_list = [];
1295 itemSvc.get_circ_mods().then(function(list){
1296 $scope.circ_modifier_list = list;
1298 createSimpleUpdateWatcher('circ_modifier');
1300 $scope.circ_type_list = [];
1301 itemSvc.get_circ_types().then(function(list){
1302 $scope.circ_type_list = list;
1304 createSimpleUpdateWatcher('circ_as_type');
1306 $scope.age_protect_list = [];
1307 itemSvc.get_age_protects().then(function(list){
1308 $scope.age_protect_list = list;
1310 createSimpleUpdateWatcher('age_protect');
1312 createSimpleUpdateWatcher('circ_lib');
1313 createSimpleUpdateWatcher('circulate');
1314 createSimpleUpdateWatcher('holdable');
1315 createSimpleUpdateWatcher('fine_level');
1316 createSimpleUpdateWatcher('loan_duration');
1317 createSimpleUpdateWatcher('cost');
1318 createSimpleUpdateWatcher('deposit');
1319 createSimpleUpdateWatcher('deposit_amount');
1320 createSimpleUpdateWatcher('mint_condition');
1321 createSimpleUpdateWatcher('opac_visible');
1322 createSimpleUpdateWatcher('ref');
1324 $scope.suffix_list = [];
1325 itemSvc.get_suffixes(egCore.auth.user().ws_ou()).then(function(list){
1326 $scope.suffix_list = list;
1329 $scope.prefix_list = [];
1330 itemSvc.get_prefixes(egCore.auth.user().ws_ou()).then(function(list){
1331 $scope.prefix_list = list;
1334 $scope.classification_list = [];
1335 itemSvc.get_classifications().then(function(list){
1336 $scope.classification_list = list;
1339 createSimpleUpdateWatcher('working.callnumber.classification');
1340 createSimpleUpdateWatcher('working.callnumber.prefix');
1341 createSimpleUpdateWatcher('working.callnumber.suffix');