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()" 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: { copy: "=", callNumber: "=", index: "@" },
206 controller : ['$scope','itemSvc','egCore',
207 function ( $scope , itemSvc , egCore ) {
208 $scope.new_part_id = 0;
210 $scope.nextBarcode = function (i) {
211 $scope.$parent.focusNextBarcode($scope.copy.id());
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)" copy="cp" call-number="callNumber"></eg-vol-copy-edit>'+
284 scope: {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) 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;
308 var el = $(next).get(0);
313 $scope.suffix_list = [];
314 itemSvc.get_suffixes($scope.callNumber.owning_lib()).then(function(list){
315 $scope.suffix_list = list;
317 $scope.updateSuffix = function () {
318 angular.forEach($scope.copies, function(cp) {
319 cp.call_number().suffix($scope.suffix);
320 cp.call_number().ischanged(1);
324 $scope.prefix_list = [];
325 itemSvc.get_prefixes($scope.callNumber.owning_lib()).then(function(list){
326 $scope.prefix_list = list;
328 $scope.updatePrefix = function () {
329 angular.forEach($scope.copies, function(cp) {
330 cp.call_number().prefix($scope.prefix);
331 cp.call_number().ischanged(1);
335 $scope.classification_list = [];
336 itemSvc.get_classifications().then(function(list){
337 $scope.classification_list = list;
339 $scope.updateClassification = function () {
340 angular.forEach($scope.copies, function(cp) {
341 cp.call_number().label_class($scope.classification);
342 cp.call_number().ischanged(1);
346 $scope.updateLabel = function () {
347 angular.forEach($scope.copies, function(cp) {
348 cp.call_number().label($scope.label);
349 cp.call_number().ischanged(1);
353 $scope.$watch('callNumber.prefix()', function (v) {
354 if (typeof v != 'object') {
355 $scope.prefix = $scope.prefix_list.filter(function (p) {
358 $scope.callNumber.prefix($scope.prefix);
362 $scope.$watch('callNumber.suffix()', function (v) {
363 if (typeof v != 'object') {
364 $scope.suffix = $scope.suffix_list.filter( function (s) {
367 $scope.callNumber.suffix($scope.suffix);
371 $scope.$watch('callNumber.label_class()', function (v) {
372 if (typeof v != 'object') {
373 $scope.classification = $scope.classification_list.filter(function (c) {
376 $scope.callNumber.label_class($scope.classification);
380 $scope.$watch('callNumber.label()', function (v) {
384 $scope.prefix = $scope.callNumber.prefix();
385 $scope.suffix = $scope.callNumber.suffix();
386 $scope.classification = $scope.callNumber.label_class();
387 $scope.label = $scope.callNumber.label();
389 $scope.copy_count = $scope.copies.length;
390 $scope.orig_copy_count = $scope.copy_count;
392 $scope.changeCPCount = function () {
393 while ($scope.copy_count > $scope.copies.length) {
394 var cp = new egCore.idl.acp();
395 cp.id( --itemSvc.new_cp_id );
397 cp.circ_lib( $scope.lib );
398 cp.call_number( $scope.callNumber );
399 $scope.copies.push( cp );
400 $scope.allcopies.push( cp );
403 if ($scope.copy_count >= $scope.orig_copy_count) {
404 var how_many = $scope.copies.length - $scope.copy_count;
406 var dead = $scope.copies.splice($scope.copy_count,how_many);
407 $scope.callNumber.copies($scope.copies);
409 // Trimming the global list is a bit more tricky
410 angular.forEach( dead, function (d) {
411 angular.forEach( $scope.allcopies, function (l, i) {
412 if (l === d) $scope.allcopies.splice(i,1);
425 .directive("egVolEdit", function () {
431 '<div class="col-xs-1"><eg-org-selector selected="owning_lib" disableTest="cant_have_vols"></eg-org-selector></div>'+
432 '<div class="col-xs-1"><input class="form-control" type="number" min="{{orig_cn_count}}" ng-model="cn_count" ng-change="changeCNCount()"/></div>'+
433 '<div class="col-xs-10">'+
434 '<eg-vol-row ng-repeat="(cn,copies) in struct track by cn" copies="copies" allcopies="allcopies"></eg-vol-row>'+
438 scope: { allcopies: "=", struct: "=", lib: "@", record: "@" },
439 controller : ['$scope','itemSvc','egCore',
440 function ( $scope , itemSvc , egCore ) {
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( --itemSvc.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( --itemSvc.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','$modal',
503 function($scope , $q , $window , $routeParams , $location , $timeout , egCore , egNet , egGridDataProvider , itemSvc , $modal) {
505 $scope.defaults = { // If defaults are not set at all, allow everything
510 loan_duration : true,
515 deposit_amount : true,
519 mint_condition : true,
522 circ_modifier : true,
530 $scope.saveDefaults = function () {
531 egCore.hatch.setItem('cat.copy.defaults', $scope.defaults);
534 $scope.fetchDefaults = function () {
535 egCore.hatch.getItem('cat.copy.defaults').then(function(t) {
538 if (!$scope.batch) $scope.batch = {};
539 $scope.batch.classification = $scope.defaults.classification;
540 $scope.batch.prefix = $scope.defaults.prefix;
541 $scope.batch.suffix = $scope.defaults.suffix;
542 $scope.working.statcat_filter = $scope.defaults.statcat_filter;
543 if ($scope.defaults.always_vols) $scope.show_vols = true;
547 $scope.fetchDefaults();
549 $scope.dirty = false;
550 $scope.$watch('dirty',
551 function(newVal, oldVal) {
552 if (newVal && newVal != oldVal) {
553 $($window).on('beforeunload.edit', function(){
554 return 'There is unsaved data!'
557 $($window).off('beforeunload.edit');
562 $scope.show_vols = true;
563 $scope.show_copies = true;
565 $scope.tracker = function (x,f) { if (x) return x[f]() };
566 $scope.idTracker = function (x) { if (x) return $scope.tracker(x,'id') };
567 $scope.cant_have_vols = function (id) { return !egCore.org.CanHaveVolumes(id); };
569 $scope.orgById = function (id) { return egCore.org.get(id) }
570 $scope.statusById = function (id) {
571 return $scope.status_list.filter( function (s) { return s.id() == id } )[0];
573 $scope.locationById = function (id) {
574 return $scope.location_cache[''+id];
577 $scope.workingToComplete = function () {
578 angular.forEach( $scope.workingGridControls.selectedItems(), function (c) {
579 angular.forEach( itemSvc.copies, function (w, i) {
581 $scope.completed_copies = $scope.completed_copies.concat(itemSvc.copies.splice(i,1));
586 $scope.completeToWorking = function () {
587 angular.forEach( $scope.completedGridControls.selectedItems(), function (c) {
588 angular.forEach( $scope.completed_copies, function (w, i) {
590 itemSvc.copies = itemSvc.copies.concat($scope.completed_copies.splice(i,1));
595 createSimpleUpdateWatcher = function (field) {
596 return $scope.$watch('working.' + field, function () {
597 var newval = $scope.working[field];
599 if (typeof newval != 'undefined') {
600 if (angular.isObject(newval)) { // we'll use the pkey
601 if (newval.id) newval = newval.id();
602 else if (newval.code) newval = newval.code();
605 if (""+newval == "" || newval == null) {
606 $scope.working[field] = undefined;
610 if ($scope.workingGridControls && $scope.workingGridControls.selectedItems) {
612 $scope.workingGridControls.selectedItems(),
614 if (cp[field]() !== newval) {
628 statcat_filter: undefined
631 $scope.statcatUpdate = function (id) {
632 var newval = $scope.working.statcats[id];
634 if (typeof newval != 'undefined') {
635 if (angular.isObject(newval)) { // we'll use the pkey
636 newval = newval.id();
639 if (""+newval == "" || newval == null) {
640 $scope.working.statcats[id] = undefined;
644 if (!$scope.in_item_select && $scope.workingGridControls && $scope.workingGridControls.selectedItems) {
646 $scope.workingGridControls.selectedItems(),
651 angular.forEach( cp.stat_cat_entries(), function (e) {
652 if (e.stat_cat() == id) { // mark deleted
659 var e = new egCore.idl.ascecm();
661 e.owning_copy( cp.id() );
663 e.stat_cat_entry( newval );
666 cp.stat_cat_entries().concat([ e ])
671 cp.stat_cat_entries( // trim out ephemeral deleted ones
672 cp.stat_cat_entries().filter(function (e) {
673 if (Boolean(e.isnew())) {
674 if (Boolean(e.isdeleted())) {
689 var dataKey = $routeParams.dataKey;
690 console.debug('dataKey: ' + dataKey);
692 if (dataKey && dataKey.length > 0) {
694 $scope.templates = {};
695 $scope.template_name = '';
696 $scope.template_name_list = [];
698 $scope.fetchTemplates = function () {
699 egCore.hatch.getItem('cat.copy.templates').then(function(t) {
701 $scope.templates = t;
702 $scope.template_name_list = Object.keys(t);
706 $scope.fetchTemplates();
708 $scope.applyTemplate = function (n) {
709 angular.forEach($scope.templates[n], function (v,k) {
710 if (!angular.isObject(v)) {
711 $scope.working[k] = angular.copy(v);
713 angular.forEach(v, function (sv,sk) {
714 if (k == 'callnumber') {
715 angular.forEach(v, function (cnv,cnk) {
716 $scope.batch[cnk] = cnv;
718 $scope.applyBatchCNValues();
720 $scope.working[k][sk] = angular.copy(sv);
721 if (k == 'statcats') $scope.statcatUpdate(sk);
726 $scope.template_name = '';
729 $scope.copytab = 'working';
731 $scope.summaryRecord = null;
732 $scope.record_id = null;
734 $scope.completed_copies = [];
735 $scope.location_orgs = [];
736 $scope.location_cache = {};
737 $scope.statcats = [];
738 if (!$scope.batch) $scope.batch = {};
740 $scope.applyBatchCNValues = function () {
741 if ($scope.data.tree) {
742 angular.forEach($scope.data.tree, function(cn_hash) {
743 angular.forEach(cn_hash, function(copies) {
744 angular.forEach(copies, function(cp) {
745 if (typeof $scope.batch.classification != 'undefined' && $scope.batch.classification != '')
746 cp.call_number().label_class($scope.batch.classification);
748 if (typeof $scope.batch.prefix != 'undefined' && $scope.batch.prefix != '')
749 cp.call_number().prefix($scope.batch.prefix);
751 if (typeof $scope.batch.label != 'undefined' && $scope.batch.label != '')
752 cp.call_number().label($scope.batch.label);
754 if (typeof $scope.batch.suffix != 'undefined' && $scope.batch.suffix != '')
755 cp.call_number().suffix($scope.batch.suffix);
763 $scope.clearWorking = function () {
764 angular.forEach($scope.working, function (v,k,o) {
765 if (!angular.isObject(v)) {
766 if (typeof v != 'undefined')
767 $scope.working[k] = undefined;
768 } else if (k != 'circ_lib') {
769 angular.forEach(v, function (sv,sk) {
770 if (typeof v != 'undefined')
771 $scope.working[k][sk] = undefined;
775 $scope.working.circ_lib = undefined; // special
778 $scope.completedGridDataProvider = egGridDataProvider.instance({
779 get : function(offset, count) {
780 //return provider.arrayNotifier(itemSvc.copies, offset, count);
781 return this.arrayNotifier($scope.completed_copies, offset, count);
785 $scope.completedGridControls = {};
787 $scope.workingGridDataProvider = egGridDataProvider.instance({
788 get : function(offset, count) {
789 //return provider.arrayNotifier(itemSvc.copies, offset, count);
790 return this.arrayNotifier(itemSvc.copies, offset, count);
794 $scope.workingGridControls = {};
798 'open-ils.actor.anon_cache.get_value',
799 dataKey, 'edit-these-copies'
800 ).then(function (data) {
803 if (data.hide_vols && !$scope.defaults.always_vols) $scope.show_vols = false;
804 if (data.hide_copies) $scope.show_copies = false;
806 $scope.record_id = data.record_id;
808 if (data.copies && data.copies.length)
809 return itemSvc.fetchIds(data.copies);
811 if (data.raw && data.raw.length) {
813 /* data.raw data structure looks like this:
815 * callnumber : $cn_id, // optional, to add a copy to a cn
816 * owner : $org, // optional, defaults to ws_ou
817 * label : $cn_label, // optional, to supply a label on a new cn
818 * barcode : $cp_barcode // optional, to supply a barcode on a new cp
821 * All can be left out and a completely empty vol/copy combo will be vivicated.
827 if (proto.callnumber) {
828 return egCore.pcrud.retrieve('acn', proto.callnumber)
830 var cp = new egCore.idl.acp();
831 cp.call_number( cn );
832 cp.id( --itemSvc.new_cp_id );
834 cp.circ_lib( $scope.record_id );
835 if (proto.barcode) cp.barcode( proto.barcode );
840 var cn = new egCore.idl.acn();
841 cn.id( --itemSvc.new_cn_id );
843 cn.owning_lib( proto.owner || egCore.auth.user().ws_ou() );
844 cn.record( $scope.record_id );
845 if (proto.label) cn.label( proto.label );
847 var cp = new egCore.idl.acp();
848 cp.call_number( cn );
849 cp.id( --itemSvc.new_cp_id );
851 cp.circ_lib( $scope.record_id );
852 if (proto.barcode) cp.barcode( proto.barcode );
860 return itemSvc.copies;
864 }).then( function() {
865 $scope.data = itemSvc;
866 $scope.workingGridDataProvider.refresh();
869 $scope.in_item_select = false;
870 $scope.afterItemSelect = function() { $scope.in_item_select = false };
871 $scope.handleItemSelect = function (item_list) {
872 if (item_list && item_list.length > 0) {
873 $scope.in_item_select = true;
875 angular.forEach(Object.keys($scope.defaults.attributes), function (attr) {
878 angular.forEach(item_list, function (item) {
881 if (angular.isObject(v)) {
882 if (v.id) v = v.id();
883 else if (v.code) v = v.code();
889 if (Object.keys(value_hash).length == 1) {
890 if (attr == 'circ_lib') {
891 $scope.working[attr] = egCore.org.get(item_list[0][attr]());
893 $scope.working[attr] = item_list[0][attr]();
896 $scope.working[attr] = undefined;
900 angular.forEach($scope.statcats, function (sc) {
905 angular.forEach(item_list, function (item) {
906 if (item.stat_cat_entries()) {
907 if (item.stat_cat_entries().length > 0) {
908 var right_sc = item.stat_cat_entries().filter(function (e) {
909 return e.stat_cat() == sc.id() && !Boolean(e.isdeleted());
912 if (right_sc.length > 0) {
913 value_hash[right_sc[0].stat_cat_entry()] = right_sc[0].stat_cat_entry();
923 if (!none && Object.keys(value_hash).length == 1) {
924 $scope.working.statcats[sc.id()] = value_hash[Object.keys(value_hash)[0]];
926 $scope.working.statcats[sc.id()] = undefined;
931 $scope.clearWorking();
936 $scope.$watch('data.copies.length', function () {
937 if ($scope.data.copies) {
938 var base_orgs = $scope.data.copies.map(function(cp){
941 $scope.data.copies.map(function(cp){
942 return cp.call_number().owning_lib()
945 [egCore.auth.user().ws_ou()]
946 ).filter(function(e,i,a){
947 return a.lastIndexOf(e) === i;
951 angular.forEach(base_orgs, function(o) {
952 all_orgs = all_orgs.concat( egCore.org.fullPath(o, true) );
955 var final_orgs = all_orgs.filter(function(e,i,a){
956 return a.lastIndexOf(e) === i;
957 }).sort(function(a,b){return b-a});
959 if ($scope.location_orgs.toString() != final_orgs.toString()) {
960 $scope.location_orgs = final_orgs;
961 if ($scope.location_orgs.length) {
962 itemSvc.get_locations($scope.location_orgs).then(function(list){
963 angular.forEach(list, function(l) {
964 $scope.location_cache[ ''+l.id() ] = l;
966 $scope.location_list = list;
969 $scope.statcat_filter_list = [];
970 angular.forEach($scope.location_orgs, function (o) {
971 $scope.statcat_filter_list.push(egCore.org.get(o));
974 itemSvc.get_statcats($scope.location_orgs).then(function(list){
975 $scope.statcats = list;
976 angular.forEach($scope.statcats, function (s) {
979 $scope.working = { statcats: {}, statcat_filter: undefined};
980 if (!$scope.working.statcats)
981 $scope.working.statcats = {};
983 if (!$scope.in_item_select) {
984 $scope.working.statcats[s.id()] = undefined;
986 createStatcatUpdateWatcher(s.id());
988 $scope.in_item_select = false;
994 $scope.workingGridDataProvider.refresh();
997 $scope.suffix_list = [];
998 itemSvc.get_suffixes(egCore.auth.user().ws_ou()).then(function(list){
999 $scope.suffix_list = list;
1002 $scope.prefix_list = [];
1003 itemSvc.get_prefixes(egCore.auth.user().ws_ou()).then(function(list){
1004 $scope.prefix_list = list;
1007 $scope.classification_list = [];
1008 itemSvc.get_classifications().then(function(list){
1009 $scope.classification_list = list;
1012 $scope.$watch('completed_copies.length', function () {
1013 $scope.completedGridDataProvider.refresh();
1016 $scope.location_list = [];
1017 itemSvc.get_locations().then(function(list){
1018 $scope.location_list = list;
1020 createSimpleUpdateWatcher('location');
1022 $scope.status_list = [];
1023 itemSvc.get_statuses().then(function(list){
1024 $scope.status_list = list;
1026 createSimpleUpdateWatcher('status');
1028 $scope.circ_modifier_list = [];
1029 itemSvc.get_circ_mods().then(function(list){
1030 $scope.circ_modifier_list = list;
1032 createSimpleUpdateWatcher('circ_modifier');
1034 $scope.circ_type_list = [];
1035 itemSvc.get_circ_types().then(function(list){
1036 $scope.circ_type_list = list;
1038 createSimpleUpdateWatcher('circ_as_type');
1040 $scope.age_protect_list = [];
1041 itemSvc.get_age_protects().then(function(list){
1042 $scope.age_protect_list = list;
1044 createSimpleUpdateWatcher('age_protect');
1046 createSimpleUpdateWatcher('circ_lib');
1047 createSimpleUpdateWatcher('circulate');
1048 createSimpleUpdateWatcher('holdable');
1049 createSimpleUpdateWatcher('fine_level');
1050 createSimpleUpdateWatcher('loan_duration');
1051 createSimpleUpdateWatcher('cost');
1052 createSimpleUpdateWatcher('deposit');
1053 createSimpleUpdateWatcher('deposit_amount');
1054 createSimpleUpdateWatcher('mint_condition');
1055 createSimpleUpdateWatcher('opac_visible');
1056 createSimpleUpdateWatcher('ref');
1058 $scope.saveCompletedCopies = function (and_exit) {
1060 var perCnCopies = {};
1061 angular.forEach( $scope.completed_copies, function (cp) {
1062 var cn_id = cp.call_number().id();
1063 if (!cnHash[cn_id]) {
1064 cnHash[cn_id] = cp.call_number();
1065 perCnCopies[cn_id] = [cp];
1067 perCnCopies[cn_id].push(cp);
1069 cp.call_number(cn_id); // prevent loops in JSON-ification
1072 angular.forEach(perCnCopies, function (v, k) {
1073 cnHash[k].copies(v);
1077 angular.forEach(cnHash, function (v, k) {
1083 'open-ils.cat.asset.volume.fleshed.batch.update.override',
1084 egCore.auth.token(), cnList, 1, { auto_merge_vols : 1, create_parts : 1 }
1085 ).then(function(update_count) {
1087 $scope.dirty = false;
1088 $timeout(function(){$window.close()});
1093 $scope.saveAndExit = function () {
1094 $scope.saveCompletedCopies(true);
1099 $scope.copy_notes_dialog = function(copy_list) {
1100 var default_pub = Boolean($scope.defaults.copy_notes_pub);
1101 if (!angular.isArray(copy_list)) copy_list = [copy_list];
1103 return $modal.open({
1104 templateUrl: './cat/volcopy/t_copy_notes',
1107 ['$scope','$modalInstance',
1108 function($scope , $modalInstance) {
1109 $scope.focusNote = true;
1111 creator : egCore.auth.user().id(),
1117 $scope.require_initials = false;
1118 egCore.org.settings([
1119 'ui.staff.require_initials.copy_notes'
1120 ]).then(function(set) {
1121 $scope.require_initials = Boolean(set['ui.staff.require_initials.copy_notes']);
1124 $scope.note_list = [];
1125 if (copy_list.length == 1) {
1126 $scope.note_list = copy_list[0].notes();
1129 $scope.ok = function(note) {
1131 if (note.initials) note.value += ' [' + note.initials + ']';
1132 angular.forEach(copy_list, function (cp) {
1133 var n = new egCore.idl.acpn();
1134 n.creator(note.creator);
1136 n.title(note.title);
1137 n.value(note.value);
1138 n.owning_copy(cp.id());
1139 cp.notes().push( n );
1142 $modalInstance.close();
1145 $scope.cancel = function($event) {
1146 $modalInstance.dismiss();
1147 $event.preventDefault();
1155 .directive("egVolTemplate", function () {
1159 template: '<div ng-include="'+"'/eg/staff/cat/volcopy/t_attr_edit'"+'"></div>',
1161 controller : ['$scope','$window','itemSvc','egCore',
1162 function ( $scope , $window , itemSvc , egCore ) {
1164 $scope.defaults = { // If defaults are not set at all, allow everything
1169 loan_duration : true,
1174 deposit_amount : true,
1175 opac_visible : true,
1178 mint_condition : true,
1181 circ_modifier : true,
1182 circ_as_type : true,
1189 $scope.fetchDefaults = function () {
1190 egCore.hatch.getItem('cat.copy.defaults').then(function(t) {
1192 $scope.defaults = t;
1193 $scope.working.statcat_filter = $scope.defaults.statcat_filter;
1197 $scope.fetchDefaults();
1199 $scope.dirty = false;
1200 $scope.$watch('dirty',
1201 function(newVal, oldVal) {
1202 if (newVal && newVal != oldVal) {
1203 $($window).on('beforeunload.template', function(){
1204 return 'There is unsaved template data!'
1207 $($window).off('beforeunload.template');
1212 $scope.template_controls = true;
1214 $scope.fetchTemplates = function () {
1215 egCore.hatch.getItem('cat.copy.templates').then(function(t) {
1217 $scope.templates = t;
1218 $scope.template_name_list = Object.keys(t);
1222 $scope.fetchTemplates();
1224 $scope.applyTemplate = function (n) {
1225 angular.forEach($scope.templates[n], function (v,k) {
1226 if (!angular.isObject(v)) {
1227 $scope.working[k] = angular.copy(v);
1229 angular.forEach(v, function (sv,sk) {
1230 $scope.working[k][sk] = angular.copy(sv);
1234 $scope.template_name = '';
1237 $scope.deleteTemplate = function (n) {
1239 delete $scope.templates[n]
1240 $scope.template_name_list = Object.keys($scope.templates);
1241 $scope.template_name = '';
1242 egCore.hatch.setItem('cat.copy.templates', $scope.templates);
1243 $scope.$parent.fetchTemplates();
1247 $scope.saveTemplate = function (n) {
1251 angular.forEach($scope.working, function (v,k) {
1252 if (angular.isObject(v)) { // we'll use the pkey
1253 if (v.id) v = v.id();
1254 else if (v.code) v = v.code();
1260 $scope.templates[n] = tmpl;
1261 $scope.template_name_list = Object.keys($scope.templates);
1263 egCore.hatch.setItem('cat.copy.templates', $scope.templates);
1264 $scope.$parent.fetchTemplates();
1266 $scope.dirty = false;
1270 $scope.templates = {};
1271 $scope.template_name = '';
1272 $scope.template_name_list = [];
1274 $scope.tracker = function (x,f) { if (x) return x[f]() };
1275 $scope.idTracker = function (x) { if (x) return $scope.tracker(x,'id') };
1276 $scope.cant_have_vols = function (id) { return !egCore.org.CanHaveVolumes(id); };
1278 $scope.orgById = function (id) { return egCore.org.get(id) }
1279 $scope.statusById = function (id) {
1280 return $scope.status_list.filter( function (s) { return s.id() == id } )[0];
1282 $scope.locationById = function (id) {
1283 return $scope.location_cache[''+id];
1286 createSimpleUpdateWatcher = function (field) {
1287 $scope.$watch('working.' + field, function () {
1288 var newval = $scope.working[field];
1290 if (typeof newval != 'undefined') {
1291 $scope.dirty = true;
1292 if (angular.isObject(newval)) { // we'll use the pkey
1293 if (newval.id) $scope.working[field] = newval.id();
1294 else if (newval.code) $scope.working[field] = newval.code();
1297 if (""+newval == "" || newval == null) {
1298 $scope.working[field] = undefined;
1307 statcat_filter: undefined
1310 createStatcatUpdateWatcher = function (id) {
1311 return $scope.$watch('working.statcats[' + id + ']', function () {
1312 if ($scope.working.statcats) {
1313 var newval = $scope.working.statcats[id];
1315 if (typeof newval != 'undefined') {
1316 $scope.dirty = true;
1317 if (angular.isObject(newval)) { // we'll use the pkey
1318 newval = newval.id();
1321 if (""+newval == "" || newval == null) {
1322 $scope.working.statcats[id] = undefined;
1331 $scope.clearWorking = function () {
1332 angular.forEach($scope.working, function (v,k,o) {
1333 if (!angular.isObject(v)) {
1334 if (typeof v != 'undefined')
1335 $scope.working[k] = undefined;
1336 } else if (k != 'circ_lib') {
1337 angular.forEach(v, function (sv,sk) {
1338 $scope.working[k][sk] = undefined;
1342 $scope.working.circ_lib = undefined; // special
1343 $scope.dirty = false;
1346 $scope.working = {};
1347 $scope.location_orgs = [];
1348 $scope.location_cache = {};
1350 $scope.location_list = [];
1351 itemSvc.get_locations(
1352 egCore.org.fullPath( egCore.auth.user().ws_ou(), true )
1353 ).then(function(list){
1354 $scope.location_list = list;
1356 createSimpleUpdateWatcher('location');
1358 $scope.statcat_filter_list = egCore.org.fullPath( egCore.auth.user().ws_ou() );
1360 $scope.statcats = [];
1361 itemSvc.get_statcats(
1362 egCore.org.fullPath( egCore.auth.user().ws_ou(), true )
1363 ).then(function(list){
1364 $scope.statcats = list;
1365 angular.forEach($scope.statcats, function (s) {
1367 if (!$scope.working)
1368 $scope.working = { statcats: {}, statcat_filter: undefined};
1369 if (!$scope.working.statcats)
1370 $scope.working.statcats = {};
1372 $scope.working.statcats[s.id()] = undefined;
1373 createStatcatUpdateWatcher(s.id());
1377 $scope.status_list = [];
1378 itemSvc.get_statuses().then(function(list){
1379 $scope.status_list = list;
1381 createSimpleUpdateWatcher('status');
1383 $scope.circ_modifier_list = [];
1384 itemSvc.get_circ_mods().then(function(list){
1385 $scope.circ_modifier_list = list;
1387 createSimpleUpdateWatcher('circ_modifier');
1389 $scope.circ_type_list = [];
1390 itemSvc.get_circ_types().then(function(list){
1391 $scope.circ_type_list = list;
1393 createSimpleUpdateWatcher('circ_as_type');
1395 $scope.age_protect_list = [];
1396 itemSvc.get_age_protects().then(function(list){
1397 $scope.age_protect_list = list;
1399 createSimpleUpdateWatcher('age_protect');
1401 createSimpleUpdateWatcher('circ_lib');
1402 createSimpleUpdateWatcher('circulate');
1403 createSimpleUpdateWatcher('holdable');
1404 createSimpleUpdateWatcher('fine_level');
1405 createSimpleUpdateWatcher('loan_duration');
1406 createSimpleUpdateWatcher('cost');
1407 createSimpleUpdateWatcher('deposit');
1408 createSimpleUpdateWatcher('deposit_amount');
1409 createSimpleUpdateWatcher('mint_condition');
1410 createSimpleUpdateWatcher('opac_visible');
1411 createSimpleUpdateWatcher('ref');
1413 $scope.suffix_list = [];
1414 itemSvc.get_suffixes(egCore.auth.user().ws_ou()).then(function(list){
1415 $scope.suffix_list = list;
1418 $scope.prefix_list = [];
1419 itemSvc.get_prefixes(egCore.auth.user().ws_ou()).then(function(list){
1420 $scope.prefix_list = list;
1423 $scope.classification_list = [];
1424 itemSvc.get_classifications().then(function(list){
1425 $scope.classification_list = list;
1428 createSimpleUpdateWatcher('working.callnumber.classification');
1429 createSimpleUpdateWatcher('working.callnumber.prefix');
1430 createSimpleUpdateWatcher('working.callnumber.suffix');