From: Galen Charlton Date: Thu, 13 Oct 2016 22:08:30 +0000 (-0400) Subject: teach egGridFields how to compile column tempates X-Git-Url: https://old-git.evergreen-ils.org/?a=commitdiff_plain;h=ed86e1a3758eb8fee490c4219e9fd838ff6330f0;p=working%2FEvergreen.git 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 Signed-off-by: Galen Charlton --- diff --git a/Open-ILS/src/templates/staff/share/t_autogrid.tt2 b/Open-ILS/src/templates/staff/share/t_autogrid.tt2 index e8f94d77bd..3767213b66 100644 --- a/Open-ILS/src/templates/staff/share/t_autogrid.tt2 +++ b/Open-ILS/src/templates/staff/share/t_autogrid.tt2 @@ -208,7 +208,7 @@
-
+
@@ -343,10 +343,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 fab8679d69..b9def0f31d 100644 --- a/Open-ILS/web/js/ui/default/staff/services/grid.js +++ b/Open-ILS/web/js/ui/default/staff/services/grid.js @@ -1212,7 +1212,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) { @@ -1220,6 +1225,7 @@ angular.module('egGridMod', angular.forEach( [ 'visible', + 'compiled', 'hidden', 'sortable', 'nonsortable', @@ -1487,6 +1493,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, @@ -2025,6 +2033,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); + } + ); + }; +}]) + /**