view app/view/window/Ortszuordnung.js @ 1284:faecbb446a04

Ortserstellung: new Messpunkt from map, clone or form functional, still needs error handling and layout
author Maximilian Krambach <mkrambach@intevation.de>
date Tue, 24 Jan 2017 12:58:26 +0100
parents 291df0037835
children e317ba349204
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.
 */

/**
 * Window to create/edit the Ort / Probe Relation
 */
Ext.define('Lada.view.window.Ortszuordnung', {
    extend: 'Ext.window.Window',
    alias: 'widget.ortszuordnungwindow',

    requires: [
        'Lada.view.form.Ortszuordnung',
        'Lada.view.form.Ortserstellung',
        'Lada.view.panel.Ort'
    ],

    collapsible: true,
    maximizable: true,
    autoshow: true,
    layout: 'fit',
    constrain: true,

    probe: null,
    parentWindow: null,
    record: null,
    grid: null,

    /**
     * This function initialises the Window
     */
    initComponent: function() {
        var i18n = Lada.getApplication().bundle;

        this.title = i18n.getMsg('ortszuordnung.window.title');

        if (this.record && this.probe) {
            // A record be edited
            this.title = i18n.getMsg('ortszuordnung.window.title')
                            + ' '
                            + i18n.getMsg('ortszuordnung.window.title2')
                            + ' '
                            + i18n.getMsg('probe')
                            + ' '
                            + this.probe.get('hauptprobenNr')
                            + ' '
                            + i18n.getMsg('edit');
        }
        else if (this.probe) {
            // A new record will be created
            this.title = i18n.getMsg('ortszuordnung.window.title')
                            + ' '
                            + i18n.getMsg('ortszuordnung.window.title2')
                            + ' '
                            + i18n.getMsg('probe')
                            + ' '
                            + this.probe.get('hauptprobenNr')
                            + ' '
                            + i18n.getMsg('create');
        }

        this.buttons = [{
            text: i18n.getMsg('close'),
            scope: this,
            handler: this.close
        }];
        this.width = 900;
        this.height = 465;
        this.bodyStyle = {background: '#fff'};

        // add listeners to change the window appearence when it becomes inactive
        this.on({
            activate: function(){
                this.getEl().removeCls('window-inactive');
            },
            deactivate: function(){
                this.getEl().addCls('window-inactive');
            }
        });


        this.items = [{
            layout: 'border',
            bodyStyle: {background: '#fff'},
            border: 0,
            items: [{
                xtype: 'map',
                region: 'center',
                layout: 'border',
                margin: '13, 5, 10, 5',
                minHeight: 380,
                externalOrteStore: true
            }, {
                xtype: 'ortszuordnungform',
                region: 'east',
                minHeight: 380,
            }, {
                region: 'south',
                border: 0,
                layout: 'fit',
                name: 'ortgrid',
                hidden: true,
                maxHeight: 240,
                items: [{
                    xtype: 'ortstammdatengrid'
                }],
                dockedItems: [{
                    xtype: 'toolbar',
                    dock: 'bottom',
                    border: '0, 1, 1, 1',
                    style: {
                        borderBottom: '1px solid #b5b8c8 !important',
                        borderLeft: '1px solid #b5b8c8 !important',
                        borderRight: '1px solid #b5b8c8 !important'
                    },
                    items: [{
                        xtype: 'textfield',
                        labelWidth: 50,
                        fieldLabel: i18n.getMsg('ortszuordnung.ortsuche'),
                    }, '->', {
                        text: i18n.getMsg('orte.new'),
                        action: 'createort'
                    }, {
                        text: i18n.getMsg('orte.frommap'),
                        action: 'frommap'
                    }, {
                        text: i18n.getMsg('orte.clone'),
                        action: 'clone'
                    }]
                }]
            }]
        }];

        this.callParent(arguments);
    },

    /**
     * Initialise the Data of this Window
     */
    initData: function() {
        var me = this;
        if (!this.record) {
            this.record = Ext.create('Lada.model.Ortszuordnung');
            if (!this.record.get('letzteAenderung')) {
                this.record.data.letzteAenderung = new Date();
            }
            this.record.set('probeId', this.probe.get('id'));
        }
        this.down('ortszuordnungform').setRecord(this.record);
        var map = this.down('map');
        var osg = this.down('ortstammdatengrid');
        this.ortstore = Ext.create('Lada.store.Orte', {
            defaultPageSize: 0,
            autoLoad: false,
            listeners: {
                beforeload: {
                    fn: function() {
                        osg.setLoading(true);
                        map.setLoading(true);
                    }
                },
                load: {
                    fn: function() {
                        osg.setLoading(false);
                        map.setLoading(false);
                        osg.setStore(me.ortstore);
                        map.addLocations(me.ortstore);
                        map.featureLayer.setVisibility(false);
                        map.selectedFeatureLayer = new OpenLayers.Layer.Vector(
                            'gewählter Messpunkt', {
                                styleMap: new OpenLayers.StyleMap({
                                    externalGraphic: 'resources/lib/OpenLayers/img/marker-blue.png',
                                    pointRadius: 10,
                                    label: '${bez}',
                                    labelAlign: 'rt',
                                    fontColor: 'blue',
                                    fontWeight: 'bold',
                                }),
                                displayInLayerSwitcher: false,
                                projection: new OpenLayers.Projection('EPSG:3857')
                            });
                        map.map.addLayer(map.selectedFeatureLayer);
                        map.selectedFeatureLayer.setZIndex(499);
                        var ortId = me.record.get('ortId');
                        if (ortId){
                            var feat = map.featureLayer.getFeaturesByAttribute('id', ortId)[0];
                            map.selectControl.select(feat);
                        }
                    }
                }
            }
        });
        this.ortstore.load();
        map.addListener('featureselected', osg.selectOrt, osg);
        osg.addListener('select', map.selectFeature, map);
    },

    /**
     * @private
     * Override to display and update the map view in the panel.
     */
    afterRender: function(){
        this.superclass.afterRender.apply(this, arguments);
        var map = this.down('map');
        map.map.addControl(new OpenLayers.Control.LayerSwitcher());
    },

    /**
     * Instructs the fields / forms listed in this method to set a message.
     * @param errors These Errors shall be shown
     * @param warnings These Warning shall be shown
     */
    setMessages: function(errors, warnings) {
        //todo this is a stub
    },

    /**
     * Instructs the fields / forms listed in this method to clear their messages.
     */
    clearMessages: function() {
        //todo this is a stub
    }
});

http://lada.wald.intevation.org