dustin@797: /* Copyright (C) 2013 by Bundesamt fuer Strahlenschutz dustin@797: * Software engineering by Intevation GmbH dustin@797: * dustin@797: * This file is Free Software under the GNU GPL (v>=3) dustin@797: * and comes with ABSOLUTELY NO WARRANTY! Check out dustin@797: * the documentation coming with IMIS-Labordaten-Application for details. dustin@797: */ dustin@797: dustin@797: /** dustin@797: * Window to add a Ort to a Messprogramm dustin@797: */ dustin@797: Ext.define('Lada.view.window.MessprogrammOrt', { dustin@797: extend: 'Ext.window.Window', dustin@797: alias: 'widget.messprogrammort', dustin@797: dustin@797: requires: [ dustin@797: 'Lada.model.Ort', dustin@797: 'Lada.view.panel.Map', dustin@797: 'Lada.view.widget.Location', dustin@797: 'Lada.view.form.Location' dustin@797: ], dustin@797: dustin@797: collapsible: true, dustin@797: maximizable: true, dustin@797: autoshow: true, dustin@797: layout: 'border', dustin@797: constrain: true, dustin@797: dustin@797: parentWindow: null, dustin@797: record: null, dustin@797: dustin@797: initComponent: function() { dustin@797: var i18n = Lada.getApplication().bundle; dustin@797: dustin@797: this.title = i18n.getMsg('messprogrammort.window.title'); dustin@797: this.buttons = [{ dustin@797: text: i18n.getMsg('apply'), dustin@797: scope: this, dustin@797: handler: this.apply dustin@797: }, { dustin@797: text: i18n.getMsg('cancel'), dustin@797: scope: this, dustin@797: handler: function() { dustin@818: this.close(); dustin@797: this.parentWindow.down('messprogrammform') dustin@797: .ortWindow = null; dustin@797: } dustin@797: }]; dustin@797: this.width = 900; dustin@797: this.height = 515; dustin@797: this.bodyStyle = {background: '#fff'}; dustin@797: dustin@797: // add listeners to change the window appearence when it becomes inactive dustin@797: this.on({ dustin@797: activate: function(){ dustin@797: this.getEl().removeCls('window-inactive'); dustin@797: }, dustin@797: deactivate: function(){ dustin@797: this.getEl().addCls('window-inactive'); dustin@818: }, dustin@818: close: function () { dustin@818: this.parentWindow.down('messprogrammform') dustin@818: .ortWindow = null; dustin@797: } dustin@797: }); dustin@797: dustin@797: this.items = [{ dustin@797: region: 'west', dustin@797: border: 0, dustin@797: layout: 'vbox', dustin@797: items: [{ dustin@797: xtype: 'fieldset', dustin@797: title: i18n.getMsg('ortId'), dustin@797: margin: 5, dustin@797: items: [{ dustin@797: border: 0, dustin@797: margin: '0, 0, 10, 0', dustin@797: items: [{ dustin@797: xtype: 'location', dustin@797: fieldLabel: i18n.getMsg('ortId'), dustin@797: labelWidth: 80, dustin@797: width: 280, dustin@797: forceSelection: true, dustin@797: name: 'ortId', dustin@797: listeners: {//Update MapPanel etc... dustin@797: select: this.updateDetails dustin@797: } dustin@797: }] dustin@797: }] dustin@797: }, { dustin@797: xtype: 'locationform', dustin@797: margin: 5, dustin@797: recordId: this.record.get('ortId') dustin@797: }] dustin@797: }, { dustin@797: xtype: 'fset', dustin@797: bodyStyle: { dustin@797: background: '#fff' dustin@797: }, dustin@797: layout: 'border', dustin@797: name: 'mapfield', dustin@797: title: 'Karte', dustin@797: region: 'center', dustin@797: padding: '5, 5', dustin@797: margin: 5, dustin@797: items: [{ dustin@797: xtype: 'map', dustin@797: region: 'center', dustin@797: layout: 'border', dustin@797: record: this.record.get('ortId') ? this.record : null, dustin@797: bodyStyle: { dustin@797: background: '#fff' dustin@797: }, dustin@797: name: 'map', dustin@797: listeners: { //A listener which listens to the mappanels featureselected event dustin@797: featureselected: this.selectedFeature dustin@797: } dustin@797: }] dustin@797: }]; dustin@797: this.callParent(arguments); dustin@797: }, dustin@797: dustin@797: initData: function() { dustin@797: //Only do this if an OrtId exists... dustin@797: var ortId = this.record.get('ortId'); dustin@797: dustin@797: if (ortId) { dustin@797: Ext.ClassManager.get('Lada.model.Ort').load(ortId, { dustin@797: failure: function(record, action) { dustin@797: // TODO dustin@797: }, dustin@797: success: function(record, response) { dustin@797: var me = this; dustin@797: if (record.get('treeModified') < record.get('parentModified')) { dustin@797: Ext.Msg.show({ dustin@797: title: 'Messprogramm nicht aktuell!', dustin@797: msg: 'Das zugehörige Messprogramm wurde verändert.\nMöchten Sie zu dem Messprogramm zurückkehren und neu laden?\nOhne das erneute Laden des Messprogrammes wird das Speichern des Ortes nicht möglich sein.', dustin@797: buttons: Ext.Msg.OKCANCEL, dustin@797: icon: Ext.Msg.WARNING, dustin@797: closable: false, dustin@797: fn: function(button) { dustin@797: if (button === 'ok') { dustin@797: me.close(); dustin@797: me.parentWindow.initData(); dustin@797: me.parentWindow.down('messprogrammform') dustin@797: .ortWindow = null; dustin@797: } dustin@797: else { dustin@797: me.record.set('treeModified', me.probe.get('treeModified')); dustin@797: } dustin@797: } dustin@797: }); dustin@797: } dustin@797: this.record = record; dustin@797: }, dustin@797: scope: this dustin@797: }); dustin@797: } dustin@797: }, dustin@797: dustin@797: /** dustin@797: * @private dustin@797: * Override to display and update the map view in the panel. dustin@797: */ dustin@797: afterRender: function(){ dustin@797: this.superclass.afterRender.apply(this, arguments); dustin@797: var map = this.down('map'); dustin@797: if (this.record.get('ortId')) { dustin@797: map.selectFeature(this.record.get('ortId')); dustin@797: } dustin@797: else { dustin@797: map.map.zoomToMaxExtent(); dustin@797: } dustin@797: }, dustin@797: dustin@797: /** dustin@797: * This function is used by the MapPanel, when a Feature was selected dustin@797: */ dustin@797: selectedFeature: function(context, args) { dustin@797: var feature = args[0]; dustin@797: if (feature.attributes.id && dustin@797: feature.attributes.id !== '') { dustin@797: var record = Ext.data.StoreManager.get('locations').getById(feature.attributes.id); dustin@797: context.up('window').down('locationform').setRecord(record); dustin@797: context.up('window').down('locationform').setReadOnly(true); dustin@797: context.up('window').down('location').down('combobox').setValue(record.id); dustin@797: } dustin@797: else { dustin@797: context.up('window').down('locationform').setRecord(this.locationRecord); dustin@797: context.up('window').down('locationform').setReadOnly(false); dustin@797: } dustin@797: }, dustin@797: dustin@797: /** dustin@797: * updateDetails is used when a value is selected within the location combobox dustin@797: * When this function is called, the map element within the window dustin@797: * which is embedding this form is updated. dustin@797: * dustin@797: * Mostly the same as in Lada.controlle.form.Ort dustin@797: */ dustin@797: updateDetails: function(combobox, record) { dustin@797: var win = combobox.up('window'); dustin@797: var details = win.down('locationform'); dustin@797: //var id = record[0].get('id'); // We are interested in the cbox... dustin@797: var id = combobox.getValue(); dustin@797: dustin@797: if (details) { dustin@797: var toLoad = Ext.data.StoreManager.get('locations').getById(id); dustin@797: win.down('locationform').setRecord(toLoad); dustin@797: win.down('map').selectFeature(id); dustin@797: } dustin@797: }, dustin@797: dustin@797: /** dustin@797: * Write the selected ortId into the record, and update the MessprogrammWindow. dustin@797: */ dustin@797: apply: function(button) { dustin@797: var win = button.up('window'); dustin@797: var ortId = win.down('location').down('combobox').value; dustin@797: if (this.parentWindow) { dustin@797: this.parentWindow.down('messprogrammform').down('location') dustin@797: .down('combobox').setValue(ortId); dustin@797: } dustin@797: dustin@797: this.parentWindow.down('messprogrammform') dustin@797: .ortWindow = null; dustin@797: this.close(); dustin@797: }, dustin@797: setMessages: function(errors, warnings) { dustin@797: //todo this is a stub dustin@797: }, dustin@797: dustin@797: clearMessages: function() { dustin@797: //todo this is a stub dustin@797: } dustin@797: }); dustin@797: