webstaff: Fixed field editor!
authorMike Rylander <mrylander@gmail.com>
Mon, 30 Mar 2015 18:14:20 +0000 (14:14 -0400)
committerJason Stephenson <jstephenson@mvlc.org>
Wed, 19 Aug 2015 17:39:14 +0000 (13:39 -0400)
Signed-off-by: Mike Rylander <mrylander@gmail.com>
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/web/js/ui/default/staff/cat/services/marcedit.js
Open-ILS/web/js/ui/default/staff/cat/services/tagtable.js
Open-ILS/web/js/ui/default/staff/marcrecord.js

index 958e823..153fa0f 100644 (file)
     <input id="mfiabc" type="text" placeholder="[% l('Barcode') %]" ng-model="fast_item_barcode"/>
     <button class="btn btn-default" ng-click="saveFastItem()">Add Item</button>
   </div>
-  <div class="marcffeditor pad-vert row col-md-12 marctypesource">
+  <div class="pad-vert row col-md-12 marctypesource">
     <div class="col-md-2"><label>Record Type:</label> {{calculated_record_type}}</div>
     <div ng-if="bre" class="col-md-2"><eg-marc-edit-bibsource/></div>
   </div>
+  <div class="marcffeditor pad-vert">
+    <div class="row col-md-12">
+        <eg-marc-edit-fixed-field fixed-field="Type" record="record"></eg-marc-edit-fixed-field>
+        <eg-marc-edit-fixed-field fixed-field="ELvl" record="record"></eg-marc-edit-fixed-field>
+        <eg-marc-edit-fixed-field fixed-field="Srce" record="record"></eg-marc-edit-fixed-field>
+        <eg-marc-edit-fixed-field fixed-field="Audn" record="record"></eg-marc-edit-fixed-field>
+        <eg-marc-edit-fixed-field fixed-field="Ctrl" record="record"></eg-marc-edit-fixed-field>
+        <eg-marc-edit-fixed-field fixed-field="Lang" record="record"></eg-marc-edit-fixed-field>
+    </div>
+    <div class="row col-md-12">
+        <eg-marc-edit-fixed-field fixed-field="BLvl" record="record"></eg-marc-edit-fixed-field>
+        <eg-marc-edit-fixed-field fixed-field="Form" record="record"></eg-marc-edit-fixed-field>
+        <eg-marc-edit-fixed-field fixed-field="Conf" record="record"></eg-marc-edit-fixed-field>
+        <eg-marc-edit-fixed-field fixed-field="Biog" record="record"></eg-marc-edit-fixed-field>
+        <eg-marc-edit-fixed-field fixed-field="MRec" record="record"></eg-marc-edit-fixed-field>
+        <eg-marc-edit-fixed-field fixed-field="Ctry" record="record"></eg-marc-edit-fixed-field>
+    </div>
+    <div class="row col-md-12">
+        <eg-marc-edit-fixed-field fixed-field="s_l" record="record"></eg-marc-edit-fixed-field>
+        <eg-marc-edit-fixed-field fixed-field="Cont" record="record"></eg-marc-edit-fixed-field>
+        <eg-marc-edit-fixed-field fixed-field="GPub" record="record"></eg-marc-edit-fixed-field>
+        <eg-marc-edit-fixed-field fixed-field="LitF" record="record"></eg-marc-edit-fixed-field>
+        <eg-marc-edit-fixed-field fixed-field="Indx" record="record"></eg-marc-edit-fixed-field>
+        <eg-marc-edit-fixed-field fixed-field="Alph" record="record"></eg-marc-edit-fixed-field>
+    </div>
+    <div class="row col-md-12">
+        <eg-marc-edit-fixed-field fixed-field="Desc" record="record"></eg-marc-edit-fixed-field>
+        <eg-marc-edit-fixed-field fixed-field="Ills" record="record"></eg-marc-edit-fixed-field>
+        <eg-marc-edit-fixed-field fixed-field="Fest" record="record"></eg-marc-edit-fixed-field>
+        <eg-marc-edit-fixed-field fixed-field="DtSt" record="record"></eg-marc-edit-fixed-field>
+        <eg-marc-edit-fixed-field fixed-field="Date1" record="record"></eg-marc-edit-fixed-field>
+        <eg-marc-edit-fixed-field fixed-field="Date2" record="record"></eg-marc-edit-fixed-field>
+    </div>
+    <div class="row col-md-12">
+        <eg-marc-edit-fixed-field fixed-field="SrTp" record="record"></eg-marc-edit-fixed-field>
+        <eg-marc-edit-fixed-field fixed-field="Regl" record="record"></eg-marc-edit-fixed-field>
+        <eg-marc-edit-fixed-field fixed-field="Orig" record="record"></eg-marc-edit-fixed-field>
+        <eg-marc-edit-fixed-field fixed-field="Freq" record="record"></eg-marc-edit-fixed-field>
+        <eg-marc-edit-fixed-field fixed-field="EntW" record="record"></eg-marc-edit-fixed-field>
+    </div>
+    <div class="row col-md-12">
+        <eg-marc-edit-fixed-field fixed-field="TrAr" record="record"></eg-marc-edit-fixed-field>
+        <eg-marc-edit-fixed-field fixed-field="Part" record="record"></eg-marc-edit-fixed-field>
+        <eg-marc-edit-fixed-field fixed-field="LTxt" record="record"></eg-marc-edit-fixed-field>
+        <eg-marc-edit-fixed-field fixed-field="FMus" record="record"></eg-marc-edit-fixed-field>
+        <eg-marc-edit-fixed-field fixed-field="AccM" record="record"></eg-marc-edit-fixed-field>
+        <eg-marc-edit-fixed-field fixed-field="Comp" record="record"></eg-marc-edit-fixed-field>
+    </div>
+    <div class="row col-md-12">
+        <eg-marc-edit-fixed-field fixed-field="SpFm" record="record"></eg-marc-edit-fixed-field>
+        <eg-marc-edit-fixed-field fixed-field="Relf" record="record"></eg-marc-edit-fixed-field>
+        <eg-marc-edit-fixed-field fixed-field="Proj" record="record"></eg-marc-edit-fixed-field>
+        <eg-marc-edit-fixed-field fixed-field="CrTp" record="record"></eg-marc-edit-fixed-field>
+    </div>
+    <div class="row col-md-12">
+        <eg-marc-edit-fixed-field fixed-field="TMat" record="record"></eg-marc-edit-fixed-field>
+        <eg-marc-edit-fixed-field fixed-field="Time" record="record"></eg-marc-edit-fixed-field>
+        <eg-marc-edit-fixed-field fixed-field="Tech" record="record"></eg-marc-edit-fixed-field>
+        <eg-marc-edit-fixed-field fixed-field="File" record="record"></eg-marc-edit-fixed-field>
+    </div>
+    <div class="row col-md-12">
+        <eg-marc-edit-fixed-field fixed-field="Type_tbmfhd" record="record"></eg-marc-edit-fixed-field>
+        <eg-marc-edit-fixed-field fixed-field="ELvl_tbmfhd" record="record"></eg-marc-edit-fixed-field>
+        <eg-marc-edit-fixed-field fixed-field="Item_tbmfhd" record="record"></eg-marc-edit-fixed-field>
+        <eg-marc-edit-fixed-field fixed-field="GeoDiv" record="record"></eg-marc-edit-fixed-field>
+        <eg-marc-edit-fixed-field fixed-field="Roman" record="record"></eg-marc-edit-fixed-field>
+        <eg-marc-edit-fixed-field fixed-field="CatLang" record="record"></eg-marc-edit-fixed-field>
+    </div>
+    <div class="row col-md-12">
+        <eg-marc-edit-fixed-field fixed-field="Kind" record="record"></eg-marc-edit-fixed-field>
+        <eg-marc-edit-fixed-field fixed-field="Rules" record="record"></eg-marc-edit-fixed-field>
+        <eg-marc-edit-fixed-field fixed-field="Subj" record="record"></eg-marc-edit-fixed-field>
+        <eg-marc-edit-fixed-field fixed-field="Series" record="record"></eg-marc-edit-fixed-field>
+        <eg-marc-edit-fixed-field fixed-field="SerNum" record="record"></eg-marc-edit-fixed-field>
+        <eg-marc-edit-fixed-field fixed-field="NameUse" record="record"></eg-marc-edit-fixed-field>
+    </div>
+    <div class="row col-md-12">
+        <eg-marc-edit-fixed-field fixed-field="SubjUse" record="record"></eg-marc-edit-fixed-field>
+        <eg-marc-edit-fixed-field fixed-field="SerUse" record="record"></eg-marc-edit-fixed-field>
+        <eg-marc-edit-fixed-field fixed-field="TypeSubd" record="record"></eg-marc-edit-fixed-field>
+        <eg-marc-edit-fixed-field fixed-field="GovAgn" record="record"></eg-marc-edit-fixed-field>
+        <eg-marc-edit-fixed-field fixed-field="RefStatus" record="record"></eg-marc-edit-fixed-field>
+        <eg-marc-edit-fixed-field fixed-field="UpdStatus" record="record"></eg-marc-edit-fixed-field>
+    </div>
+    <div class="row col-md-12">
+        <eg-marc-edit-fixed-field fixed-field="Name" record="record"></eg-marc-edit-fixed-field>
+        <eg-marc-edit-fixed-field fixed-field="Status" record="record"></eg-marc-edit-fixed-field>
+        <eg-marc-edit-fixed-field fixed-field="ModRec" record="record"></eg-marc-edit-fixed-field>
+        <eg-marc-edit-fixed-field fixed-field="Source" record="record"></eg-marc-edit-fixed-field>
+    </div>
+  </div>
   <div class="marcrecord pad-vert">
     <div>
       <eg-marc-edit-leader record="record" on-keydown="onKeydown"/>
