torsten@109: Ext.define('Lada.controller.Orte', { torsten@109: extend: 'Ext.app.Controller', torsten@109: views: [ torsten@109: 'orte.List', torsten@109: 'orte.Create' torsten@109: ], torsten@109: stores: [ torsten@109: ], torsten@109: models: [ torsten@109: 'Ort' torsten@109: ], torsten@109: init: function() { torsten@109: console.log('Initialising the Orte controller'); torsten@109: this.control({ torsten@109: // CSS like selector to select element in the viewport. See torsten@109: // ComponentQuery documentation for more details. torsten@109: 'ortelist': { torsten@109: itemdblclick: this.editOrt torsten@109: }, torsten@109: 'ortelist toolbar button[action=add]': { torsten@109: click: this.addOrt torsten@109: }, torsten@109: 'ortelist toolbar button[action=delete]': { torsten@109: click: this.deleteOrt torsten@109: }, torsten@109: 'ortecreate form': { torsten@109: savesuccess: this.createSuccess, torsten@109: savefailure: this.createFailure torsten@109: }, torsten@109: 'orteedit form': { torsten@109: savesuccess: this.editSuccess, torsten@109: savefailure: this.editFailure torsten@109: } torsten@109: }); torsten@109: }, torsten@109: addOrt: function(button) { torsten@109: console.log('Adding new Ort'); torsten@109: var view = Ext.widget('ortecreate'); torsten@109: }, torsten@109: editOrt: function(grid, record) { torsten@109: console.log('Editing Ort'); torsten@109: var view = Ext.widget('ortecreate', {model: record}); torsten@109: console.log("Loaded Ort with ID " + record.getId()); //outputs ID torsten@109: }, torsten@109: deleteOrt: function(button) { torsten@109: // Get selected item in grid torsten@109: var grid = button.up('grid'); torsten@109: var selection = grid.getView().getSelectionModel().getSelection()[0]; torsten@109: Ext.MessageBox.confirm('Löschen', 'Sind Sie sicher?', function(btn){ torsten@109: if(btn === 'yes'){ torsten@109: var store = grid.getStore(); torsten@109: store.remove(selection); torsten@109: store.sync(); torsten@109: console.log('Deleting Kommentar'); torsten@109: } else { torsten@109: console.log('Cancel Deleting Kommentar'); torsten@109: } torsten@109: }); torsten@109: }, torsten@109: createSuccess: function(form, record, operation) { torsten@109: // Reload store torsten@109: var store = this.getOrteStore(); torsten@109: store.reload(); torsten@109: var win = form.up('window'); torsten@109: win.close(); torsten@109: }, torsten@109: createFailure: function(form, record, operation) { torsten@109: Ext.MessageBox.show({ torsten@109: title: 'Fehler beim Speichern', torsten@109: msg: form.message, torsten@109: icon: Ext.MessageBox.ERROR, torsten@109: buttons: Ext.Msg.OK torsten@109: }); torsten@109: }, torsten@109: editSuccess: function(form, record, operation) { torsten@109: // Reload store torsten@109: var store = this.getOrteStore(); torsten@109: store.reload(); torsten@109: var win = form.up('window'); torsten@109: win.close(); torsten@109: }, torsten@109: editFailure: function(form, record, operation) { torsten@109: Ext.MessageBox.show({ torsten@109: title: 'Fehler beim Speichern', torsten@109: msg: form.message, torsten@109: icon: Ext.MessageBox.ERROR, torsten@109: buttons: Ext.Msg.OK torsten@109: }); torsten@109: } torsten@109: });