.config(function($routeProvider, $locationProvider, $compileProvider) {
$locationProvider.html5Mode(true);
- $compileProvider.aHrefSanitizationWhitelist(/^\s*(https?|blob):/); // grid export
-
+ $compileProvider.aHrefSanitizationWhitelist(/^\s*(https?|mailto|blob):/); // grid export
+
var resolver = {delay : function(egStartup) {return egStartup.go()}};
// search page shows the list view by default
$routeProvider.otherwise({redirectTo : '/cat/item/search'});
})
-.factory('itemSvc',
- ['egCore','egCirc','$uibModal','$q','$timeout','$window','egConfirmDialog',
-function(egCore , egCirc , $uibModal , $q , $timeout , $window , egConfirmDialog ) {
-
- var service = {
- copies : [], // copy barcode search results
- index : 0 // search grid index
- };
-
- service.flesh = {
- flesh : 3,
- flesh_fields : {
- acp : ['call_number','location','status','location','floating','circ_modifier',
- 'age_protect','circ_lib'],
- acn : ['record','prefix','suffix','label_class'],
- bre : ['simple_record','creator','editor']
- },
- select : {
- // avoid fleshing MARC on the bre
- // note: don't add simple_record.. not sure why
- bre : ['id','tcn_value','creator','editor'],
- }
- }
-
- service.circFlesh = {
- flesh : 2,
- flesh_fields : {
- circ : [
- 'usr',
- 'workstation',
- 'checkin_workstation',
- 'checkin_lib',
- 'duration_rule',
- 'max_fine_rule',
- 'recurring_fine_rule'
- ],
- au : ['card']
- },
- order_by : {circ : 'xact_start desc'},
- limit : 1
- }
-
- //Retrieve separate copy, aacs, and accs information
- service.getCopy = function(barcode, id) {
- if (barcode) {
- // handle barcode completion
- return egCirc.handle_barcode_completion(barcode)
- .then(function(actual_barcode) {
- return egCore.pcrud.search(
- 'acp', {barcode : actual_barcode, deleted : 'f'},
- service.flesh).then(function(copy) {return copy});
- });
- }
-
- return egCore.pcrud.retrieve( 'acp', id, service.flesh)
- .then(function(copy) {return copy});
- }
- service.getCirc = function(id) {
- return egCore.pcrud.search('aacs', { target_copy : id },
- service.circFlesh).then(function(circ) {return circ});
- }
- service.getSummary = function(id) {
- return circ_summary = egCore.net.request(
- 'open-ils.circ',
- 'open-ils.circ.renewal_chain.retrieve_by_circ.summary',
- egCore.auth.token(), id).then(
- function(circ_summary) {return circ_summary});
- }
-
- //Combine copy, circ, and accs information
- service.retrieveCopyData = function(barcode, id) {
- var copyData = {};
-
- var fetchCopy = function(barcode, id) {
- return service.getCopy(barcode, id)
- .then(function(copy) {
- copyData.copy = copy;
- return copyData;
- });
- }
- var fetchCirc = function(copy) {
- return service.getCirc(copy.id())
- .then(function(circ) {
- copyData.circ = circ;
- return copyData;
- });
- }
- var fetchSummary = function(circ) {
- return service.getSummary(circ.id())
- .then(function(summary) {
- copyData.circ_summary = summary;
- return copyData;
- });
- }
- return fetchCopy(barcode, id).then(function(res) {
- return fetchCirc(copyData.copy).then(function(res) {
- if (copyData.circ) {
- return fetchSummary(copyData.circ).then(function() {
- return copyData;
- });
- } else {
- return copyData;
- }
- });
- });
-
- }
-
- // resolved with the last received copy
- service.fetch = function(barcode, id, noListDupes) {
- var copy;
- var circ;
- var circ_summary;
- var lastRes = {};
-
- return service.retrieveCopyData(barcode, id)
- .then(function(copyData) {
- //Make sure we're getting a completed copyData - no plain acp or circ objects
- if (copyData.circ) {
- // flesh circ_lib locally
- copyData.circ.circ_lib(egCore.org.get(copyData.circ.circ_lib()));
- copyData.circ.checkin_workstation(
- egCore.org.get(copyData.circ.checkin_workstation()));
- }
- var flatCopy;
-
- if (noListDupes) {
- // use the existing copy if possible
- flatCopy = service.copies.filter(
- function(c) {return c.id == copyData.copy.id()})[0];
- }
-
- if (!flatCopy) {
- flatCopy = egCore.idl.toHash(copyData.copy, true);
-
- if (copyData.circ) {
- flatCopy._circ = egCore.idl.toHash(copyData.circ, true);
- flatCopy._circ_summary = egCore.idl.toHash(copyData.circ_summary, true);
- flatCopy._circ_lib = copyData.circ.circ_lib();
- flatCopy._duration = copyData.circ.duration();
- }
- flatCopy.index = service.index++;
- service.copies.unshift(flatCopy);
- }
-
- //Get in-house use count
- egCore.pcrud.search('aihu',
- {item : flatCopy.id}, {}, {idlist : true, atomic : true})
- .then(function(uses) {
- flatCopy._inHouseUseCount = uses.length;
- copyData.copy._inHouseUseCount = uses.length;
- });
-
- return lastRes = {
- copy : copyData.copy,
- index : flatCopy.index
- }
- });
-
-
- }
-
- service.add_copies_to_bucket = function(copy_list) {
- if (copy_list.length == 0) return;
-
- return $uibModal.open({
- templateUrl: './cat/catalog/t_add_to_bucket',
- animation: true,
- size: 'md',
- controller:
- ['$scope','$uibModalInstance',
- function($scope , $uibModalInstance) {
-
- $scope.bucket_id = 0;
- $scope.newBucketName = '';
- $scope.allBuckets = [];
-
- egCore.net.request(
- 'open-ils.actor',
- 'open-ils.actor.container.retrieve_by_class.authoritative',
- egCore.auth.token(), egCore.auth.user().id(),
- 'copy', 'staff_client'
- ).then(function(buckets) { $scope.allBuckets = buckets; });
-
- $scope.add_to_bucket = function() {
- var promises = [];
- angular.forEach(copy_list, function (cp) {
- var item = new egCore.idl.ccbi()
- item.bucket($scope.bucket_id);
- item.target_copy(cp);
- promises.push(
- egCore.net.request(
- 'open-ils.actor',
- 'open-ils.actor.container.item.create',
- egCore.auth.token(), 'copy', item
- )
- );
-
- return $q.all(promises).then(function() {
- $uibModalInstance.close();
- });
- });
- }
-
- $scope.add_to_new_bucket = function() {
- var bucket = new egCore.idl.ccb();
- bucket.owner(egCore.auth.user().id());
- bucket.name($scope.newBucketName);
- bucket.description('');
- bucket.btype('staff_client');
-
- return egCore.net.request(
- 'open-ils.actor',
- 'open-ils.actor.container.create',
- egCore.auth.token(), 'copy', bucket
- ).then(function(bucket) {
- $scope.bucket_id = bucket;
- $scope.add_to_bucket();
- });
- }
-
- $scope.cancel = function() {
- $uibModalInstance.dismiss();
- }
- }]
- });
- }
-
- service.make_copies_bookable = function(items) {
-
- var copies_by_record = {};
- var record_list = [];
- angular.forEach(
- items,
- function (item) {
- var record_id = item['call_number.record.id'];
- if (typeof copies_by_record[ record_id ] == 'undefined') {
- copies_by_record[ record_id ] = [];
- record_list.push( record_id );
- }
- copies_by_record[ record_id ].push(item.id);
- }
- );
-
- var promises = [];
- var combined_results = [];
- angular.forEach(record_list, function(record_id) {
- promises.push(
- egCore.net.request(
- 'open-ils.booking',
- 'open-ils.booking.resources.create_from_copies',
- egCore.auth.token(),
- copies_by_record[record_id]
- ).then(function(results) {
- if (results && results['brsrc']) {
- combined_results = combined_results.concat(results['brsrc']);
- }
- })
- );
- });
-
- $q.all(promises).then(function() {
- if (combined_results.length > 0) {
- $uibModal.open({
- template: '<eg-embed-frame url="booking_admin_url" handlers="funcs"></eg-embed-frame>',
- animation: true,
- size: 'md',
- controller:
- ['$scope','$location','egCore','$uibModalInstance',
- function($scope , $location , egCore , $uibModalInstance) {
-
- $scope.funcs = {
- ses : egCore.auth.token(),
- resultant_brsrc : combined_results.map(function(o) { return o[0]; })
- }
-
- var booking_path = '/eg/conify/global/booking/resource';
-
- $scope.booking_admin_url =
- $location.absUrl().replace(/\/eg\/staff.*/, booking_path);
- }]
- });
- }
- });
- }
-
- service.book_copies_now = function(items) {
- var copies_by_record = {};
- var record_list = [];
- angular.forEach(
- items,
- function (item) {
- var record_id = item['call_number.record.id'];
- if (typeof copies_by_record[ record_id ] == 'undefined') {
- copies_by_record[ record_id ] = [];
- record_list.push( record_id );
- }
- copies_by_record[ record_id ].push(item.id);
- }
- );
-
- var promises = [];
- var combined_brt = [];
- var combined_brsrc = [];
- angular.forEach(record_list, function(record_id) {
- promises.push(
- egCore.net.request(
- 'open-ils.booking',
- 'open-ils.booking.resources.create_from_copies',
- egCore.auth.token(),
- copies_by_record[record_id]
- ).then(function(results) {
- if (results && results['brt']) {
- combined_brt = combined_brt.concat(results['brt']);
- }
- if (results && results['brsrc']) {
- combined_brsrc = combined_brsrc.concat(results['brsrc']);
- }
- })
- );
- });
-
- $q.all(promises).then(function() {
- if (combined_brt.length > 0 || combined_brsrc.length > 0) {
- $uibModal.open({
- template: '<eg-embed-frame url="booking_admin_url" handlers="funcs"></eg-embed-frame>',
- animation: true,
- size: 'md',
- controller:
- ['$scope','$location','egCore','$uibModalInstance',
- function($scope , $location , egCore , $uibModalInstance) {
-
- $scope.funcs = {
- ses : egCore.auth.token(),
- bresv_interface_opts : {
- booking_results : {
- brt : combined_brt
- ,brsrc : combined_brsrc
- }
- }
- }
-
- var booking_path = '/eg/booking/reservation';
-
- $scope.booking_admin_url =
- $location.absUrl().replace(/\/eg\/staff.*/, booking_path);
-
- }]
- });
- }
- });
- }
-
- service.requestItems = function(copy_list) {
- if (copy_list.length == 0) return;
-
- return $uibModal.open({
- templateUrl: './cat/catalog/t_request_items',
- animation: true,
- controller:
- ['$scope','$uibModalInstance','egUser',
- function($scope , $uibModalInstance , egUser) {
- $scope.user = null;
- $scope.first_user_fetch = true;
-
- $scope.hold_data = {
- hold_type : 'C',
- copy_list : copy_list,
- pickup_lib: egCore.org.get(egCore.auth.user().ws_ou()),
- user : egCore.auth.user().id()
- };
-
- egUser.get( $scope.hold_data.user ).then(function(u) {
- $scope.user = u;
- $scope.barcode = u.card().barcode();
- $scope.user_name = egUser.format_name(u);
- $scope.hold_data.user = u.id();
- });
-
- $scope.user_name = '';
- $scope.barcode = '';
- $scope.$watch('barcode', function (n) {
- if (!$scope.first_user_fetch) {
- egUser.getByBarcode(n).then(function(u) {
- $scope.user = u;
- $scope.user_name = egUser.format_name(u);
- $scope.hold_data.user = u.id();
- }, function() {
- $scope.user = null;
- $scope.user_name = '';
- delete $scope.hold_data.user;
- });
- }
- $scope.first_user_fetch = false;
- });
-
- $scope.ok = function(h) {
- var args = {
- patronid : h.user,
- hold_type : h.hold_type,
- pickup_lib: h.pickup_lib.id(),
- depth : 0
- };
-
- egCore.net.request(
- 'open-ils.circ',
- 'open-ils.circ.holds.test_and_create.batch.override',
- egCore.auth.token(), args, h.copy_list
- );
-
- $uibModalInstance.close();
- }
-
- $scope.cancel = function($event) {
- $uibModalInstance.dismiss();
- $event.preventDefault();
- }
- }]
- });
- }
-
- service.attach_to_peer_bib = function(items) {
- if (items.length == 0) return;
-
- egCore.hatch.getItem('eg.cat.marked_conjoined_record').then(function(target_record) {
- if (!target_record) return;
-
- return $uibModal.open({
- templateUrl: './cat/catalog/t_conjoined_selector',
- animation: true,
- controller:
- ['$scope','$uibModalInstance',
- function($scope , $uibModalInstance) {
- $scope.update = false;
-
- $scope.peer_type = null;
- $scope.peer_type_list = [];
-
- get_peer_types = function() {
- if (egCore.env.bpt)
- return $q.when(egCore.env.bpt.list);
-
- return egCore.pcrud.retrieveAll('bpt', null, {atomic : true})
- .then(function(list) {
- egCore.env.absorbList(list, 'bpt');
- return list;
- });
- }
-
- get_peer_types().then(function(list){
- $scope.peer_type_list = list;
- });
-
- $scope.ok = function(type) {
- var promises = [];
-
- angular.forEach(items, function (cp) {
- var n = new egCore.idl.bpbcm();
- n.isnew(true);
- n.peer_record(target_record);
- n.target_copy(cp.id);
- n.peer_type(type);
- promises.push(egCore.pcrud.create(n).then(function(){service.add_barcode_to_list(cp.barcode)}));
- });
-
- return $q.all(promises).then(function(){$uibModalInstance.close()});
- }
-
- $scope.cancel = function($event) {
- $uibModalInstance.dismiss();
- $event.preventDefault();
- }
- }]
- });
- });
- }
-
- service.selectedHoldingsCopyDelete = function (items) {
- if (items.length == 0) return;
-
- var copy_objects = [];
- egCore.pcrud.search('acp',
- {deleted : 'f', id : items.map(function(el){return el.id;}) },
- { flesh : 1, flesh_fields : { acp : ['call_number'] } }
- ).then(function(copy) {
- copy_objects.push(copy);
- }).then(function() {
-
- var cnHash = {};
- var perCnCopies = {};
-
- var cn_count = 0;
- var cp_count = 0;
-
- angular.forEach(
- copy_objects,
- function (cp) {
- cp.isdeleted(1);
- cp_count++;
- var cn_id = cp.call_number().id();
- if (!cnHash[cn_id]) {
- cnHash[cn_id] = cp.call_number();
- perCnCopies[cn_id] = [cp];
- } else {
- perCnCopies[cn_id].push(cp);
- }
- cp.call_number(cn_id); // prevent loops in JSON-ification
- }
- );
-
- angular.forEach(perCnCopies, function (v, k) {
- cnHash[k].copies(v);
- });
-
- cnList = [];
- angular.forEach(cnHash, function (v, k) {
- cnList.push(v);
- });
-
- if (cnList.length == 0) return;
-
- var flags = {};
-
- egConfirmDialog.open(
- egCore.strings.CONFIRM_DELETE_COPIES_VOLUMES,
- egCore.strings.CONFIRM_DELETE_COPIES_VOLUMES_MESSAGE,
- {copies : cp_count, volumes : cn_count}
- ).result.then(function() {
- egCore.net.request(
- 'open-ils.cat',
- 'open-ils.cat.asset.volume.fleshed.batch.update.override',
- egCore.auth.token(), cnList, 1, flags
- ).then(function(){
- angular.forEach(items, function(cp){service.add_barcode_to_list(cp.barcode)});
- });
- });
- });
- }
-
- service.checkin = function (items) {
- angular.forEach(items, function (cp) {
- egCirc.checkin({copy_barcode:cp.barcode}).then(
- function() { service.add_barcode_to_list(cp.barcode) }
- );
- });
- }
-
- service.renew = function (items) {
- angular.forEach(items, function (cp) {
- egCirc.renew({copy_barcode:cp.barcode}).then(
- function() { service.add_barcode_to_list(cp.barcode) }
- );
- });
- }
-
- service.cancel_transit = function (items) {
- angular.forEach(items, function(cp) {
- egCirc.find_copy_transit(null, {copy_barcode:cp.barcode})
- .then(function(t) { return egCirc.abort_transit(t.id()) })
- .then(function() { return service.add_barcode_to_list(cp.barcode) });
- });
- }
-
- service.selectedHoldingsDamaged = function (items) {
- egCirc.mark_damaged(items.map(function(el){return el.id;})).then(function(){
- angular.forEach(items, function(cp){service.add_barcode_to_list(cp.barcode)});
- });
- }
-
- service.selectedHoldingsMissing = function (items) {
- egCirc.mark_missing(items.map(function(el){return el.id;})).then(function(){
- angular.forEach(items, function(cp){service.add_barcode_to_list(cp.barcode)});
- });
- }
-
- service.gatherSelectedRecordIds = function (items) {
- var rid_list = [];
- angular.forEach(
- items,
- function (item) {
- if (rid_list.indexOf(item['call_number.record.id']) == -1)
- rid_list.push(item['call_number.record.id'])
- }
- );
- return rid_list;
- }
-
- service.gatherSelectedVolumeIds = function (items,rid) {
- var cn_id_list = [];
- angular.forEach(
- items,
- function (item) {
- if (rid && item['call_number.record.id'] != rid) return;
- if (cn_id_list.indexOf(item['call_number.id']) == -1)
- cn_id_list.push(item['call_number.id'])
- }
- );
- return cn_id_list;
- }
-
- service.gatherSelectedHoldingsIds = function (items,rid) {
- var cp_id_list = [];
- angular.forEach(
- items,
- function (item) {
- if (rid && item['call_number.record.id'] != rid) return;
- cp_id_list.push(item.id)
- }
- );
- return cp_id_list;
- }
-
- service.spawnHoldingsAdd = function (items,use_vols,use_copies){
- angular.forEach(service.gatherSelectedRecordIds(items), function (r) {
- var raw = [];
- if (use_copies) { // just a copy on existing volumes
- angular.forEach(service.gatherSelectedVolumeIds(items,r), function (v) {
- raw.push( {callnumber : v} );
- });
- } else if (use_vols) {
- angular.forEach(
- service.gatherSelectedHoldingsIds(items,r),
- function (i) {
- angular.forEach(items, function(item) {
- if (i == item.id) raw.push({owner : item['call_number.owning_lib']});
- });
- }
- );
- }
-
- if (raw.length == 0) raw.push({});
-
- egCore.net.request(
- 'open-ils.actor',
- 'open-ils.actor.anon_cache.set_value',
- null, 'edit-these-copies', {
- record_id: r,
- raw: raw,
- hide_vols : false,
- hide_copies : false
- }
- ).then(function(key) {
- if (key) {
- var url = egCore.env.basePath + 'cat/volcopy/' + key;
- $timeout(function() { $window.open(url, '_blank') });
- } else {
- alert('Could not create anonymous cache key!');
- }
- });
- });
- }
-
- service.spawnHoldingsEdit = function (items,hide_vols,hide_copies){
- angular.forEach(service.gatherSelectedRecordIds(items), function (r) {
- egCore.net.request(
- 'open-ils.actor',
- 'open-ils.actor.anon_cache.set_value',
- null, 'edit-these-copies', {
- record_id: r,
- copies: service.gatherSelectedHoldingsIds(items,r),
- raw: {},
- hide_vols : hide_vols,
- hide_copies : hide_copies
- }
- ).then(function(key) {
- if (key) {
- var url = egCore.env.basePath + 'cat/volcopy/' + key;
- $timeout(function() { $window.open(url, '_blank') });
- } else {
- alert('Could not create anonymous cache key!');
- }
- });
- });
- }
-
- service.replaceBarcodes = function(items) {
- angular.forEach(items, function (cp) {
- $uibModal.open({
- templateUrl: './cat/share/t_replace_barcode',
- animation: true,
- controller:
- ['$scope','$uibModalInstance',
- function($scope , $uibModalInstance) {
- $scope.isModal = true;
- $scope.focusBarcode = false;
- $scope.focusBarcode2 = true;
- $scope.barcode1 = cp.barcode;
-
- $scope.updateBarcode = function() {
- $scope.copyNotFound = false;
- $scope.updateOK = false;
-
- egCore.pcrud.search('acp',
- {deleted : 'f', barcode : $scope.barcode1})
- .then(function(copy) {
-
- if (!copy) {
- $scope.focusBarcode = true;
- $scope.copyNotFound = true;
- return;
- }
-
- $scope.copyId = copy.id();
- copy.barcode($scope.barcode2);
-
- egCore.pcrud.update(copy).then(function(stat) {
- $scope.updateOK = stat;
- $scope.focusBarcode = true;
- if (stat) service.add_barcode_to_list(copy.barcode());
- });
-
- });
- $uibModalInstance.close();
- }
-
- $scope.cancel = function($event) {
- $uibModalInstance.dismiss();
- $event.preventDefault();
- }
- }
- ]
- });
- });
- }
-
- // this "transfers" selected copies to a new owning library,
- // auto-creating volumes and deleting unused volumes as required.
- service.changeItemOwningLib = function(items) {
- var xfer_target = egCore.hatch.getLocalItem('eg.cat.volume_transfer_target');
- if (!xfer_target || !items.length) {
- return;
- }
- var vols_to_move = {};
- var copies_to_move = {};
- angular.forEach(items, function(item) {
- if (item['call_number.owning_lib'] != xfer_target) {
- if (item['call_number.id'] in vols_to_move) {
- copies_to_move[item['call_number.id']].push(item.id);
- } else {
- vols_to_move[item['call_number.id']] = {
- label : item['call_number.label'],
- label_class : item['call_number.label_class'],
- record : item['call_number.record.id'],
- prefix : item['call_number.prefix.id'],
- suffix : item['call_number.suffix.id']
- };
- copies_to_move[item['call_number.id']] = new Array;
- copies_to_move[item['call_number.id']].push(item.id);
- }
- }
- });
-
- var promises = [];
- angular.forEach(vols_to_move, function(vol) {
- promises.push(egCore.net.request(
- 'open-ils.cat',
- 'open-ils.cat.call_number.find_or_create',
- egCore.auth.token(),
- vol.label,
- vol.record,
- xfer_target,
- vol.prefix,
- vol.suffix,
- vol.label_class
- ).then(function(resp) {
- var evt = egCore.evt.parse(resp);
- if (evt) return;
- return egCore.net.request(
- 'open-ils.cat',
- 'open-ils.cat.transfer_copies_to_volume',
- egCore.auth.token(),
- resp.acn_id,
- copies_to_move[vol.id]
- );
- }));
- });
-
- angular.forEach(
- items,
- function(cp){
- promises.push(
- function(){ service.add_barcode_to_list(cp.barcode) }
- )
- }
- );
- $q.all(promises);
- }
-
- service.transferItems = function (items){
- var xfer_target = egCore.hatch.getLocalItem('eg.cat.item_transfer_target');
- var copy_ids = service.gatherSelectedHoldingsIds(items);
- if (xfer_target && copy_ids.length > 0) {
- egCore.net.request(
- 'open-ils.cat',
- 'open-ils.cat.transfer_copies_to_volume',
- egCore.auth.token(),
- xfer_target,
- copy_ids
- ).then(
- function(resp) { // oncomplete
- var evt = egCore.evt.parse(resp);
- if (evt) {
- egConfirmDialog.open(
- egCore.strings.OVERRIDE_TRANSFER_COPIES_TO_MARKED_VOLUME_TITLE,
- egCore.strings.OVERRIDE_TRANSFER_COPIES_TO_MARKED_VOLUME_BODY,
- {'evt_desc': evt}
- ).result.then(function() {
- egCore.net.request(
- 'open-ils.cat',
- 'open-ils.cat.transfer_copies_to_volume.override',
- egCore.auth.token(),
- xfer_target,
- copy_ids,
- { events: ['TITLE_LAST_COPY', 'COPY_DELETE_WARNING'] }
- );
- }).then(function() {
- angular.forEach(items, function(cp){service.add_barcode_to_list(cp.barcode)});
- });
- } else {
- angular.forEach(items, function(cp){service.add_barcode_to_list(cp.barcode)});
- }
-
- },
- null, // onerror
- null // onprogress
- );
- }
- }
-
- return service;
-}])
-
/**
* Search bar along the top of the page.
* Parent scope for list and detail views
*/
.controller('SearchCtrl',
- ['$scope','$location','$timeout','egCore','egGridDataProvider','itemSvc',
-function($scope , $location , $timeout , egCore , egGridDataProvider , itemSvc) {
+ ['$scope','$q','$window','$location','$timeout','egCore','egNet','egGridDataProvider','egItem',
+function($scope , $q , $window , $location , $timeout , egCore , egNet , egGridDataProvider , itemSvc) {
$scope.args = {}; // search args
// sub-scopes (search / detail-view) apply their version
}]);
}
+ $scope.findAcquisition = function() {
+ var acqData;
+ var promises = [];
+ $scope.openAcquisitionLineItem([$scope.args.copyId]);
+ }
+
+ $scope.openAcquisitionLineItem = function (cp_list) {
+ var hasResults = false;
+ var promises = [];
+
+ angular.forEach(cp_list, function (copyId) {
+ promises.push(
+ egNet.request(
+ 'open-ils.acq',
+ 'open-ils.acq.lineitem.retrieve.by_copy_id',
+ egCore.auth.token(),
+ copyId
+ ).then(function (acqData) {
+ if (acqData) {
+ if (acqData.a) {
+ acqData = egCore.idl.toHash(acqData);
+ var url = '/eg/acq/po/view/' + acqData.purchase_order + '/' + acqData.id;
+ $timeout(function () { $window.open(url, '_blank') });
+ hasResults = true;
+ }
+ }
+ })
+ )
+ });
+
+ $q.all(promises).then(function () {
+ !hasResults ? alert('There is no corresponding purchase order for this item.') : false;
+ });
+ }
+
$scope.requestItems = function() {
itemSvc.requestItems([$scope.args.copyId]);
}
+ $scope.update_inventory = function() {
+ itemSvc.updateInventory([$scope.args.copyId], null)
+ .then(function(res) {
+ $timeout(function() { location.href = location.href; }, 1000);
+ });
+ }
+
$scope.attach_to_peer_bib = function() {
itemSvc.attach_to_peer_bib([{
id : $scope.args.copyId,
$scope.selectedHoldingsDamaged = function () {
itemSvc.selectedHoldingsDamaged([{
id : $scope.args.copyId,
- barcode : $scope.args.copyBarcode
+ barcode : $scope.args.copyBarcode,
+ refresh : true
}]);
}
* List view - grid stuff
*/
.controller('ListCtrl',
- ['$scope','$q','$routeParams','$location','$timeout','$window','egCore','egGridDataProvider','itemSvc','egUser','$uibModal','egCirc','egConfirmDialog',
-function($scope , $q , $routeParams , $location , $timeout , $window , egCore , egGridDataProvider , itemSvc , egUser , $uibModal , egCirc , egConfirmDialog) {
+ ['$scope','$q','$routeParams','$location','$timeout','$window','egCore',
+ 'egGridDataProvider','egItem','egUser','$uibModal','egCirc','egConfirmDialog',
+ 'egProgressDialog', 'ngToast',
+// function($scope , $q , $routeParams , $location , $timeout , $window , egCore ,
+// egGridDataProvider , itemSvc , egUser , $uibModal , egCirc , egConfirmDialog,
+// egProgressDialog, ngToast) {
+ function($scope , $q , $routeParams , $location , $timeout , $window , egCore , egGridDataProvider , itemSvc , egUser , $uibModal , egCirc , egConfirmDialog,
+ egProgressDialog, ngToast) {
var copyId = [];
var cp_list = $routeParams.idList;
if (cp_list) {
barcodes.push(line);
});
- if (barcodes.length > 0) {
- var promises = [];
- angular.forEach(barcodes, function (b) {
- promises.push(itemSvc.fetch(b));
- });
+ // Serialize copy retrieval since there may be many, many copies.
+ function fetch_next_copy() {
+ var barcode = barcodes.pop();
+ egProgressDialog.increment();
- $q.all(promises).then(
- function() {
- copyGrid.refresh();
- copyGrid.selectItems([itemSvc.copies[0].index]);
- }
- );
+ if (!barcode) { // All done here.
+ egProgressDialog.close();
+ copyGrid.refresh();
+ copyGrid.selectItems([itemSvc.copies[0].index]);
+ return;
+ }
+
+ itemSvc.fetch(barcode).then(fetch_next_copy);
+ }
+
+ if (barcodes.length) {
+ egProgressDialog.open({value: 0, max: barcodes.length});
+ fetch_next_copy();
}
}
});
itemSvc.add_copies_to_bucket(copy_list);
}
+ $scope.locateAcquisition = function() {
+ if (gatherSelectedHoldingsIds) {
+ var cp_list = gatherSelectedHoldingsIds();
+ if (cp_list) {
+ if (cp_list.length > 0) {
+ $scope.openAcquisitionLineItem(cp_list);
+ }
+ }
+ }
+ }
+
+ $scope.update_inventory = function() {
+ var copy_list = gatherSelectedHoldingsIds();
+ itemSvc.updateInventory(copy_list, $scope.gridControls.allItems()).then(function(res) {
+ if (res) {
+ $scope.gridControls.allItems(res);
+ ngToast.create(egCore.strings.SUCCESS_UPDATE_INVENTORY);
+ } else {
+ ngToast.warning(egCore.strings.FAIL_UPDATE_INVENTORY);
+ }
+ });
+ }
+
$scope.need_one_selected = function() {
var items = $scope.gridControls.selectedItems();
if (items.length == 1) return false;
itemSvc.spawnHoldingsAdd(copyGrid.selectedItems(),false,true);
}
+ $scope.selectedHoldingsCopyAlertsAdd = function(items) {
+ var copy_ids = [];
+ angular.forEach(items, function(item) {
+ if (item.id) copy_ids.push(item.id);
+ });
+ egCirc.add_copy_alerts(copy_ids).then(function() {
+ // update grid items?
+ });
+ }
+
+ $scope.selectedHoldingsCopyAlertsEdit = function(items) {
+ var copy_ids = [];
+ angular.forEach(items, function(item) {
+ if (item.id) copy_ids.push(item.id);
+ });
+ egCirc.manage_copy_alerts(copy_ids).then(function() {
+ // update grid items?
+ });
+ }
+
+ $scope.gridCellHandlers = {};
+ $scope.gridCellHandlers.copyAlertsEdit = function(id) {
+ egCirc.manage_copy_alerts([id]).then(function() {
+ // update grid items?
+ });
+ };
+
$scope.showBibHolds = function () {
angular.forEach(gatherSelectedRecordIds(), function (r) {
var url = egCore.env.basePath + 'cat/catalog/record/' + r + '/holds';
});
}
+ $scope.show_in_catalog = function(){
+ itemSvc.show_in_catalog(copyGrid.selectedItems());
+ }
+
if (copyId.length > 0) {
itemSvc.fetch(null,copyId).then(
function() {
* Detail view -- shows one copy
*/
.controller('ViewCtrl',
- ['$scope','$q','$location','$routeParams','$timeout','$window','egCore','itemSvc','egBilling',
-function($scope , $q , $location , $routeParams , $timeout , $window , egCore , itemSvc , egBilling) {
+ ['$scope','$q','$location','$routeParams','$timeout','$window','egCore','egItem','egBilling','egCirc',
+function($scope , $q , $location , $routeParams , $timeout , $window , egCore , itemSvc , egBilling , egCirc) {
var copyId = $routeParams.id;
$scope.args.copyId = copyId;
$scope.tab = $routeParams.tab || 'summary';
// use the cached record info
if (itemSvc.copy) {
+ $scope.copy_alert_count = itemSvc.copy.copy_alerts().filter(function(aca) {
+ return !aca.ack_time();
+ }).length;
$scope.recordId = itemSvc.copy.call_number().record().id();
$scope.args.recordId = $scope.recordId;
$scope.args.cnId = itemSvc.copy.call_number().id();
// regardless of whether it matches the current item.
if (!barcode && itemSvc.copy && itemSvc.copy.id() == copyId) {
$scope.copy = itemSvc.copy;
+ if (itemSvc.latest_inventory && itemSvc.latest_inventory.copy() == copyId) {
+ $scope.latest_inventory = itemSvc.latest_inventory;
+ }
+ $scope.copy_alert_count = itemSvc.copy.copy_alerts().filter(function(aca) {
+ return !aca.ack_time();
+ }).length;
$scope.recordId = itemSvc.copy.call_number().record().id();
$scope.args.recordId = $scope.recordId;
$scope.args.cnId = itemSvc.copy.call_number().id();
var copy = res.copy;
itemSvc.copy = copy;
+ if (res.latest_inventory) itemSvc.latest_inventory = res.latest_inventory;
$scope.copy = copy;
+ $scope.latest_inventory = res.latest_inventory;
+ $scope.copy_alert_count = copy.copy_alerts().filter(function(aca) {
+ return !aca.ack_time();
+ }).length;
+console.debug($scope.copy_alert_count);
$scope.recordId = copy.call_number().record().id();
$scope.args.recordId = $scope.recordId;
$scope.args.cnId = itemSvc.copy.call_number().id();
return deferred.promise;
}
- // if loadPrev load the two most recent circulations
- function loadCurrentCirc(loadPrev) {
+ // load the two most recent circulations in /circs tab
+ function loadCurrentCirc() {
delete $scope.circ;
delete $scope.circ_summary;
delete $scope.prev_circ_summary;
delete $scope.prev_circ_usr;
if (!copyId) return;
- egCore.pcrud.search('aacs',
- {target_copy : copyId},
- { flesh : 2,
- flesh_fields : {
- aacs : [
- 'usr',
- 'workstation',
- 'checkin_workstation',
- 'duration_rule',
- 'max_fine_rule',
- 'recurring_fine_rule'
- ],
- au : ['card']
- },
- order_by : {aacs : 'xact_start desc'},
- limit : 1
+ var copy_org =
+ itemSvc.copy.call_number().id() == -1 ?
+ itemSvc.copy.circ_lib().id() :
+ itemSvc.copy.call_number().owning_lib().id();
+
+ // since a user can still view patron checkout history here, check perms
+ egCore.perm.hasPermAt('VIEW_COPY_CHECKOUT_HISTORY', true)
+ .then(function(orgIds){
+ if(orgIds.indexOf(copy_org) == -1){
+ console.warn('User is not allowed to view circ history!');
+ $q.when(0);
}
- ).then(null, null, function(circ) {
- $scope.circ = circ;
+ return fetchMaxCircHistory();
+ })
+ .then(function(maxHistCount){
- // load the chain for this circ
- egCore.net.request(
- 'open-ils.circ',
- 'open-ils.circ.renewal_chain.retrieve_by_circ.summary',
- egCore.auth.token(), $scope.circ.id()
- ).then(function(summary) {
- $scope.circ_summary = summary;
- });
+ if (!maxHistCount) $scope.isMaxCircHistoryZero = true;
- if (!loadPrev) return;
+ egCore.pcrud.search('aacs',
+ {target_copy : copyId},
+ { flesh : 2,
+ flesh_fields : {
+ aacs : [
+ 'usr',
+ 'workstation',
+ 'checkin_workstation',
+ 'duration_rule',
+ 'max_fine_rule',
+ 'recurring_fine_rule'
+ ],
+ au : ['card']
+ },
+ order_by : {aacs : 'xact_start desc'},
+ limit : 1
+ }
- // load the chain for the previous circ, plus the user
- egCore.net.request(
- 'open-ils.circ',
- 'open-ils.circ.prev_renewal_chain.retrieve_by_circ.summary',
- egCore.auth.token(), $scope.circ.id()
+ ).then(null, null, function(circ) {
+ $scope.circ = circ;
- ).then(null, null, function(summary) {
- $scope.prev_circ_summary = summary.summary;
+ if (!circ) return $q.when();
- if (summary.usr) { // aged circs have no 'usr'.
- egCore.pcrud.retrieve('au', summary.usr,
- {flesh : 1, flesh_fields : {au : ['card']}})
+ // load the chain for this circ
+ egCore.net.request(
+ 'open-ils.circ',
+ 'open-ils.circ.renewal_chain.retrieve_by_circ.summary',
+ egCore.auth.token(), $scope.circ.id()
+ ).then(function(summary) {
+ $scope.circ_summary = summary;
+ });
- .then(function(user) { $scope.prev_circ_usr = user });
- }
+ if (maxHistCount <= 1) return;
+
+ // load the chain for the previous circ, plus the user
+ egCore.net.request(
+ 'open-ils.circ',
+ 'open-ils.circ.prev_renewal_chain.retrieve_by_circ.summary',
+ egCore.auth.token(), $scope.circ.id()
+
+ ).then(null, null, function(summary) {
+ $scope.prev_circ_summary = summary.summary;
+
+ if (summary.usr) { // aged circs have no 'usr'.
+ egCore.pcrud.retrieve('au', summary.usr,
+ {flesh : 1, flesh_fields : {au : ['card']}})
+
+ .then(function(user) { $scope.prev_circ_usr = user });
+ }
+ });
});
- });
+ })
}
var maxHistory;
'circ.item_checkout_history.max')
.then(function(set) {
maxHistory = set['circ.item_checkout_history.max'] || 4;
- return maxHistory;
+ return Number(maxHistory);
});
}
});
}
+ // load data for /circ_list tab
function loadCircHistory() {
$scope.circ_list = [];
var copy_org =
itemSvc.copy.call_number().id() == -1 ?
itemSvc.copy.circ_lib().id() :
- itemSvc.copy.call_number().owning_lib().id()
+ itemSvc.copy.call_number().owning_lib().id();
// there is an extra layer of permissibility over circ
// history views
return fetchMaxCircHistory();
- }).then(function(count) {
+ }).then(function(maxHistCount) {
- egCore.pcrud.search('aacs',
+ if(!maxHistCount) $scope.isMaxCircHistoryZero = true;
+
+ egCore.pcrud.search('aacs',
{target_copy : copyId},
{ flesh : 2,
flesh_fields : {
aacs : [
'usr',
- 'workstation',
- 'checkin_workstation',
- 'recurring_fine_rule'
+ 'workstation',
+ 'checkin_workstation',
+ 'recurring_fine_rule'
],
au : ['card']
},
- order_by : {aacs : 'xact_start desc'},
- limit : count
+ order_by : {aacs : 'xact_start desc'},
+ // fetch at least one to see if copy ever circulated
+ limit : $scope.isMaxCircHistoryZero ? 1 : maxHistCount
}
).then(null, null, function(circ) {
+ $scope.circ = circ;
+
// flesh circ_lib locally
circ.circ_lib(egCore.org.get(circ.circ_lib()));
circ.checkin_lib(egCore.org.get(circ.checkin_lib()));
return c.year() == new Date().getFullYear();
});
- $scope.total_circs_this_year =
- this_year.length ? this_year[0].count() : 0;
+ $scope.total_circs_this_year = (function() {
+ total = 0;
+ if (this_year.length == 2) {
+ total = (Number(this_year[0].count()) + Number(this_year[1].count()));
+ } else if (this_year.length == 1) {
+ total = Number(this_year[0].count());
+ }
+ return total;
+ })();
var prev_year = counts.filter(function(c) {
return c.year() == new Date().getFullYear() - 1;
});
- $scope.total_circs_prev_year =
- prev_year.length ? prev_year[0].count() : 0;
+ $scope.total_circs_prev_year = (function() {
+ total = 0;
+ if (prev_year.length == 2) {
+ total = (Number(prev_year[0].count()) + Number(prev_year[1].count()));
+ } else if (prev_year.length == 1) {
+ total = Number(prev_year[0].count());
+ }
+ return total;
+ })();
});
}
});
}
- function loadTransits() {
+ function loadMostRecentTransit() {
delete $scope.transit;
delete $scope.hold_transit;
if (!copyId) return;
egCore.pcrud.search('atc',
{target_copy : copyId},
- {order_by : {atc : 'source_send_time DESC'}}
+ {
+ order_by : {atc : 'source_send_time DESC'},
+ limit : 1
+ }
).then(null, null, function(transit) {
+ // use progress callback since we'll get up to one result
$scope.transit = transit;
transit.source(egCore.org.get(transit.source()));
transit.dest(egCore.org.get(transit.dest()));
break;
case 'circs':
- loadCurrentCirc(true);
+ loadCurrentCirc();
break;
case 'circ_list':
case 'holds':
loadHolds()
- loadTransits();
+ loadMostRecentTransit();
break;
case 'triggered_events':
return;
}
+ $scope.addCopyAlerts = function(copy_id) {
+ egCirc.add_copy_alerts([copy_id]).then(function() {
+ // force a refresh
+ loadCopy($scope.copy.barcode()).then(loadTabData);
+ });
+ }
+ $scope.manageCopyAlerts = function(copy_id) {
+ egCirc.manage_copy_alerts([copy_id]).then(function() {
+ // force a refresh
+ loadCopy($scope.copy.barcode()).then(loadTabData);
+ });
+ }
+
$scope.context.toggleDisplay = function() {
$location.path('/cat/item/search');
}