# HG changeset patch # User Maximilian Krambach # Date 1485259106 -3600 # Node ID faecbb446a049b0be868850e5baa789511505fea # Parent 9d298c82575fc11e43dba46a90c25920d6b686ce Ortserstellung: new Messpunkt from map, clone or form functional, still needs error handling and layout diff -r 9d298c82575f -r faecbb446a04 app/controller/grid/Ortszuordnung.js --- a/app/controller/grid/Ortszuordnung.js Wed Jan 18 16:03:40 2017 +0100 +++ b/app/controller/grid/Ortszuordnung.js Tue Jan 24 12:58:26 2017 +0100 @@ -14,7 +14,7 @@ requires: [ 'Lada.view.window.Ortszuordnung', - 'Lada.view.form.Ortserstellung' + 'Lada.view.window.Ortserstellung' ], /** @@ -119,25 +119,21 @@ * Opens the form for a new Messpunkt */ createort: function() { - Ext.create('Lada.view.form.Ortserstellung').show(); + Ext.create('Lada.view.window.Ortserstellung',{ + parentWindow: button.up('ortszuordnungwindow') + }).show(); }, /** * - * Opens the form for a new Messpunkt, with prefilled coordinates. - * TODO Not functional yet + * Creates an event listener for a map click */ frommap: function(button) { var map = button.up('ortszuordnungwindow').down('map'); - // map.getClick(); - //TODO: wait for click return - Ext.create('Lada.view.form.Ortserstellung', { - presets: { - kda_id: 4, - koord_x_extern: 35000000, //TODO dummy values - koord_y_extern: 1000000 - } - }).show(); + var me = this; + map.map.events.register('click', button, me.newOrtfromMapClick); + // TODO visual feedback that map click is active. + // TODO Deactivate event listener if button is destroyed }, /** @@ -147,8 +143,29 @@ cloneort: function(button) { var grid = button.up('ortszuordnungwindow').down('ortstammdatengrid').getView(); var selected = grid.getSelectionModel().getSelection()[0]; - Ext.create('Lada.view.form.Ortserstellung', { - presets: selected.data + Ext.create('Lada.view.window.Ortserstellung', { + record: Ext.create('Lada.model.Ort', selected.data), + parentWindow: button.up('ortszuordnungwindow') + }).show(); + }, + + /** + * Gets the clicked map's coordinates and opens a new Messpunkt window with coordinates prefilled + */ + newOrtfromMapClick: function(evt) { + var me = this; //this = button(action:frommap) + var map = this.up('ortszuordnungwindow').down('map').map; + var lonlat = map.getLonLatFromViewPortPx(evt.xy).transform(new OpenLayers.Projection('EPSG:3857'), + new OpenLayers.Projection('EPSG:4326')); + var controller = Lada.app.getController('Lada.controller.grid.Ortszuordnung'); + map.events.unregister('click', this, controller.newOrtfromMapClick); + Ext.create('Lada.view.window.Ortserstellung', { + record: Ext.create('Lada.model.Ort',{ + koordXExtern: lonlat.lon, + koordYExtern: lonlat.lat, + kdaId : 4 + }), + parentWindow: this.up('ortszuordnungwindow') }).show(); } }); diff -r 9d298c82575f -r faecbb446a04 app/model/Ort.js --- a/app/model/Ort.js Wed Jan 18 16:03:40 2017 +0100 +++ b/app/model/Ort.js Tue Jan 24 12:58:26 2017 +0100 @@ -29,7 +29,13 @@ }, { name: 'staatId' }, { - name: 'kdaId' + name: 'kdaId', + convert: function(v) { + if (v === '') { + return null; + } + return v; + } }, { name: 'ozId', serialize: function(v) { @@ -59,9 +65,21 @@ }, { name: 'hoeheLand' }, { - name: 'koordXExtern' + name: 'koordXExtern', + convert: function(v) { + if (v === '') { + return null; + } + return v; + } }, { - name: 'koordYExtern' + name: 'koordYExtern', + convert: function(v) { + if (v === '') { + return null; + } + return v; + } }, { name: 'longitude', type: 'float' diff -r 9d298c82575f -r faecbb446a04 app/view/form/Ortserstellung.js --- a/app/view/form/Ortserstellung.js Wed Jan 18 16:03:40 2017 +0100 +++ b/app/view/form/Ortserstellung.js Tue Jan 24 12:58:26 2017 +0100 @@ -8,165 +8,149 @@ /** * Form to create a new Messpunkt - * TODO: layout, saving, model + * TODO: layout */ Ext.define('Lada.view.form.Ortserstellung', { extend: 'Ext.form.Panel', alias: 'widget.ortserstellungsform', - - model: 'Lada.model.Ortszuordnung',//TODO correct model needed requires: [ 'Lada.view.widget.Verwaltungseinheit', 'Lada.view.widget.Staat' ], + model: null, - width: 900, - height: 700, - bodyStyle: {background: '#fff'}, - layout: 'vbox', - scrollable: true, - margin: '5, 5, 0, 5', - border: 0, - floating: true, - closable: true, - - /** - * Preset values - */ - presets: null, + record: null, initComponent: function() { var i18n = Lada.getApplication().bundle; var me = this; - this.items = [{ //TODO: layout and input types - title: 'Neuen Messpunkt anlegen', - 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: ['->', { - text: i18n.getMsg('save'), - disabled: true, - action: 'save', - handler: me.saveOrt - }, { - text: i18n.getMsg('close'), - action: 'close', - handler: function() { - me.close(); - } - }] - }], - items : [{ - xtype: 'netzbetreiber', - editable: false, - readOnly: true, - submitValue: true, - fieldLabel: i18n.getMsg('netzbetreiberId'), - margin : '0, 5, 5, 5', - labelWidth: 80, - // value: XXX - // TODO: get netzbetreiber of current user - }, { - xtype: 'checkbox', - name: 'aktiv', - fieldLabel: 'aktiv:', - value: me.presets.aktiv? me.presets.aktiv:null - }, { - xtype: 'displayfield', - value: 'D', - labelWidth: 125, - maxLength: 1, - name: 'messpunktart', - fieldLabel: 'Art des Messpunktes:' - },{ - xtype: 'displayfield', - labelWidth: 125, - maxLength: 100, - name: 'OrtID', - fieldLabel: 'Ort/Messpunkt-ID:', - // TODO: needed? We can't set it, and it is not yet given - // for a new messpunkt - editable: false + this.items = [{ + xtype: 'netzbetreiber', + editable: false, + readOnly: true, + submitValue: true, + fieldLabel: i18n.getMsg('netzbetreiberId'), + margin : '0, 5, 5, 5', + labelWidth: 80, + width: 150, + value: Lada.netzbetreiber }, { - xtype: 'staat', - labelWidth: 100, - fieldLabel: i18n.getMsg('staat'), - name: 'staatId', - width: 160, - listeners: { - change: { - fn: function() { me.checkCommitEnabled() } - } + xtype: 'checkbox', + name: 'aktiv', + fieldLabel: 'aktiv:' + }, { + xtype: 'displayfield', + align: 'right', + value: 'D', + labelWidth: 125, + maxLength: 1, + name: 'messpunktart', + fieldLabel: 'Art des Messpunktes:' + },{ + xtype: 'staat', + labelWidth: 125, + fieldLabel: i18n.getMsg('staat'), + name: 'staatId', + listeners: { + change: { + fn: function() { me.checkCommitEnabled() } } - }, { - xtype: 'verwaltungseinheit', - labelWidth: 125, - fieldLabel: i18n.getMsg('orte.gemeinde'), - name: 'gemeinde', - listeners: { - change: { - fn: function() { me.checkCommitEnabled() } - } + } + }, { + xtype: 'verwaltungseinheit', + labelWidth: 125, + fieldLabel: i18n.getMsg('orte.gemeinde'), + name: 'gemId', + listeners: { + change: { + fn: function() { me.checkCommitEnabled() } } - }, { - xtype: 'displayfield', - labelWidth: 125, - fieldLabel: i18n.getMsg('orte.kda'), - name: 'kdaId', - listeners: { - change: { - fn: function() { me.checkCommitEnabled() } - } + } + }, { + xtype: 'numfield', + labelWidth: 125, + fieldLabel: i18n.getMsg('orte.kda'), + allowDecimals: false, + maxLength: 1, + name: 'kdaId', + listeners: { + change: { + fn: function() { me.checkCommitEnabled() } } + } + }, { + xtype: 'numfield', + labelWidth: 125, + fieldLabel: i18n.getMsg('orte.koordx'), + name: 'koordXExtern', + allowDecimals: true, + decimalPrecision: 5, + maxLength: 10, + listeners: { + change: { + fn: function() { me.checkCommitEnabled() } + } + } + }, { + xtype: 'numfield', + labelWidth: 125, + fieldLabel: i18n.getMsg('orte.koordy'), + name: 'koordYExtern', + allowDecimals: true, + decimalPrecision: 5, + maxLength: 10, + listeners: { + change: { + fn: function() { me.checkCommitEnabled() } + } + } + }, { + xtype: 'numfield', + labelWidth: 125, + fieldLabel: 'Höhe:', + name: 'hoeheLand', + maxLength: 10, + allowDecimals: true + }, { + xtype: 'tfield', + labelWidth: 125, + maxLength: 100, + name: 'kurztext', + fieldLabel: i18n.getMsg('orte.kurztext'), + },{ + xtype: 'tfield', + labelWidth: 125, + fieldLabel: i18n.getMsg('orte.langtext'), + name: 'langtext' + },{ + xtype: 'tfield', + labelWidth: 125, + fieldLabel: 'Berichtstext:', + name: 'berichtstext' + }]; + this.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: ['->', { + text: i18n.getMsg('save'), + action: 'save', + handler: me.saveOrt, + disabled: true }, { - xtype: 'displayfield', - labelWidth: 125, - fieldLabel: i18n.getMsg('orte.koordx'), - name: 'koordXExtern', - listeners: { - change: { - fn: function() { me.checkCommitEnabled() } - } - } - }, { - xtype: 'displayfield', - labelWidth: 125, - fieldLabel: i18n.getMsg('orte.koordy'), - name: 'koordYExtern', - listeners: { - change: { - fn: function() { me.checkCommitEnabled() } - } + text: i18n.getMsg('close'), + action: 'close', + handler: function() { + me.close(); } - }, { - xtype: 'displayfield', - labelWidth: 125, - fieldLabel: 'Höhe:', - name: 'hoehe', //TODO: hohe_ueber_NN? - }, { - xtype: 'displayfield', - labelWidth: 125, - maxLength: 100, - name: 'kurztext', - fieldLabel: 'Kurztext:' - },{ - xtype: 'displayfield', - labelWidth: 125, - fieldLabel: i18n.getMsg('orte.langtext'), - name: 'langtext' - },{ - xtype: 'displayfield', - labelWidth: 125, - fieldLabel: 'Berichtstext:', - name: 'berichtstext' }] }]; + //TODO: // 'Anlage:'? // zone @@ -176,8 +160,8 @@ // 'Prog.-Punkt:', ? // nutsCode // Ortszusatz-ID (ozId) - me.callParent(arguments); - this.prefillForm(); + this.callParent(arguments); + this.getForm().loadRecord(this.record); }, /** @@ -186,15 +170,21 @@ */ // TODO messpunktart is not yet finally defined checkCommitEnabled: function() { - var savebutton = this.down('toolbar').down('button[action=save]'); + var savebutton = this.down('toolbar').down('button[action=save]'); var form = this.getForm(); - if (this.checkCoordinates()) { - form.findField('messpunktart').setValue('D'); - savebutton.setDisabled(false); - } else if (form.findField('gemeinde').getValue()) { + if (this.getForm().findField('kdaId').getValue() || + this.getForm().findField('koordYExtern').getValue() || + this.getForm().findField('koordXExtern').getValue()) { + if (this.checkCoordinates()) { + form.findField('messpunktart').setValue('D'); + savebutton.setDisabled(false); + } else { + savebutton.setDisabled(true); + } + } else if (form.findField('gemId').getValue()) { form.findField('messpunktart').setValue('V'); savebutton.setDisabled(false); - } else if (form.findField('staatId')) { + } else if (form.findField('staatId').getValue()) { form.findField('messpunktart').setValue('S'); savebutton.setDisabled(false); } else { @@ -237,50 +227,67 @@ } }, - saveOrt: function(){ - // TODO not yet implemented - alert("save!"); - }, - - /** - * Fill the form with values passed by presets. - // TODO Find a shorter way of setting all these - */ - prefillForm: function() { - var form = this.getForm(); - if (this.presets.aktiv) { - form.findField('aktiv').setValue(this.presets.aktiv); - } - if (this.presets.staatId) { - // TODO: staatID != staatISO - form.findField('staatId').setValue(me.presets.staatId); - } - if (this.presets.gemeinde) { - // TODO: ortId != gemeinde - form.findField('gemeinde').setValue(this.presets.gemeinde); + saveOrt: function() { + var this_panel = this.up('panel'); + var form = this_panel.getForm(); + var data = form.getFieldValues(true); + for (var key in data) { + form.getRecord().set(key, data[key]); } - if (this.presets.kdaId) { - form.findField('kdaId').setValue(this.presets.kdaId); - } - if (this.presets.koordXExtern) { - form.findField('koordXExtern').setValue(this.presets.koordXExtern); - } - if (this.presets.koordYExtern) { - form.findField('koordYExtern').setValue(this.presets.koordYExtern); - } - if (this.presets.hoehe) { - // TODO hohe_ueber_NN? - form.findField('hoehe').setValue(me.presets.hoehe); - } - if (this.presets.kurztext) { - form.findField('kurztext').setValue(this.presets.kurztext); - } - if (this.presets.langtext) { - form.findField('langtext').setValue(this.presets.langtext); - } - if (this.presets.berichtstext) { - form.findField('berichtstext').setValue(this.presets.berichtstext); - } + this_panel.record.set('letzteAenderung', 0); + this_panel.record.set('id', null); + this_panel.record.set('ortId', null); + this_panel.record.set('netzbetreiberId', Lada.netzbetreiber[0]); + console.log(this_panel.record); + this_panel.record.save({ + success: function(record, response) { + console.log(response); + var newOrtId; + Ext.Msg.show({ + title: Lada.getApplication().bundle.getMsg('success'), + autoScroll: true, + msg: 'Ort erfolgreich angelegt!', + buttons: Ext.Msg.OK + }); + var ozw = this_panel.up().parentWindow; + ozw.ortstore.load({ + callback: function(records, operation, success) { + ozw.down('map').addLocations(ozw.ortstore); + ozw.down('ortstammdatengrid').setStore(ozw.ortstore); + var id = Ext.decode(response.response.responseText).data.id; + var record = ozw.down('ortstammdatengrid').store.getById(id); + var selectionmodel = ozw.down('ortstammdatengrid').getSelectionModel(); + console.log(record); + selectionmodel.select(record); + this_panel.close(); + }, + scope: this + }); + }, + failure: function(record, response) { + console.log(response); + // TODO +// response.error.status +// response.error.statusText +// var json = Ext.decode(response.response.responseText); +// if (json) { +// if(json.errors.totalCount > 0 || json.warnings.totalCount > 0){ +// console.log(json.errors); +// console.log(json.warnings); +// formPanel.setMessages(json.errors, json.warnings); +// } +// if(json.message){ +// Ext.Msg.alert(Lada.getApplication().bundle.getMsg('err.msg.save.title') +// +' #'+json.message, +// Lada.getApplication().bundle.getMsg(json.message)); +// } else { +// Ext.Msg.alert(Lada.getApplication().bundle.getMsg('err.msg.save.title'), +// Lada.getApplication().bundle.getMsg('err.msg.generic.body')); +// } +// } else { +// Ext.Msg.alert(Lada.getApplication().bundle.getMsg('err.msg.save.title'), +// Lada.getApplication().bundle.getMsg('err.msg.response.body')); + } + }); } }); - diff -r 9d298c82575f -r faecbb446a04 app/view/widget/base/NumberField.js --- a/app/view/widget/base/NumberField.js Wed Jan 18 16:03:40 2017 +0100 +++ b/app/view/widget/base/NumberField.js Tue Jan 24 12:58:26 2017 +0100 @@ -25,6 +25,7 @@ name: this.name, msgTarget: 'none', allowDecimals: this.allowDecimals, + decimalPrecision: this.decimalPrecision || 2, maxLength: this.maxLength || 1000, enforceMaxLength: this.enforceMaxLength || true, fieldLabel: this.fieldLabel, diff -r 9d298c82575f -r faecbb446a04 app/view/window/Ortserstellung.js --- /dev/null Thu Jan 01 00:00:00 1970 +0000 +++ b/app/view/window/Ortserstellung.js Tue Jan 24 12:58:26 2017 +0100 @@ -0,0 +1,54 @@ +/* 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 for new Ort, wraps around a {@link Lada.view.form.Ortsertellung} + */ +Ext.define('Lada.view.window.Ortserstellung', { + extend: 'Ext.window.Window', + alias: 'window.ortserstellung', + requires: [ + 'Lada.model.Ort', + 'Lada.view.form.Ortserstellung' + ], + + minWidth: 350, + + margin: 5, + + border: 0, + + bodyStyle: {background: '#fff'}, + + layout: 'fit', + + title: 'Neuen Messpunkt anlegen', + + /** + * The record for the new Ort. Should be a {@link Lada.model.Ort} + */ + record: null, + + parentWindow: null, + + initComponent: function() { + var me = this; + if (this.record === null) { + this.record = Ext.create('Lada.model.Ort'); + } + this.items = [ + Ext.create('Lada.view.form.Ortserstellung', { + record: me.record, + listeners: { + destroy: {fn: function() {me.close();}} + } + }) + ]; + this.callParent(arguments); + } +}); \ No newline at end of file diff -r 9d298c82575f -r faecbb446a04 app/view/window/Ortszuordnung.js --- a/app/view/window/Ortszuordnung.js Wed Jan 18 16:03:40 2017 +0100 +++ b/app/view/window/Ortszuordnung.js Tue Jan 24 12:58:26 2017 +0100 @@ -153,7 +153,7 @@ this.down('ortszuordnungform').setRecord(this.record); var map = this.down('map'); var osg = this.down('ortstammdatengrid'); - var ortstore = Ext.create('Lada.store.Orte', { + this.ortstore = Ext.create('Lada.store.Orte', { defaultPageSize: 0, autoLoad: false, listeners: { @@ -167,8 +167,8 @@ fn: function() { osg.setLoading(false); map.setLoading(false); - osg.setStore(ortstore); - map.addLocations(ortstore); + osg.setStore(me.ortstore); + map.addLocations(me.ortstore); map.featureLayer.setVisibility(false); map.selectedFeatureLayer = new OpenLayers.Layer.Vector( 'gewählter Messpunkt', { @@ -194,7 +194,7 @@ } } }); - ortstore.load(); + this.ortstore.load(); map.addListener('featureselected', osg.selectOrt, osg); osg.addListener('select', map.selectFeature, map); },