browser staff : prefs page shows local and remote prefs
authorBill Erickson <berick@esilibrary.com>
Fri, 25 Apr 2014 14:52:35 +0000 (10:52 -0400)
committerBill Erickson <berick@esilibrary.com>
Fri, 25 Apr 2014 14:52:35 +0000 (10:52 -0400)
Signed-off-by: Bill Erickson <berick@esilibrary.com>
Open-ILS/src/templates/staff/admin/workstation/t_stored_prefs.tt2
Open-ILS/web/js/ui/default/staff/admin/workstation/app.js

index 0efa9cf..dc031b4 100644 (file)
@@ -22,32 +22,44 @@ Click on the delete (X) button to remove a preference's value.
   </div>
 
   <div class="row">
-
-    <!-- key list -->
     <div class="col-md-4">
-      <div class="row" ng-repeat="key in keys">
-        <div class="col-md-1">{{$index + 1}}.</div>
-        <div class="col-md-8 stored-prefs-key" 
-          ng-class="{selected : currentKey == key}">
-          <a href='' ng-click="selectKey(key)">{{key}}</a>
-        </div>
-        <div class="col-md-1">
-          <!-- padding to give the buttom some overflow space -->
-        </div>
-        <div class="col-md-1" class="stored-prefs-remove-button">
-          <button class="btn btn-default btn-danger"
-            ng-class="{disabled : !userHasDeletePerm}"
-            ng-click="removeKey(key)" title="[% l('Remove Item') %]">
-            <span class="glyphicon glyphicon-remove"></span>
-          </button>
-        </div>
-      </div><!-- row -->
+
+      <ul class="nav nav-tabs">
+        <li ng-class="{active : context == 'local'}">
+          <a href='' ng-click="setContext('local')">[% l('Local Prefs') %]</a>
+        </li>
+        <li ng-class="{active : context == 'remote'}">
+          <a href='' ng-click="setContext('remote')">[% l('Remote Prefs') %]</a>
+        </li>
+      </ul>
+      <div class="tab-content">
+        <div class="tab-pane active">
+
+          <div class="row" ng-repeat="key in keys[context]">
+            <div class="col-md-1">{{$index + 1}}.</div>
+            <div class="col-md-8 stored-prefs-key" 
+              ng-class="{selected : currentKey == key}">
+              <a href='' ng-click="selectKey(key)">{{key}}</a>
+            </div>
+            <div class="col-md-1">
+              <!-- padding to give the buttom some overflow space -->
+            </div>
+            <div class="col-md-1" class="stored-prefs-remove-button">
+              <button class="btn btn-default btn-danger"
+                ng-class="{disabled : !userHasDeletePerm}"
+                ng-click="removeKey(key)" title="[% l('Remove Item') %]">
+                <span class="glyphicon glyphicon-remove"></span>
+              </button>
+            </div>
+          </div><!-- row -->
+
+        </div><!-- tab pane -->
+      </div><!-- tab content -->
     </div><!-- col -->
 
-    <!-- content -->
     <div class="col-md-8">
       <pre>{{getCurrentKeyContent()}}</pre>
-    </div>
+    </div><!-- col -->
 
   </div><!-- row -->
 </div><!-- container -->
index 54c4821..743c9af 100644 (file)
@@ -168,38 +168,49 @@ function($scope , egPrintStore) {
 }])
 
 .controller('StoredPrefsCtrl',
-       ['$scope','egUser','egPrintStore','egConfirmDialog','egAppStrings',
-function($scope , egUser , egPrintStore , egConfirmDialog , egAppStrings) {
+       ['$scope','egUser','egPrintStore','egConfirmDialog','egAppStrings','$q',
+function($scope , egUser , egPrintStore , egConfirmDialog , egAppStrings , $q) {
     console.log('StoredPrefsCtrl');
 
+    $scope.setContext = function(ctx) {
+        $scope.context = ctx;
+    }
+    $scope.setContext('local');
+
+    // grab the edit perm
     $scope.userHasDeletePerm = false;
     egUser.hasPermHere('DELETE_WORKSTATION_PREFS')
     .then(function(bool) { $scope.userHasDeletePerm = bool });
 
+    // fetch the keys
+
     function refreshKeys() {
-        egPrintStore.getKeys()
-        .then(function(keys) { $scope.keys = keys.sort() })
+        $scope.keys = {local : [], remote : []};
+
+        egPrintStore.getRemoteKeys().then(
+            function(keys) { $scope.keys.remote = keys.sort() })
+    
+        // local calls are non-async
+        $scope.keys.local = egPrintStore.getLocalKeys();
     }
     refreshKeys();
 
     $scope.selectKey = function(key) {
         $scope.currentKey = key;
         $scope.currentKeyContent = null;
-        egPrintStore.getItem(key)
-        .then(function(content) {
-            $scope.currentKeyContent = content
-        });
+
+        if ($scope.context == 'local') {
+            $scope.currentKeyContent = egPrintStore.getLocalItem(key);
+        } else {
+            egPrintStore.getRemoteItem(key)
+            .then(function(content) {
+                $scope.currentKeyContent = content
+            });
+        }
     }
 
     $scope.getCurrentKeyContent = function() {
-        try {
-            // if the content is JSON-encoded (most), re-stringify
-            // with the pretty printer.
-            return JSON.stringify($scope.currentKeyContent, null, 2);
-        } catch(E) {
-            // otherwise, return the bare value
-            return $scope.currentKeyContent;
-        }
+        return JSON.stringify($scope.currentKeyContent, null, 2);
     }
 
     $scope.removeKey = function(key) {
@@ -207,17 +218,16 @@ function($scope , egUser , egPrintStore , egConfirmDialog , egAppStrings) {
             egAppStrings.PREFS_REMOVE_KEY_CONFIRM, '',
             {   deleteKey : key,
                 ok : function() {
-                    egPrintStore.removeItem(key)
-                    .then(function() { 
-                        // delete succeeded, remove item from list
-                        $scope.keys = $scope.keys.filter(
-                            function(k) { return k != key }
-                        );
-                    });
+                    if ($scope.context == 'local') {
+                        egPrintStore.removeLocalItem(key);
+                        refreshKeys();
+                    } else {
+                        egPrintStore.removeItem(key)
+                        .then(function() { refreshKeys() });
+                    }
                 },
                 cancel : function() {} // user canceled, nothing to do
             }
         );
     }
 }])
-