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: dustin@893: /** dustin@893: * Grid to list the result of the Filter raimund@548: */ raimund@548: Ext.define('Lada.view.grid.FilterResult', { raimund@548: extend: 'Ext.grid.Panel', raimund@548: alias: 'widget.filterresultgrid', raimund@548: dustin@856: requires: 'Lada.view.window.DeleteProbe', dustin@856: 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() { dustin@837: var i18n = Lada.getApplication().bundle; dustin@837: raimund@548: this.dockedItems = [{ raimund@548: xtype: 'toolbar', raimund@548: dock: 'top', raimund@548: items: [{ dustin@753: xtype: 'tbtext', dustin@753: id: 'tbtitle', dustin@837: text: i18n.getMsg('probelist') 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: '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@923: }, { dustin@923: text: 'Auswahl Drucken', dustin@923: icon: 'resources/img/printer.png', dustin@923: action: 'print', dustin@923: disabled: true dustin@860: }, dustin@860: '-', dustin@860: { dustin@860: text: 'Messprogramm erstellen', dustin@860: icon: 'resources/img/list-add.png', dustin@860: action: 'addMessprogramm', dustin@860: disabled: true dustin@860: }, { dustin@860: text: 'Proben generieren', dustin@860: icon: 'resources/img/view-time-schedule-insert.png', dustin@860: action: 'genProbenFromMessprogramm', dustin@860: disabled: true dustin@860: }] 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@860: this.down('button[action=genProbenFromMessprogramm]').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@923: this.down('button[action=print]').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@860: this.down('button[action=genProbenFromMessprogramm]').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@923: this.down('button[action=print]').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} dustin@878: * The Images for the Read-Write Icon are defined in CSS raimund@548: */ raimund@548: setupColumns: function(cols) { raimund@548: var resultColumns = []; raimund@548: var fields = []; raimund@548: dustin@856: fields.push(new Ext.data.Field({ dustin@856: name: 'owner' dustin@856: })); dustin@856: fields.push(new Ext.data.Field({ dustin@856: name: 'readonly' dustin@856: })); dustin@856: raimund@548: resultColumns.push({ dustin@878: xtype: 'actioncolumn', dustin@878: text: 'RW', raimund@548: dataIndex: 'readonly', dustin@682: sortable: false, dustin@878: tooltip: 'Probe öffnen', raimund@548: width: 30, dustin@878: getClass: function (val, meta, rec) { dustin@878: return rec.get('readonly') === false ? "edit" : "noedit"; dustin@878: }, dustin@878: handler: function(grid, rowIndex, colIndex) { dustin@878: var rec = grid.getStore().getAt(rowIndex); dustin@878: grid.fireEvent('itemdblclick', grid, rec); dustin@878: } raimund@548: }); dustin@856: 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: } dustin@856: if (this.store.$className == 'Lada.store.ProbenList') { dustin@856: // Add a Delete-Button dustin@856: // TODO: Might need to be extended to Messprogramme dustin@856: resultColumns.push({ dustin@856: xtype: 'actioncolumn', dustin@878: text: 'Aktion', dustin@856: sortable: false, dustin@856: width: 30, dustin@856: items: [{ rrenkert@868: icon: 'resources/img/edit-delete.png', dustin@856: tooltip: 'Löschen', dustin@856: isDisabled: function(grid, rowIndex, colIndex) { dustin@856: var rec = grid.getStore().getAt(rowIndex); dustin@856: if ( rec.get('readonly') || !rec.get('owner')) { dustin@856: return true; dustin@856: } dustin@856: return false; dustin@856: }, dustin@856: handler: function(grid, rowIndex, colIndex){ dustin@856: var rec = grid.getStore().getAt(rowIndex); dustin@856: dustin@856: var winname = 'Lada.view.window.DeleteProbe'; dustin@856: var win = Ext.create(winname, { dustin@856: record: rec, dustin@856: parentWindow: this dustin@856: }); dustin@856: win.show(); dustin@856: win.initData(); dustin@856: } dustin@856: }] dustin@856: }); dustin@856: } raimund@548: this.store.model.setFields(fields); raimund@548: this.reconfigure(this.store, resultColumns); raimund@548: } raimund@548: });