Mercurial > lada > lada-client
diff app/view/form/Ortserstellung.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 | 08085b7d1d0b |
line wrap: on
line diff
--- 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')); + } + }); } }); -