dustin@1013: /* Copyright (C) 2013 by Bundesamt fuer Strahlenschutz dustin@1013: * Software engineering by Intevation GmbH dustin@1013: * dustin@1013: * This file is Free Software under the GNU GPL (v>=3) dustin@1013: * and comes with ABSOLUTELY NO WARRANTY! Check out dustin@1013: * the documentation coming with IMIS-Labordaten-Application for details. dustin@1013: */ dustin@1013: dustin@1013: /** mkrambach@1289: * Window to create/edit the Ort/Probe or Ort/Messprogramm Relation dustin@1013: */ mkrambach@1289: dustin@1013: Ext.define('Lada.view.window.Ortszuordnung', { dustin@1013: extend: 'Ext.window.Window', dustin@1013: alias: 'widget.ortszuordnungwindow', dustin@1013: dustin@1013: requires: [ mkrambach@1289: 'Lada.model.Ortszuordnung', mkrambach@1289: 'Lada.model.OrtszuordnungMp', dustin@1021: 'Lada.view.form.Ortszuordnung', mkrambach@1279: 'Lada.view.form.Ortserstellung', mkrambach@1288: 'Lada.view.panel.Map', mkrambach@1288: 'Lada.view.grid.Orte' dustin@1013: ], dustin@1013: dustin@1013: collapsible: true, dustin@1013: maximizable: true, dustin@1013: autoshow: true, raimund@1274: layout: 'fit', dustin@1013: constrain: true, dustin@1013: dustin@1013: probe: null, mkrambach@1289: messprogramm: null, mkrambach@1288: dustin@1013: parentWindow: null, dustin@1013: record: null, dustin@1013: grid: null, dustin@1013: dustin@1013: /** dustin@1013: * This function initialises the Window dustin@1013: */ dustin@1013: initComponent: function() { dustin@1013: var i18n = Lada.getApplication().bundle; dustin@1013: this.title = i18n.getMsg('ortszuordnung.window.title'); mkrambach@1289: var recordtype; mkrambach@1289: if (this.probe) { mkrambach@1289: if (this.record) { mkrambach@1289: // A probe record will be edited mkrambach@1289: this.title = i18n.getMsg('ortszuordnung.window.title') dustin@1013: + ' ' dustin@1013: + i18n.getMsg('ortszuordnung.window.title2') dustin@1013: + ' ' dustin@1013: + i18n.getMsg('probe') dustin@1013: + ' ' raimund@1138: + this.probe.get('hauptprobenNr') dustin@1013: + ' ' dustin@1013: + i18n.getMsg('edit'); mkrambach@1289: } else { mkrambach@1289: // A new probe record will be created mkrambach@1289: this.title = i18n.getMsg('ortszuordnung.window.title') dustin@1013: + ' ' dustin@1013: + i18n.getMsg('ortszuordnung.window.title2') dustin@1013: + ' ' dustin@1013: + i18n.getMsg('probe') dustin@1013: + ' ' raimund@1138: + this.probe.get('hauptprobenNr') dustin@1013: + ' ' dustin@1013: + i18n.getMsg('create'); mkrambach@1289: } mkrambach@1289: } else if (this.messprogramm) { mkrambach@1289: if (this.record) { mkrambach@1289: // A messprogramm record will be edited mkrambach@1289: this.title = i18n.getMsg('ortszuordnung.window.title') mkrambach@1289: + ' ' mkrambach@1289: + i18n.getMsg('ortszuordnung.window.title2') mkrambach@1289: + ' ' mkrambach@1289: + i18n.getMsg('messprogramm') mkrambach@1289: + ' ' mkrambach@1289: + i18n.getMsg('edit'); mkrambach@1289: } else { mkrambach@1289: // A new messprogramm record will be created mkrambach@1289: this.title = i18n.getMsg('ortszuordnung.window.title') mkrambach@1289: + ' ' mkrambach@1289: + i18n.getMsg('ortszuordnung.window.title2') mkrambach@1289: + ' ' mkrambach@1289: + i18n.getMsg('messprogramm') mkrambach@1289: + ' ' mkrambach@1289: + i18n.getMsg('create'); mkrambach@1289: } dustin@1013: } mkrambach@1289: dustin@1013: this.buttons = [{ dustin@1013: text: i18n.getMsg('close'), dustin@1013: scope: this, dustin@1013: handler: this.close dustin@1013: }]; dustin@1013: this.width = 900; raimund@1274: this.height = 465; dustin@1013: this.bodyStyle = {background: '#fff'}; dustin@1013: dustin@1013: // add listeners to change the window appearence when it becomes inactive dustin@1013: this.on({ dustin@1013: activate: function(){ dustin@1013: this.getEl().removeCls('window-inactive'); dustin@1013: }, dustin@1013: deactivate: function(){ dustin@1013: this.getEl().addCls('window-inactive'); dustin@1013: } dustin@1013: }); dustin@1013: dustin@1013: this.items = [{ raimund@1274: layout: 'border', raimund@1274: bodyStyle: {background: '#fff'}, raimund@1274: border: 0, raimund@1274: items: [{ raimund@1274: xtype: 'map', raimund@1274: region: 'center', raimund@1274: layout: 'border', raimund@1274: margin: '13, 5, 10, 5', raimund@1274: minHeight: 380, raimund@1274: externalOrteStore: true raimund@1274: }, { raimund@1274: xtype: 'ortszuordnungform', raimund@1274: region: 'east', raimund@1274: minHeight: 380, mkrambach@1289: type: this.probe? 'probe': 'mpr' raimund@1274: }, { raimund@1274: region: 'south', raimund@1274: border: 0, raimund@1274: layout: 'fit', raimund@1274: name: 'ortgrid', raimund@1274: hidden: true, mkrambach@1279: maxHeight: 240, raimund@1274: items: [{ mkrambach@1279: xtype: 'ortstammdatengrid' raimund@1274: }], raimund@1274: dockedItems: [{ raimund@1274: xtype: 'toolbar', raimund@1274: dock: 'bottom', mkrambach@1294: ui: 'footer', raimund@1274: border: '0, 1, 1, 1', raimund@1274: style: { raimund@1274: borderBottom: '1px solid #b5b8c8 !important', raimund@1274: borderLeft: '1px solid #b5b8c8 !important', raimund@1274: borderRight: '1px solid #b5b8c8 !important' raimund@1274: }, raimund@1274: items: [{ raimund@1274: xtype: 'textfield', raimund@1287: name: 'search', raimund@1274: labelWidth: 50, raimund@1287: enableKeyEvents: true, raimund@1274: fieldLabel: i18n.getMsg('ortszuordnung.ortsuche'), raimund@1274: }, '->', { raimund@1274: text: i18n.getMsg('orte.new'), mkrambach@1279: action: 'createort' raimund@1274: }, { raimund@1274: text: i18n.getMsg('orte.frommap'), mkrambach@1279: action: 'frommap' raimund@1274: }, { raimund@1274: text: i18n.getMsg('orte.clone'), mkrambach@1292: action: 'clone', mkrambach@1292: disabled : true raimund@1274: }] raimund@1274: }] raimund@1274: }] dustin@1013: }]; dustin@1013: this.callParent(arguments); dustin@1013: }, dustin@1013: dustin@1013: /** dustin@1013: * Initialise the Data of this Window dustin@1013: */ dustin@1013: initData: function() { raimund@1274: var me = this; raimund@1134: if (!this.record) { mkrambach@1289: if (this.probe) { mkrambach@1289: this.record = Ext.create('Lada.model.Ortszuordnung'); mkrambach@1289: this.record.set('probeId', this.probe.get('id')); mkrambach@1289: } else { mkrambach@1289: this.record = Ext.create('Lada.model.OrtszuordnungMp'); mkrambach@1289: this.record.set('messprogrammId', this.messprogramm.get('id')); mkrambach@1289: } raimund@1134: if (!this.record.get('letzteAenderung')) { raimund@1134: this.record.data.letzteAenderung = new Date(); raimund@1134: } raimund@1134: } dustin@1013: this.down('ortszuordnungform').setRecord(this.record); raimund@1274: var map = this.down('map'); raimund@1274: var osg = this.down('ortstammdatengrid'); mkrambach@1284: this.ortstore = Ext.create('Lada.store.Orte', { raimund@1274: defaultPageSize: 0, raimund@1274: autoLoad: false, raimund@1274: listeners: { raimund@1274: beforeload: { raimund@1274: fn: function() { raimund@1274: osg.setLoading(true); raimund@1274: map.setLoading(true); raimund@1274: } raimund@1274: }, raimund@1274: load: { raimund@1274: fn: function() { raimund@1274: osg.setLoading(false); raimund@1274: map.setLoading(false); mkrambach@1284: osg.setStore(me.ortstore); mkrambach@1284: map.addLocations(me.ortstore); mkrambach@1279: map.featureLayer.setVisibility(false); mkrambach@1279: map.selectedFeatureLayer = new OpenLayers.Layer.Vector( mkrambach@1279: 'gewählter Messpunkt', { mkrambach@1279: styleMap: new OpenLayers.StyleMap({ mkrambach@1279: externalGraphic: 'resources/lib/OpenLayers/img/marker-blue.png', mkrambach@1289: pointRadius: 12, mkrambach@1279: label: '${bez}', mkrambach@1279: labelAlign: 'rt', mkrambach@1279: fontColor: 'blue', mkrambach@1279: fontWeight: 'bold', mkrambach@1279: }), mkrambach@1279: displayInLayerSwitcher: false, mkrambach@1279: projection: new OpenLayers.Projection('EPSG:3857') mkrambach@1279: }); mkrambach@1279: map.map.addLayer(map.selectedFeatureLayer); mkrambach@1279: map.selectedFeatureLayer.setZIndex(499); mkrambach@1289: var ortId = me.messprogramm? me.record.get('ort') : me.record.get('ortId'); mkrambach@1279: if (ortId){ mkrambach@1289: var feat = map.featureLayer.getFeaturesByAttribute('id', ortId); mkrambach@1289: var ortrecord = this.findRecord('id', ortId); mkrambach@1289: osg.selectOrt(map, feat); mkrambach@1289: map.selectFeature(this.model, ortrecord); mkrambach@1289: me.down('ortszuordnungform').setOrt(null,ortrecord); mkrambach@1279: } raimund@1274: } raimund@1274: } raimund@1274: } raimund@1274: }); mkrambach@1284: this.ortstore.load(); mkrambach@1279: map.addListener('featureselected', osg.selectOrt, osg); mkrambach@1279: osg.addListener('select', map.selectFeature, map); mkrambach@1292: osg.addListener('select', me.activateCloneButton, me); dustin@1021: }, dustin@1021: dustin@1021: /** dustin@1021: * @private dustin@1021: * Override to display and update the map view in the panel. dustin@1021: */ dustin@1021: afterRender: function(){ dustin@1021: this.superclass.afterRender.apply(this, arguments); raimund@1274: var map = this.down('map'); raimund@1274: map.map.addControl(new OpenLayers.Control.LayerSwitcher()); dustin@1013: }, dustin@1013: dustin@1013: /** dustin@1013: * Instructs the fields / forms listed in this method to set a message. dustin@1013: * @param errors These Errors shall be shown dustin@1013: * @param warnings These Warning shall be shown dustin@1013: */ dustin@1013: setMessages: function(errors, warnings) { dustin@1013: //todo this is a stub dustin@1013: }, dustin@1013: dustin@1013: /** dustin@1013: * Instructs the fields / forms listed in this method to clear their messages. dustin@1013: */ dustin@1013: clearMessages: function() { dustin@1013: //todo this is a stub mkrambach@1292: }, mkrambach@1292: mkrambach@1292: activateCloneButton: function() { mkrambach@1292: var toolbar = this.down('panel[name=ortgrid]').getDockedItems()[0]; mkrambach@1292: toolbar.down('button[action=clone]').enable(); dustin@1013: } dustin@1013: }); dustin@1013: