torsten@205: Ext.define('Lada.controller.MKommentare', { torsten@207: extend: 'Ext.app.Controller', torsten@207: views: [ torsten@207: 'mkommentare.Create' torsten@207: ], torsten@205: stores: [ torsten@205: 'MKommentare' torsten@205: ], torsten@205: models: [ torsten@205: 'MKommentar' torsten@205: ], torsten@207: init: function() { torsten@207: console.log('Initialising the MKommentare controller'); torsten@207: this.control({ torsten@207: // CSS like selector to select element in the viewport. See torsten@207: // ComponentQuery documentation for more details. torsten@207: 'mkommentarelist': { torsten@207: itemdblclick: this.editKommentar torsten@207: }, torsten@207: 'mkommentarelist toolbar button[action=add]': { torsten@207: click: this.addKommentar torsten@207: }, torsten@207: 'mkommentarelist toolbar button[action=delete]': { torsten@207: click: this.deleteKommentar torsten@207: }, torsten@207: 'mkommentarecreate button[action=save]': { torsten@207: click: this.saveKommentar torsten@207: }, torsten@207: 'mkommentarecreate form': { torsten@207: savesuccess: this.createSuccess, torsten@207: savefailure: this.createFailure torsten@207: } torsten@207: }); torsten@207: }, torsten@207: saveKommentar: function(button) { torsten@207: console.log('Saving MKommentar'); torsten@207: var form = button.up('window').down('form'); torsten@207: form.commit(); torsten@207: }, torsten@205: addKommentar: function(button) { torsten@207: console.log('Adding new MKommentar for Messung ' + button.parentId + ' Probe ' + button.probeId); torsten@205: var kommentar = Ext.create('Lada.model.MKommentar'); torsten@205: kommentar.set('probeId', button.probeId); torsten@205: kommentar.set('messungsId', button.parentId); torsten@207: var view = Ext.widget('mkommentarecreate', {model: kommentar}); torsten@207: }, torsten@207: editKommentar: function(grid, record) { torsten@207: console.log('Editing Kommentar'); torsten@207: var view = Ext.widget('mkommentarecreate', {model: record}); torsten@207: console.log("Loaded MKommentar with ID " + record.getId()); //outputs ID torsten@207: }, torsten@207: deleteKommentar: function(button) { torsten@207: // Get selected item in grid torsten@207: var grid = button.up('grid'); torsten@207: var selection = grid.getView().getSelectionModel().getSelection()[0]; torsten@207: Ext.MessageBox.confirm('Löschen', 'Sind Sie sicher?', function(btn){ torsten@207: if(btn === 'yes'){ torsten@207: var store = grid.getStore(); torsten@207: var deleteUrl = selection.getProxy().url + selection.getEidi(); torsten@207: Ext.Ajax.request({ torsten@207: url: deleteUrl, torsten@207: method: 'DELETE', torsten@207: success: function(response, opts) { torsten@207: store.reload(); torsten@207: } torsten@207: }); torsten@207: console.log('Deleting MKommentar'); torsten@207: } else { torsten@207: console.log('Cancel Deleting MKommentar'); torsten@207: } torsten@207: }); torsten@205: }, torsten@205: createSuccess: function(form, record, operation) { torsten@205: // Reload store torsten@205: var store = this.getMKommentareStore(); torsten@205: store.reload(); torsten@205: var win = form.up('window'); torsten@205: win.close(); torsten@205: }, torsten@207: createFailure: function(form, record, operation) { torsten@207: Ext.MessageBox.show({ torsten@207: title: 'Fehler beim Speichern', torsten@207: msg: form.message, torsten@207: icon: Ext.MessageBox.ERROR, torsten@207: buttons: Ext.Msg.OK torsten@207: }); torsten@205: } torsten@205: });