From: Galen Charlton Date: Wed, 16 Nov 2016 02:20:24 +0000 (-0500) Subject: webstaff: teach egJsonExporter about generators X-Git-Url: https://old-git.evergreen-ils.org/?a=commitdiff_plain;h=df4972887b8249bc9d078b32152d8f7aec58aa41;p=evergreen%2Fmasslnc.git webstaff: teach egJsonExporter about generators This patch adds an attribute called 'generator' to the eg-json-exporter directive as an alternative to using 'container' to pass a JavaScript object. 'generator' should be a function that returns a promise with the data to be exported. Signed-off-by: Galen Charlton Signed-off-by: Kathy Lussier --- diff --git a/Open-ILS/web/js/ui/default/staff/services/file.js b/Open-ILS/web/js/ui/default/staff/services/file.js index 473f4feba6..83e0d295d8 100644 --- a/Open-ILS/web/js/ui/default/staff/services/file.js +++ b/Open-ILS/web/js/ui/default/staff/services/file.js @@ -31,12 +31,20 @@ angular.module('egCoreMod') return { scope: { container: '=', + generator: '=', defaultFileName: '=' }, link: function (scope, element, attributes) { element.bind('click', function (clickEvent) { - var data = new Blob([JSON.stringify(scope.container)], {type : 'application/json'}); - FileSaver.saveAs(data, scope.defaultFileName); + if (scope.generator) { + scope.generator().then(function(value) { + var data = new Blob([JSON.stringify(value)], {type : 'application/json'}); + FileSaver.saveAs(data, scope.defaultFileName); + }); + } else { + var data = new Blob([JSON.stringify(scope.container)], {type : 'application/json'}); + FileSaver.saveAs(data, scope.defaultFileName); + } }); } }