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: //'probenedit button[action=save]': { torsten@54: // click: this.updateProbe torsten@54: //} 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: console.log("Searching grid"); 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: console.log('Double click on ' + record.get('id')); 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@54: updateKommentar: function(button) { torsten@54: //console.log('Click save'); torsten@54: //// We only have a reference to the button here but we really wnat to torsten@54: //// get the form and the window. So first get the window and form and torsten@54: //// the the record an values. torsten@54: //var win = button.up('window'); torsten@54: //var form = win.down('form'); torsten@54: //var record = form.getRecord(); torsten@54: //var values = form.getValues(); torsten@54: torsten@54: //record.set(values); torsten@54: //win.close(); torsten@54: //// synchronize the store after editing the record torsten@54: //// NOTE: The function 'getProbenStore' will be generated torsten@54: //// dynamically based on the Name of the configured Store!!! torsten@54: //this.getProbenStore().sync(); 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: });