Mercurial > lada > lada-client
changeset 1076:e32c10cf5499
Added model/store, view and controller for messung list.
author | Raimund Renkert <raimund.renkert@intevation.de> |
---|---|
date | Fri, 08 Apr 2016 19:32:02 +0200 |
parents | d23427c68285 |
children | 2a5d42045c63 |
files | app/controller/grid/MessungList.js app/model/MessungList.js app/store/MessungQueries.js app/store/MessungenList.js app/view/grid/MessungList.js |
diffstat | 5 files changed, 413 insertions(+), 0 deletions(-) [+] |
line wrap: on
line diff
--- /dev/null Thu Jan 01 00:00:00 1970 +0000 +++ b/app/controller/grid/MessungList.js Fri Apr 08 19:32:02 2016 +0200 @@ -0,0 +1,275 @@ +/* Copyright (C) 2013 by Bundesamt fuer Strahlenschutz + * Software engineering by Intevation GmbH + * + * This file is Free Software under the GNU GPL (v>=3) + * and comes with ABSOLUTELY NO WARRANTY! Check out + * the documentation coming with IMIS-Labordaten-Application for details. + */ + +/** + * Controller for the MessungList result grid. + */ +Ext.define('Lada.controller.grid.MessungList', { + extend: 'Ext.app.Controller', + requires: [ + 'Lada.view.window.ProbeEdit' + ], + + /** + * Initialize the Controller with listeners + */ + init: function() { + this.control({ + 'messunglistgrid': { + itemdblclick: this.editItem, + select: this.activateButtons, + deselect: this.deactivateButtons + } + }); + this.callParent(arguments); + }, + + /** + * This function is called after a Row in the + * {@link Lada.view.grid.ProbeList} + * was double-clicked. + * The function opens a {@link Lada.view.window.ProbeEdit} + * or a {@link Lada.view.window.Messprogramm}. + * To determine which window has to be opened, the function + * analyse the records modelname. + */ + editItem: function(grid, record) { + var probeRecord = Ext.create('Lada.model.ProbeList'); + probeRecord.setId(record.get('probeId')); + probeRecord.set('owner', record.get('owner')); + probeRecord.set('readonly', record.get('readonly')); + + var probeWin = Ext.create('Lada.view.window.ProbeEdit', { + record: probeRecord, + style: 'z-index: -1;' //Fixes an Issue where windows could not be created in IE8 + }); + + probeWin.setPosition(30); + probeWin.show(); + probeWin.initData(); + + Ext.ClassManager.get('Lada.model.Probe').load(record.get('probeId'), { + failure: function(record, action) { + me.setLoading(false); + // TODO + console.log('An unhandled Failure occured. See following Response and Record'); + console.log(action); + console.log(record); + }, + success: function(precord, response) { + var messungWin = Ext.create('Lada.view.window.MessungEdit', { + parentWindow: grid.up('window'), + probe: precord, + record: record, + grid: grid + }); + messungWin.show(); + messungWin.setPosition(window.innerWidth - 30 - messungWin.width); + messungWin.initData(); + } + }); + }, + + /** + * Send the selection to a Printservice + */ + printSelection: function(button) { + + //disable Button and setLoading... + button.disable(); + button.setLoading(true); + + var grid = button.up('grid'); + var selection = grid.getView().getSelectionModel().getSelection(); + var i18n = Lada.getApplication().bundle; + var me = this; + var columns = []; + var columnNames = []; + var visibleColumns = []; + var displayName = ''; + var data = []; + + // Write the columns to an array + try { + for (key in selection[0].data) { + // Do not write owner or readonly or id + if (["owner", "readonly", "id", "probeId"].indexOf(key) == -1){ + columns.push(key); + } + } + } + catch (e) { + console.log(e); + } + + //Retrieve visible columns' id's and names. + // and set displayName + try { + var grid = button.up('grid'); + var cman = grid.columnManager; + var cols = cman.getColumns(); + + displayName = grid.down('tbtext').text; + + for (key in cols) { + if (cols[key].dataIndex) { + visibleColumns[cols[key].dataIndex] = cols[key].text; + } + } + } + catch (e) { + console.log(e); + } + + + // Retrieve Data from selection + try { + for (item in selection) { + var row = selection[item].data; + var out = []; + //Lookup every column and write to data array. + for (key in columns){ + var attr = columns[key]; + //Only write data to output when the column is not hidden. + if (row[attr] != null && + visibleColumns[attr] != null) { + out.push(row[attr].toString()); + } + else if (visibleColumns[attr] != null) { + out.push(''); + } + } + data.push(out); + } + } + catch (e){ + console.log(e); + } + + //Retrieve the names of the columns. + try { + var grid = button.up('grid'); + var cman = grid.columnManager; + var cols = cman.getColumns(); + //Iterate columns and find column names for the key... + // This WILL run into bad behaviour when column-keys exist twice. + for (key in columns){ + for (k in cols){ + if (cols[k].dataIndex == columns[key]){ + columnNames.push(cols[k].text); + break; + } + } + } + } + catch (e) { + console.log(e); + } + + var printData = { + 'layout': 'A4 landscape', + 'outputFormat': 'pdf', + 'attributes': { + 'title': 'Auszug aus LADA', + 'displayName': displayName, + 'table': { + 'columns': columnNames, + 'data': data + } + } + } + + Ext.Ajax.request({ + url: 'lada-printer/buildreport.pdf', + //configure a proxy in apache conf! + jsonData: printData, + binary: true, + success: function(response) { + var content = response.responseBytes; + var filetype = response.getResponseHeader('Content-Type'); + var blob = new Blob([content],{type: filetype}); + saveAs(blob, 'lada-print.pdf'); + button.enable(); + button.setLoading(false); + }, + failure: function(response) { + console.log('failure'); + // Error handling + // TODO + //console.log(response.responseText) + button.enable(); + button.setLoading(false); + 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')); + } + } + }); + }, + + /** + * Toggles the buttons in the toolbar + **/ + activateButtons: function(rowModel, record) { + var grid = rowModel.view.up('grid'); + this.buttonToggle(true, grid); + }, + + /** + * Toggles the buttons in the toolbar + **/ + deactivateButtons: function(rowModel, record) { + var grid = rowModel.view.up('grid'); + // Only disable buttons when nothing is selected + if (rowModel.selected.items == 0) { + this.buttonToggle(false, grid); + } + }, + + /** + * Enables/Disables a set of buttons + **/ + buttonToggle: function(enabled, grid) { + if (!enabled) { + grid.down('button[action=print]').disable(); + grid.down('button[action=setStatus]').disable(); + } + else { + grid.down('button[action=print]').enable(); + // TODO: enable button only on messungen with owner == true and + // readonly == false + grid.down('button[action=setStatus]').enable(); + } + }, + + reload: function(btn) { + if (btn === 'yes') { + location.reload(); + } + } +});
--- /dev/null Thu Jan 01 00:00:00 1970 +0000 +++ b/app/model/MessungList.js Fri Apr 08 19:32:02 2016 +0200 @@ -0,0 +1,33 @@ +/* Copyright (C) 2013 by Bundesamt fuer Strahlenschutz + * Software engineering by Intevation GmbH + * + * This file is Free Software under the GNU GPL (v>=3) + * and comes with ABSOLUTELY NO WARRANTY! Check out + * the documentation coming with IMIS-Labordaten-Application for details. + */ + +/** + * A MessungList. + * This class represents the result list of 'Messungen' in the search query + * */ +Ext.define('Lada.model.MessungList', { + extend: 'Ext.data.Model', + + fields: [{ + name: 'readonly' + }, { + name: 'owner' + }], + + idProperty: 'id', + + proxy: { + type: 'rest', + url: 'lada-server/rest/messung', + reader: { + type: 'json', + root: 'data', + totalProperty: 'totalCount' + } + } +});
--- /dev/null Thu Jan 01 00:00:00 1970 +0000 +++ b/app/store/MessungQueries.js Fri Apr 08 19:32:02 2016 +0200 @@ -0,0 +1,24 @@ +/* Copyright (C) 2013 by Bundesamt fuer Strahlenschutz + * Software engineering by Intevation GmbH + * + * This file is Free Software under the GNU GPL (v>=3) + * and comes with ABSOLUTELY NO WARRANTY! Check out + * the documentation coming with IMIS-Labordaten-Application for details. + */ + +/** + * Store for Queries + */ +Ext.define('Lada.store.MessungQueries', { + extend: 'Ext.data.Store', + model: 'Lada.model.Query', + autoLoad: true, + proxy: { + type: 'rest', + url: 'lada-server/rest/query/messung', + reader: { + type: 'json', + root: 'data' + } + } +});
--- /dev/null Thu Jan 01 00:00:00 1970 +0000 +++ b/app/store/MessungenList.js Fri Apr 08 19:32:02 2016 +0200 @@ -0,0 +1,17 @@ +/* Copyright (C) 2013 by Bundesamt fuer Strahlenschutz + * Software engineering by Intevation GmbH + * + * This file is Free Software under the GNU GPL (v>=3) + * and comes with ABSOLUTELY NO WARRANTY! Check out + * the documentation coming with IMIS-Labordaten-Application for details. + */ + +/** + * Store for Messungen, it is used in the {@link Lada.view.grid.MessungenList} + */ +Ext.define('Lada.store.MessungenList', { + extend: 'Ext.data.Store', + model: 'Lada.model.MessungList', + pageSize: 50, + remoteSort: true +});
--- /dev/null Thu Jan 01 00:00:00 1970 +0000 +++ b/app/view/grid/MessungList.js Fri Apr 08 19:32:02 2016 +0200 @@ -0,0 +1,64 @@ +/* Copyright (C) 2013 by Bundesamt fuer Strahlenschutz + * Software engineering by Intevation GmbH + * + * This file is Free Software under the GNU GPL (v>=3) + * and comes with ABSOLUTELY NO WARRANTY! Check out + * the documentation coming with IMIS-Labordaten-Application for details. + */ + +/** + * Grid to list the result of the Filter + */ +Ext.define('Lada.view.grid.MessungList', { + extend: 'Lada.view.widget.DynamicGrid', + alias: 'widget.messunglistgrid', + + initComponent: function() { + var i18n = Lada.getApplication().bundle; + this.emptyText = i18n.getMsg('messung.emptyGrid'); + this.selModel = Ext.create('Ext.selection.CheckboxModel', { + checkOnly: true + }); + + this.dockedItems = [{ + xtype: 'toolbar', + dock: 'top', + items: [{ + xtype: 'tbtext', + text: i18n.getMsg('messung.gridTitle') + }, + '->', + { + text: i18n.getMsg('probe.button.print'), + icon: 'resources/img/printer.png', + action: 'print', + disabled: true //disabled on start, enabled by the controller + }, { + text: i18n.getMsg('statusSetzen'), + icon: 'resources/img/emblem-important.png', + action: 'setStatus', + disabled: true //disabled on start, enabled by the controller + }] + }]; + this.columns = []; + this.callParent(arguments); + }, + + /** + * Setup columns of the Grid dynamically based on a list of given cols. + * The function is called from the {@link Lada.controller.Filter#search + * search event} + * The Images for the Read-Write Icon are defined in CSS + * This Method overrides setupColumns of the parents class, + * becaus the delete colum is required. + */ + setupColumns: function(cols) { + var caf = this.generateColumnsAndFields(cols); + var columns = caf[0]; + var fields = caf[1]; + var i18n = Lada.getApplication().bundle; + + this.store.model.setFields(fields); + this.reconfigure(this.store, columns); + } +});