raimund@548: /* Copyright (C) 2013 by Bundesamt fuer Strahlenschutz raimund@548: * Software engineering by Intevation GmbH raimund@548: * raimund@548: * This file is Free Software under the GNU GPL (v>=3) raimund@548: * and comes with ABSOLUTELY NO WARRANTY! Check out raimund@548: * the documentation coming with IMIS-Labordaten-Application for details. raimund@548: */ raimund@548: raimund@548: /** raimund@548: * Controller for filter result grid. raimund@548: */ raimund@548: Ext.define('Lada.controller.FilterResult', { raimund@548: extend: 'Ext.app.Controller', raimund@548: requires: [ dustin@754: 'Lada.view.window.ProbeEdit', dustin@759: 'Lada.view.window.Messprogramm' raimund@548: ], raimund@548: dustin@742: /** dustin@810: * Initialize the Controller with listeners dustin@742: */ raimund@548: init: function() { raimund@548: this.control({ raimund@548: 'filterresultgrid': { raimund@548: itemdblclick: this.editItem raimund@548: }, dustin@754: 'filterresultgrid toolbar button[action=addProbe]': { dustin@754: click: this.addProbeItem raimund@548: }, dustin@755: 'filterresultgrid toolbar button[action=addMessprogramm]': { dustin@755: click: this.addMessprogrammItem dustin@755: }, dustin@860: 'filterresultgrid toolbar button[action=genProbenFromMessprogramm]': { dustin@860: click: this.genProbenFromMessprogramm dustin@860: }, raimund@548: 'filterresultgrid toolbar button[action=import]': { raimund@548: click: this.uploadFile raimund@548: }, raimund@548: 'filterresultgrid toolbar button[action=export]': { raimund@548: click: this.downloadFile dustin@923: }, dustin@923: 'filterresultgrid toolbar button[action=print]': { dustin@923: click: this.printSelection raimund@548: } raimund@548: }); raimund@548: this.callParent(arguments); raimund@548: }, raimund@548: dustin@742: /** dustin@742: * This function is called after a Row in the dustin@742: * {@link Lada.view.grid.FilterResult} dustin@742: * was double-clicked. dustin@742: * The function opens a {@link Lada.view.window.ProbeEdit} dustin@895: * or a {@link Lada.view.window.Messprogramm}. dustin@754: * To determine which window has to be opened, the function dustin@754: * analyse the records modelname. dustin@742: */ raimund@548: editItem: function(grid, record) { dustin@754: var mname = record.store.model.modelName || ''; dustin@754: var winname = ''; dustin@754: dustin@754: //Based upon the Model that was loaded, act differently dustin@754: if (mname == 'Lada.model.ProbeList'){ dustin@754: winname = 'Lada.view.window.ProbeEdit'; dustin@754: } dustin@754: else if (mname == 'Lada.model.MessprogrammList'){ dustin@759: winname = 'Lada.view.window.Messprogramm'; dustin@754: } dustin@754: if (winname){ dustin@754: var win = Ext.create(winname, { dustin@814: record: record, dustin@814: style: 'z-index: -1;' //Fixes an Issue where windows could not be created in IE8 dustin@754: }); dustin@754: win.show(); dustin@754: win.initData(); dustin@754: } dustin@754: else { dustin@754: console.log('The model is unknown.' dustin@754: +'No window was configured to display the data.' dustin@754: +'I retrieved a model named:' + mname dustin@754: ); dustin@754: } dustin@754: }, dustin@754: dustin@754: /** dustin@754: * This function opens a new window to create a Probe dustin@754: * {@link Lada.view.window.ProbeCreate} dustin@754: */ dustin@754: addProbeItem: function() { dustin@754: var win = Ext.create('Lada.view.window.ProbeCreate'); raimund@548: win.show(); raimund@548: win.initData(); raimund@548: }, raimund@548: dustin@742: /** dustin@742: * This function opens a new window to create a Probe dustin@895: * {@link Lada.view.window.Messprogramm} dustin@742: */ dustin@754: addMessprogrammItem: function() { dustin@759: var win = Ext.create('Lada.view.window.Messprogramm'); dustin@755: win.show(); dustin@755: win.initData(); raimund@548: }, raimund@548: dustin@742: /** dustin@860: * This button creates a window to generate Proben dustin@860: * from a selected messprogramm. dustin@860: */ dustin@860: genProbenFromMessprogramm: function(button) { dustin@860: var grid = button.up('grid'); dustin@860: var selection = grid.getView().getSelectionModel().getSelection(); dustin@860: var i18n = Lada.getApplication().bundle; dustin@860: var proben = []; dustin@860: for (var i = 0; i < selection.length; i++) { dustin@860: proben.push(selection[i].get('id')); dustin@860: } dustin@860: var me = this; dustin@860: dustin@860: var winname = 'Lada.view.window.GenProbenFromMessprogramm'; dustin@860: for (p in proben) { dustin@860: grid.setLoading(true); dustin@860: Ext.ClassManager.get('Lada.model.Messprogramm').load(proben[p], { dustin@860: failure: function(record, action) { dustin@860: me.setLoading(false); dustin@860: // TODO dustin@860: console.log('An unhandled Failure occured. See following Response and Record'); dustin@860: console.log(action); dustin@860: console.log(record); dustin@860: }, dustin@860: success: function(record, response) { dustin@860: grid.setLoading(false); dustin@860: dustin@860: var win = Ext.create(winname, { dustin@860: record: record, dustin@860: parentWindow: null dustin@860: }); dustin@860: win.show(); dustin@860: win.initData(); dustin@860: }, dustin@860: scope: this dustin@860: }); dustin@860: } dustin@860: }, dustin@860: dustin@860: /** dustin@742: * This function opens a {@link Lada.view.window.FileUpload} dustin@742: * window to upload a LAF-File dustin@742: */ raimund@725: uploadFile: function() { raimund@725: var win = Ext.create('Lada.view.window.FileUpload', { raimund@725: title: 'Datenimport', raimund@725: modal: true raimund@725: }); raimund@548: raimund@725: win.show(); raimund@548: }, raimund@548: dustin@742: /** dustin@742: * This function can be used to Download the items which dustin@742: * were selected in the {@link Lada.view.grid.FilterResult} dustin@742: * The Download does not work with Internet Explorers older than v.10 dustin@742: */ raimund@548: downloadFile: function(button) { raimund@725: var grid = button.up('grid'); raimund@725: var selection = grid.getView().getSelectionModel().getSelection(); dustin@754: var i18n = Lada.getApplication().bundle; raimund@725: var proben = []; raimund@725: for (var i = 0; i < selection.length; i++) { raimund@725: proben.push(selection[i].get('id')); raimund@725: } dustin@825: var me = this; raimund@725: Ext.Ajax.request({ raimund@725: method: 'POST', dustin@727: url: 'lada-server/export/laf', raimund@725: jsonData: {'proben': proben}, raimund@725: success: function(response) { raimund@725: var content = response.responseText; raimund@725: var blob = new Blob([content],{type: 'text/plain'}); raimund@725: saveAs(blob, 'export.laf'); raimund@725: }, dustin@812: failure: function(response) { dustin@920: /* dustin@920: SSO will send a 302 if the Client is not authenticated dustin@920: unfortunately this seems to be filtered by the browser. dustin@920: We assume that a 302 was send when the follwing statement dustin@920: is true. dustin@920: */ dustin@920: if (response.status == 0 && response.responseText === "") { dustin@920: Ext.MessageBox.confirm('Erneutes Login erforderlich', dustin@920: 'Ihre Session ist abgelaufen.
'+ dustin@920: 'Für ein erneutes Login muss die Anwendung neu geladen werden.
' + dustin@920: 'Alle ungesicherten Daten gehen dabei verloren.
' + dustin@920: 'Soll die Anwendung jetzt neu geladen werden?', this.reload); dustin@920: } dustin@920: // further error handling dustin@812: var json = Ext.JSON.decode(response.responseText); dustin@812: if (json) { dustin@812: if(json.errors.totalCount > 0 || json.warnings.totalCount > 0){ dustin@812: formPanel.setMessages(json.errors, json.warnings); dustin@812: } dustin@920: if(json.message){ dustin@812: Ext.Msg.alert(Lada.getApplication().bundle.getMsg('err.msg.generic.title') dustin@812: +' #'+json.message, dustin@812: Lada.getApplication().bundle.getMsg(json.message)); dustin@812: } else { dustin@812: Ext.Msg.alert(i18n.getMsg('err.msg.generic.title'), dustin@812: i18n.getMsg('err.msg.laf.filecreatefailed')); dustin@812: } dustin@812: } else { dustin@812: Ext.Msg.alert(i18n.getMsg('err.msg.generic.title'), dustin@754: i18n.getMsg('err.msg.laf.filecreatefailed')); dustin@812: } raimund@725: } raimund@725: }); dustin@812: }, dustin@812: dustin@923: /** dustin@923: * Send the selection to a Printservice dustin@923: */ dustin@923: printSelection: function(button) { dustin@923: var grid = button.up('grid'); dustin@923: var selection = grid.getView().getSelectionModel().getSelection(); dustin@923: var i18n = Lada.getApplication().bundle; dustin@923: var proben = []; dustin@923: for (var i = 0; i < selection.length; i++) { dustin@923: proben.push(selection[i].get('id')); dustin@923: } dustin@923: var me = this; dustin@923: Ext.Ajax.request({ dustin@923: method: 'POST', dustin@923: url: '127.0.0.1', // TODO dustin@923: jsonData: {'proben': proben}, // TODO dustin@923: success: function(response) { dustin@923: console.log('success'); dustin@923: var content = response.responseText; dustin@923: var blob = new Blob([content],{type: 'application/pdf'}); dustin@923: saveAs(blob, 'lada-print.pdf'); dustin@923: }, dustin@923: failure: function(response) { dustin@923: console.log('failure'); dustin@923: // Error handling dustin@923: // TODO dustin@923: if (response.responseText) { dustin@923: try { dustin@923: var json = Ext.JSON.decode(response.responseText); dustin@923: } dustin@923: catch(e){ dustin@923: console.log(e); dustin@923: } dustin@923: } dustin@923: if (json) { dustin@923: if(json.errors.totalCount > 0 || json.warnings.totalCount > 0){ dustin@923: formPanel.setMessages(json.errors, json.warnings); dustin@923: } dustin@923: if(json.message){ dustin@923: Ext.Msg.alert(Lada.getApplication().bundle.getMsg('err.msg.generic.title') dustin@923: +' #'+json.message, dustin@923: Lada.getApplication().bundle.getMsg(json.message)); dustin@923: } else { dustin@923: Ext.Msg.alert(i18n.getMsg('err.msg.generic.title'), dustin@923: i18n.getMsg('err.msg.print.noContact')); dustin@923: } dustin@923: } else { dustin@923: Ext.Msg.alert(i18n.getMsg('err.msg.generic.title'), dustin@923: i18n.getMsg('err.msg.print.noContact')); dustin@923: } dustin@923: } dustin@923: }); dustin@923: }, dustin@923: dustin@812: reload: function(btn) { dustin@812: if (btn === 'yes') { dustin@812: location.reload(); dustin@812: } raimund@548: } raimund@548: });