Commit 61ceb6888afbc8096cd45f3674991f63dbfa6635

Authored by luis.camargo
1 parent 8347ab0d
Exists in master

redmine #4856 Criando método para visualizar relatório via requisição http post;

cit-portal-web/src/main/webapp/assets/js/angular/custom/controller/AppController.js
... ... @@ -756,35 +756,33 @@ citApp.controller('AppController', ['$scope', '$routeParams', '$timeout', '$loca
756 756 $scope.setLoadingRelatorio(true);
757 757 $http.get(url, {responseType:'arraybuffer'}).success(function (response) {
758 758  
759   - var file = new Blob([response], {type: 'application/pdf'});
760   - var fileURL = URL.createObjectURL(file);
761   -
762   - $scope.idRelatorio = ++idRelatorioCount;
763   -
764   - $scope.arrayContentReports[$scope.idRelatorio] = angular.copy($sce.trustAsResourceUrl(fileURL));
765   -
766   - obterWorskspaceAtiva();
767   - $timeout(function(){
768   - $scope.addNewWorkspace(titleTab, "relatorioTab.html", true, $scope.workspaceAtiva ? $scope.workspaceAtiva.classePagina : classePaginaPortal , undefined, undefined, undefined, $scope.idRelatorio);
769   -
770   - $timeout(function(){
  759 + abrirRelatorio(response, titleTab);
  760 + }).error(function(data, status){
  761 + if(status == 412){
  762 + $scope.showAlert("warning", $translate.instant("PORTAL.MSG.RELATORIO_SEM_DADOS") + " ", false );
  763 + } else{
  764 + $scope.showAlert("error", $translate.instant("PORTAL.MSG.ERRO_RELATORIO") + " ", false );
  765 + }
  766 + $scope.setLoading(false);
771 767  
772   - var relatorios = $scope.workspaces.filter(function(f){
773   - return f.idRelatorio === $scope.idRelatorio;
774   - });
  768 + });
  769 + };
  770 +
  771 + $scope.visualizarRelatorioPost = function(url, data, titleTab) {
775 772  
776   - if(relatorios && relatorios.length > 0){
777   - $scope.activeWorkspace(relatorios[0]);
778   - } else{
779   - $scope.workspaces.splice($scope.workspaces.length - 1, 1);
780   - $scope.showAlert("error", $translate.instant("PORTAL.MSG.ERRO_RELATORIO") + " ", false );
781   - }
  773 + $scope.titleReport = titleTab;
782 774  
783   - $scope.setLoading(false);
784   - }, 2000);
  775 + var info = getAcrobatInfo();
  776 + if(info.acrobat){
  777 + data.download = false;
  778 + }else{
  779 + data.download = true;
  780 + }
785 781  
786   - });
  782 + $scope.setLoadingRelatorio(true);
  783 + $http.post(url, data, {responseType:'arraybuffer'}).success(function (response) {
787 784  
  785 + abrirRelatorio(response, titleTab);
788 786 }).error(function(data, status){
789 787 if(status == 412){
790 788 $scope.showAlert("warning", $translate.instant("PORTAL.MSG.RELATORIO_SEM_DADOS") + " ", false );
... ... @@ -796,35 +794,34 @@ citApp.controller('AppController', ['$scope', '$routeParams', '$timeout', '$loca
796 794 });
797 795 };
798 796  
799   - $scope.abrirRelatorio = function(response, titleTab) {
800   -
  797 + function abrirRelatorio (response, titleTab) {
801 798 var file = new Blob([response], {type: 'application/pdf'});
802 799 var fileURL = URL.createObjectURL(file);
803   -
  800 +
804 801 $scope.idRelatorio = ++idRelatorioCount;
805   -
  802 +
806 803 $scope.arrayContentReports[$scope.idRelatorio] = angular.copy($sce.trustAsResourceUrl(fileURL));
807   -
  804 +
808 805 obterWorskspaceAtiva();
809 806 $timeout(function(){
810 807 $scope.addNewWorkspace(titleTab, "relatorioTab.html", true, $scope.workspaceAtiva ? $scope.workspaceAtiva.classePagina : classePaginaPortal , undefined, undefined, undefined, $scope.idRelatorio);
811   -
  808 +
812 809 $timeout(function(){
813   -
  810 +
814 811 var relatorios = $scope.workspaces.filter(function(f){
815 812 return f.idRelatorio === $scope.idRelatorio;
816 813 });
817   -
  814 +
818 815 if(relatorios && relatorios.length > 0){
819 816 $scope.activeWorkspace(relatorios[0]);
820 817 } else{
821 818 $scope.workspaces.splice($scope.workspaces.length - 1, 1);
822 819 $scope.showAlert("error", $translate.instant("PORTAL.MSG.ERRO_RELATORIO") + " ", false );
823 820 }
824   -
  821 +
825 822 $scope.setLoading(false);
826 823 }, 2000);
827   -
  824 +
828 825 });
829 826 };
830 827  
... ...