webstaff: MARC editor - AngularJS egTagTable service
authorGalen Charlton <gmc@esilibrary.com>
Mon, 16 Mar 2015 18:48:39 +0000 (18:48 +0000)
committerJason Stephenson <jstephenson@mvlc.org>
Wed, 19 Aug 2015 17:39:13 +0000 (13:39 -0400)
This also adds context menus for tags, subfield codes, and indicator
values

Signed-off-by: Galen Charlton <gmc@esilibrary.com>
Signed-off-by: Jason Stephenson <jstephenson@mvlc.org>
Open-ILS/src/templates/staff/cat/catalog/index.tt2
Open-ILS/web/js/ui/default/staff/cat/services/marcedit.js
Open-ILS/web/js/ui/default/staff/cat/services/tagtable.js [new file with mode: 0644]

index 56a4ea9..26c450f 100644 (file)
@@ -9,6 +9,7 @@
 <script src="[% ctx.media_prefix %]/js/ui/default/staff/services/grid.js"></script>
 <script src="[% ctx.media_prefix %]/js/ui/default/staff/services/eframe.js"></script>
 <script src="[% ctx.media_prefix %]/js/ui/default/staff/cat/services/record.js"></script>
+<script src="[% ctx.media_prefix %]/js/ui/default/staff/cat/services/tagtable.js"></script>
 <script src="[% ctx.media_prefix %]/js/ui/default/staff/cat/services/marcedit.js"></script>
 <script src="[% ctx.media_prefix %]/js/ui/default/staff/circ/services/circ.js"></script>
 [% INCLUDE 'staff/circ/share/circ_strings.tt2' %]
index 65c36a1..34fc9fe 100644 (file)
@@ -54,22 +54,25 @@ angular.module('egMarcMod', ['egCoreMod', 'ui.bootstrap'])
             max: '@',
             itype: '@'
         },
-        controller : ['$scope',
-            function ( $scope ) {
+        controller : ['$scope', 'egTagTable',
+            function ( $scope ,  egTagTable) {
 
-/* XXX Example, for testing.  We'll get this from the tag-table services for realz
- *
                 if (!$scope.contextItemContainer) {
-                    $scope.contextItemContainer = "default_context";
-                    $scope.$parent[$scope.contextItemContainer] = [
-                        { value: 'a' },
-                        { value: 'b' },
-                        { value: 'c' },
-                    ];
+                    if ($scope.itype === 'tag') {
+                        $scope.contextItemContainer = "default_context";
+                        // FIXME use contextItemGenerator
+                        $scope.$parent[$scope.contextItemContainer] = egTagTable.getFieldTags();
+                    } else if ($scope.itype === 'sfc') {
+                        $scope.contextItemContainer = "default_context";
+                        $scope.$parent[$scope.contextItemContainer] = 
+                            egTagTable.getSubfieldCodes($scope.$parent.field.tag);
+                    } else if ($scope.itype === 'ind') {
+                        $scope.contextItemContainer = "default_context";
+                        $scope.$parent[$scope.contextItemContainer] = 
+                            egTagTable.getIndicatorValues($scope.$parent.field.tag, $scope.$parent.indNumber);
+                    }
                 }
 
- *
- */
 
                 if ($scope.contextItemContainer && angular.isArray($scope.$parent[$scope.contextItemContainer]))
                     $scope.item_container = $scope.$parent[$scope.contextItemContainer];
@@ -294,8 +297,8 @@ angular.module('egMarcMod', ['egCoreMod', 'ui.bootstrap'])
             });
 
         },
-        controller : ['$timeout','$scope','egCore',
-            function ( $timeout , $scope , egCore ) {
+        controller : ['$timeout','$scope','egCore', 'egTagTable',
+            function ( $timeout , $scope , egCore ,  egTagTable ) {
 
                 $scope.bib_source = null;
                 $scope.record_type = $scope.recordType || 'bre';
@@ -309,6 +312,8 @@ angular.module('egMarcMod', ['egCoreMod', 'ui.bootstrap'])
                 $scope.controlfields = [];
                 $scope.datafields = [];
 
+                egTagTable.loadTagTable();
+
                 $scope.onKeydown = function (event) {
                     var event_return = true;
 
diff --git a/Open-ILS/web/js/ui/default/staff/cat/services/tagtable.js b/Open-ILS/web/js/ui/default/staff/cat/services/tagtable.js
new file mode 100644 (file)
index 0000000..22a715c
--- /dev/null
@@ -0,0 +1,107 @@
+/*
+ * Retrieve, cache, and query MARC tag tables
+ */
+angular.module('egCoreMod')
+.factory('egTagTable', 
+       ['$q', 'egCore', 'egAuth',
+function($q,   egCore,   egAuth) {
+
+    var service = {
+        defaultTagTableSelector : {
+            marcFormat     : 'marc21',
+            marcRecordType : 'biblio',
+        },
+        fields : { }
+    };
+
+    // allow 'bre' and 'biblio' to be synonyms, etc.
+    service.normalizeRecordType = function(recordType) {
+        if (recordType === 'sre') {
+            return 'serial';
+        } else if (recordType === 'bre') {
+            return 'biblio';
+        } else if (recordType === 'are') {
+            return 'authority';
+        } else {
+            return recordType;
+        }
+    };
+
+    service.loadTagTable = function(args) {
+        var fields = service.defaultTagTableSelector;
+        if (args) {
+            if (args.marcFormat) {
+                fields.marcFormat = args.marcFormat;
+            }
+            if (args.marcRecordType) {
+                fields.marcFormat = service.normalizeRecordType(args.marcFormat);
+            }
+        }
+        var tt_key = 'current_tag_table_' + fields.marcFormat + '_' +
+                     fields.marcRecordType;
+        egCore.hatch.getItem(tt_key).then(function(tt) {
+            if (tt) {
+                service.fields = tt;
+            } else {
+                service.loadRemoteTagTable(fields, tt_key);
+            }
+        });
+    };
+
+    service.loadRemoteTagTable = function(fields, tt_key) {
+        egCore.net.request(
+            'open-ils.cat',
+            'open-ils.cat.tag_table.all.retrieve.local',
+            egAuth.token(), fields.marcFormat, fields.marcRecordType
+        ).then(
+            function (data)  {
+                egCore.hatch.setItem(tt_key, service.fields);
+            },
+            function (err)   { console.err('error fetch tag table: ' + err) }, 
+            function (field) {
+                if (!field) return;
+                service.fields[field.tag] = field;
+            }
+        );
+    };
+
+    service.getFieldTags = function() {
+        var list = [];
+        angular.forEach(service.fields, function(value, key) {
+            this.push({ 
+                value: key,
+                label: key + ': ' + value.name
+            });
+        }, list);
+        return list;
+    }
+
+    service.getSubfieldCodes = function(tag) {
+        var list = [];
+        if (!tag) return;
+        if (!service.fields[tag]) return;
+        angular.forEach(service.fields[tag].subfields, function(value) {
+            this.push({
+                value: value.code,
+                label: value.code + ': ' + value.description
+            });
+        }, list);
+        return list;
+    }
+
+    service.getIndicatorValues = function(tag, pos) {
+        var list = [];
+        if (!tag) return list;
+        if (!service.fields[tag]) return;
+        if (!service.fields[tag]["ind" + pos]) return;
+        angular.forEach(service.fields[tag]["ind" + pos], function(value) {
+            this.push({
+                value: value.code,
+                label: value.code + ': ' + value.value
+            });
+        }, list);
+        return list;
+    }
+
+    return service;
+}]);