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 osg = this.down('ortstammdatengrid'); mkrambach@1302: var map = this.down('map'); mkrambach@1302: osg.setLoading(true); mkrambach@1302: map.setLoading(true); mkrambach@1302: this.ortstore = Ext.data.StoreManager.get('orte'); mkrambach@1303: this.ortstore.load(); mkrambach@1302: var ortId; mkrambach@1302: if (this.messprogramm) { mkrambach@1302: ortId = this.record.get('ort'); mkrambach@1302: } else { mkrambach@1302: ortId = this.record.get('ortId'); mkrambach@1302: } mkrambach@1302: if (ortId !== undefined && !this.ortstore.findRecord('id', ortId)) { mkrambach@1302: var record = Ext.create('Lada.model.Ort'); mkrambach@1302: record.set('id', ortId); mkrambach@1302: this.ortstore.add(record); mkrambach@1302: Lada.model.Ort.load(ortId, { mkrambach@1302: success: function(rec) { mkrambach@1302: record.beginEdit(); mkrambach@1302: for (key in rec.getData()) { mkrambach@1302: record.set(key, rec.getData()[key]); raimund@1274: } mkrambach@1302: record.endEdit(); mkrambach@1302: me.onStoreLoaded(); raimund@1274: } mkrambach@1302: }); mkrambach@1302: } else { mkrambach@1302: me.onStoreLoaded(); mkrambach@1302: } 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(); mkrambach@1302: }, mkrambach@1302: mkrambach@1302: /** mkrambach@1302: * childs will be populated with store entries after all entries are loaded mkrambach@1302: * from all sources mkrambach@1302: */ mkrambach@1302: onStoreLoaded: function() { mkrambach@1302: var map = this.down('map'); mkrambach@1302: var osg = this.down('ortstammdatengrid'); mkrambach@1302: osg.setStore(this.ortstore); mkrambach@1302: map.addLocations(this.ortstore); mkrambach@1302: map.featureLayer.setVisibility(false); mkrambach@1302: map.selectedFeatureLayer = new OpenLayers.Layer.Vector( mkrambach@1302: 'gewählter Messpunkt', { mkrambach@1302: styleMap: new OpenLayers.StyleMap({ mkrambach@1302: externalGraphic: 'resources/lib/OpenLayers/img/marker-blue.png', mkrambach@1302: pointRadius: 12, mkrambach@1302: label: '${bez}', mkrambach@1302: labelAlign: 'rt', mkrambach@1302: fontColor: 'blue', mkrambach@1302: fontWeight: 'bold', mkrambach@1307: labelOutlineColor: 'white', mkrambach@1307: labelOutlineWidth: 3 mkrambach@1302: }), mkrambach@1302: displayInLayerSwitcher: false, mkrambach@1302: projection: new OpenLayers.Projection('EPSG:3857') mkrambach@1302: }); mkrambach@1302: map.map.addLayer(map.selectedFeatureLayer); mkrambach@1302: var ortId; mkrambach@1302: if (this.messprogramm) { mkrambach@1302: ortId = this.record.get('ort'); mkrambach@1302: } else { mkrambach@1302: ortId = this.record.get('ortId'); mkrambach@1302: } mkrambach@1302: if (ortId){ mkrambach@1302: var feat = map.featureLayer.getFeaturesByAttribute('id', ortId); mkrambach@1302: var ortrecord = this.ortstore.findRecord('id', ortId); mkrambach@1302: osg.selectOrt(map, feat); mkrambach@1302: map.selectFeature(this.model, ortrecord); mkrambach@1302: this.down('ortszuordnungform').setOrt(null,ortrecord); mkrambach@1302: } mkrambach@1302: osg.setLoading(false); mkrambach@1302: map.setLoading(false); raimund@1304: }, raimund@1304: raimund@1304: onEsc: function() { raimund@1304: var me = this; raimund@1304: var search = me.down('textfield[name=search]'); raimund@1304: if (search.hasFocus) { raimund@1304: return; raimund@1304: } raimund@1304: me.callParent(arguments); raimund@1304: } dustin@1013: }); dustin@1013: