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: /** raimund@548: * Grid to list Kommentare raimund@548: */ raimund@548: Ext.define('Lada.view.grid.PKommentar', { raimund@548: extend: 'Ext.grid.Panel', raimund@548: alias: 'widget.pkommentargrid', raimund@548: raimund@548: requires: [ raimund@572: 'Ext.toolbar.Toolbar', raimund@572: 'Lada.store.PKommentare' raimund@548: ], raimund@548: raimund@548: maxHeight: 350, mkrambach@1389: emptyText: 'Keine Kommentare gefunden.', raimund@572: minHeight: 110, raimund@548: viewConfig: { raimund@548: deferEmptyText: false raimund@548: }, raimund@548: raimund@548: recordId: null, dustin@823: readOnly: true, dustin@823: allowDeselect: true, raimund@548: raimund@548: initComponent: function() { raimund@572: this.rowEditing = Ext.create('Ext.grid.plugin.RowEditing', { raimund@548: clicksToMoveEditor: 1, dustin@683: autoCancel: false, dustin@703: disabled: false, dustin@684: pluginId: 'rowedit', dustin@683: listeners:{ dustin@683: // Make row ineditable when readonly is set to true dustin@683: // Normally this would belong into a controller an not the view. dustin@703: // But the RowEditPlugin is not handled there. dustin@683: beforeedit: function(e, o) { dustin@703: var readonlywin = o.grid.up('window').record.get('readonly'); dustin@703: var readonlygrid = o.record.get('readonly'); dustin@703: if (readonlywin == true || readonlygrid == true || this.disabled) { dustin@683: return false; dustin@683: } dustin@683: return true; dustin@683: } dustin@683: } dustin@703: }); raimund@572: this.plugins = [this.rowEditing]; raimund@548: this.dockedItems = [{ raimund@548: xtype: 'toolbar', raimund@548: dock: 'bottom', raimund@548: items: ['->', { raimund@548: text: 'Hinzufügen', raimund@548: icon: 'resources/img/list-add.png', raimund@548: action: 'add', raimund@548: probeId: this.probeId raimund@548: }, { raimund@548: text: 'Löschen', raimund@548: icon: 'resources/img/list-remove.png', raimund@548: action: 'delete' raimund@548: }] raimund@548: }]; raimund@548: this.columns = [{ mstanko@943: header: 'erstellt', mstanko@943: dataIndex: 'datum', mstanko@943: xtype: 'datecolumn', mstanko@943: format: 'd.m.Y H:i', dustin@966: width: 110 mstanko@943: }, { raimund@548: header: 'Erzeuger', tom@1217: dataIndex: 'mstId', raimund@572: width: 140, raimund@572: renderer: function(value) { dustin@959: var r = ''; raimund@572: if (!value || value === '') { dustin@959: r = 'Error'; raimund@572: } raimund@572: var store = Ext.data.StoreManager.get('messstellen'); raimund@572: var record = store.getById(value); dustin@959: if (record) { dustin@959: r = record.get('messStelle'); dustin@959: } dustin@959: return r; raimund@572: }, raimund@548: editor: { raimund@572: xtype: 'combobox', dustin@971: store: Ext.data.StoreManager.get('messstellenFiltered'), raimund@572: displayField: 'messStelle', raimund@572: valueField: 'id', raimund@548: allowBlank: false raimund@548: } raimund@548: }, { raimund@548: header: 'Text', raimund@548: dataIndex: 'text', raimund@548: flex: 1, raimund@572: renderer: function(value) { raimund@572: return '
' + raimund@572: value + '
'; raimund@572: }, raimund@548: editor: { raimund@572: xtype: 'textarea', raimund@548: allowBlank: false raimund@548: } raimund@548: }]; dustin@823: this.listeners = { dustin@823: select: { dustin@823: fn: this.activateRemoveButton, dustin@823: scope: this dustin@823: }, dustin@823: deselect: { dustin@823: fn: this.deactivateRemoveButton, dustin@823: scope: this dustin@823: } dustin@823: }; raimund@572: this.initData(); raimund@548: this.callParent(arguments); dustin@823: this.setReadOnly(true); //Grid is always initialised as RO raimund@572: }, raimund@572: raimund@572: initData: function() { raimund@572: this.store = Ext.create('Lada.store.PKommentare'); raimund@572: this.store.load({ raimund@572: params: { raimund@572: probeId: this.recordId raimund@572: } raimund@572: }); dustin@684: }, dustin@684: dustin@684: setReadOnly: function(b) { raimund@1034: this.readOnly = b; raimund@1034: if (b) { dustin@684: //Readonly raimund@1035: if (this.getPlugin('rowedit')) { dustin@684: this.getPlugin('rowedit').disable(); dustin@684: } dustin@684: this.down('button[action=delete]').disable(); dustin@684: this.down('button[action=add]').disable(); raimund@1035: } raimund@1035: else { dustin@684: //Writable raimund@1035: if (this.getPlugin('rowedit')) { dustin@684: this.getPlugin('rowedit').enable(); dustin@684: } dustin@824: //this.down('button[action=delete]').enable(); dustin@684: this.down('button[action=add]').enable(); dustin@684: } dustin@823: }, dustin@823: /** dustin@823: * Activate the Remove Button dustin@823: */ dustin@823: activateRemoveButton: function(selection, record) { dustin@823: var grid = this; dustin@823: //only enable the remove buttone, when the grid is editable. dustin@823: if (! grid.readOnly) { dustin@823: grid.down('button[action=delete]').enable(); dustin@823: } dustin@823: }, dustin@823: /** dustin@823: * Activate the Remove Button dustin@823: */ dustin@823: deactivateRemoveButton: function(selection, record) { dustin@823: var grid = this; dustin@823: //only enable the remove buttone, when the grid is editable. dustin@823: if (! grid.readOnly) { dustin@823: grid.down('button[action=delete]').disable(); dustin@823: } raimund@548: } dustin@823: raimund@548: });