raimund@588: /* Copyright (C) 2013 by Bundesamt fuer Strahlenschutz raimund@588: * Software engineering by Intevation GmbH raimund@588: * raimund@588: * This file is Free Software under the GNU GPL (v>=3) raimund@588: * and comes with ABSOLUTELY NO WARRANTY! Check out raimund@588: * the documentation coming with IMIS-Labordaten-Application for details. raimund@588: */ raimund@588: dustin@893: /** raimund@588: * Grid to list Messungen raimund@588: */ raimund@588: Ext.define('Lada.view.grid.Messung', { raimund@588: extend: 'Ext.grid.Panel', raimund@588: alias: 'widget.messunggrid', raimund@588: raimund@588: maxHeight: 350, raimund@588: emptyText: 'Keine Messungen gefunden', raimund@588: minHeight: 110, raimund@588: viewConfig: { raimund@588: deferEmptyText: false raimund@588: }, raimund@588: margin: '0, 5, 5, 5', raimund@588: raimund@588: recordId: null, raimund@588: raimund@588: warnings: null, raimund@588: errors: null, dustin@823: readOnly: true, dustin@823: allowDeselect: true, raimund@588: raimund@588: initComponent: function() { raimund@588: this.dockedItems = [{ raimund@588: xtype: 'toolbar', raimund@588: dock: 'bottom', raimund@588: items: ['->', { raimund@588: text: 'Hinzufügen', raimund@588: icon: 'resources/img/list-add.png', raimund@588: action: 'add', raimund@588: probeId: this.probeId raimund@588: }, { raimund@588: text: 'Löschen', raimund@588: icon: 'resources/img/list-remove.png', raimund@588: action: 'delete' raimund@588: }] raimund@588: }]; raimund@588: this.columns = [{ raimund@588: header: 'Mess-ID', raimund@588: dataIndex: 'id', raimund@588: flex: 1, raimund@588: editor: { raimund@588: allowBlank: false raimund@588: } raimund@588: }, { raimund@588: header: 'Nebenproben-Nr.', raimund@588: dataIndex: 'nebenprobenNr', raimund@588: flex: 1, raimund@588: editor: { raimund@588: allowBlank: false raimund@588: } raimund@588: }, { raimund@588: header: 'MMT', raimund@588: dataIndex: 'mmtId', raimund@588: flex: 1, raimund@588: editor: { raimund@588: allowBlank: false raimund@588: } raimund@588: }, { raimund@588: header: 'Messzeit', raimund@588: dataIndex: 'messzeitpunkt', dustin@627: xtype: 'datecolumn', dustin@627: format: 'd.m.Y H:i', raimund@588: flex: 2, raimund@588: editor: { raimund@588: xtype: 'datefield', raimund@588: allowBlank: false, dustin@627: format: 'd.m.Y H:i', raimund@588: // minValue: '01.01.2001', //todo: gibt es das? raimund@588: // minText: 'Das Datum der Messung darf nicht vor dem 01.01.2001 liegen.', dustin@627: maxValue: Ext.Date.format(new Date(), 'd.m.Y H:i') raimund@588: } raimund@588: }, { raimund@588: header: 'Status', raimund@588: flex: 1, raimund@588: dataIndex: 'id', raimund@588: renderer: function(value) { dustin@945: var statusId = this.store.getById(value).get('status'); dustin@945: var divId = 'messung-status-item' + value; dustin@945: this.updateStatus(value, divId, statusId); dustin@945: return '
Lade...
'; raimund@588: } raimund@588: }, { raimund@588: header: 'OK-Flag', raimund@588: dataIndex: 'fertig', raimund@588: flex: 1, raimund@588: renderer: function(value) { raimund@588: if (value) { raimund@588: return 'Ja'; raimund@588: } raimund@588: return 'Nein'; raimund@588: }, raimund@588: editor: { raimund@588: xtype: 'checkboxfield', raimund@588: allowBlank: false raimund@588: } raimund@588: }, { raimund@588: header: 'Anzahl Nuklide', raimund@588: // Gibt die Anzahl der Messwerte wieder, raimund@588: // NICHT die Anzahl der verschiedenen Nukleide raimund@588: // Eventuell ist die Bezeichnug daher irreführend raimund@588: dataIndex: 'id', raimund@588: flex: 1, raimund@588: renderer: function(value) { raimund@588: var id = 'messung-nuklid-item' + value; raimund@588: this.updateNuklide(value, id); raimund@588: return '
Lade...
'; raimund@588: } raimund@588: }, { raimund@588: header: 'Anzahl Kommentare', raimund@588: flex: 1, raimund@588: dataIndex: 'id', raimund@588: renderer: function(value) { raimund@588: var id = 'messung-kommentar-item' + value; raimund@588: this.updateKommentare(value, id); raimund@588: return '
Lade...
'; raimund@588: } raimund@588: }]; 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@588: this.initData(); raimund@588: this.callParent(arguments); dustin@823: this.setReadOnly(true); //Grid is always initialised as RO raimund@588: }, raimund@588: raimund@588: initData: function() { raimund@588: this.store = Ext.create('Lada.store.Messungen'); raimund@588: this.store.load({ raimund@588: params: { raimund@588: probeId: this.recordId raimund@588: } raimund@588: }); raimund@588: }, raimund@588: dustin@945: /** dustin@945: * Load the statusstore, dustin@945: * afterwards: retrieve the statusid dustin@945: */ dustin@945: updateStatus: function(value, divId, statusId) { raimund@588: var statusStore = Ext.create('Lada.store.Status'); raimund@588: statusStore.on('load', raimund@588: this.updateStatusColumn, raimund@588: this, dustin@945: {divId: divId, statusId: statusId}); raimund@588: statusStore.load({ raimund@588: params: { raimund@588: messungsId: value raimund@588: } raimund@588: }); raimund@588: }, raimund@588: raimund@588: updateNuklide: function(value, divId) { raimund@588: var messwerte = Ext.create('Lada.store.Messwerte'); raimund@588: messwerte.on('load', raimund@588: this.updateColumn, raimund@588: this, raimund@588: {divId: divId}); raimund@588: messwerte.load({ raimund@588: params: { raimund@588: messungsId: value raimund@588: } raimund@588: }); raimund@588: }, raimund@588: raimund@588: updateKommentare: function(value, divId) { raimund@588: var kommentare = Ext.create('Lada.store.MKommentare'); raimund@588: kommentare.on('load', raimund@588: this.updateColumn, raimund@588: this, raimund@588: {divId: divId}); raimund@588: kommentare.load({ raimund@588: params: { raimund@588: messungsId: value raimund@588: } raimund@588: }); raimund@588: }, raimund@588: raimund@588: updateColumn: function(store, record, success, opts) { raimund@588: var value; raimund@588: if (store.getTotalCount() === 0) { raimund@588: value = 'Keine'; raimund@588: } raimund@588: else { raimund@588: value = store.getTotalCount(); raimund@588: } raimund@588: Ext.fly(opts.divId).update(value); raimund@588: }, raimund@588: dustin@945: /** dustin@945: * Retrieve Statuswert and update the column dustin@945: */ raimund@588: updateStatusColumn: function(sstore, record, success, opts) { dustin@945: var value = 0; raimund@588: if (sstore.getTotalCount() === 0) { dustin@813: value = 0; raimund@588: } raimund@588: else { dustin@945: value = sstore.getById(opts.statusId).get('statusWert'); raimund@588: } raimund@588: if (Ext.fly(opts.divId)) { dustin@945: var sta = Ext.StoreManager.lookup('StatusWerte'); dustin@945: if (!sta) { dustin@945: var sta = Ext.create('Lada.store.StatusWerte'); dustin@945: } dustin@945: var val = 'error'; dustin@945: sta.load({ dustin@945: scope: this, dustin@945: callback: function(records, operation, success) { dustin@945: if (success) { dustin@945: try { dustin@945: val = sta.getById(value).get('wert'); dustin@945: } dustin@945: catch (e) { dustin@945: } dustin@945: } dustin@945: Ext.fly(opts.divId).update(val); dustin@945: } dustin@945: }); raimund@588: } 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@823: //this.down('button[action=delete]').enable(); dustin@823: //always disabled, unless a row was selected 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@588: } raimund@588: });