replace grid linkpath w/ support for inline, ad-hoc cell templates
authorBill Erickson <berick@esilibrary.com>
Mon, 19 May 2014 18:26:52 +0000 (14:26 -0400)
committerBill Erickson <berick@esilibrary.com>
Mon, 19 May 2014 18:26:52 +0000 (14:26 -0400)
Signed-off-by: Bill Erickson <berick@esilibrary.com>
Open-ILS/src/templates/staff/cat/item/t_list.tt2
Open-ILS/src/templates/staff/circ/patron/t_items_out.tt2
Open-ILS/src/templates/staff/share/t_autogrid.tt2
Open-ILS/web/js/ui/default/staff/services/grid.js

index 220a853..e472107 100644 (file)
   <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>
 
-  <!-- linkpath value must be a quoted string to avoid compile-time 
-      interpolation, hence the &quot;'s -->
   <eg-grid-field label="[% l('Title') %]"       
-    path="call_number.record.simple_record.title" visible
-    linkpath="&quot;[% ctx.base_path %]/opac/record/{{item['call_number.record.id']}}&quot;">
+    path="call_number.record.simple_record.title" visible>
+    <a href="[% ctx.base_path %]/opac/record/{{item['call_number.record.id']}}">
+      {{item['call_number.record.simple_record.title']}}
+    </a>
   </eg-grid-field>
 </eg-grid>
 
index d381e32..9fbd09b 100644 (file)
@@ -8,16 +8,19 @@
   items-provider="gridDataProvider"
   persist-key="circ.patron.items_out">
   <eg-grid-field label="[% l('Circ ID') %]" path='id' visible></eg-grid-field>
-  <eg-grid-field label="[% l('Barcode') %]" path='target_copy.barcode' 
-    visible linkpath="'./cat/item/{{item.target_copy().id()}}'">
+  <eg-grid-field label="[% l('Barcode') %]" path='target_copy.barcode' visible>
+    <a href="./cat/item/{{item.target_copy().id()}}" target="_self">
+      {{item.target_copy().barcode()}}
+    </a>
   </eg-grid-field>
   <eg-grid-field label="[% l('Due Date') %]" path='due_date' visible></eg-grid-field>
   <eg-grid-field label="[% l('Checkout / Renewal Library') %]" path='circ_lib.shortname' visible></eg-grid-field>
   <eg-grid-field label="[% l('Renewals Remaining') %]" path='renewal_remaining' visible></eg-grid-field>
   <eg-grid-field label="[% l('Fines Stopped') %]" path='stop_fines' visible></eg-grid-field>
-  <eg-grid-field label="[% l('Title') %]" 
-    path='target_copy.call_number.record.simple_record.title' visible
-    linkpath="'[% ctx.base_path %]/opac/record/{{item.target_copy().call_number().record().id()}}'">
+  <eg-grid-field label="[% l('Title') %]" name="title" visible>
+    <a href="[% ctx.base_path %]/opac/record/{{item.target_copy().call_number().record().id()}}">
+      {{item.target_copy().call_number().record().simple_record().title()}}
+    </a>
   </eg-grid-field>
 </eg-grid>
 
index 06e8546..b48d61d 100644 (file)
           ng-repeat="col in columns"
           style="flex:{{col.flex}}"
           ng-show="col.visible">
-          
-          <!-- TODO: add support for configurable intra-app routing via 
-               linkpath. i.e. don't always assume target=_self -->
-          <a ng-if="col.linkpath" target="_self"
-            ng-href="{{generateLinkPath(col, item)}}">
-            {{itemFieldValue(item, col)}}
-          </a>
-          <span ng-if="!col.linkpath">
+
+          <!-- if the cell comes with its own template,
+               translate that content into HTML and insert it here -->
+          <span ng-if="col.template" 
+            ng-bind-html="translateCellTemplate(col, item)">
+          </span>
+
+          <!-- otherwise, simply display the item value, which may 
+               pass through datatype-specific filtering. -->
+          <span ng-if="!col.template">
             {{itemFieldValue(item, col)}}
           </span>
       </div>
index 5051681..0ca633b 100644 (file)
@@ -85,9 +85,9 @@ angular.module('egGridMod',
 
         controller : [
                     '$scope','$q','egCore','egGridFlatDataProvider',
-                    'egGridColumnsProvider','$filter','$window',
+                    'egGridColumnsProvider','$filter','$window','$sce',
             function($scope,  $q , egCore,  egGridFlatDataProvider,  
-                     egGridColumnsProvider , $filter , $window) {
+                     egGridColumnsProvider , $filter , $window , $sce) {
 
             var grid = this;
 
@@ -668,6 +668,16 @@ angular.module('egGridMod',
                 return egCore.strings.$replace(col.linkpath, {item : item});
             }
 
+            // If a column provides its own HTML template, translate it,
+            // using the current item for the template scope.
+            // note: $sce is required to avoid security restrictions and
+            // is OK here, since the template comes directly from a
+            // local HTML template (not user input).
+            $scope.translateCellTemplate = function(col, item) {
+                var html = egCore.strings.$replace(col.template, {item : item});
+                return $sce.trustAsHtml(html);
+            }
+
             $scope.collect = function() { grid.collect() }
 
             // asks the dataProvider for a page of data
@@ -705,13 +715,6 @@ angular.module('egGridMod',
             path  : '@', // optional; flesh path
             label : '@', // optional; display label
             flex  : '@',  // optional; default flex width
-
-            // optional: url path string for generating links from grid cells.
-            // The path must be a quoted string and may include interpolation 
-            // expressions.  e.g.
-            // linkpath="'./cat/item/{{item.id()}}'"
-            linkpath : '=', 
-            
         },
         link : function(scope, element, attrs, egGridCtrl) {
 
@@ -731,6 +734,7 @@ angular.module('egGridMod',
                         scope[field] = true;
                 }
             );
+            scope.template = element.html();
             egGridCtrl.columnsProvider.add(scope);
             scope.$destroy();
         }
@@ -843,6 +847,7 @@ angular.module('egGridMod',
                 sort  : Number(colSpec.sort) || 0,
                 required : colSpec.required,
                 linkpath : colSpec.linkpath,
+                template : colSpec.template,
                 visible  : colSpec.visible,
                 hidden   : colSpec.hidden,
                 datatype : colSpec.datatype,