raimund@590: /* Copyright (C) 2013 by Bundesamt fuer Strahlenschutz raimund@590: * Software engineering by Intevation GmbH raimund@590: * raimund@590: * This file is Free Software under the GNU GPL (v>=3) raimund@590: * and comes with ABSOLUTELY NO WARRANTY! Check out raimund@590: * the documentation coming with IMIS-Labordaten-Application for details. raimund@590: */ raimund@590: dustin@893: /** raimund@590: * Grid to list Messwerte raimund@590: */ raimund@590: Ext.define('Lada.view.grid.Messwert', { raimund@590: extend: 'Ext.grid.Panel', raimund@590: alias: 'widget.messwertgrid', raimund@590: raimund@590: requires: [ tom@1119: 'Lada.view.form.ExpNumberField', raimund@590: 'Lada.view.widget.Messgroesse', raimund@590: 'Lada.view.widget.Messeinheit' raimund@590: ], raimund@590: raimund@590: maxHeight: 350, raimund@590: emptyText: 'Keine Messwerte gefunden.', raimund@590: minHeight: 110, raimund@590: viewConfig: { raimund@590: deferEmptyText: false raimund@590: }, raimund@590: margin: '0, 5, 5, 5', raimund@590: raimund@590: recordId: null, dustin@824: readOnly: true, dustin@824: allowDeselect: true, raimund@845: messgroesseStore: null, raimund@1112: bottomBar: true, raimund@590: raimund@590: initComponent: function() { raimund@590: this.rowEditing = Ext.create('Ext.grid.plugin.RowEditing', { raimund@590: 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) { raimund@1112: // We are not in a messung window! raimund@1112: if (!o.grid.up('window')) { raimund@1112: return false; raimund@1112: } raimund@1112: // We are in a messung window and should check if we can raimund@1112: // edit. 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: } raimund@845: }); raimund@845: var me = this; raimund@590: this.plugins = [this.rowEditing]; raimund@590: raimund@590: this.dockedItems = [{ raimund@590: xtype: 'toolbar', raimund@590: dock: 'bottom', raimund@590: items: ['->', { raimund@590: text: 'Hinzufügen', raimund@590: icon: 'resources/img/list-add.png', raimund@590: action: 'add', raimund@590: probeId: this.probeId, raimund@590: parentId: this.parentId raimund@590: }, { raimund@590: text: 'Löschen', raimund@590: icon: 'resources/img/list-remove.png', raimund@590: action: 'delete' raimund@590: }] raimund@590: }]; raimund@590: this.columns = [{ raimund@590: header: 'Messgröße', raimund@590: dataIndex: 'messgroesseId', raimund@590: width: 80, raimund@590: renderer: function(value) { raimund@590: if (!value || value === '') { raimund@590: return ''; raimund@590: } raimund@590: var store = Ext.data.StoreManager.get('messgroessen'); dustin@736: return store.findRecord('id', value, 0, false, false, true).get('messgroesse'); raimund@590: }, raimund@590: editor: { raimund@590: xtype: 'combobox', raimund@845: store: me.messgroesseStore, raimund@590: displayField: 'messgroesse', raimund@590: valueField: 'id', dustin@662: allowBlank: false, dustin@739: editable: true, dustin@739: forceSelection: true, dustin@739: autoSelect: true, dustin@739: queryMode: 'local', dustin@739: minChars: 0, dustin@739: typeAhead: false, dustin@739: triggerAction: 'all' raimund@590: } raimund@590: }, { mstanko@991: header: '<NWG', mstanko@991: width: 60, mstanko@991: dataIndex: 'messwertNwg', mstanko@991: editor: { mstanko@993: xtype: 'checkbox', raimund@1054: inputValue: '<' mstanko@991: } mstanko@991: }, { raimund@590: header: 'Messwert', raimund@590: dataIndex: 'messwert', raimund@590: width: 80, raimund@590: editor: { tom@1119: xtype: 'expnumberfield', dustin@662: allowBlank: false, tom@1123: maxValue: 9.99e+99, tom@1123: minValue: 1e-99 tom@1119: }, tom@1119: renderer: function(value) { tom@1123: if (!value || value === '') { tom@1123: return value; tom@1123: } tom@1123: var strValue = value.toExponential(2).toString() tom@1123: .replace('.', Ext.util.Format.decimalSeparator); tom@1123: var splitted = strValue.split('e'); tom@1123: var exponent = parseInt(splitted[1]); tom@1123: return splitted[0] + 'e' tom@1123: + ((exponent < 0) ? '-' : '+') tom@1123: + ((Math.abs(exponent) < 10) ? '0' : '') tom@1123: + Math.abs(exponent).toString(); raimund@590: } raimund@590: }, { raimund@590: header: 'Messeinheit', raimund@590: dataIndex: 'mehId', raimund@590: width: 90, raimund@590: renderer: function(value) { raimund@590: if (!value || value === '') { raimund@590: return ''; raimund@590: } raimund@590: var store = Ext.data.StoreManager.get('messeinheiten'); dustin@736: return store.findRecord('id', value, 0, false, false, true).get('einheit'); raimund@590: }, raimund@590: editor: { raimund@590: xtype: 'combobox', raimund@590: store: Ext.data.StoreManager.get('messeinheiten'), raimund@590: displayField: 'einheit', raimund@590: valueField: 'id', dustin@662: allowBlank: false, dustin@740: editable: true, dustin@740: forceSelection: true, dustin@740: autoSelect: true, dustin@740: queryMode: 'local', dustin@740: minChars: 0, dustin@740: typeAhead: false, dustin@740: triggerAction: 'all' raimund@590: } raimund@590: }, { raimund@590: header: 'Messfehler', raimund@590: dataIndex: 'messfehler', dustin@624: xtype: 'numbercolumn', raimund@590: width: 80, raimund@590: editor: { raimund@590: xtype: 'numberfield', dustin@662: allowBlank: false, dustin@662: maxLength: 10, dustin@662: allowExponential: false, dustin@718: enforceMaxLength: true raimund@590: } raimund@590: }, { mstanko@991: header: 'Nachweisgrenze', mstanko@991: dataIndex: 'nwgZuMesswert', mstanko@991: width: 80, mstanko@991: editor: { tom@1123: xtype: 'expnumberfield', tom@1123: maxValue: 9.99e+99, tom@1123: minValue: 1e-99 tom@1119: }, tom@1119: renderer: function(value) { tom@1119: if (!value || value === '') { tom@1119: return value; tom@1119: } tom@1123: var strValue = value.toExponential(2).toString() tom@1123: .replace('.', Ext.util.Format.decimalSeparator); tom@1123: var splitted = strValue.split('e'); tom@1123: var exponent = parseInt(splitted[1]); tom@1123: return splitted[0] + 'e' tom@1123: + ((exponent < 0) ? '-' : '+') tom@1123: + ((Math.abs(exponent) < 10) ? '0' : '') tom@1123: + Math.abs(exponent).toString(); mstanko@991: } mstanko@991: }, { raimund@590: header: 'Grenzwertüberschreitung', raimund@590: dataIndex: 'grenzwertueberschreitung', raimund@590: flex: 1, raimund@590: renderer: function(value) { raimund@590: if (value === true) { raimund@590: return 'Ja'; raimund@590: } raimund@590: return 'Nein'; raimund@590: }, raimund@590: editor: { raimund@590: xtype: 'checkbox' raimund@590: } raimund@590: }]; 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@590: this.initData(); raimund@590: this.callParent(arguments); dustin@824: this.setReadOnly(true); //Grid is always initialised as RO raimund@1112: if (!me.bottomBar) { raimund@1112: this.down('toolbar[dock=bottom]').hide(); raimund@1112: } raimund@590: }, raimund@590: raimund@590: initData: function() { raimund@590: if (this.store) { raimund@590: this.store.removeAll(); raimund@590: } raimund@590: else { raimund@590: this.store = Ext.create('Lada.store.Messwerte'); raimund@590: } raimund@590: this.store.load({ raimund@590: params: { raimund@590: messungsId: this.recordId raimund@590: } raimund@590: }); 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@687: if (this.getPlugin('rowedit')){ dustin@687: this.getPlugin('rowedit').enable(); dustin@687: } dustin@824: //this.down('button[action=delete]').enable(); dustin@687: this.down('button[action=add]').enable(); dustin@687: } 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@590: } raimund@590: });