From: Bill Erickson Date: Wed, 17 May 2017 20:34:43 +0000 (-0400) Subject: LP#1251394 Webstaff Display fields utility functions X-Git-Url: https://old-git.evergreen-ils.org/?a=commitdiff_plain;h=refs%2Fheads%2Fuser%2Fberick%2Flp1251394-metabib-display-fields-rebase-circa-2.12;p=working%2FEvergreen.git LP#1251394 Webstaff Display fields utility functions Adds functions for translating bib record display field data into a variety of useful formats and structures. Some are best suited for grids, others for lists of values, etc. Signed-off-by: Bill Erickson --- diff --git a/Open-ILS/web/js/ui/default/staff/cat/services/record.js b/Open-ILS/web/js/ui/default/staff/cat/services/record.js index 81a8cf7acd..8dbbef2d4d 100644 --- a/Open-ILS/web/js/ui/default/staff/cat/services/record.js +++ b/Open-ILS/web/js/ui/default/staff/cat/services/record.js @@ -223,3 +223,70 @@ angular.module('egCoreMod') ] } }) + +/** + * Utility functions for translating bib record display fields into + * various formats / structures. + * + * Note that 'mwde' objects (which are proper IDL objects) only contain + * the prescribed fields from the IDL (and database view), while the + * 'mfde' hash-based objects contain all configured display fields, + * including local/custom fields. + */ +.factory('egBibDisplay', ['$q', 'egCore', function($q, egCore) { + var service = {}; + + /** + * Converts JSON-encoded values within a mwde object to Javascript + * native strings, numbers, and arrays. + */ + service.mwdeJSONToJS = function(entry) { + angular.forEach(egCore.idl.classes.mwde.fields, function(f) { + if (f.virtual) return; + entry[f.name](JSON.parse(entry[f.name]())); + }); + } + + /** + * Converts a list of 'mfde' entry objects to a simple key=>value hash. + * Non-multi values are strings or numbers. + * Multi values are arrays of strings or numbers. + */ + service.mfdeToHash = function(entries) { + var hash = service.mfdeToMetaHash(entries); + angular.forEach(hash, + function(sub_hash, name) { hash[name] = sub_hash.value }); + return hash; + } + + /** + * Converts a list of 'mfde' entry objects to a nested hash like so: + * {name => field_name, label => field_label, value => scalar_or_array} + * The scalar_or_array value is a string/number or an array of + * string/numbers + */ + service.mfdeToMetaHash = function(entries) { + var hash = {}; + angular.forEach(entries, function(entry) { + + if (!hash[entry.name()]) { + hash[entry.name()] = { + name : entry.name(), + label : entry.label(), + multi : entry.multi() == 't', + value : entry.multi() == 't' ? [] : null + } + } + + if (entry.multi() == 't') { + hash[entry.name()].value.push(entry.value()); + } else { + hash[entry.name()].value = entry.value(); + } + }); + + return hash; + } + + return service; +}]) diff --git a/Open-ILS/web/js/ui/default/staff/circ/patron/items_out.js b/Open-ILS/web/js/ui/default/staff/circ/patron/items_out.js index ebba76239d..55825bebfd 100644 --- a/Open-ILS/web/js/ui/default/staff/circ/patron/items_out.js +++ b/Open-ILS/web/js/ui/default/staff/circ/patron/items_out.js @@ -7,8 +7,10 @@ angular.module('egPatronApp') .controller('PatronItemsOutCtrl', ['$scope','$q','$routeParams','$timeout','egCore','egUser','patronSvc','$location', 'egGridDataProvider','$uibModal','egCirc','egConfirmDialog','egBilling','$window', + 'egBibDisplay', function($scope, $q, $routeParams, $timeout, egCore , egUser, patronSvc , $location, - egGridDataProvider , $uibModal , egCirc , egConfirmDialog , egBilling , $window) { + egGridDataProvider , $uibModal , egCirc , egConfirmDialog , egBilling , $window, + egBibDisplay) { // list of noncatatloged circulations. Define before initTab to // avoid any possibility of race condition, since they are loaded @@ -114,13 +116,8 @@ function($scope, $q, $routeParams, $timeout, egCore , egUser, patronSvc , $ }).then(null, null, function(circ) { circ.circ_lib(egCore.org.get(circ.circ_lib())); // local fleshing - // TODO: move to shared service - // Un-JSON-ify display field data - var wde = circ.target_copy().call_number().record().wide_display_entry(); - angular.forEach(egCore.idl.classes.mwde.fields, function(f) { - if (f.virtual) return; - wde[f.name](JSON.parse(wde[f.name]())); - }); + egBibDisplay.mwdeJSONToJS( + circ.target_copy().call_number().record().wide_display_entry()); if (circ.target_copy().call_number().id() == -1) { // dummy-up a record for precat items