webstaff: make chron caption directive that can be linked
authorGalen Charlton <gmc@equinoxinitiative.org>
Mon, 12 Jun 2017 16:56:53 +0000 (12:56 -0400)
committerGalen Charlton <gmc@equinoxinitiative.org>
Mon, 12 Jun 2017 16:56:53 +0000 (12:56 -0400)
Signed-off-by: Galen Charlton <gmc@equinoxinitiative.org>
Open-ILS/src/templates/staff/serials/index.tt2
Open-ILS/src/templates/staff/serials/t_chron_selector.tt2 [new file with mode: 0644]
Open-ILS/src/templates/staff/serials/t_prediction_wizard.tt2
Open-ILS/web/js/ui/default/staff/serials/directives/prediction_wizard.js

index 20b8994..b09dca2 100644 (file)
@@ -62,6 +62,13 @@ angular.module('egCoreMod').run(['egStrings', function(s) {
 
     s.CONFIRM_DELETE_MFHDS = "[% l('Delete selected MFHD(s)?') %]";
     s.CONFIRM_DELETE_MFHDS_MESSAGE = "[% l('Will delete {{items}} MFHD(s).') %]";
+
+    s.CHRON_LABEL_YEAR   = "[% l('Year') %]";
+    s.CHRON_LABEL_SEASON = "[% l('Season') %]";
+    s.CHRON_LABEL_MONTH  = "[% l('Month') %]";
+    s.CHRON_LABEL_WEEK   = "[% l('Week') %]";
+    s.CHRON_LABEL_DAY    = "[% l('Day') %]";
+    s.CHRON_LABEL_HOUR   = "[% l('Hour') %]";
 }]);
 </script>
 [% END %]
diff --git a/Open-ILS/src/templates/staff/serials/t_chron_selector.tt2 b/Open-ILS/src/templates/staff/serials/t_chron_selector.tt2
new file mode 100644 (file)
index 0000000..af5a43c
--- /dev/null
@@ -0,0 +1,5 @@
+<select ng-model="ngModel">
+  <option 
+    ng-repeat="c in options track by c.value" value="{{c.value}}"
+    ng-disabled="c.disabled">{{c.label}}</option>
+</select>
index 3dc1bdd..8dd4bdd 100644 (file)
             <div class="col-md-1"></div>
             <div class="col-md-1">[% l('Level [_1]', '{{$index + 1}}')  %]</div>
             <div class="col-md-2">
-              <select ng-model="chron.caption">
-                <option value="year">[% l('Year') %]</option>
-                <option value="season">[% l('Season') %]</option>
-                <option value="month">[% l('Month') %]</option>
-                <option value="week">[% l('Week') %]</option>
-                <option value="day">[% l('Day') %]</option>
-                <option value="hour">[% l('Hour') %]</option>
-              </select>
+              <eg-chron-selector ng-model="chron.caption" chron-level="$index" linked-selector="chron_captions">
             </div>
             <div class="col-md-2">
               <input type="checkbox" ng-model="chron.display_caption"></input>
                 <div class="col-md-1"></div>
                 <div class="col-md-1">[% l('Level [_1]', '{{$index + 1}}')  %]</div>
                 <div class="col-md-2">
-                  <select ng-model="chron.caption">
-                    <option value="year">[% l('Year') %]</option>
-                    <option value="season">[% l('Season') %]</option>
-                    <option value="month">[% l('Month') %]</option>
-                    <option value="week">[% l('Week') %]</option>
-                    <option value="day">[% l('Day') %]</option>
-                    <option value="hour">[% l('Hour') %]</option>
-                  </select>
+                  <eg-chron-selector ng-model="chron.caption" chron-level="$index" linked-selector="alt_chron_captions">
                 </div>
                 <div class="col-md-2">
                   <input type="checkbox" ng-model="chron.display_caption"></input>
index ec743a9..1eafdfc 100644 (file)
@@ -508,6 +508,9 @@ function($scope , $q , egSerialsCoreSvc , egCore , egGridDataProvider) {
         depth        : 0
     };
 
+    $scope.chron_captions = [];
+    $scope.alt_chron_captions = [];
+
     $scope.handle_save = function() {
         $scope.patternCode = JSON.stringify($scope.pattern.compile());
         if ($scope.share.pattern_name !== null) {
@@ -532,6 +535,51 @@ function($scope , $q , egSerialsCoreSvc , egCore , egGridDataProvider) {
     }
 })
 
+.directive('egChronSelector', function() {
+    return {
+        transclude: true,
+        restrict:   'E',
+        scope: {
+            ngModel        : '=',
+            chronLevel     : '=',
+            linkedSelector : '=',
+        },
+        templateUrl: './serials/t_chron_selector',
+        controller:
+       ['$scope','$q','egCore',
+function($scope , $q , egCore) {
+        $scope.options = [
+            { value : 'year',   label : egCore.strings.CHRON_LABEL_YEAR,   disabled: false },
+            { value : 'season', label : egCore.strings.CHRON_LABEL_SEASON, disabled: false },
+            { value : 'month',  label : egCore.strings.CHRON_LABEL_MONTH,  disabled: false },
+            { value : 'week',   label : egCore.strings.CHRON_LABEL_WEEK,   disabled: false },
+            { value : 'day',    label : egCore.strings.CHRON_LABEL_DAY,    disabled: false },
+            { value : 'hour',   label : egCore.strings.CHRON_LABEL_HOUR,   disabled: false }
+        ];
+        var levels = {
+            'year'   : 0,
+            'season' : 1,
+            'month'  : 1,
+            'week'   : 2,
+            'day'    : 3,
+            'hour'   : 4
+        };
+        $scope.$watch('ngModel', function(newVal, oldVal) {
+            $scope.linkedSelector[$scope.chronLevel] = $scope.ngModel;
+        });
+        $scope.$watch('linkedSelector', function(newVal, oldVal) {
+            if ($scope.chronLevel > 0 && $scope.linkedSelector[$scope.chronLevel - 1]) {
+                var level_to_disable = levels[ $scope.linkedSelector[$scope.chronLevel - 1] ];
+                for (var i = 0; i < $scope.options.length; i++) {
+                    $scope.options[i].disabled =
+                        (levels[ $scope.options[i].value ] <= level_to_disable);
+                }
+            }
+        }, true);
+}]
+    }
+})
+
 .directive('egMonthSelector', function() {
     return {
         transclude: true,