Skip to content

Commit

Permalink
fix: adding warning message if document is not found
Browse files Browse the repository at this point in the history
This commit adds a notify warning if a document/file isn't found.  However, this is only shown if the server has not sent back another error.
  • Loading branch information
lomamech authored and jniles committed Jun 5, 2017
1 parent 6a9b159 commit 5269e3c
Show file tree
Hide file tree
Showing 3 changed files with 14 additions and 4 deletions.
1 change: 1 addition & 0 deletions client/src/i18n/en/form.json
Original file line number Diff line number Diff line change
Expand Up @@ -557,6 +557,7 @@
"REQUIRED_EMAIL":"required Email",
"UNIQUE":"This field must be unique. This value is already taken."},
"WARNINGS":{"BAD_FILE_TYPE":"Bad file type",
"DOC_NOT_FOUND":"The document was not found on the server",
"EMPTY_SELECTION":"Empty Selection",
"NOT_AUTHORISED":"The requested page is not authorised",
"NOT_FOUND":"Not found",
Expand Down
1 change: 1 addition & 0 deletions client/src/i18n/fr/form.json
Original file line number Diff line number Diff line change
Expand Up @@ -556,6 +556,7 @@
"REQUIRED_EMAIL":"Email requis",
"UNIQUE":"Ce champ doit être unique. Cette valeur a déjà été utilisée."},
"WARNINGS":{"BAD_FILE_TYPE":"Type de fichier incorrect",
"DOC_NOT_FOUND":"Le document n'a pas était retrouvé au serveur",
"EMPTY_SELECTION":"Sélection vide",
"NOT_AUTHORISED":"La page demandée n'est pas autorisée",
"NOT_FOUND":"Non trouvee",
Expand Down
16 changes: 12 additions & 4 deletions client/src/js/components/bhPDFPrint.js
Original file line number Diff line number Diff line change
Expand Up @@ -33,7 +33,7 @@ angular.module('bhima.components')
});


bhPDFPrintController.$inject = ['$scope', '$window', '$http', '$sce', '$timeout', 'LanguageService'];
bhPDFPrintController.$inject = ['$scope', '$window', '$http', '$sce', '$timeout', 'LanguageService', 'NotifyService'];

/**
* @class bhPDFPrintController
Expand Down Expand Up @@ -61,7 +61,7 @@ bhPDFPrintController.$inject = ['$scope', '$window', '$http', '$sce', '$timeout'
* disable-cache="false">
* </bh-pdf-print>
*/
function bhPDFPrintController($scope, $window, $http, $sce, $timeout, Languages) {
function bhPDFPrintController($scope, $window, $http, $sce, $timeout, Languages, Notify) {
var cachedRequest;
var component = this;

Expand Down Expand Up @@ -91,7 +91,7 @@ function bhPDFPrintController($scope, $window, $http, $sce, $timeout, Languages)
// to compensate for the delay in browsers opening the print dialog
var loadingIndicatorDelay = 1000;

function print() {
function print() {
var url = component.pdfUrl;
var configuration = requestOptions();

Expand All @@ -104,13 +104,16 @@ function bhPDFPrintController($scope, $window, $http, $sce, $timeout, Languages)

cachedRequest = configuration;
component.$loading = true;

var testUrl = false;
// return the value to allow the controller to perform error handling
return $http.get(url, {params : configuration, responseType : responseType})
.then(function (result) {
var file = new Blob([result.data], {type : pdfType});
var fileURL = URL.createObjectURL(file);

// Check if fileURL return a valide file
testUrl = fileURL ? true : false;

// expose the stored pdf to the hidden view
// the print method is automatically called with the load listener on the $window option
component.src = $sce.trustAsResourceUrl(fileURL);
Expand All @@ -127,6 +130,11 @@ function bhPDFPrintController($scope, $window, $http, $sce, $timeout, Languages)
})
.finally(function () {
$timeout(toggleLoading, loadingIndicatorDelay);
// Check if was not found on the server
if(!testUrl) {
Notify.danger('FORM.WARNINGS.DOC_NOT_FOUND');
}

});
}

Expand Down

0 comments on commit 5269e3c

Please sign in to comment.