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: * Grid to list Proben
raimund@548: */
raimund@548: Ext.define('Lada.view.grid.FilterResult', {
raimund@548: extend: 'Ext.grid.Panel',
raimund@548: alias: 'widget.filterresultgrid',
raimund@548:
dustin@751: store: null, //'ProbenList',
raimund@548:
raimund@548: multiSelect: true,
raimund@548:
raimund@548: viewConfig: {
dustin@753: emptyText: 'Keine Ergebnisse gefunden.',
raimund@548: deferEmptyText: false
raimund@548: },
raimund@548:
raimund@548: initComponent: function() {
raimund@548: this.dockedItems = [{
raimund@548: xtype: 'toolbar',
raimund@548: dock: 'top',
raimund@548: items: [{
dustin@753: xtype: 'tbtext',
dustin@753: id: 'tbtitle',
dustin@753: text: '',
dustin@753: },
dustin@753: '->',
dustin@753: {
dustin@753: text: 'Probe erstellen',
raimund@548: icon: 'resources/img/list-add.png',
dustin@792: action: 'addProbe',
dustin@792: disabled: false
raimund@548: }, {
dustin@753: text: 'Messprogramm erstellen',
dustin@753: icon: 'resources/img/list-add.png',
dustin@792: action: 'addMessprogramm',
dustin@792: disabled: false
dustin@753: },
dustin@753: '-',
dustin@753: {
dustin@753: text: 'Proben Importieren',
raimund@548: icon: 'resources/img/svn-commit.png',
dustin@792: action: 'import',
dustin@792: disabled: false
raimund@548: }, {
dustin@753: text: 'Proben Exportieren',
raimund@548: icon: 'resources/img/svn-update.png',
dustin@792: action: 'export',
dustin@792: disabled: true
dustin@753: }
dustin@753: ]
raimund@548: }];
raimund@548: this.columns = [];
raimund@548: this.callParent(arguments);
raimund@548: },
raimund@548:
raimund@548: /**
dustin@751: * This sets the Store of the FilterResultGrid
dustin@751: */
dustin@751: setStore: function(store){
dustin@753: var i18n = Lada.getApplication().bundle;
dustin@753:
dustin@751: this.removeDocked(Ext.getCmp('ptbar'), true);
dustin@751: this.reconfigure(store);
dustin@751: this.addDocked([{
dustin@751: xtype: 'pagingtoolbar',
dustin@751: id: 'ptbar',
dustin@751: dock: 'bottom',
dustin@751: store: store,
dustin@751: displayInfo: true
dustin@751: }]);
dustin@753:
dustin@792: //Configure the Toolbar.
dustin@792: this.setMode(store);
dustin@792: },
dustin@792:
dustin@792: /**
dustin@792: * Enables or disables Toolbar-Buttons according to the selected mode
dustin@792: */
dustin@792: setMode: function(store) {
dustin@753: var t = Ext.getCmp('tbtitle');
dustin@792: var i18n = Lada.getApplication().bundle;
dustin@792: if (store.model.modelName == 'Lada.model.ProbeList'){
dustin@792: t.setText(i18n.getMsg('probelist'));
dustin@792: this.down('button[action=addMessprogramm]').disable();
dustin@792: this.down('button[action=addProbe]').enable();
dustin@792: this.down('button[action=import]').enable();
dustin@792: this.down('button[action=export]').enable();
dustin@792: }
dustin@792: else if (store.model.modelName == 'Lada.model.MessprogrammList') {
dustin@753: t.setText(i18n.getMsg('probeplanning'));
dustin@792: this.down('button[action=addMessprogramm]').enable();
dustin@792: this.down('button[action=addProbe]').disable();
dustin@792: this.down('button[action=import]').disable();
dustin@792: this.down('button[action=export]').disable();
dustin@753: }
dustin@753: else {
dustin@753: t.setText('');
dustin@753: console.log('The model '+store.model.modelName+
dustin@753: 'was not defined in the FilterResultGrid.' +
dustin@753: ' Hence the title could not be set.');
dustin@753: }
dustin@751: },
dustin@792:
dustin@751: /**
raimund@548: * Setup columns of the Grid dynamically based on a list of given cols.
dustin@795: * The function is called from the {@link Lada.controller.Filter#search
dustin@795: * search event}
raimund@548: */
raimund@548: setupColumns: function(cols) {
raimund@548: var resultColumns = [];
raimund@548: var fields = [];
raimund@548:
raimund@548: resultColumns.push({
raimund@548: header: 'RW',
raimund@548: dataIndex: 'readonly',
dustin@682: sortable: false,
raimund@548: width: 30,
raimund@548: renderer: function(value) {
raimund@548: if (value) {
dustin@806: return '';
raimund@548: }
dustin@806: return '';
raimund@548: }
raimund@548: });
raimund@548: fields.push(new Ext.data.Field({
raimund@548: name: 'readonly'
raimund@548: }));
raimund@548: for (var i = cols.length - 1; i >= 0; i--) {
raimund@548: if (cols[i] === 'id') {
raimund@548: continue;
raimund@548: }
raimund@548: resultColumns.push(cols[i]);
raimund@548: fields.push(new Ext.data.Field({
raimund@548: name: cols[i].dataIndex
raimund@548: }));
raimund@548: }
raimund@548: this.store.model.setFields(fields);
raimund@548: this.reconfigure(this.store, resultColumns);
raimund@548: }
raimund@548: });