torsten@289: /** torsten@289: * Controller for Messungen torsten@289: */ torsten@108: Ext.define('Lada.controller.Messungen', { torsten@289: extend: 'Lada.controller.Base', 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@312: this.callParent(); torsten@289: }, torsten@289: addListeners: function() { torsten@108: this.control({ torsten@108: 'messungenlist': { torsten@289: itemdblclick: this.editItem torsten@108: }, torsten@108: 'messungenlist toolbar button[action=add]': { torsten@289: click: this.addItem torsten@108: }, torsten@108: 'messungenlist toolbar button[action=delete]': { torsten@289: click: this.deleteItem torsten@193: }, torsten@193: 'messungencreate button[action=save]': { torsten@289: click: this.saveItem torsten@108: }, torsten@233: 'messungenedit button[action=save]': { torsten@289: click: this.saveItem 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@289: saveItem: 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@289: addItem: 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@289: editItem: 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@281: // TODO: Field "fertig" must be editable (issue51). So we need to remove the torsten@281: // readonly status if the user would be allowed to edit the probe torsten@281: // if the "fertig" flag has not been set. (ti) <2013-08-08 10:24> torsten@281: var ignore = Array(); torsten@281: ignore.push('fertig'); torsten@281: form.setReadOnly(true, ignore); torsten@232: } torsten@224: console.log("Loaded Messung with ID " + record.getId()); //outputs ID torsten@108: }, torsten@289: deleteItem: 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: 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: 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: });