# HG changeset patch # User Raimund Renkert # Date 1426076036 -3600 # Node ID 4251601c6305ab6ebb4a0f0dbfae2424bddbeba0 # Parent 8ed6c3fb8bda6f279a977cc291457f5cf0486789 Load status, messwerte and kommentare asynchronously. diff -r 8ed6c3fb8bda -r 4251601c6305 app/controller/MessungenGrid.js --- a/app/controller/MessungenGrid.js Wed Mar 11 13:12:44 2015 +0100 +++ b/app/controller/MessungenGrid.js Wed Mar 11 13:13:56 2015 +0100 @@ -30,53 +30,36 @@ }); }, - selectionChanged: function(grid, record) { - if (record) { - grid.view.panel.down('button[action=open]').enable(); - } - }, - - gridSave: function(editor, context) { - context.record.save({ - success: function() { - context.grid.store.reload(); - context.grid.up('window').initData(); - }, - failure: function() { - // TODO - } - }); - }, - open: function(grid, record) { //Opens a detailed view of the Messung var win = Ext.create('Lada.view.window.MessungEdit', { - record: this.record + record: record }); win.show(); win.initData(); - // todo - console.log('opened window'); }, add: function() { - // todo + // TODO console.log('add'); }, remove: function(button) { var grid = button.up('grid'); var selection = grid.getView().getSelectionModel().getSelection()[0]; - Ext.MessageBox.confirm('Messung löschen', 'Sind Sie sicher?', function(btn) { - if (btn === 'yes') { - selection.destroy({ - success: function() { - button.up('window').initData(); - }, - failure: function() { - } - }); - } + Ext.MessageBox.confirm( + 'Messung löschen', + 'Sind Sie sicher?', + function(btn) { + if (btn === 'yes') { + selection.destroy({ + success: function() { + button.up('window').initData(); + }, + failure: function() { + } + }); + } }); } }); diff -r 8ed6c3fb8bda -r 4251601c6305 app/view/grid/Messungen.js --- a/app/view/grid/Messungen.js Wed Mar 11 13:12:44 2015 +0100 +++ b/app/view/grid/Messungen.js Wed Mar 11 13:13:56 2015 +0100 @@ -70,28 +70,16 @@ flex: 1, dataIndex: 'id', renderer: function(value) { -//fixme: dezeit existiert nur 1 status daher immer unbekannt - this.statusStore.load( - { - params: { - messungsId: value, - } - }); - - if (!this.statusStore){ - return 'unbekannt'; - } - if (this.statusStore.getTotalCount() === 0) { - return 'unbekannt'; - } - return this.statusStore.last().get('status'); + var id = 'messung-status-item' + value; + this.updateStatus(value, id); + return '
Lade...
'; } }, { header: 'OK-Flag', dataIndex: 'fertig', flex: 1, - renderer: function(value){ - if(value){ + renderer: function(value) { + if (value) { return 'Ja'; } return 'Nein'; @@ -105,57 +93,96 @@ // Gibt die Anzahl der Messwerte wieder, // NICHT die Anzahl der verschiedenen Nukleide // Eventuell ist die Bezeichnug daher irreführend + dataIndex: 'id', flex: 1, - dataIndex: 'id', renderer: function(value) { -//fixme: gibt immer 0 aus - this.messwerteStore.load({ - params: { - messungId: value, - } - }); - - if (!this.messwerteStore){ - return 'unbekannt'; - } - return this.messwerteStore.getCount(); + var id = 'messung-nuklid-item' + value; + this.updateNuklide(value, id); + return '
Lade...
'; } }, { header: 'Anzahl Kommentare', flex: 1, dataIndex: 'id', renderer: function(value) { -//fixme: gibt immer 0 aus - this.mKommentareStore.load({ - params: { - messungsId: value, - } - }); - - if (!this.mKommentareStore){ - return 'unbekannt'; - } - - return this.mKommentareStore.getTotalCount(); + var id = 'messung-kommentar-item' + value; + this.updateKommentare(value, id); + return '
Lade...
'; } }]; this.initData(); this.callParent(arguments); }, - initData: function(){ + initData: function() { this.store = Ext.create('Lada.store.Messungen'); - this.statusStore = Ext.create('Lada.store.Status'); - this.messwerteStore = Ext.create('Lada.store.Messwerte'); - this.mKommentareStore = Ext.create('Lada.store.MKommentare'); - this.store.load({ params: { probeId: this.recordId - }, - success: function(record, response){ - console.log(Ext.getClassName(response)); } }); + }, + + updateStatus: function(value, divId) { + var statusStore = Ext.create('Lada.store.Status'); + statusStore.on('load', + this.updateStatusColumn, + this, + {divId: divId}); + statusStore.load({ + params: { + messungsId: value + } + }); + }, + + updateNuklide: function(value, divId) { + var messwerte = Ext.create('Lada.store.Messwerte'); + messwerte.on('load', + this.updateColumn, + this, + {divId: divId}); + messwerte.load({ + params: { + messungsId: value + } + }); + }, + + updateKommentare: function(value, divId) { + var kommentare = Ext.create('Lada.store.MKommentare'); + kommentare.on('load', + this.updateColumn, + this, + {divId: divId}); + kommentare.load({ + params: { + messungsId: value + } + }); + }, + + updateColumn: function(store, record, success, opts) { + var value; + if (store.getTotalCount() === 0) { + value = 'Keine'; + } + else { + value = store.getTotalCount(); + } + Ext.fly(opts.divId).update(value); + }, + + updateStatusColumn: function(sstore, record, success, opts) { + var value; + if (sstore.getTotalCount() === 0) { + value = 'unbekannt'; + } + else { + value = sstore.last().get('status'); + } + if (Ext.fly(opts.divId)) { + Ext.fly(opts.divId).update(value); + } } });