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) {
53 return $q.when(egCore.env.acnp.list);
55 return egCore.pcrud.search('acnp',
56 {owning_lib : egCore.org.fullPath(org, true)},
58 ).then(function(list) {
59 egCore.env.absorbList(list, 'acnp');
65 service.get_suffixes = function(org) {
67 return $q.when(egCore.env.acns.list);
69 return egCore.pcrud.search('acns',
70 {owning_lib : egCore.org.fullPath(org, true)},
72 ).then(function(list) {
73 egCore.env.absorbList(list, 'acns');
79 service.bmp_parts = {};
80 service.get_parts = function(rec) {
81 if (service.bmp_parts[rec])
82 return $q.when(service.bmp_parts[rec]);
84 return egCore.pcrud.search('bmp',
87 ).then(function(list) {
88 service.bmp_parts[rec] = list;
97 acp : ['call_number','parts'],
98 acn : ['label_class','prefix','suffix']
101 // avoid fleshing MARC on the bre
102 // note: don't add simple_record.. not sure why
103 bre : ['id','tcn_value','creator','editor'],
107 service.addCopy = function (cp) {
109 var lib = cp.call_number().owning_lib();
110 var cn = cp.call_number().id();
112 // XXX need to change this data structure, likely...
113 if (!service.tree[lib]) service.tree[lib] = {};
114 if (!service.tree[lib][cn]) service.tree[lib][cn] = [];
116 service.tree[lib][cn].push(cp);
117 service.copies.push(cp);
120 service.fetchIds = function(idList) {
121 service.tree = {}; // clear the tree on fetch
122 service.copies = []; // clear the copy list on fetch
123 return egCore.pcrud.search('acp', { 'id' : idList }, service.flesh).then(null,null,
125 service.addCopy(copy);
133 .directive("egVolCopyEdit", function () {
139 '<div class="col-xs-6"><input type="text" ng-model="barcode" ng-change="updateBarcode()"/></div>'+
140 '<div class="col-xs-2"><input type="number" ng-model="copy_number" ng-change="updateCopyNo()"/></div>'+
141 '<div class="col-xs-4"><eg-basic-combo-box list="parts" selected="part"></eg-basic-combo-box></div>'+
144 scope: { copy: "=", callNumber: "=" },
145 controller : ['$scope','itemSvc',
146 function ( $scope , itemSvc ) {
147 $scope.new_part_id = 0;
149 $scope.updateBarcode = function () { $scope.copy.barcode($scope.barcode) };
150 $scope.updateCopyNo = function () { $scope.copy.copy_number($scope.copy_number) };
151 $scope.updatePart = function () {
152 var p = angular.filter($scope.part_list, function (x) {
153 return x.label() == $scope.part
155 if (p.length > 0) { // preexisting part
157 } else { // create one...
158 var part = new egCore.idl.bmp();
159 part.id( --$scope.new_part_id );
161 part.label( $scope.part );
162 part.record( $scope.callNumber.owning_lib() );
163 $scope.copy.parts([part]);
167 $scope.barcode = $scope.copy.barcode();
168 $scope.copy_number = $scope.copy.copy_number();
170 if ($scope.copy.parts()) {
171 $scope.part = $scope.copy.parts()[0];
172 if ($scope.part) $scope.part = $scope.part.label();
176 $scope.part_list = [];
178 itemSvc.get_parts($scope.callNumber.record()).then(function(list){
179 $scope.part_list = list;
180 angular.forEach(list, function(p){ $scope.parts.push(p.label()) });
189 .directive("egVolRow", function () {
196 '<div class="col-xs-1">'+
197 '<select ng-model="classification" ng-options="cl.name() for cl in classification_list track by idTracker(cl)"/>'+
199 '<div class="col-xs-1">'+
200 '<select ng-model="prefix" ng-change="updatePrefix()" ng-options="p.label() for p in prefix_list track by idTracker(p)"/>'+
202 '<div class="col-xs-3"><input type="text" ng-change="updateLabel()" ng-model="label"/></div>'+
203 '<div class="col-xs-1">'+
204 '<select ng-model="suffix" ng-change="updateSuffix()" ng-options="s.label() for s in suffix_list track by idTracker(s)"/>'+
206 '<div class="col-xs-1"><input type="number" ng-model="copy_count" min="{{orig_copy_count}}" ng-change="changeCPCount()"></div>'+
207 '<div class="col-xs-5">'+
208 '<div class="container-fluid">'+
209 '<eg-vol-copy-edit ng-repeat="cp in copies track by idTracker(cp)" copy="cp" call-number="callNumber"></eg-vol-copy-edit>'+
214 scope: { copies: "=" },
215 controller : ['$scope','itemSvc','egCore',
216 function ( $scope , itemSvc , egCore ) {
217 $scope.new_cp_id = 0;
218 $scope.callNumber = $scope.copies[0].call_number();
220 $scope.idTracker = function (x) { if (x) return x.id() };
222 $scope.suffix_list = [];
223 itemSvc.get_suffixes($scope.callNumber.owning_lib()).then(function(list){
224 $scope.suffix_list = list;
226 $scope.updateSuffix = function () { $scope.callNumber.suffix($scope.suffix) };
228 $scope.prefix_list = [];
229 itemSvc.get_prefixes($scope.callNumber.owning_lib()).then(function(list){
230 $scope.prefix_list = list;
232 $scope.updatePrefix = function () { $scope.callNumber.prefix($scope.prefix) };
234 $scope.classification_list = [];
235 itemSvc.get_classifications().then(function(list){
236 $scope.classification_list = list;
238 $scope.updateClassification = function () { $scope.callNumber.label_class($scope.classification) };
240 $scope.classification = $scope.callNumber.label_class();
241 $scope.prefix = $scope.callNumber.prefix();
242 $scope.suffix = $scope.callNumber.suffix();
244 $scope.label = $scope.callNumber.label();
245 $scope.updateLabel = function () { $scope.callNumber.label($scope.label) };
247 $scope.copy_count = $scope.copies.length;
248 $scope.orig_copy_count = $scope.copy_count;
250 $scope.changeCPCount = function () {
251 while ($scope.copy_count > $scope.copies.length) {
252 var cp = new egCore.idl.acp();
253 cp.id( --$scope.new_cp_id );
255 cp.circ_lib( $scope.lib );
256 cp.call_number( $scope.callNumber );
257 $scope.copies.push( cp );
260 var how_many = $scope.copies.length - $scope.copy_count;
262 $scope.copies.splice($scope.copy_count,how_many);
263 $scope.callNumber.copies($scope.copies);
273 .directive("egVolEdit", function () {
279 '<div class="col-xs-1"><eg-org-selector selected="owning_lib" disableTest="cant_have_vols"></eg-org-selector></div>'+
280 '<div class="col-xs-1"><input type="number" min="{{orig_cn_count}}" ng-model="cn_count" ng-change="changeCNCount()"/></div>'+
281 '<div class="col-xs-10">'+
282 '<div class="container-fluid">'+
283 '<eg-vol-row ng-repeat="(cn,copies) in struct track by cn" copies="copies"></eg-vol-row>'+
288 scope: { struct: "=", lib: "@", record: "@" },
289 controller : ['$scope','itemSvc','egCore',
290 function ( $scope , itemSvc , egCore ) {
291 $scope.new_cn_id = 0;
292 $scope.first_cn = Object.keys($scope.struct)[0];
293 $scope.full_cn = $scope.struct[$scope.first_cn][0].call_number();
295 $scope.cn_count = Object.keys($scope.struct).length;
296 $scope.orig_cn_count = $scope.cn_count;
298 $scope.owning_lib = egCore.org.get($scope.lib);
300 $scope.cant_have_vols = function (id) { return !egCore.org.CanHaveVolumes(id); };
302 $scope.$watch('cn_count', function (n) {
303 var o = Object.keys($scope.struct).length;
304 if (n > o) { // adding
305 for (var i = o; o < n; o++) {
306 var cn = new egCore.idl.acn();
307 cn.id( --$scope.new_cn_id );
309 cn.owning_lib( $scope.owning_lib );
310 cn.record( $scope.full_cn.record() );
312 var cp = new egCore.idl.acp();
313 cp.id( --$scope.new_cp_id );
315 cp.circ_lib( $scope.owning_lib );
316 cp.call_number( cn );
318 $scope.struct[cn.id()] = [cp];
320 } else if (n < o) { // removing
321 var how_many = o - n;
324 .sort(function(a, b){return a-b})
326 for (var i = how_many; i > 0; i--) {
327 delete $scope.struct[list[i]];
340 .controller('EditCtrl',
341 ['$scope','$q','$routeParams','$location','$timeout','egCore','egNet','egGridDataProvider','itemSvc',
342 function($scope , $q , $routeParams , $location , $timeout , egCore , egNet , egGridDataProvider , itemSvc) {
346 var dataKey = $routeParams.dataKey;
347 console.debug('dataKey: ' + dataKey);
349 if (dataKey && dataKey.length > 0) {
351 $scope.summaryRecord = null;
352 $scope.record_id = null;
355 $scope.gridDataProvider = egGridDataProvider.instance({
356 get : function(offset, count) {
357 //return provider.arrayNotifier(itemSvc.copies, offset, count);
358 return this.arrayNotifier(itemSvc.copies, offset, count);
364 'open-ils.actor.anon_cache.get_value',
365 dataKey, 'edit-these-copies'
366 ).then(function (data) {
367 $scope.record_id = data.record_id;
368 return itemSvc.fetchIds(data.copies);
369 }).then( function() {
370 $scope.data = itemSvc.tree;
371 $scope.gridDataProvider.refresh();