From 4fce3581676354c4348490d4a96cf0d457463370 Mon Sep 17 00:00:00 2001 From: Bill Erickson Date: Fri, 12 Jul 2019 10:14:18 -0400 Subject: [PATCH] Revert "LP1825851 AngJS tries server-managed templates first" This reverts commit 8d7eface94bbf13bafd444d09bacde366a3b96df. --- Open-ILS/web/js/ui/default/staff/services/print.js | 75 +++++++++------------- 1 file changed, 29 insertions(+), 46 deletions(-) diff --git a/Open-ILS/web/js/ui/default/staff/services/print.js b/Open-ILS/web/js/ui/default/staff/services/print.js index fe36a30769..8c2ddcab55 100644 --- a/Open-ILS/web/js/ui/default/staff/services/print.js +++ b/Open-ILS/web/js/ui/default/staff/services/print.js @@ -22,10 +22,6 @@ function($q , $window , $timeout , $http , egHatch , egAuth , egIDL , egOrg , eg service.template_base_path = 'share/print_templates/t_'; service.server_template_path = '/print_template'; - // Cache of template names that are known to be generated from - // traditional TT2 files instead of being server-manged. - service.localTemplates = {}; - /* * context : 'default', 'receipt','label', etc. * scope : data loaded into the template environment @@ -81,14 +77,7 @@ function($q , $window , $timeout , $http , egHatch , egAuth , egIDL , egOrg , eg content: xhttp.responseText, contentType: this.getResponseHeader('content-type') }); - - } else if (this.status === 404) { - console.debug('Template ' + templateName + ' is not ' - + 'hosted on the server; using local template'); - reject(); - } else { - // other error reject('Error compiling print template'); } } @@ -249,24 +238,6 @@ function($q , $window , $timeout , $http , egHatch , egAuth , egIDL , egOrg , eg }); } - - service.getTt2PrintTemplate = function(name) { - var path = service.template_base_path + name; - console.debug('fetching TT2 print template: ' + path); - - return $http.get(path).then( - function(data) { - console.debug('Found server template file for ' + name); - service.localTemplates[name] = true; - return data.data; - }, - function() { - console.error('unable to locate print template: ' + name); - return $q.reject(); - } - ); - } - // loads an HTML print template by name from the server If no // template is available in local/hatch storage, fetch the template // as an HTML file from the server. if no HTML file is available, @@ -285,26 +256,38 @@ function($q , $window , $timeout , $http , egHatch , egAuth , egIDL , egOrg , eg return; } - if (service.localTemplates[name]) { - service.getTt2PrintTemplate(name) - .then(deferred.resolve, deferred.reject); - return; - } + var path = service.template_base_path + name; + console.debug('fetching template ' + path); + + $http.get(path).then( + function(data) { + + if (data.data.match(/Print Template Not Found/)) { + + // AngJS templates return a dummy template w/ the + // above text if the template is not found instead + // of a 404. + return service.compileRemoteTemplate(name, args.scope) + .then( + function(response) { + console.debug('Found server-hosted template for ' + name); + args.content_type = response.contentType; + args.content = response.content; + deferred.resolve(args.content); + }, + function() { + console.error('unable to locate print template: ' + name); + deferred.reject(); + } + ); + } - // Template may be TT2 or server-managed. - // Try server-managed first, then fall back to TT2. - return service.compileRemoteTemplate(name, args.scope) - .then( - function(response) { - console.debug('Found server-hosted template for ' + name); - args.content_type = response.contentType; - args.content = response.content; - deferred.resolve(args.content); + console.debug('Found server template file for ' + name); + deferred.resolve(data.data) }, function() { - console.debug('Template ' + name + ' is not server-managed'); - service.getTt2PrintTemplate(name) - .then(deferred.resolve, deferred.reject); + console.error('unable to locate print template: ' + name); + deferred.reject(); } ); }); -- 2.11.0