torsten@54: Ext.define('Lada.controller.Kommentare', { torsten@54: extend: 'Ext.app.Controller', torsten@54: views: [ torsten@55: 'kommentare.List', torsten@55: 'kommentare.Edit' 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: // Map Doubleclick on rows of the probenlist. 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@60: 'kommentaredit button[action=save]': { torsten@60: click: this.saveKommentar torsten@55: } torsten@54: }); torsten@54: }, torsten@60: addKommentar: function(button) { torsten@60: console.log('Adding new Kommentar'); torsten@60: var view = Ext.widget('kommentaredit'); torsten@60: var form = view.down('form'); torsten@60: // Create a new Kommentar torsten@60: var record = Ext.create('Lada.model.Kommentar'); torsten@60: form.loadRecord(record); 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@59: store.remove(selection); torsten@59: store.sync(); torsten@59: console.log('Deleting Kommentar'); torsten@59: } else { torsten@59: console.log('Cancel Deleting Kommentar'); torsten@59: } torsten@59: }); torsten@59: }, torsten@54: editKommentar: function(grid, record) { torsten@55: // Create new window to edit the seletced record. torsten@55: var view = Ext.widget('kommentaredit'); torsten@55: var form = view.down('form'); torsten@55: form.loadRecord(record); torsten@54: }, torsten@60: saveKommentar: function(button) { torsten@60: var win = button.up('window'); torsten@60: var form = win.down('form'); torsten@60: var record = form.getRecord(); torsten@60: var values = form.getValues(); torsten@60: var store = this.getKommentareStore(); torsten@60: record.set(values); torsten@60: store.add(record); torsten@60: store.sync(); torsten@60: console.log('Saving Kommentar'); torsten@60: win.close(); torsten@54: } torsten@54: });