From eba7e511eb4338a71ec954ce8ff6e69356bda558 Mon Sep 17 00:00:00 2001 From: Galen Charlton Date: Thu, 13 Oct 2016 18:08:30 -0400 Subject: [PATCH] teach egGridFields how to compile column tempates This adds two optional attributes to eg-grid-field: compiled: if present, treat the template inside the element as a template to be compiled handlers: if present, contains an object with a bucket of functions (or whatever) that can be invoked inside the template as "col.handlers.foo" Signed-off-by: Galen Charlton --- Open-ILS/src/templates/staff/share/t_autogrid.tt2 | 8 ++++-- Open-ILS/web/js/ui/default/staff/services/grid.js | 35 ++++++++++++++++++++++- 2 files changed, 40 insertions(+), 3 deletions(-) diff --git a/Open-ILS/src/templates/staff/share/t_autogrid.tt2 b/Open-ILS/src/templates/staff/share/t_autogrid.tt2 index cf5ac460a2..e8124dd7b0 100644 --- a/Open-ILS/src/templates/staff/share/t_autogrid.tt2 +++ b/Open-ILS/src/templates/staff/share/t_autogrid.tt2 @@ -203,7 +203,7 @@
-
+
@@ -338,10 +338,14 @@ - + + + diff --git a/Open-ILS/web/js/ui/default/staff/services/grid.js b/Open-ILS/web/js/ui/default/staff/services/grid.js index 96c4a9eda9..61e495cbba 100644 --- a/Open-ILS/web/js/ui/default/staff/services/grid.js +++ b/Open-ILS/web/js/ui/default/staff/services/grid.js @@ -1104,7 +1104,12 @@ angular.module('egGridMod', // optional: for non-IDL columns, specifying a datatype // lets the caller control which display filter is used. // datatype should match the standard IDL datatypes. - datatype : '@' + datatype : '@', + + // optional hash of functions that can be imported into + // the directive's scope; meant for cases where the "compiled" + // attribute is set + handlers : '=' }, link : function(scope, element, attrs, egGridCtrl) { @@ -1112,6 +1117,7 @@ angular.module('egGridMod', angular.forEach( [ 'visible', + 'compiled', 'hidden', 'sortable', 'nonsortable', @@ -1378,6 +1384,8 @@ angular.module('egGridMod', linkpath : colSpec.linkpath, template : colSpec.template, visible : colSpec.visible, + compiled : colSpec.compiled, + handlers : colSpec.handlers, hidden : colSpec.hidden, datatype : colSpec.datatype, sortable : colSpec.sortable, @@ -1901,6 +1909,31 @@ angular.module('egGridMod', }; }) +/* https://stackoverflow.com/questions/17343696/adding-an-ng-click-event-inside-a-filter/17344875#17344875 */ +.directive('compile', ['$compile', function ($compile) { + return function(scope, element, attrs) { + // pass through column defs from grid cell's scope + scope.col = scope.$parent.col; + scope.$watch( + function(scope) { + // watch the 'compile' expression for changes + return scope.$eval(attrs.compile); + }, + function(value) { + // when the 'compile' expression changes + // assign it into the current DOM + element.html(value); + + // compile the new DOM and link it to the current + // scope. + // NOTE: we only compile .childNodes so that + // we don't get into infinite loop compiling ourselves + $compile(element.contents())(scope); + } + ); + }; +}]) + /** -- 2.11.0