dustin@975: /* Copyright (C) 2013 by Bundesamt fuer Strahlenschutz dustin@975: * Software engineering by Intevation GmbH dustin@975: * dustin@975: * This file is Free Software under the GNU GPL (v>=3) dustin@975: * and comes with ABSOLUTELY NO WARRANTY! Check out dustin@975: * the documentation coming with IMIS-Labordaten-Application for details. dustin@975: */ dustin@975: dustin@975: /** dustin@975: * Grid to list Probenehmer Stammdaten dustin@975: */ dustin@975: Ext.define('Lada.view.grid.Probenehmer', { dustin@975: extend: 'Ext.grid.Panel', dustin@975: alias: 'widget.probenehmergrid', dustin@975: dustin@975: // minHeight and deferEmptyText are needed to be able to show the dustin@975: // emptyText message. dustin@975: minHeight: 110, dustin@975: viewConfig: { dustin@975: deferEmptyText: false dustin@975: }, dustin@975: dustin@975: warnings: null, dustin@975: errors: null, dustin@975: readOnly: true, dustin@975: allowDeselect: true, dustin@975: dustin@975: initComponent: function() { dustin@975: var i18n = Lada.getApplication().bundle; dustin@975: this.emptyText = i18n.getMsg('pn.emptyGrid'); dustin@975: dustin@975: // TODO: Which docked Items are required? dustin@975: this.dockedItems = [{ dustin@975: xtype: 'toolbar', dustin@975: dock: 'top', dustin@975: items: [{ dustin@975: xtype: 'tbtext', dustin@975: id: 'tbtitle', dustin@975: text: i18n.getMsg('pn.gridTitle') dustin@975: }] dustin@975: /* dustin@975: //bottom toolbar? dustin@975: }, { dustin@975: xtype: 'toolbar', dustin@975: dock: 'bottom', dustin@975: items: ['->', { dustin@975: text: 'Hinzufügen', dustin@975: icon: 'resources/img/list-add.png', dustin@975: action: 'add', dustin@975: probeId: this.probeId dustin@975: }, { dustin@975: text: 'Löschen', dustin@975: icon: 'resources/img/list-remove.png', dustin@975: action: 'delete' dustin@975: }] dustin@975: */ dustin@975: }]; dustin@975: /* dustin@975: // Do we have row-editing dustin@975: this.rowEditing = Ext.create('Ext.grid.plugin.RowEditing', { dustin@975: clicksToMoveEditor: 1, dustin@975: autoCancel: false, dustin@975: disabled: false, dustin@975: pluginId: 'rowedit', dustin@975: listeners:{ dustin@975: // Make row ineditable when readonly is set to true dustin@975: // Normally this would belong into a controller an not the view. dustin@975: // But the RowEditPlugin is not handled there. dustin@975: beforeedit: function(e, o) { dustin@975: var readonlywin = o.grid.up('window').record.get('readonly'); dustin@975: var readonlygrid = o.record.get('readonly'); dustin@975: if (readonlywin == true || readonlygrid == true || this.disabled) { dustin@975: return false; dustin@975: } dustin@975: return true; dustin@975: } dustin@975: } dustin@975: }); dustin@975: this.plugins = [this.rowEditing]; dustin@975: */ dustin@975: this.columns = [{ dustin@975: header: i18n.getMsg('netzbetreiberId'), dustin@975: dataIndex: 'netzbetreiberId', dustin@975: renderer: function(value) { dustin@975: var r = ''; dustin@975: if (!value || value === '') { dustin@975: r = 'Error'; dustin@975: } dustin@975: var store = Ext.data.StoreManager.get('netzbetreiber'); dustin@975: var record = store.getById(value); dustin@975: if (record) { dustin@975: r = record.get('netzbetreiber'); dustin@975: } dustin@975: return r; dustin@975: }, dustin@975: editor: { dustin@975: xtype: 'combobox', dustin@975: store: Ext.data.StoreManager.get('netzbetreiber'), dustin@975: displayField: 'netzbetreiber', dustin@975: valueField: 'id', dustin@975: allowBlank: false dustin@975: } dustin@975: }, { dustin@975: header: i18n.getMsg('bearbeiter'), dustin@975: dataIndex: 'bearbeiter', dustin@975: editor: { dustin@975: allowBlank: false dustin@975: } dustin@975: }, { dustin@975: header: i18n.getMsg('prnId'), dustin@975: dataIndex: 'prnId', dustin@975: editor: { dustin@975: allowBlank: false dustin@975: } dustin@975: }, { dustin@975: header: i18n.getMsg('bemerkung'), dustin@975: dataIndex: 'bemerkung', dustin@975: editor: { dustin@975: allowBlank: false dustin@975: } dustin@975: }, { dustin@975: header: i18n.getMsg('kurzBezeichnung'), dustin@975: dataIndex: 'kurzBezeichnung', dustin@975: editor: { dustin@975: allowBlank: false dustin@975: } dustin@975: }, { dustin@975: header: i18n.getMsg('ort'), dustin@975: dataIndex: 'ort', dustin@975: editor: { dustin@975: allowBlank: false dustin@975: } dustin@975: }, { dustin@975: header: i18n.getMsg('plz'), dustin@975: dataIndex: 'plz', dustin@975: editor: { dustin@975: allowBlank: false dustin@975: } dustin@975: }, { dustin@975: header: i18n.getMsg('strasse'), dustin@975: dataIndex: 'strasse', dustin@975: editor: { dustin@975: allowBlank: false dustin@975: } dustin@975: }, { dustin@975: header: i18n.getMsg('telefon'), dustin@975: dataIndex: 'telefon', dustin@975: editor: { dustin@975: allowBlank: false dustin@975: } dustin@975: }, { dustin@975: header: i18n.getMsg('tp'), dustin@975: dataIndex: 'tp', dustin@975: editor: { dustin@975: allowBlank: false dustin@975: } dustin@975: }, { dustin@975: header: i18n.getMsg('typ'), dustin@975: dataIndex: 'typ', dustin@975: editor: { dustin@975: allowBlank: false dustin@975: } dustin@975: }, { dustin@975: header: i18n.getMsg('letzteAenderung'), dustin@975: dataIndex: 'letzteAenderung' dustin@975: }]; dustin@975: this.listeners = { dustin@975: select: { dustin@975: fn: this.activateRemoveButton, dustin@975: scope: this dustin@975: }, dustin@975: deselect: { dustin@975: fn: this.deactivateRemoveButton, dustin@975: scope: this dustin@975: } dustin@975: }; dustin@975: // this.initData(); //This will be called by the Query Component. dustin@975: this.callParent(arguments); dustin@975: //TODO this.setReadOnly(true); //Grid is always initialised as RO dustin@975: }, dustin@975: dustin@975: initData: function() { dustin@975: this.store = Ext.create('Lada.store.DatensatzErzeuger'); dustin@975: this.store.load(); //TODO: Params? dustin@975: }, dustin@975: dustin@975: setReadOnly: function(b) { dustin@975: if (b == true){ dustin@975: //Readonly dustin@975: if (this.getPlugin('rowedit')){ dustin@975: this.getPlugin('rowedit').disable(); dustin@975: } dustin@975: try { dustin@975: this.down('button[action=delete]').disable(); dustin@975: this.down('button[action=add]').disable(); dustin@975: } dustin@975: catch(e) { dustin@975: //TODO: Do Nothing... dustin@975: } dustin@975: }else{ dustin@975: //Writable dustin@975: if (this.getPlugin('rowedit')){ dustin@975: this.getPlugin('rowedit').enable(); dustin@975: } dustin@975: try { dustin@975: this.down('button[action=delete]').enable(); dustin@975: this.down('button[action=add]').enable(); dustin@975: } dustin@975: catch(e) { dustin@975: //TODO: Do Nothing... dustin@975: } dustin@975: } dustin@975: }, dustin@975: /** dustin@975: * Activate the Remove Button dustin@975: */ dustin@975: activateRemoveButton: function(selection, record) { dustin@975: var grid = this; dustin@975: //only enable the remove buttone, when the grid is editable. dustin@975: if (! grid.readOnly) { dustin@975: try { dustin@975: grid.down('button[action=delete]').enable(); dustin@975: } dustin@975: catch(e) { dustin@975: //TODO: Do Nothing dustin@975: } dustin@975: } dustin@975: }, dustin@975: /** dustin@975: * deactivate the Remove Button dustin@975: */ dustin@975: deactivateRemoveButton: function(selection, record) { dustin@975: var grid = this; dustin@975: //only enable the remove buttone, when the grid is editable. dustin@975: if (! grid.readOnly) { dustin@975: try { dustin@975: grid.down('button[action=delete]').disable(); dustin@975: } dustin@975: catch(e) { dustin@975: //TODO: Do Nothing dustin@975: } dustin@975: } dustin@975: } dustin@975: }); dustin@975: