item status UI continued; broken ATM
authorBill Erickson <berick@esilibrary.com>
Thu, 15 May 2014 02:32:16 +0000 (22:32 -0400)
committerBill Erickson <berick@esilibrary.com>
Thu, 15 May 2014 02:32:16 +0000 (22:32 -0400)
Signed-off-by: Bill Erickson <berick@esilibrary.com>
Open-ILS/src/templates/staff/cat/item/index.tt2
Open-ILS/src/templates/staff/cat/item/t_list.tt2
Open-ILS/web/js/ui/default/staff/cat/item/app.js
Open-ILS/web/js/ui/default/staff/services/idl.js

index 2e99a90..7a774df 100644 (file)
 <script src="[% ctx.media_prefix %]/js/ui/default/staff/cat/item/app.js"></script>
 [% END %]
 
-<h1>search bar goes here</h1>
+<style>
+  /* FIXME: MOVE ME */
+  #item-status-barcode {width: 16em;}
+  #item-status-form { 
+    padding-bottom: 10px; 
+    margin-bottom: 10px; 
+    border-bottom: 1px solid #CCC; 
+  }
+</style>
+
+<h1>[% l('Scan Item') %]</h1>
+
+<form id="item-status-form" ng-submit="fetchCopy(args)" role="form">
+  <div class="row">
+    <div class="col-md-6">
+      <div class="input-group">
+        <input type="text" id="item-status-barcode" focus-me="focusBarcode"
+          class="form-control" ng-model="args.barcode">
+        <input class="btn btn-default" 
+          type="submit" value="[% l('Submit') %]"/>
+      </div><!-- input group -->
+    </div><!-- col -->
+  </div><!-- row -->
+</form>
 
 <div ng-view></div>
 
index 7b02743..316a9f0 100644 (file)
@@ -1 +1,13 @@
-<h1>LIST</h1>
+<eg-grid
+  id-field="id"
+  idl-class="acp"
+  features="-display,-sort,-multisort"
+  main-label="[% l('Item Status') %]"
+  items-provider="gridDataProvider"
+  persist-key="cat.items">
+  <eg-grid-field label="[% l('Barcode') %]"     path='barcode' visible></eg-grid-field>
+  <eg-grid-field label="[% l('Call Number') %]" path="call_number.label" visible></eg-grid-field>
+  <eg-grid-field label="[% l('Location') %]"    path="location.name" visible></eg-grid-field>
+  <eg-grid-field label="[% l('Title') %]"       path="call_number.record.simple_record.title" visible></eg-grid-field>
+</eg-grid>
+
index 3699fbb..c36e621 100644 (file)
@@ -33,9 +33,63 @@ angular.module('egItemStatus',
  * Parent scope for list and detail views
  */
 .controller('SearchCtrl', 
-       ['$scope','$location','egCore',
-function($scope , $location , egCore) {
-//    $location.path('/cat/item/view/' + 46879);
+       ['$scope','$location','egCore','egGridDataProvider',
+function($scope , $location , egCore , egGridDataProvider) {
+    
+    $scope.focusBarcode = true;
+    var copies = [];
+
+    var provider = egGridDataProvider.instance({});
+    provider.get = function(offset, count) {
+        return provider.arrayNotifier(copies, offset, count);
+    }
+    provider.itemFieldValue = provider.flatItemFieldValue;
+    $scope.gridDataProvider = provider;
+
+    $scope.searchCopy = function(args) {
+        $scope.fetchCopy(args.barcode)
+        .then(function(copy) {
+            if (copy) {
+                copies.unshift(egCore.idl.toHash(copy, true));
+                provider.increment();
+            } else {
+                $scope.copyNotFound = true;
+            }
+        });
+    }
+
+    $scope.fetchCopy(barcode, id) {
+        var flesh = {   
+            flesh : 3, 
+            flesh_fields : {
+                acp : ['call_number','location','status','location'],
+                acn : ['record'],
+                bre : ['simple_record','creator','editor']
+            },
+            select : { 
+                // avoid fleshing MARC on the bre
+                // note: don't add simple_record.. not sure why
+                bre : ['id','tcn_value','creator','editor'],
+            } 
+        };
+
+        var promise;
+        
+        if (barcode) {
+            promise = egCore.pcrud.search('acp', 
+                {barcode : barcode, deleted : 'f'}, flesh);
+        } else {
+            promise = egCore.pcrud.retrieve('acp', id, flesh);
+        }
+
+        promise.then(function(copy) { 
+            if (!copy) {
+                $scope.copyNotFound = true;
+                return;
+            }
+            return egCore.idl.toHash(copy, true) 
+        });
+    }
 }])
 
 /**
@@ -60,27 +114,12 @@ function($scope , $location , $routeParams , egCore) {
     // TODO: cache data per copy
 
     function loadCopy() {
-
-        egCore.pcrud.retrieve('acp', copyId, {   
-            flesh : 3, 
-            flesh_fields : {
-                acp : ['call_number','location','status','location'],
-                acn : ['record'],
-                bre : ['simple_record','creator','editor']
-            },
-
-            select : { 
-                // avoid fleshing MARC on the bre
-                // note: don't add simple_record.. not sure why
-                bre : ['id','tcn_value','creator','editor'],
-            } 
+        $scope.fetchCopy(null, copyId)
 
         }).then(function(copy) {
+            if (!copy) return;
 
-            if (!copy) {
-                $scope.copyNotFound = true;
-                return;
-            }
+            // TODO: FLATTEN EVERYTHING
 
             // locally flesh org units
             copy.circ_lib(egCore.org.get(copy.circ_lib()));
@@ -130,16 +169,6 @@ function($scope , $location , $routeParams , egCore) {
                     egCore.auth.token(), circ.id()
                 ).then(function(summary) {
                     $scope.circ_summary = summary;
-
-                    console.log(js2JSON(summary));
-                    console.log(summary.last_checkin_workstation());
-
-                    angular.forEach(egCore.idl.classes.accs.field_map,
-                        function(val, key) {
-                            console.log(key + ' => ' + summary[key]());
-
-                        }
-                    );
                 });
             }
         });
index f18e60f..8ad4b66 100644 (file)
@@ -59,13 +59,41 @@ angular.module('egCoreMod')
             mkclass(cls, service.classes[cls].fields);
     };
 
-    service.toHash = function(obj) {
+    /**
+     * Generate a hash version of an IDL object.
+     *
+     * Flatten determines if nested objects should be squashed into
+     * the top-level hash.
+     *
+     * If 'flatten' is false, e.g.:
+     *
+     * {"call_number" : {"label" :  "foo"}}
+     *
+     * If 'flatten' is true, e.g.:
+     *
+     * e.g.  {"call_number.label" : "foo"}
+     */
+    service.toHash = function(obj, flatten) {
         var hash = {};
         angular.forEach(
             service.classes[obj.classname].fields, 
             function(field) { 
-                if (field.virtual) return;
-                hash[field.name] = obj[field.name]() 
+                var val = obj[field.name]();
+                if (val === null || val === undefined) return;
+
+                if (angular.isObject(val) && val._isfieldmapper) {
+                    if (flatten) {
+                        var subhash = service.toHash(val, true);
+                        angular.forEach(subhash, function(val, key) {
+                            var fname = field.name + '.' + key;
+                            hash[fname] = val;
+                        });
+                    } else {
+                        hash[field.name] = service.toHash(val);
+                    }
+                } else {
+                    hash[field.name] = val;
+                }
             }
         )
         return hash;