From: Galen Charlton Date: Wed, 10 May 2017 21:36:44 +0000 (-0400) Subject: webstaff: teach egEditFmRecord how to use custom template for a field X-Git-Url: https://old-git.evergreen-ils.org/?a=commitdiff_plain;h=2c8ac103191c8e17feae297b6083ea2528721147;p=working%2FEvergreen.git webstaff: teach egEditFmRecord how to use custom template for a field Signed-off-by: Galen Charlton --- diff --git a/Open-ILS/src/templates/staff/share/t_fm_record_editor.tt2 b/Open-ILS/src/templates/staff/share/t_fm_record_editor.tt2 index f7a7a6ed21..2b7788ce3b 100644 --- a/Open-ILS/src/templates/staff/share/t_fm_record_editor.tt2 +++ b/Open-ILS/src/templates/staff/share/t_fm_record_editor.tt2 @@ -11,47 +11,52 @@
- {{rec[field.name]()}} - - - - - - - - - - + + + + - + + + + + + + + - -
diff --git a/Open-ILS/web/js/ui/default/staff/services/fm_record_editor.js b/Open-ILS/web/js/ui/default/staff/services/fm_record_editor.js index be048444a7..5c62eb3fca 100644 --- a/Open-ILS/web/js/ui/default/staff/services/fm_record_editor.js +++ b/Open-ILS/web/js/ui/default/staff/services/fm_record_editor.js @@ -16,6 +16,14 @@ angular.module('egFmRecordEditorMod', // record ID to update recordId : '=', + // fields with custom templates + // hash keyed on field name; may contain + // template - Angular template; should access + // field value using rec_flat[field.name] + // handlers - any functions you want to pass + // in to the custom template + customFieldTemplates : '=', + // comma-separated list of fields that should not be // displayed hiddenFields : '@', @@ -74,6 +82,7 @@ angular.module('egFmRecordEditorMod', $scope.record_label = egCore.idl.classes[$scope.idlClass].label; $scope.rec_orgs = {}; + $scope.rec_flat = {}; $scope.rec_org_values = {}; if ($scope.mode == 'update') { @@ -110,6 +119,12 @@ angular.module('egFmRecordEditorMod', rec[field.name]('f'); } } + // retrieve values from any fields controlled + // by custom templates, which for the moment all + // expect to be passed an ordinary flat value + if (field.name in $scope.rec_flat) { + rec[field.name]($scope.rec_flat[field.name]); + } }); } @@ -166,6 +181,12 @@ angular.module('egFmRecordEditorMod', $scope.rec_org_values[field.name] = $scope.rec_orgs[field.name](); } } + if (field.name in $scope.customFieldTemplates) { + field.use_custom_template = true; + field.custom_template = $scope.customFieldTemplates[field.name].template; + field.handlers = $scope.customFieldTemplates[field.name].handlers; + $scope.rec_flat[field.name] = $scope.rec[field.name](); + } }); return fields.filter(function(field) { return !(field.name in $scope.hidden) }); } @@ -189,3 +210,17 @@ angular.module('egFmRecordEditorMod', }] }; }) + +.directive('egFmCustomFieldInput', function($compile) { + return { + restrict : 'E', + scope : { + template : '=', + handlers : '=' + }, + link : function(scope, element, attrs) { + element.html(scope.template); + $compile(element.contents())(scope.$parent); + } + }; +})