view app/controller/Messwert.js @ 493:9fec6df13be8

Fixed the controller.
author Raimund Renkert <raimund.renkert@intevation.de>
date Sat, 01 Nov 2014 13:12:37 +0100
parents 850ccfe5f3c4
children d07e5086a64b
line wrap: on
line source
/* Copyright (C) 2013 by Bundesamt fuer Strahlenschutz
 * Software engineering by Intevation GmbH
 *
 * This file is Free Software under the GNU GPL (v>=3)
 * and comes with ABSOLUTELY NO WARRANTY! Check out
 * the documentation coming with IMIS-Labordaten-Application for details. 
 */

/**
 * Controller for Messwerte
 */
Ext.define('Lada.controller.Messwert', {
    extend: 'Lada.controller.Base',

    views: [
        'messwerte.Create'
    ],

    stores: [
        'Proben',
        'Messungen',
        'Messwerte',
        'StaMesseinheiten',
        'StaMessgroessen'
    ],

    init: function() {
        console.log('Initialising the Messwert controller');
        this.callParent(arguments);
    },

    addListeners: function() {
        this.control({
            'messwertelist': {
                itemdblclick: this.editItem
            },
            'messwertelist toolbar button[action=add]': {
                click: this.addItem
            },
            'messwertelist toolbar button[action=delete]': {
                click: this.deleteItem
            },
            'messwertecreate button[action=save]': {
                click: this.saveItem
            },
            'messwertecreate form': {
                savesuccess: this.createSuccess,
                savefailure: this.createFailure
            }
        });
    },

    saveItem: function(button) {
        console.log('Saving MesswerMesswert');
        var form = button.up('window').down('form');
        form.commit();
    },

    addItem: function(button) {
        var messung = Ext.create('Lada.model.Messwert');
        messung.set('probeId', button.probeId);
        messung.set('messungsId', button.parentId);
        var view = Ext.widget('messwertecreate', {model: messung});
    },

    editItem: function(grid, record) {
        console.log('Editing Messwert');
        var mstore = Ext.data.StoreManager.get('Messungen');
        var pstore = Ext.data.StoreManager.get('Proben');
        var messung = mstore.getById(record.get('messungsId'))
        record.getAuthInfo(this.initEditWindow, messung.get('probeId'));
        console.log("Loaded Messwert with ID " + record.getId()); //outputs ID
    },

    initEditWindow: function(record, readonly, owner) {
        var view = Ext.widget('messwertecreate', {
            model: record
        });
        var ignore = Array();
        if (readonly) {
            var form = view.down('form');
            form.setReadOnly(true, ignore);
        }
    },

    deleteItem: function(button) {
        var grid = button.up('grid');
        var selection = grid.getView().getSelectionModel().getSelection()[0];
        Ext.MessageBox.confirm('Löschen', 'Sind Sie sicher?', function(btn) {
            if (btn === 'yes') {
                var store = grid.getStore();
                var deleteUrl = selection.getProxy().url + selection.getId();
                Ext.Ajax.request({
                    url: deleteUrl,
                    method: 'DELETE',
                    success: function(response, opts) {
                        store.reload();
                    }
                });
                console.log('Deleting Messwert');
            } else {
                console.log('Cancel Deleting Messwert');
            }
        });
    },

    createSuccess: function(form, record, operation) {
        // Reload store
        var store = this.getMesswerteStore();
        store.reload();
        var win = form.up('window');
        win.close();
    },

    createFailure: function(form, record, operation) {
        Ext.MessageBox.show({
            title: 'Fehler beim Speichern',
            msg: form.message,
            icon: Ext.MessageBox.ERROR,
            buttons: Ext.Msg.OK
        });
    },

    editSuccess: function(form, record, operation) {
        // Reload store
        var store = this.getMesswerteStore();
        store.reload();
        var win = form.up('window');
        win.close();
    },

    editFailure: function(form, record, operation) {
        Ext.MessageBox.show({
            title: 'Fehler beim Speichern',
            msg: form.message,
            icon: Ext.MessageBox.ERROR,
            buttons: Ext.Msg.OK
        });
    }
});

http://lada.wald.intevation.org