raimund@596: /* Copyright (C) 2013 by Bundesamt fuer Strahlenschutz raimund@596: * Software engineering by Intevation GmbH raimund@596: * raimund@596: * This file is Free Software under the GNU GPL (v>=3) raimund@596: * and comes with ABSOLUTELY NO WARRANTY! Check out raimund@596: * the documentation coming with IMIS-Labordaten-Application for details. raimund@596: */ raimund@596: dustin@893: /** raimund@596: * Grid to list Kommentare for Messunge raimund@596: */ raimund@596: Ext.define('Lada.view.grid.MKommentar', { raimund@596: extend: 'Ext.grid.Panel', raimund@596: alias: 'widget.mkommentargrid', raimund@596: raimund@596: maxHeight: 350, raimund@596: emptyText: 'Keine Kommentare gefunden.', raimund@596: minHeight: 110, raimund@596: viewConfig: { raimund@596: deferEmptyText: false raimund@596: }, raimund@596: raimund@596: recordId: null, dustin@824: readOnly: true, dustin@824: allowDeselect: true, raimund@596: raimund@596: initComponent: function() { raimund@596: this.rowEditing = Ext.create('Ext.grid.plugin.RowEditing', { raimund@596: 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@596: this.plugins = [this.rowEditing]; raimund@596: this.dockedItems = [{ raimund@596: xtype: 'toolbar', raimund@596: dock: 'bottom', raimund@596: items: ['->', { raimund@596: text: 'Hinzufügen', raimund@596: icon: 'resources/img/list-add.png', raimund@596: action: 'add' raimund@596: }, { raimund@596: text: 'Löschen', raimund@596: icon: 'resources/img/list-remove.png', raimund@596: action: 'delete' raimund@596: }] raimund@596: }]; raimund@596: 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@596: header: 'Erzeuger', raimund@596: dataIndex: 'erzeuger', raimund@596: renderer: function(value) { dustin@959: var r = ''; raimund@596: if (!value || value === '') { dustin@959: r = 'Error'; raimund@596: } dustin@959: var store = Ext.data.StoreManager.get('messstellen'); dustin@959: var record = store.getById(value); dustin@959: if (record) { dustin@959: r = record.get('messStelle'); dustin@959: } dustin@959: return r; raimund@596: }, raimund@596: editor: { raimund@596: xtype: 'combobox', dustin@971: store: Ext.data.StoreManager.get('messstellenFiltered'), raimund@596: displayField: 'messStelle', raimund@596: valueField: 'id', dustin@664: allowBlank: false, dustin@718: editable: false raimund@596: } raimund@596: }, { raimund@596: header: 'Text', raimund@596: dataIndex: 'text', raimund@596: flex: 1, ehuber@1172: renderer: function(value) { ehuber@1172: return '
' + ehuber@1172: value + '
'; ehuber@1172: }, raimund@596: editor: { ehuber@1172: xtype: 'textarea', dustin@664: allowBlank: false, dustin@664: maxLength: 1000, dustin@664: enforceMaxLength: true raimund@596: } raimund@596: }]; dustin@824: this.listeners = { dustin@824: select: { dustin@824: fn: this.activateRemoveButton, dustin@824: scope: this dustin@824: }, dustin@824: deselect: { dustin@824: fn: this.deactivateRemoveButton, dustin@824: scope: this dustin@824: } dustin@824: }; raimund@596: this.initData(); raimund@596: this.callParent(arguments); dustin@824: this.setReadOnly(true); //Grid is always initialised as RO raimund@596: }, raimund@596: raimund@596: initData: function() { raimund@596: if (this.store) { raimund@596: this.store.removeAll(); raimund@596: } raimund@596: else { raimund@596: this.store = Ext.create('Lada.store.MKommentare'); raimund@596: } raimund@596: this.store.load({ raimund@596: params: { raimund@596: messungsId: this.recordId raimund@596: } raimund@596: }); dustin@684: }, dustin@684: dustin@684: setReadOnly: function(b) { dustin@684: if (b == true){ dustin@684: //Readonly dustin@684: 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(); dustin@684: }else{ dustin@684: //Writable dustin@684: 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@824: }, dustin@824: /** dustin@824: * Activate the Remove Button dustin@824: */ dustin@824: activateRemoveButton: function(selection, record) { dustin@824: var grid = this; dustin@824: //only enable the remove buttone, when the grid is editable. dustin@824: if (! grid.readOnly) { dustin@824: grid.down('button[action=delete]').enable(); dustin@824: } dustin@824: }, dustin@824: /** dustin@824: * Activate the Remove Button dustin@824: */ dustin@824: deactivateRemoveButton: function(selection, record) { dustin@824: var grid = this; dustin@824: //only enable the remove buttone, when the grid is editable. dustin@824: if (! grid.readOnly) { dustin@824: grid.down('button[action=delete]').disable(); dustin@824: } raimund@596: } raimund@596: });