webstaff: add Validate (headings) button to MARC editor
authorGalen Charlton <gmc@esilibrary.com>
Thu, 3 Sep 2015 20:26:24 +0000 (20:26 +0000)
committerJason Stephenson <jstephenson@mvlc.org>
Mon, 14 Sep 2015 19:44:19 +0000 (15:44 -0400)
Signed-off-by: Galen Charlton <gmc@esilibrary.com>
Signed-off-by: Jason Stephenson <jstephenson@mvlc.org>
Open-ILS/src/templates/staff/cat/share/t_marcedit.tt2
Open-ILS/src/templates/staff/css/cat.css.tt2
Open-ILS/web/js/ui/default/staff/cat/services/marcedit.js
Open-ILS/web/js/ui/default/staff/cat/services/tagtable.js

index f450316..eef0f6a 100644 (file)
@@ -18,6 +18,9 @@
       <eg-marc-edit-bibsource/>
     </div>
     <div class="col-md-1">
+      <button class="btn btn-default" ng-show="record_type == 'bre'" ng-click="validateHeadings()">[% l('Validate') %]</button>
+    </div>
+    <div class="col-md-1">
       <button class="btn btn-default" ng-click="saveRecord()">Save</button>
     </div>
     <div class="col-md-1">
index fcd98bd..f3f27d2 100644 (file)
@@ -43,6 +43,10 @@ input.marcedit:focus {
     border-right: 0px !important;
 }
 
+.unvalidatedheading {
+    color: red;
+}
+
 .marctag, .marcind {
     text-align: center;
 }
index ca161f5..9d11cd7 100644 (file)
@@ -363,7 +363,7 @@ angular.module('egMarcMod', ['egCoreMod', 'ui.bootstrap'])
                     '<span><eg-marc-edit-tag field="field" tag="field.tag" on-keydown="onKeydown"/></span>'+
                     '<span><eg-marc-edit-ind field="field" ind="field.ind1" on-keydown="onKeydown" ind-number="1"/></span>'+
                     '<span><eg-marc-edit-ind field="field" ind="field.ind2" on-keydown="onKeydown" ind-number="2"/></span>'+
-                    '<span><eg-marc-edit-subfield ng-repeat="subfield in field.subfields" subfield="subfield" field="field" on-keydown="onKeydown"/></span>'+
+                    '<span><eg-marc-edit-subfield ng-class="{ \'unvalidatedheading\' : field.heading_checked && !field.heading_valid}" ng-repeat="subfield in field.subfields" subfield="subfield" field="field" on-keydown="onKeydown"/></span>'+
                     // FIXME: template should probably be moved to file to improve
                     // translatibility
                     '<button class="btn btn-info btn-xs" '+
@@ -373,6 +373,8 @@ angular.module('egMarcMod', ['egCoreMod', 'ui.bootstrap'])
                     '>'+
                     '<span class="glyphicon glyphicon-link"></span>'+
                     '</button>'+
+                    '<span ng-show="field.heading_checked && field.heading_valid" class="glyphicon glyphicon-ok-sign"></span>'+
+                    '<span ng-show="field.heading_checked && !field.heading_valid" class="glyphicon glyphicon-question-sign"></span>'+
                   '</div>',
         scope: { field: "=", onKeydown: '=' },
         replace: true,
@@ -991,6 +993,40 @@ angular.module('egMarcMod', ['egCoreMod', 'ui.bootstrap'])
                     return $scope.saveRecord();
                 };
 
+                $scope.validateHeadings = function () {
+                    if ($scope.record_type != 'bre') return;
+                    angular.forEach($scope.record.fields, function(f) {
+                        if (!$scope.controlSet.bibFieldByTag(f.tag)) return;
+                        // if heading already has a $0, assume it's good
+                        if (f.subfield('0', true).length) {
+                            f.heading_checked = true;
+                            f.heading_valid = true;
+                            return;
+                        }
+                        var auth_match = $scope.controlSet.bibToAuthorities(f);
+                        egCore.net.request(
+                            'open-ils.search',
+                            'open-ils.search.authority.simple_heading.from_xml.batch.atomic',
+                            auth_match[0]
+                        ).then(function (matches) {
+                            f.heading_valid = false;
+                            if (matches[0]) { // probably set
+                                for (var cset in matches[0]) {
+                                    var arr = matches[0][cset];
+                                    if (arr.length) {
+                                        // protect against errant empty string values
+                                        if (arr.length == 1 && arr[0] == '')
+                                            continue;
+                                        f.heading_valid = true;
+                                        break;
+                                    }
+                                }
+                            }
+                            f.heading_checked = true;
+                        });
+                    });
+                }
+
                 $scope.saveRecord = function () {
                     if ($scope.inPlaceMode) {
                         $scope.marcXml = $scope.record.toXmlString();
index 1580ca5..6c3e10c 100644 (file)
@@ -489,16 +489,6 @@ function($q,   egCore,   egAuth) {
             return auth_list;
         }
     
-        // This should not be used in an angular world.  Instead, the call
-        // to open-ils.search.authority.simple_heading.from_xml.batch.atomic should
-        // be performed by the code that wants to find matching authorities.
-        this.findMatchingAuthorities = function (field) {
-            return fieldmapper.standardRequest(
-                [ 'open-ils.search', 'open-ils.search.authority.simple_heading.from_xml.batch.atomic' ],
-                this.bibToAuthorities(field)
-            );
-        }
-
     }
 
     service.getAuthorityControlSet = function() {