@@ -140,6 +140,7 @@ protected native void initDropzone(Element e, Element template, String previews,
140140 var previewContainer = $wnd.jQuery("#" + previews).html();
141141 previewNode.id = "";
142142 var previewTemplate = previewNode.parent().html();
143+ var globalResponse = "";
143144
144145 var totalFiles = 0;
145146 var zdrop = new $wnd.Dropzone(e, {
@@ -206,8 +207,18 @@ protected native void initDropzone(Element e, Element template, String previews,
206207 if(file.xhr !== undefined) {
207208 code = file.xhr.status;
208209 }
210+ if(response.indexOf("401") >= 0) {
211+ response = "Unautharized. Probably Your's session expired. Log in and try again.";
212+ globalResponse = response;
213+ that.@gwt.material.design.addins.client.fileuploader.MaterialFileUploader::fireUnauthorizedEvent(*)(file.name , file.lastModifiedDate , file.size , file.type, file.xhr.status, file.xhr.statusText, response);
214+ }
209215 if(response.indexOf("404") >= 0) {
210216 response = "There's a problem uploading your file.";
217+ globalResponse = response;
218+ }
219+ if(response.indexOf("500") >= 0) {
220+ response = "There's a problem uploading your file.";
221+ globalResponse = response;
211222 }
212223 file.previewElement.querySelector("#error-message").innerHTML = response;
213224 that.@gwt.material.design.addins.client.fileuploader.MaterialFileUploader::fireErrorEvent(*)(file.name , file.lastModifiedDate , file.size , file.type, code, response);
@@ -226,11 +237,12 @@ protected native void initDropzone(Element e, Element template, String previews,
226237 });
227238
228239 zdrop.on('success', function (file, response) {
229- that.@gwt.material.design.addins.client.fileuploader.MaterialFileUploader::fireSuccessEvent(*)(file.name , file.lastModifiedDate , file.size , file.type, file.xhr.status, response);
240+ globalResponse = response;
241+ that.@gwt.material.design.addins.client.fileuploader.MaterialFileUploader::fireSuccessEvent(*)(file.name , file.lastModifiedDate , file.size , file.type, file.xhr.status, file.xhr.statusText, response);
230242 });
231243
232244 zdrop.on('complete', function (file) {
233- that.@gwt.material.design.addins.client.fileuploader.MaterialFileUploader::fireCompleteEvent(*)(file.name , file.lastModifiedDate , file.size , file.type, file.xhr.status, file.xhr.statusText);
245+ that.@gwt.material.design.addins.client.fileuploader.MaterialFileUploader::fireCompleteEvent(*)(file.name , file.lastModifiedDate , file.size , file.type, file.xhr.status, file.xhr.statusText, globalResponse );
234246 });
235247
236248 zdrop.on('canceled', function (file) {
@@ -511,8 +523,25 @@ public void onError(ErrorEvent<UploadFile> event) {
511523 }
512524
513525 @ Override
514- public void fireErrorEvent (String fileName , String lastModified , String size , String type , String responseCode , String responseMessage ) {
515- ErrorEvent .fire (this , new UploadFile (fileName , new Date (lastModified ), Double .parseDouble (size ), type ), new UploadResponse (responseCode , responseMessage ));
526+ public void fireErrorEvent (String fileName , String lastModified , String size , String type , String responseCode , String responseMessage , String responseBody ) {
527+ ErrorEvent .fire (this , new UploadFile (fileName , new Date (lastModified ), Double .parseDouble (size ), type ), new UploadResponse (responseCode , responseMessage , responseBody ));
528+ }
529+
530+ @ Override
531+ public HandlerRegistration addUnauthorizedHandler (final UnauthorizedEvent .UnauthorizedHandler <UploadFile > handler ) {
532+ return addHandler (new UnauthorizedEvent .UnauthorizedHandler <UploadFile >() {
533+ @ Override
534+ public void onUnauthorized (UnauthorizedEvent <UploadFile > event ) {
535+ if (isEnabled ()) {
536+ handler .onUnauthorized (event );
537+ }
538+ }
539+ }, UnauthorizedEvent .getType ());
540+ }
541+
542+ @ Override
543+ public void fireUnauthorizedEvent (String fileName , String lastModified , String size , String type , String responseCode , String responseMessage , String responseBody ) {
544+ UnauthorizedEvent .fire (this , new UploadFile (fileName , new Date (lastModified ), Double .parseDouble (size ), type ), new UploadResponse (responseCode , responseMessage , responseBody ));
516545 }
517546
518547 @ Override
@@ -562,8 +591,8 @@ public void onSuccess(SuccessEvent<UploadFile> event) {
562591 }
563592
564593 @ Override
565- public void fireSuccessEvent (String fileName , String lastModified , String size , String type , String responseCode , String responseMessage ) {
566- SuccessEvent .fire (this , new UploadFile (fileName , new Date (lastModified ), Double .parseDouble (size ), type ), new UploadResponse (responseCode , responseMessage ));
594+ public void fireSuccessEvent (String fileName , String lastModified , String size , String type , String responseCode , String responseMessage , String responseBody ) {
595+ SuccessEvent .fire (this , new UploadFile (fileName , new Date (lastModified ), Double .parseDouble (size ), type ), new UploadResponse (responseCode , responseMessage , responseBody ));
567596 }
568597
569598 @ Override
@@ -579,8 +608,8 @@ public void onComplete(CompleteEvent<UploadFile> event) {
579608 }
580609
581610 @ Override
582- public void fireCompleteEvent (String fileName , String lastModified , String size , String type , String responseCode , String responseMessage ) {
583- CompleteEvent .fire (this , new UploadFile (fileName , new Date (lastModified ), Double .parseDouble (size ), type ), new UploadResponse (responseCode , responseMessage ));
611+ public void fireCompleteEvent (String fileName , String lastModified , String size , String type , String responseCode , String responseMessage , String responseBody ) {
612+ CompleteEvent .fire (this , new UploadFile (fileName , new Date (lastModified ), Double .parseDouble (size ), type ), new UploadResponse (responseCode , responseMessage , responseBody ));
584613 }
585614
586615 @ Override
0 commit comments