torsten@472: /* Copyright (C) 2013 by Bundesamt fuer Strahlenschutz torsten@472: * Software engineering by Intevation GmbH torsten@472: * torsten@472: * This file is Free Software under the GNU GPL (v>=3) torsten@472: * and comes with ABSOLUTELY NO WARRANTY! Check out raimund@497: * the documentation coming with IMIS-Labordaten-Application for details. torsten@472: */ torsten@472: 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: this.addListeners(); torsten@286: }, torsten@286: /** raimund@497: * Function to add listeners for various events in UI items. The UI Items raimund@497: * are selected with a CSS like selector.See ComponentQuery documentation raimund@497: * for more details. raimund@497: * 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: 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: */ raimund@497: addItem: function() { raimund@497: return; raimund@497: }, 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: */ raimund@497: editItem: function() { raimund@497: return; raimund@497: }, 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]; raimund@491: Ext.MessageBox.confirm('Löschen', 'Sind Sie sicher?', function(btn) { raimund@491: if (btn === 'yes') { torsten@287: var store = grid.getStore(); raimund@490: var deleteUrl = selection.getProxy().url + selection.getId(); torsten@287: Ext.Ajax.request({ torsten@287: url: deleteUrl, torsten@287: method: 'DELETE', raimund@497: success: function() { torsten@287: store.reload(); torsten@287: } torsten@287: }); 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: */ raimund@497: createSuccess: function() { raimund@497: return; raimund@497: }, 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: */ raimund@497: createFailure: function(form) { 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: */ raimund@497: editSuccess: function() { raimund@497: return; raimund@497: }, 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: */ raimund@497: editFailure: function(form) { 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@360: } torsten@286: });