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: [ raimund@548: 'Lada.view.window.ProbeEdit' raimund@548: ], raimund@548: dustin@742: /** dustin@742: * Initialize the Controller with 4 listeners dustin@742: */ raimund@548: init: function() { raimund@548: this.control({ raimund@548: 'filterresultgrid': { raimund@548: itemdblclick: this.editItem raimund@548: }, raimund@548: 'filterresultgrid toolbar button[action=add]': { raimund@548: click: this.addItem raimund@548: }, 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 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@742: */ raimund@548: editItem: function(grid, record) { dustin@751: console.log(record); raimund@548: var win = Ext.create('Lada.view.window.ProbeEdit', { raimund@548: record: record raimund@548: }); 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@742: * {@link Lada.view.window.ProbeEdit} dustin@742: */ raimund@725: addItem: function() { raimund@620: var win = Ext.create('Lada.view.window.ProbeCreate'); raimund@620: win.show(); raimund@620: win.initData(); raimund@548: }, raimund@548: dustin@742: /** 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(); raimund@725: var proben = []; raimund@725: for (var i = 0; i < selection.length; i++) { raimund@725: proben.push(selection[i].get('id')); raimund@725: } raimund@548: raimund@725: Ext.Ajax.request({ raimund@725: method: 'POST', dustin@727: url: 'lada-server/export/laf', raimund@725: jsonData: {'proben': proben}, raimund@725: headers: {'X-OPENID-PARAMS': Lada.openIDParams}, 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: }, raimund@725: failure: function() { raimund@725: Ext.Msg.alert('Fehler', 'Failed to create LAF-File!'); raimund@725: } raimund@725: }); raimund@548: } raimund@548: });