index d779857..729ca7e 100644 (file)
@@ -128,38 +128,40 @@ angular.module('egMarcMod', ['egCoreMod', 'ui.bootstrap'])
     return {
         transclude: true,
         restrict: 'E',
-        template: '<div class="cols-md-2 text-right">'+
-                    '<label name="{{fixedField}}" for="{{fixedField}}_ff_input">{{fixedField}}</label>'+
-                    '<input type="text" size="4" id="{{fixedField}}_ff_input"/>'+
-                  '</div>,
+        template: '<div class="col-md-2">'+
+                    '<div class="col-md-1"><label name="{{fixedField}}" for="{{fixedField}}_ff_input">{{fixedField}}</label></div>'+
+                    '<div class="col-md-1"><input type="text" style="padding-left: 5px; margin-left: 1em" size="4" id="{{fixedField}}_ff_input"/></div>'+
+                  '</div>',
         scope: { record: "=", fixedField: "@" },
         replace: true,
         controller : ['$scope', '$element', 'egTagTable',
             function ( $scope ,  $element ,  egTagTable) {
                 $($element).children().css({ display : 'none' });
-                $scope.rtype = $scope.record.recordType();
                 $scope.me = null;
 
-                egTagTable.fetchFFPosTable( $scope.rtype ).then(function (ff_list) {
-                    ff_list.forEach( function (ff) {
-                        if (!$scope.me && ff.tag != '006') { // we're going to ignore 006 for now...
-                            if (ff.fixed_field == $scope.fixedField && ff.rec_type == $scope.rtype) {
-                                $($element).children().css({ display : 'block' });
-                                $scope.me = ff;
-                            }
-                        }
-                    });
-                }).then(function () {
-                    if ($scope.me) {
-                        var input = $('#' + $scope.fixedField + '_ff_input');
-                        input.attr('maxlength', $scope.me.length)
-                        input.val($scope.record.getFixedField($scope.me.fixed_field);
-                        input.on('keypress', function(e) {
-                            $scope.record.setFixedField($scope.me.fixed_field, input.val());
+                $scope.$watch('record.ready', function (newVal, oldVal) {
+                    if (newVal && newVal != oldVal) {
+                        $scope.rtype = $scope.record.recordType();
+                        egTagTable.fetchFFPosTable( $scope.rtype ).then(function (ff_list) { // This does not work when fetching from hatch...
+                            angular.forEach(ff_list, function (ff) {
+                                if (!$scope.me) {
+                                    if (ff.fixed_field == $scope.fixedField && ff.rec_type == $scope.rtype) {
+                                        $scope.me = ff;
+                                        $($element).children().css({ display : 'inline' });
+
+                                        var input = $($element).find('input');
+                                        input.attr('maxlength', $scope.me.length);
+                                        input.val($scope.record.extractFixedField($scope.me.fixed_field));
+                                        input.on('keyup', function(e) {
+                                            $scope.record.setFixedField($scope.me.fixed_field, input.val());
+                                            $scope.$parent.$digest();
+                                        });
+                                    }
+                                }
+                            });
                         });
                     }
                 });
-
             }
         ]
     }
@@ -711,6 +713,8 @@ angular.module('egMarcMod', ['egCoreMod', 'ui.bootstrap'])
 
                     }).then(function(){
                         return egTagTable.fetchFFPosTable($scope.calculated_record_type)
+                    }).then(function(){
+                        return egTagTable.fetchFFValueTable($scope.calculated_record_type)
                     }).then(setCaret);
                 }
 
@@ -731,7 +735,6 @@ angular.module('egMarcMod', ['egCoreMod', 'ui.bootstrap'])
                     }
 
                     if ($scope.record_undo_stack.length != $scope.save_stack_depth) {
-                        console.log('should get a listener... does not');
                         $scope.dirtyFlag = true;
                     } else {
                         $scope.dirtyFlag = false;
index 5d3202d..7390816 100644 (file)
@@ -53,26 +53,52 @@ function($q,   egCore,   egAuth) {
     service.fetchFFPosTable = function(rtype) {
         var deferred = $q.defer();
 
-        if (service.ff_pos_map[rtype]) {
-            deferred.resolve(service.ff_pos_map[rtype]);
-            return deferred.promise;
-        }
+        var hatch_pos_key = 'FFPosTable_'+rtype;
+
+        egCore.hatch.getItem(hatch_pos_key).then(function(cached_table) {
+            if (cached_table) {
+                service.ff_pos_map[rtype] = cached_table;
+                deferred.resolve(cached_table);
 
-        egCore.net.request( // First, get the list of FFs (minus 006)
-            'open-ils.fielder',
-            'open-ils.fielder.cmfpm.atomic',
-            { query : { tag : { '!=' : '006' } } }
-        ).then(function (data)  {
-            service.ff_pos_map[rtype] = data;
-        }).then(function() { // Then, get the value maps
-            return egCore.net.request(
-                'open-ils.cat',
-                'open-ils.cat.biblio.fixed_field_values.by_rec_type',
-                rtype
-            );
-        }).then(function (data)  {
-            service.ff_value_map[rtype] = data;
-            deferred.resolve(service.ff_pos_map[rtype]);
+            } else {
+
+                egCore.net.request( // First, get the list of FFs (minus 006)
+                    'open-ils.fielder',
+                    'open-ils.fielder.cmfpm.atomic',
+                    { query : { tag : { '!=' : '006' } } }
+                ).then(function (data)  {
+                    service.ff_pos_map[rtype] = data;
+                    egCore.hatch.setItem(hatch_pos_key, data);
+                    deferred.resolve(data);
+                });
+            }
+        });
+
+        return deferred.promise;
+    };
+
+    service.fetchFFValueTable = function(rtype) {
+        var deferred = $q.defer();
+
+        var hatch_value_key = 'FFValueTable_'+rtype;
+
+        egCore.hatch.getItem(hatch_value_key).then(function(cached_table) {
+            if (cached_table) {
+                service.ff_value_map[rtype] = cached_table;
+                deferred.resolve(cached_table);
+
+            } else {
+
+                egCore.net.request(
+                        'open-ils.cat',
+                        'open-ils.cat.biblio.fixed_field_values.by_rec_type',
+                        rtype
+                ).then(function (data)  {
+                    service.ff_value_map[rtype] = data;
+                    deferred.resolve(data);
+                    egCore.hatch.setItem(hatch_value_key, data);
+                });
+            }
         });
 
         return deferred.promise;
index 7cc42b3..58b54d2 100644 (file)
@@ -476,39 +476,49 @@ var MARC21 = {
         
             var rtype = this.recordType();
         
-            var val;
-        
+            var done = false;
             if (MARC21.Record._ff_pos[field].ldr && _l) {
                 if (MARC21.Record._ff_pos[field].ldr[rtype]) { // It's in the leader
-                    val = value.substr(0, MARC21.Record._ff_pos[field].ldr[rtype].len);
+                    if (value.length > MARC21.Record._ff_pos[field].ldr[rtype].len)
+                        value = value.substr(0, MARC21.Record._ff_pos[field].ldr[rtype].len);
+                    while (value.length < MARC21.Record._ff_pos[field].ldr[rtype].len)
+                        value += MARC21.Record._ff_pos[field].ldr[rtype].def;
                     this.leader =
                         _l.substring(0, MARC21.Record._ff_pos[field].ldr[rtype].start) +
-                        val +
+                        value +
                         _l.substring(
                             MARC21.Record._ff_pos[field].ldr[rtype].start
                             + MARC21.Record._ff_pos[field].ldr[rtype].len
                         );
+                    done = true;
                 }
             } else if (MARC21.Record._ff_pos[field]._8 && _8) {
                 if (MARC21.Record._ff_pos[field]._8[rtype]) { // Nope, it's in the 008
-                    val = value.substr(0, MARC21.Record._ff_pos[field]._8[rtype].len);
+                    if (value.length > MARC21.Record._ff_pos[field]._8[rtype].len)
+                        value = value.substr(0, MARC21.Record._ff_pos[field]._8[rtype].len);
+                    while (value.length < MARC21.Record._ff_pos[field]._8[rtype].len)
+                        value += MARC21.Record._ff_pos[field]._8[rtype].def;
                     this.field('008').update(
                         _8.substring(0, MARC21.Record._ff_pos[field]._8[rtype].start) +
-                        val +
+                        value +
                         _8.substring(
                             MARC21.Record._ff_pos[field]._8[rtype].start
                             + MARC21.Record._ff_pos[field]._8[rtype].len
                         )
                     );
+                    done = true;
                 }
             }
         
-            if (!val && MARC21.Record._ff_pos[field]._6 && _6) {
+            if (!done && MARC21.Record._ff_pos[field]._6 && _6) {
                 if (MARC21.Record._ff_pos[field]._6[rtype]) { // ok, maybe the 006?
-                    val = value.substr(0, MARC21.Record._ff_pos[field]._6[rtype].len);
+                    if (value.length > MARC21.Record._ff_pos[field]._6[rtype].len)
+                        value = value.substr(0, MARC21.Record._ff_pos[field]._6[rtype].len);
+                    while (value.length < MARC21.Record._ff_pos[field]._6[rtype].len)
+                        value += MARC21.Record._ff_pos[field]._6[rtype].def;
                     this.field('006').update(
                         _6.substring(0, MARC21.Record._ff_pos[field]._6[rtype].start) +
-                        val +
+                        value +
                         _6.substring(
                             MARC21.Record._ff_pos[field]._6[rtype].start
                             + MARC21.Record._ff_pos[field]._6[rtype].len
@@ -517,7 +527,7 @@ var MARC21 = {
                 }
             }
     
-            return val;
+            return value;
         }
 
         this.ready = false;