diff app/controller/FilterResult.js @ 923:7cbbe0485d0d

Added a Print-button which sends a selection of proben to a service which still has to be specified.
author Dustin Demuth <dustin@intevation.de>
date Thu, 20 Aug 2015 14:37:37 +0200
parents f220ba587c89
children 3e3e737050b7
line wrap: on
line diff
--- a/app/controller/FilterResult.js	Fri Aug 14 13:31:30 2015 +0200
+++ b/app/controller/FilterResult.js	Thu Aug 20 14:37:37 2015 +0200
@@ -38,6 +38,9 @@
             },
             'filterresultgrid toolbar button[action=export]': {
                 click: this.downloadFile
+            },
+            'filterresultgrid toolbar button[action=print]': {
+                click: this.printSelection
             }
         });
         this.callParent(arguments);
@@ -211,6 +214,60 @@
         });
     },
 
+    /**
+     * Send the selection to a Printservice
+     */
+    printSelection: function(button) {
+        var grid = button.up('grid');
+        var selection = grid.getView().getSelectionModel().getSelection();
+        var i18n = Lada.getApplication().bundle;
+        var proben = [];
+        for (var i = 0; i < selection.length; i++) {
+            proben.push(selection[i].get('id'));
+        }
+        var me = this;
+        Ext.Ajax.request({
+            method: 'POST',
+            url: '127.0.0.1', // TODO
+            jsonData: {'proben': proben},  // TODO
+            success: function(response) {
+                console.log('success');
+                var content = response.responseText;
+                var blob = new Blob([content],{type: 'application/pdf'});
+                saveAs(blob, 'lada-print.pdf');
+            },
+            failure: function(response) {
+                console.log('failure');
+                // Error handling
+                // TODO
+                if (response.responseText) {
+                    try {
+                        var json = Ext.JSON.decode(response.responseText);
+                    }
+                    catch(e){
+                        console.log(e);
+                    }
+                }
+                if (json) {
+                    if(json.errors.totalCount > 0 || json.warnings.totalCount > 0){
+                        formPanel.setMessages(json.errors, json.warnings);
+                    }
+                    if(json.message){
+                        Ext.Msg.alert(Lada.getApplication().bundle.getMsg('err.msg.generic.title')
+                            +' #'+json.message,
+                            Lada.getApplication().bundle.getMsg(json.message));
+                    } else {
+                        Ext.Msg.alert(i18n.getMsg('err.msg.generic.title'),
+                            i18n.getMsg('err.msg.print.noContact'));
+                    }
+                } else {
+                    Ext.Msg.alert(i18n.getMsg('err.msg.generic.title'),
+                    i18n.getMsg('err.msg.print.noContact'));
+                }
+            }
+        });
+    },
+
     reload: function(btn) {
         if (btn === 'yes') {
             location.reload();

http://lada.wald.intevation.org