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.get_statuses = function() {
81 return $q.when(egCore.env.ccs.list);
83 return egCore.pcrud.retrieveAll('ccs', {}, {atomic : true}).then(
85 egCore.env.absorbList(list, 'ccs');
92 service.bmp_parts = {};
93 service.get_parts = function(rec) {
94 if (service.bmp_parts[rec])
95 return $q.when(service.bmp_parts[rec]);
97 return egCore.pcrud.search('bmp',
100 ).then(function(list) {
101 service.bmp_parts[rec] = list;
110 acp : ['call_number','parts','location'],
111 acn : ['label_class','prefix','suffix']
115 service.addCopy = function (cp) {
117 if (!cp.parts()) cp.parts([]); // just in case...
119 var lib = cp.call_number().owning_lib();
120 var cn = cp.call_number().id();
122 if (!service.tree[lib]) service.tree[lib] = {};
123 if (!service.tree[lib][cn]) service.tree[lib][cn] = [];
125 service.tree[lib][cn].push(cp);
126 service.copies.push(cp);
129 service.fetchIds = function(idList) {
130 service.tree = {}; // clear the tree on fetch
131 service.copies = []; // clear the copy list on fetch
132 return egCore.pcrud.search('acp', { 'id' : idList }, service.flesh).then(null,null,
134 service.addCopy(copy);
142 .directive("egVolCopyEdit", function () {
148 '<div class="col-xs-6"><input type="text" ng-model="barcode" ng-change="updateBarcode()"/></div>'+
149 '<div class="col-xs-2"><input type="number" ng-model="copy_number" ng-change="updateCopyNo()"/></div>'+
150 '<div class="col-xs-4"><eg-basic-combo-box list="parts" selected="part"></eg-basic-combo-box></div>'+
153 scope: { copy: "=", callNumber: "=" },
154 controller : ['$scope','itemSvc',
155 function ( $scope , itemSvc ) {
156 $scope.new_part_id = 0;
158 $scope.updateBarcode = function () { $scope.copy.barcode($scope.barcode); $scope.copy.ischanged(1); };
159 $scope.updateCopyNo = function () { $scope.copy.copy_number($scope.copy_number); $scope.copy.ischanged(1); };
160 $scope.updatePart = function () {
161 var p = angular.filter($scope.part_list, function (x) {
162 return x.label() == $scope.part
164 if (p.length > 0) { // preexisting part
166 } else { // create one...
167 var part = new egCore.idl.bmp();
168 part.id( --$scope.new_part_id );
170 part.label( $scope.part );
171 part.record( $scope.callNumber.owning_lib() );
172 $scope.copy.parts([part]);
173 $scope.copy.ischanged(1);
177 $scope.barcode = $scope.copy.barcode();
178 $scope.copy_number = $scope.copy.copy_number();
180 if ($scope.copy.parts()) {
181 $scope.part = $scope.copy.parts()[0];
182 if ($scope.part) $scope.part = $scope.part.label();
186 $scope.part_list = [];
188 itemSvc.get_parts($scope.callNumber.record()).then(function(list){
189 $scope.part_list = list;
190 angular.forEach(list, function(p){ $scope.parts.push(p.label()) });
199 .directive("egVolRow", function () {
206 '<div class="col-xs-1">'+
207 '<select ng-model="classification" ng-options="cl.name() for cl in classification_list track by idTracker(cl)"/>'+
209 '<div class="col-xs-1">'+
210 '<select ng-model="prefix" ng-change="updatePrefix()" ng-options="p.label() for p in prefix_list track by idTracker(p)"/>'+
212 '<div class="col-xs-3"><input type="text" ng-change="updateLabel()" ng-model="label"/></div>'+
213 '<div class="col-xs-1">'+
214 '<select ng-model="suffix" ng-change="updateSuffix()" ng-options="s.label() for s in suffix_list track by idTracker(s)"/>'+
216 '<div class="col-xs-1"><input type="number" ng-model="copy_count" min="{{orig_copy_count}}" ng-change="changeCPCount()"></div>'+
217 '<div class="col-xs-5">'+
218 '<div class="container-fluid">'+
219 '<eg-vol-copy-edit ng-repeat="cp in copies track by idTracker(cp)" copy="cp" call-number="callNumber"></eg-vol-copy-edit>'+
224 scope: {allcopies: "=", copies: "=" },
225 controller : ['$scope','itemSvc','egCore',
226 function ( $scope , itemSvc , egCore ) {
227 $scope.new_cp_id = 0;
228 $scope.callNumber = $scope.copies[0].call_number();
230 $scope.idTracker = function (x) { if (x) return x.id() };
232 $scope.suffix_list = [];
233 itemSvc.get_suffixes($scope.callNumber.owning_lib()).then(function(list){
234 $scope.suffix_list = list;
236 $scope.updateSuffix = function () { $scope.callNumber.suffix($scope.suffix); $scope.callNumber.ischanged(1); };
238 $scope.prefix_list = [];
239 itemSvc.get_prefixes($scope.callNumber.owning_lib()).then(function(list){
240 $scope.prefix_list = list;
242 $scope.updatePrefix = function () { $scope.callNumber.prefix($scope.prefix); $scope.callNumber.ischanged(1); };
244 $scope.classification_list = [];
245 itemSvc.get_classifications().then(function(list){
246 $scope.classification_list = list;
248 $scope.updateClassification = function () { $scope.callNumber.label_class($scope.classification); $scope.callNumber.ischanged(1); };
250 $scope.classification = $scope.callNumber.label_class();
251 $scope.prefix = $scope.callNumber.prefix();
252 $scope.suffix = $scope.callNumber.suffix();
254 $scope.label = $scope.callNumber.label();
255 $scope.updateLabel = function () { $scope.callNumber.label($scope.label); $scope.callNumber.ischanged(1); };
257 $scope.copy_count = $scope.copies.length;
258 $scope.orig_copy_count = $scope.copy_count;
260 $scope.changeCPCount = function () {
261 while ($scope.copy_count > $scope.copies.length) {
262 var cp = new egCore.idl.acp();
263 cp.id( --$scope.new_cp_id );
265 cp.circ_lib( $scope.lib );
266 cp.call_number( $scope.callNumber );
267 $scope.copies.push( cp );
268 $scope.allcopies.push( cp );
271 var how_many = $scope.copies.length - $scope.copy_count;
273 var dead = $scope.copies.splice($scope.copy_count,how_many);
274 $scope.callNumber.copies($scope.copies);
276 // Trimming the global list is a bit more tricky
277 angular.forEach( dead, function (d) {
278 angular.forEach( $scope.allcopies, function (l, i) {
279 if (l === d) $scope.allcopies.splice(i,1);
291 .directive("egVolEdit", function () {
297 '<div class="col-xs-1"><eg-org-selector selected="owning_lib" disableTest="cant_have_vols"></eg-org-selector></div>'+
298 '<div class="col-xs-1"><input type="number" min="{{orig_cn_count}}" ng-model="cn_count" ng-change="changeCNCount()"/></div>'+
299 '<div class="col-xs-10">'+
300 '<div class="container-fluid">'+
301 '<eg-vol-row ng-repeat="(cn,copies) in struct track by cn" copies="copies" allcopies="allcopies"></eg-vol-row>'+
306 scope: { allcopies: "=", struct: "=", lib: "@", record: "@" },
307 controller : ['$scope','itemSvc','egCore',
308 function ( $scope , itemSvc , egCore ) {
309 $scope.new_cn_id = 0;
310 $scope.first_cn = Object.keys($scope.struct)[0];
311 $scope.full_cn = $scope.struct[$scope.first_cn][0].call_number();
313 $scope.cn_count = Object.keys($scope.struct).length;
314 $scope.orig_cn_count = $scope.cn_count;
316 $scope.owning_lib = egCore.org.get($scope.lib);
318 $scope.cant_have_vols = function (id) { return !egCore.org.CanHaveVolumes(id); };
320 $scope.$watch('cn_count', function (n) {
321 var o = Object.keys($scope.struct).length;
322 if (n > o) { // adding
323 for (var i = o; o < n; o++) {
324 var cn = new egCore.idl.acn();
325 cn.id( --$scope.new_cn_id );
327 cn.owning_lib( $scope.owning_lib );
328 cn.record( $scope.full_cn.record() );
330 var cp = new egCore.idl.acp();
331 cp.id( --$scope.new_cp_id );
333 cp.circ_lib( $scope.owning_lib );
334 cp.call_number( cn );
336 $scope.struct[cn.id()] = [cp];
337 $scope.allcopies.push(cp);
339 } else if (n < o) { // removing
340 var how_many = o - n;
343 .sort(function(a, b){return a-b})
345 for (var i = how_many; i > 0; i--) {
346 // Trimming the global list is a bit more tricky
347 angular.forEach($scope.struct[list[i]], function (d) {
348 angular.forEach( $scope.allcopies, function (l, j) {
349 if (l === d) $scope.allcopies.splice(j,1);
352 delete $scope.struct[list[i]];
365 .controller('EditCtrl',
366 ['$scope','$q','$routeParams','$location','$timeout','egCore','egNet','egGridDataProvider','itemSvc',
367 function($scope , $q , $routeParams , $location , $timeout , egCore , egNet , egGridDataProvider , itemSvc) {
369 $scope.show_vols = true;
370 $scope.show_copies = true;
372 $scope.idTracker = function (x) { if (x) return x.id() };
376 var dataKey = $routeParams.dataKey;
377 console.debug('dataKey: ' + dataKey);
379 if (dataKey && dataKey.length > 0) {
383 $scope.summaryRecord = null;
384 $scope.record_id = null;
387 $scope.workingGridDataProvider = egGridDataProvider.instance({
388 get : function(offset, count) {
389 //return provider.arrayNotifier(itemSvc.copies, offset, count);
390 return this.arrayNotifier(itemSvc.copies, offset, count);
394 $scope.workingGridControls = {};
398 'open-ils.actor.anon_cache.get_value',
399 dataKey, 'edit-these-copies'
400 ).then(function (data) {
402 if (data.hide_vols) $scope.show_vols = false;
403 if (data.hide_copies) $scope.show_copies = false;
405 $scope.record_id = data.record_id;
407 if (data.copies && data.copies.length)
408 return itemSvc.fetchIds(data.copies);
410 if (data.raw && data.raw.length) {
412 /* data.raw must be an array of copies with (at least)
413 * the call number fleshed on each. For new copies
414 * create from whole cloth, the id for each should
415 * probably be negative and isnew() should return true.
416 * Each /distinct/ call number must have a distinct id
417 * as well, probably negative also if they're new. Clear?
422 function (cp) { itemSvc.addCopy(cp) }
425 return itemSvc.copies;
428 }).then( function() {
429 $scope.data = itemSvc;
430 $scope.workingGridDataProvider.refresh();
433 $scope.$watch('data.copies.length', function () {
434 console.log('data.copies.length changed');
435 $scope.workingGridDataProvider.refresh();
438 $scope.status_list = [];
439 itemSvc.get_statuses().then(function(list){
440 $scope.status_list = list;
442 $scope.updateWorkingStatus = function () {
444 $scope.workingGridControls.selectedItems(),
445 function (cp) { cp.status($scope.working.status.id()); cp.ischanged(1); }