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', ehuber@1163: minHeight: 44, raimund@588: viewConfig: { raimund@588: deferEmptyText: false raimund@588: }, ehuber@1163: margin: '0, 5, 15, 5', raimund@588: raimund@588: recordId: null, raimund@588: raimund@588: warnings: null, raimund@588: errors: null, dustin@823: readOnly: true, raimund@1111: bottomBar: 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 = [{ mstanko@1257: xtype: 'actioncolumn', mstanko@1257: text: '', mstanko@1257: dataIndex: 'readonly', mstanko@1257: sortable: false, mstanko@1257: width: 30, mstanko@1257: getClass: function (val, meta, rec) { mstanko@1257: if (rec.get('readonly') === false) { mstanko@1257: return 'edit'; mstanko@1257: } mstanko@1257: return 'noedit'; mstanko@1257: }, mstanko@1257: handler: function(grid, rowIndex, colIndex) { mstanko@1257: var rec = grid.getStore().getAt(rowIndex); mstanko@1257: grid.fireEvent('itemdblclick', grid, rec); mstanko@1257: } mstanko@1257: }, { 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, tom@1217: dataIndex: 'statusKombi', raimund@1032: renderer: function(value, meta, record, rNdx, cNdx) { raimund@1032: var statusId = record.get('status'); raimund@1032: var mId = record.get('id'); dustin@963: //also fwd the record to the asynchronous loading of statuswerte dustin@963: // in order to add the statuswert to the record, dustin@963: // after the grid was rendered... tom@1217: if (!value || value === '') { raimund@1032: this.updateStatus(mId, statusId, record); raimund@1032: return 'Lade...'; raimund@1032: } tom@1217: var kombis = Ext.data.StoreManager.get('statuskombi'); tom@1217: var kombi = kombis.getById(value); tom@1217: var st = kombi.raw.statusWert.wert tom@1217: return st; raimund@588: } raimund@588: }, { raimund@1062: header: 'Stufe', raimund@1062: flex: 1, tom@1217: dataIndex: 'statusKombi', raimund@1062: renderer: function(value, meta, record, rNdx, cNdx) { raimund@1062: var statusId = record.get('status'); raimund@1062: var mId = record.get('id'); raimund@1062: //also fwd the record to the asynchronous loading of statuswerte raimund@1062: // in order to add the statuswert to the record, raimund@1062: // after the grid was rendered... tom@1217: if (!value || value === '') { raimund@1062: this.updateStatus(mId, statusId, record); raimund@1062: return 'Lade...'; raimund@1062: } tom@1217: var kombis = Ext.data.StoreManager.get('statuskombi'); tom@1217: var kombi = kombis.getById(value); tom@1217: var st = kombi.raw.statusStufe.stufe tom@1217: return st; raimund@1062: } raimund@1062: }, { 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@1032: dataIndex: 'messwerteCount', raimund@588: flex: 1, raimund@1032: renderer: function(value, meta, record) { raimund@1032: if (value === '') { raimund@1032: var mId = record.get('id'); raimund@1032: this.updateNuklide(mId, record); raimund@1032: return 'Lade...'; raimund@1032: } raimund@1032: return value; raimund@588: } raimund@588: }, { raimund@588: header: 'Anzahl Kommentare', raimund@588: flex: 1, raimund@1032: dataIndex: 'kommentarCount', raimund@1032: renderer: function(value, meta, record) { raimund@1032: if (value === '') { raimund@1032: var mId = record.get('id'); raimund@1032: this.updateKommentare(mId, record); raimund@1032: return 'Lade...'; raimund@1032: } raimund@1032: return value; 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); raimund@1111: if (!this.bottomBar) { raimund@1111: this.down('toolbar[dock=bottom]').hide(); raimund@1111: } dustin@823: this.setReadOnly(true); //Grid is always initialised as RO raimund@588: }, raimund@588: raimund@588: initData: function() { dustin@963: this.setLoading(true); raimund@588: this.store = Ext.create('Lada.store.Messungen'); raimund@588: this.store.load({ raimund@588: params: { raimund@588: probeId: this.recordId dustin@963: }, dustin@963: callback: function (records, operation, success) { dustin@963: this.setLoading(false); dustin@963: }, dustin@963: scope: this raimund@588: }); raimund@588: }, raimund@588: dustin@945: /** dustin@945: * Load the statusstore, dustin@945: * afterwards: retrieve the statusid dustin@945: */ raimund@1032: updateStatus: function(value, statusId, record) { raimund@588: var statusStore = Ext.create('Lada.store.Status'); raimund@588: statusStore.on('load', raimund@588: this.updateStatusColumn, raimund@588: this, raimund@1032: {statusId: statusId, record: record}); raimund@588: statusStore.load({ raimund@588: params: { raimund@588: messungsId: value raimund@588: } raimund@588: }); raimund@588: }, raimund@588: raimund@1032: updateNuklide: function(id, record) { raimund@588: var messwerte = Ext.create('Lada.store.Messwerte'); raimund@588: messwerte.on('load', raimund@588: this.updateColumn, raimund@588: this, raimund@1032: {record: record, type: 'messwerteCount'}); raimund@588: messwerte.load({ raimund@588: params: { raimund@1032: messungsId: id raimund@588: } raimund@588: }); raimund@588: }, raimund@588: raimund@1032: updateKommentare: function(id, record) { raimund@588: var kommentare = Ext.create('Lada.store.MKommentare'); raimund@588: kommentare.on('load', raimund@588: this.updateColumn, raimund@588: this, raimund@1032: {record: record, type: 'kommentarCount'}); raimund@588: kommentare.load({ raimund@588: params: { raimund@1032: messungsId: id raimund@588: } raimund@588: }); raimund@588: }, raimund@588: raimund@588: updateColumn: function(store, record, success, opts) { raimund@588: var value; dustin@973: if (success) { dustin@973: if (store.getTotalCount() === 0) { ehuber@1177: value = '0'; dustin@973: } dustin@973: else { dustin@973: value = store.getTotalCount(); dustin@973: } raimund@588: } raimund@588: else { ehuber@1177: value = '-'; raimund@588: } raimund@1032: opts.record.beginEdit(); raimund@1032: opts.record.set(opts.type, value); raimund@1032: opts.record.endEdit(); 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; dustin@950: if (sstore.getTotalCount() === 0 || !opts.statusId) { dustin@813: value = 0; raimund@588: } raimund@588: else { dustin@963: var rec = sstore.getById(opts.statusId); dustin@963: if (rec) { tom@1217: value = rec.get('statusKombi'); dustin@963: //add the determined statuswert to the record. dustin@963: // this is necessary to let the controller determine dustin@963: // which actions are allowed. raimund@1032: opts.record.beginEdit(); tom@1217: opts.record.set('statusKombi', value); raimund@1032: opts.record.endEdit(); dustin@963: } raimund@588: } dustin@684: }, dustin@684: dustin@684: setReadOnly: function(b) { raimund@1034: this.readOnly = b; raimund@1034: if (b === true) { 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@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. raimund@1033: if (! grid.readOnly && raimund@1410: record.get('statusKombi') === 1 && raimund@1033: record.get('owner')) { 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: });