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