raimund@594: /* Copyright (C) 2013 by Bundesamt fuer Strahlenschutz raimund@594: * Software engineering by Intevation GmbH raimund@594: * raimund@594: * This file is Free Software under the GNU GPL (v>=3) raimund@594: * and comes with ABSOLUTELY NO WARRANTY! Check out raimund@594: * the documentation coming with IMIS-Labordaten-Application for details. raimund@594: */ raimund@594: dustin@893: /** raimund@594: * Grid to list Status raimund@594: */ raimund@594: Ext.define('Lada.view.grid.Status', { raimund@594: extend: 'Ext.grid.Panel', raimund@594: alias: 'widget.statusgrid', raimund@594: raimund@594: maxHeight: 350, raimund@594: emptyText: 'Keine Statusangaben gefunden.', raimund@594: minHeight: 110, raimund@594: viewConfig: { raimund@594: deferEmptyText: false raimund@594: }, raimund@594: raimund@594: recordId: null, dustin@824: readOnly: true, dustin@824: allowDeselect: true, raimund@594: raimund@594: initComponent: function() { raimund@594: this.rowEditing = Ext.create('Ext.grid.plugin.RowEditing', { raimund@594: clicksToMoveEditor: 1, dustin@683: autoCancel: false, dustin@945: disabled: true, 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@945: 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@945: }); raimund@594: this.plugins = [this.rowEditing]; raimund@594: dustin@956: var statusWerteStore = Ext.create('Lada.store.StatusWerte'); dustin@956: statusWerteStore.load(); dustin@956: var statusStufeStore = Ext.create('Lada.store.StatusStufe'); dustin@956: statusStufeStore.load(); raimund@594: this.dockedItems = [{ raimund@594: xtype: 'toolbar', raimund@594: dock: 'bottom', raimund@594: items: ['->', { raimund@594: text: 'Hinzufügen', raimund@594: icon: 'resources/img/list-add.png', raimund@594: action: 'add', raimund@594: probeId: this.probeId, raimund@594: parentId: this.parentId raimund@594: }, { raimund@594: text: 'Löschen', raimund@594: icon: 'resources/img/list-remove.png', raimund@594: action: 'delete' raimund@594: }] raimund@594: }]; raimund@594: this.columns = [{ mstanko@944: header: 'erstellt', dustin@945: dataIndex: 'datum', mstanko@944: xtype: 'datecolumn', mstanko@944: format: 'd.m.Y H:i', mstanko@944: width: 110, dustin@945: sortable: false, mstanko@944: }, { raimund@594: header: 'Erzeuger', raimund@594: dataIndex: 'erzeuger', raimund@594: renderer: function(value) { raimund@594: if (!value || value === '') { raimund@594: return ''; raimund@594: } raimund@594: var mstore = Ext.data.StoreManager.get('messstellen'); raimund@594: return mstore.getById(value).get('messStelle'); raimund@594: }, raimund@594: editor: { raimund@594: xtype: 'combobox', raimund@594: store: Ext.data.StoreManager.get('messstellen'), raimund@594: displayField: 'messStelle', raimund@594: valueField: 'id', dustin@663: allowBlank: false, dustin@663: editable: false dustin@945: }, dustin@945: sortable: false, raimund@594: }, { dustin@956: header: 'Stufe', dustin@956: dataIndex: 'statusStufe', dustin@956: renderer: function(value) { dustin@956: if (value===null || value === '' || value === 0) { dustin@956: return 'Fehlerhafte Daten'; dustin@956: } dustin@956: var r = statusStufeStore.getById(value).get('stufe') dustin@956: if (r === null) { dustin@956: r = 'Error'; dustin@956: } dustin@956: return r; dustin@956: }, dustin@956: editor: { dustin@956: xtype: 'combobox', dustin@956: store: statusStufeStore, dustin@956: displayField: 'stufe', dustin@956: valueField: 'id', dustin@956: allowBlank: false, dustin@956: editable: false dustin@956: }, dustin@956: sortable: false, dustin@956: }, { raimund@594: header: 'Status', dustin@945: dataIndex: 'statusWert', raimund@594: renderer: function(value) { dustin@950: if (value===null || value === '') { raimund@594: return ''; raimund@594: } dustin@956: var r = statusWerteStore.getById(value).get('wert') dustin@956: if (r === null) { dustin@956: r = 'Error'; dustin@956: } dustin@956: return r; raimund@594: }, raimund@594: editor: { raimund@594: xtype: 'combobox', dustin@956: store: statusWerteStore, dustin@945: displayField: 'wert', raimund@594: valueField: 'id', dustin@663: allowBlank: false, dustin@663: editable: false dustin@945: }, dustin@945: sortable: false, raimund@594: }, { raimund@594: header: 'Text', dustin@945: dataIndex: 'text', raimund@594: flex: 1, raimund@594: editor: { dustin@663: allowBlank: true, dustin@663: maxLength: 1000, dustin@663: enforceMaxLength: true dustin@945: }, dustin@945: sortable: false, raimund@594: }]; 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@594: this.initData(); raimund@594: this.callParent(arguments); dustin@824: this.setReadOnly(true); //Grid is always initialised as RO raimund@594: }, raimund@594: raimund@594: initData: function() { raimund@594: if (this.store) { raimund@594: this.store.removeAll(); raimund@594: } raimund@594: else { raimund@594: this.store = Ext.create('Lada.store.Status'); raimund@594: } raimund@594: this.store.load({ raimund@594: params: { raimund@594: messungsId: this.recordId raimund@594: } raimund@594: }); 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@945: * 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@945: * Deactivate 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@594: } raimund@594: });