LP#1668314 - Webstaff make marcEditor's flateditor checkbox sticky
authorCesar Velez <cesar.velez@equinoxinitiative.org>
Thu, 29 Jun 2017 17:27:40 +0000 (13:27 -0400)
committerGalen Charlton <gmc@equinoxinitiative.org>
Fri, 21 Jul 2017 16:25:36 +0000 (12:25 -0400)
Just followed the same pattern of using $watch and localstorage
to store a boolean for FlatEditor checkbox. Made $scope.flatEditor
be an object wrapping an isEnabled :bool to avoid *future* ng-if
parent scope issues that could (potentially) occur.

Signed-off by: Cesar Velez <cesar.velez@equinoxinitiative.org>

Signed-off-by: Josh Stompro <stomproj@larl.org>
Signed-off-by: Galen Charlton <gmc@equinoxinitiative.org>
Open-ILS/src/templates/staff/cat/share/t_marcedit.tt2
Open-ILS/web/js/ui/default/staff/cat/services/marcedit.js

index d7ed391..c9dfdbc 100644 (file)
@@ -14,7 +14,7 @@
   <div class="pad-vert row marctypesource">
     <div class="col-md-2 form-group" ng-show="!flatOnly">
       <label>
-        <input type="checkbox" ng-model="flatEditor" ng-change="refreshVisual()"/>
+        <input type="checkbox" ng-model="flatEditor.isEnabled" ng-change="refreshVisual()"/>
         [% l('Flat Text Editor') %]
       </label>
     </div>
     </div>
   </div>
 
-  <div ng-show="flatEditor">
+  <div ng-show="flatEditor.isEnabled">
     <textarea class="marcflateditor" cols="120" rows="40" ng-model="flat_text_marc" ng-blur="saveFlatTextMARC()"></textarea>
   </div>
-  <div ng-show="!flatEditor">
+  <div ng-show="!flatEditor.isEnabled">
     <div class="row pad-vert">
       <div class="marcffeditor">
         <div class="row col-md-12">
index 1e9460b..fb3a05a 100644 (file)
@@ -666,7 +666,17 @@ angular.module('egMarcMod', ['egCoreMod', 'ui.bootstrap'])
                 $scope.enable_fast_add = false;
                 $scope.fast_item_callnumber = '';
                 $scope.fast_item_barcode = '';
-                $scope.flatEditor = $scope.flatOnly ? true : false;
+                
+                $scope.flatEditor = { isEnabled : $scope.flatOnly ? true : false };
+                
+                egCore.hatch.getItem('cat.marcedit.flateditor').then(function(val) {
+                    $scope.flatEditor.isEnabled = val;
+                });
+                
+                $scope.$watch('flatEditor.isEnabled', function (newVal, oldVal) {
+                    if (newVal != oldVal) egCore.hatch.setItem('cat.marcedit.flateditor', newVal);
+                });
+
                 $scope.brandNewRecord = false;
                 $scope.bib_source = null;
                 $scope.record_type = $scope.recordType || 'bre';
@@ -696,7 +706,7 @@ angular.module('egMarcMod', ['egCoreMod', 'ui.bootstrap'])
                 };
 
                 $scope.refreshVisual = function () {
-                    if (!$scope.flatEditor) {
+                    if (!$scope.flatEditor.isEnabled) {
                         $scope.controlfields = $scope.record.fields.filter(function(f){ return f.isControlfield() });
                         $scope.datafields = $scope.record.fields.filter(function(f){ return !f.isControlfield() });
                     }