torsten@108: Ext.define('Lada.controller.Messungen', { torsten@108: extend: 'Ext.app.Controller', torsten@172: views: [ torsten@232: 'messungen.Create', torsten@232: 'messungen.Edit' torsten@172: ], torsten@108: stores: [ torsten@229: 'Proben', torsten@163: 'Messungen', torsten@168: 'Messwerte', torsten@168: 'MKommentare', torsten@181: 'Status', torsten@181: 'Messgroessen' torsten@108: ], torsten@108: init: function() { torsten@108: console.log('Initialising the Messungen controller'); torsten@108: this.control({ torsten@108: // CSS like selector to select element in the viewpzusatzwert. See torsten@108: // ComponentQuery documentation for more details. torsten@108: 'messungenlist': { torsten@193: itemdblclick: this.editMessung torsten@108: }, torsten@108: 'messungenlist toolbar button[action=add]': { torsten@193: click: this.addMessung torsten@108: }, torsten@108: 'messungenlist toolbar button[action=delete]': { torsten@193: click: this.deleteMessung torsten@193: }, torsten@193: 'messungencreate button[action=save]': { torsten@193: click: this.saveMessung torsten@108: }, torsten@233: 'messungenedit button[action=save]': { torsten@233: click: this.saveMessung torsten@233: }, torsten@108: 'messungencreate form': { torsten@108: savesuccess: this.createSuccess, torsten@108: savefailure: this.createFailure torsten@108: }, torsten@108: 'messungenedit form': { torsten@108: savesuccess: this.editSuccess, torsten@108: savefailure: this.editFailure torsten@108: } torsten@108: }); torsten@108: }, torsten@194: saveMessung: function(button) { torsten@194: console.log('Saving new Messung for Probe ' + button.probeId); torsten@194: var form = button.up('window').down('form'); torsten@194: form.commit(); torsten@194: }, torsten@194: addMessung: function(button) { torsten@172: console.log('Adding new Messung for Probe ' + button.probeId); torsten@172: var messung = Ext.create('Lada.model.Messung'); torsten@172: messung.set('probeId', button.probeId); torsten@172: var view = Ext.widget('messungencreate', {model: messung}); torsten@108: }, torsten@194: editMessung: function(grid, record) { torsten@194: console.log('Editing Messung'); torsten@195: var kstore = this.getMKommentareStore(); torsten@195: kstore.load({ torsten@195: params: { torsten@224: probeId: record.get('probeId'), torsten@195: messungsId: record.get('messungsId') torsten@195: } torsten@195: }); torsten@195: var sstore = this.getStatusStore(); torsten@195: sstore.load({ torsten@195: params: { torsten@224: probeId: record.get('probeId'), torsten@195: messungsId: record.get('messungsId') torsten@195: } torsten@195: }); torsten@224: var mstore = this.getMesswerteStore(); torsten@195: mstore.load({ torsten@195: params: { torsten@224: probeId: record.get('probeId'), torsten@195: messungsId: record.get('messungsId') torsten@195: } torsten@195: }); torsten@229: var probe = this.getProbenStore().getById(record.get('probeId')); torsten@232: var view = Ext.widget('messungenedit', {model: record}); torsten@232: if (probe.get('readonly') === true) { torsten@232: var form = view.down('form'); torsten@232: form.setReadOnly(true); torsten@232: } torsten@224: console.log("Loaded Messung with ID " + record.getId()); //outputs ID torsten@108: }, torsten@194: deleteMessung: function(button) { torsten@108: // Get selected item in grid torsten@108: var grid = button.up('grid'); torsten@108: var selection = grid.getView().getSelectionModel().getSelection()[0]; torsten@108: Ext.MessageBox.confirm('Löschen', 'Sind Sie sicher?', function(btn){ torsten@108: if(btn === 'yes'){ torsten@108: var store = grid.getStore(); torsten@218: var deleteUrl = selection.getProxy().url + selection.getEidi(); torsten@218: Ext.Ajax.request({ torsten@218: url: deleteUrl, torsten@218: method: 'DELETE', torsten@218: success: function(response, opts) { torsten@218: store.reload(); torsten@218: } torsten@218: }); torsten@218: console.log('Deleting Messung'); torsten@108: } else { torsten@218: console.log('Cancel Deleting Messung'); torsten@108: } torsten@108: }); torsten@108: }, torsten@108: createSuccess: function(form, record, operation) { torsten@108: // Reload store torsten@108: var store = this.getMessungenStore(); torsten@108: store.reload(); torsten@108: var win = form.up('window'); torsten@108: win.close(); torsten@108: }, torsten@108: createFailure: function(form, record, operation) { torsten@108: Ext.MessageBox.show({ torsten@108: title: 'Fehler beim Speichern', torsten@108: msg: form.message, torsten@108: icon: Ext.MessageBox.ERROR, torsten@108: buttons: Ext.Msg.OK torsten@108: }); torsten@108: }, torsten@108: editSuccess: function(form, record, operation) { torsten@108: // Reload store torsten@108: var store = this.getMessungenStore(); torsten@108: store.reload(); torsten@108: var win = form.up('window'); torsten@108: win.close(); torsten@108: }, torsten@108: editFailure: function(form, record, operation) { torsten@108: Ext.MessageBox.show({ torsten@108: title: 'Fehler beim Speichern', torsten@108: msg: form.message, torsten@108: icon: Ext.MessageBox.ERROR, torsten@108: buttons: Ext.Msg.OK torsten@108: }); torsten@108: } torsten@108: });