torsten@286: /** torsten@286: * Base Controller torsten@286: * torsten@286: * The controller defines the main logic of the application. It provides torsten@286: * various methods which are bound to listeners and called when the defined torsten@286: * events in the various UI elements occour (e.g User clicks on a button) torsten@286: */ torsten@286: Ext.define('Lada.controller.Base', { torsten@286: extend: 'Ext.app.Controller', torsten@286: /** torsten@286: * Define required views for this controller torsten@286: */ torsten@286: views: [], torsten@286: /** torsten@286: * Define required stores for this controller torsten@286: */ torsten@286: stores: [], torsten@286: /** torsten@286: * Define required models for this controller torsten@286: */ torsten@286: models: [], torsten@286: init: function() { torsten@286: console.log('Initialising the Kommentare controller'); torsten@286: this.addListeners(); torsten@286: }, torsten@286: /** torsten@286: * Function to add listeners for various events in UI items. The UI Items are selected torsten@286: * with a CSS like selector.See ComponentQuery documentation for more torsten@286: * details. The function is called while initializing the controller. torsten@286: * torsten@286: * The function should be overwritten by a specfic implementation. torsten@286: */ torsten@286: addListeners: function() { torsten@286: this.control({}); torsten@286: }, torsten@286: /** torsten@286: * Method to save the kommentar in the database. The method is called when torsten@286: * the user clicks on the "Save" button torsten@286: */ torsten@287: saveItem: function(button) { torsten@287: console.log('Saving ...'); torsten@287: var form = button.up('window').down('form'); torsten@287: form.commit(); torsten@287: }, torsten@286: /** torsten@286: * Method to open a window to enter the values for a new kommentar. torsten@286: * The method is called when the user clicks on the "Add" button in the torsten@286: * grid toolbar. torsten@286: */ torsten@286: addItem: function(button) {}, torsten@286: /** torsten@286: * Method to open a window to edit the values for an existing kommentar. torsten@286: * The method is called when the user doubleclicks on the item in the torsten@286: * grid. torsten@286: */ torsten@286: editItem: function(grid, record) {}, torsten@286: /** torsten@286: * Method to delete a kommentar. This will trigger the display of a torsten@286: * Confirmation dialog. After the deletion the related store will be torsten@286: * refreshed. torsten@286: * The method is called when the user selects the item in the grid and torsten@286: * selects the delete button in the grid toolbar. torsten@286: */ torsten@287: deleteItem: function(button) { torsten@287: var grid = button.up('grid'); torsten@287: var selection = grid.getView().getSelectionModel().getSelection()[0]; torsten@287: Ext.MessageBox.confirm('Löschen', 'Sind Sie sicher?', function(btn){ torsten@287: if(btn === 'yes'){ torsten@287: var store = grid.getStore(); torsten@287: var deleteUrl = selection.getProxy().url + selection.getEidi(); torsten@287: Ext.Ajax.request({ torsten@287: url: deleteUrl, torsten@287: method: 'DELETE', torsten@287: success: function(response, opts) { torsten@287: store.reload(); torsten@287: } torsten@287: }); torsten@287: console.log('Deleting ' + selection); torsten@287: } else { torsten@287: console.log('Cancel Deleting ' + selection); torsten@287: } torsten@287: }); torsten@287: }, torsten@286: /** torsten@287: * Method to trigger the action after successfull save (create). torsten@286: * In this case the related store is refreshed and the window is closed. torsten@286: */ torsten@286: createSuccess: function(form, record, operation) {}, torsten@286: /** torsten@287: * Method to trigger the action after save (create) fails. torsten@286: * In this case a Message Boss with a general error is shown. torsten@286: */ torsten@287: createFailure: function(form, record, operation) { torsten@287: Ext.MessageBox.show({ torsten@287: title: 'Fehler beim Speichern', torsten@287: msg: form.message, torsten@287: icon: Ext.MessageBox.ERROR, torsten@287: buttons: Ext.Msg.OK torsten@287: }); torsten@287: }, torsten@287: /** torsten@287: * Method to trigger the action after successfull save (edit). torsten@287: * In this case the related store is refreshed and the window is closed. torsten@287: */ torsten@287: editSuccess: function(form, record, operation) {}, torsten@287: /** torsten@287: * Method to trigger the action after save ( edit) fails. torsten@287: * In this case a Message Boss with a general error is shown. torsten@287: */ torsten@287: editFailure: function(form, record, operation) { torsten@287: Ext.MessageBox.show({ torsten@287: title: 'Fehler beim Speichern', torsten@287: msg: form.message, torsten@287: icon: Ext.MessageBox.ERROR, torsten@287: buttons: Ext.Msg.OK torsten@287: }); torsten@287: }, torsten@286: });