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: /** dustin@1013: * Form to edit the Ortszuordnung of a Probe dustin@1013: */ dustin@1013: Ext.define('Lada.view.form.Ortszuordnung', { dustin@1013: extend: 'Ext.form.Panel', dustin@1013: alias: 'widget.ortszuordnungform', dustin@1013: dustin@1013: model: 'Lada.model.Ortszuordnung', dustin@1021: dustin@1021: requires: [ dustin@1021: 'Lada.view.widget.Verwaltungseinheit', dustin@1021: 'Lada.view.widget.Staat' dustin@1021: ], dustin@1021: dustin@1021: layout: 'fit', dustin@1013: margin: 5, dustin@1013: border: 0, dustin@1013: dustin@1013: record: null, dustin@1013: dustin@1022: trackResetOnLoad: true, dustin@1013: dustin@1013: initComponent: function() { dustin@1013: var i18n = Lada.getApplication().bundle; dustin@1013: this.items = [{ dustin@1013: xtype: 'fieldset', dustin@1013: title: i18n.getMsg('ortszuordnung.form.fset.title'), dustin@1021: layout: 'fit', dustin@1013: items: [{ dustin@1021: layout: 'hbox', dustin@1013: border: 0, dustin@1013: margin: '0, 0, 10, 0', dustin@1013: dockedItems: [{ dustin@1013: xtype: 'toolbar', dustin@1013: dock: 'bottom', dustin@1013: border: '0, 1, 1, 1', dustin@1013: style: { dustin@1013: borderBottom: '1px solid #b5b8c8 !important', dustin@1013: borderLeft: '1px solid #b5b8c8 !important', dustin@1013: borderRight: '1px solid #b5b8c8 !important' dustin@1013: }, dustin@1021: items: [{ dustin@1021: text: i18n.getMsg('ortszuordnung.form.setOrt'), dustin@1178: tooltip: i18n.getMsg('ortszuordnung.form.setOrt.qtip'), dustin@1021: icon: 'resources/img/dialog-ok-apply.png', dustin@1021: action: 'setOrt', dustin@1021: enableToggle: true, dustin@1021: disabled: true dustin@1021: }, '->', { dustin@1013: text: i18n.getMsg('save'), dustin@1178: tooltip: i18n.getMsg('save.qtip'), dustin@1013: icon: 'resources/img/dialog-ok-apply.png', dustin@1013: action: 'save', dustin@1013: disabled: true dustin@1013: }, { dustin@1013: text: i18n.getMsg('discard'), dustin@1178: tooltip: i18n.getMsg('discard.qtip'), dustin@1013: icon: 'resources/img/dialog-cancel.png', dustin@1013: action: 'discard', dustin@1013: disabled: true dustin@1013: }] dustin@1013: }], dustin@1013: items: [{ dustin@1021: layout: 'vbox', dustin@1021: border: 0, raimund@1049: margin: '0, 10, 0, 0', dustin@1013: items: [{ dustin@1013: xtype: 'tfield', raimund@1049: labelWidth: 125, dustin@1013: maxLength: 100, dustin@1013: name: 'ortszusatztext', raimund@1049: fieldLabel: i18n.getMsg('ortszuordnung.form.field.ortszusatztext') dustin@1013: }, { tom@1147: xtype: 'textfield', raimund@1049: labelWidth: 125, raimund@1144: maxLength: 1, raimund@1144: allowBlank: false, tom@1147: regex: /[UEZA]/, tom@1147: activeError: 'U, E, Z oder A eingeben', dustin@1013: name: 'ortszuordnungTyp', raimund@1049: fieldLabel: i18n.getMsg('ortszuordnung.form.field.ortszuordnungtyp') dustin@1021: }, { dustin@1021: xtype: 'textfield', dustin@1022: submitValue: true, dustin@1021: readOnly: true, dustin@1021: hidden: true, dustin@1021: name: 'ortId' dustin@1021: }] dustin@1021: }, { dustin@1021: layout: 'vbox', raimund@1049: flex: 1, raimund@1049: margin: '0, 10, 0, 0', dustin@1021: border: 0, dustin@1021: items: [{ dustin@1021: xtype: 'displayfield', raimund@1049: labelWidth: 125, raimund@1049: fieldLabel: i18n.getMsg('orte.gemeinde'), dustin@1021: name: 'gemeinde' dustin@1021: }, { dustin@1021: xtype: 'displayfield', raimund@1049: labelWidth: 125, dustin@1021: fieldLabel: i18n.getMsg('staat'), dustin@1021: name: 'staat' dustin@1013: }] raimund@1049: }, { raimund@1049: layout: 'vbox', raimund@1049: flex: 1, raimund@1049: margin: '0, 10, 0, 0', raimund@1049: border: 0, raimund@1049: items: [{ raimund@1049: xtype: 'displayfield', raimund@1049: labelWidth: 125, raimund@1049: fieldLabel: i18n.getMsg('orte.lon'), raimund@1049: name: 'lon' raimund@1049: }, { raimund@1049: xtype: 'displayfield', raimund@1049: labelWidth: 125, raimund@1049: fieldLabel: i18n.getMsg('orte.lat'), raimund@1049: name: 'lat' raimund@1049: }] dustin@1013: }] dustin@1013: }] dustin@1013: }]; dustin@1013: this.callParent(arguments); dustin@1013: }, dustin@1013: dustin@1013: setRecord: function(record) { dustin@1013: this.getForm().loadRecord(record); dustin@1021: dustin@1021: if (! record.get('readonly')) { dustin@1021: this.down('[action=setOrt]').enable(); dustin@1021: this.setReadOnly(false); dustin@1021: } dustin@1021: else { dustin@1021: this.setReadOnly(true); dustin@1021: } dustin@1022: var ortId = this.getRecord().get('ortId'); dustin@1022: this.refreshOrt(ortId); dustin@1021: }, dustin@1021: dustin@1022: refreshOrt: function(ortId) { dustin@1021: var orteStore = Ext.StoreManager.get('orte'); dustin@1021: var ort = orteStore.getById(ortId); raimund@1134: if (!ort) { raimund@1134: return; raimund@1134: } raimund@1049: var verwStore = Ext.StoreManager.get('verwaltungseinheiten'); dustin@1021: var verw = verwStore.getById(ort.get('gemId')); raimund@1049: var staatStore = Ext.StoreManager.get('staaten'); dustin@1021: var staat = staatStore.getById(ort.get('staatId')); dustin@1021: dustin@1021: this.getForm().setValues({ dustin@1021: gemeinde: verw.get('bezeichnung'), raimund@1049: staat: staat.get('staatIso'), raimund@1049: lon: ort.get('longitude'), raimund@1049: lat: ort.get('latitude') dustin@1021: }); dustin@1021: }, dustin@1021: dustin@1021: /** dustin@1021: * setOrt can be called from a CallbackFunction, ie select from a grid. dustin@1021: * it will set the ortId of this record dustin@1021: */ dustin@1021: setOrt: function(row, selRecord, index, opts) { dustin@1021: var newOrtId = selRecord.get('id'); dustin@1021: var r = this.getRecord(); dustin@1021: if (newOrtId) { dustin@1021: if (newOrtId != r.get('ortId')) { raimund@1051: r.set('ortId', newOrtId); raimund@1051: this.getForm().setValues({ortId: newOrtId}); dustin@1022: this.refreshOrt(newOrtId); dustin@1021: //set dirty... dustin@1022: this.fireEvent('dirtychange', this.getForm(), true); dustin@1021: } dustin@1021: } dustin@1013: }, dustin@1013: dustin@1013: setMessages: function(errors, warnings) { dustin@1013: var key; dustin@1013: var element; dustin@1013: var content; dustin@1013: var i18n = Lada.getApplication().bundle; dustin@1013: if (warnings) { dustin@1013: for (key in warnings) { dustin@1013: element = this.down('component[name=' + key + ']'); dustin@1013: if (!element) { dustin@1013: continue; dustin@1013: } dustin@1013: content = warnings[key]; dustin@1013: var warnText = ''; dustin@1013: for (var i = 0; i < content.length; i++) { dustin@1013: warnText += i18n.getMsg(content[i].toString()) + '\n'; dustin@1013: } dustin@1013: element.showWarnings(warnText); dustin@1013: } dustin@1013: } dustin@1013: if (errors) { dustin@1013: for (key in errors) { dustin@1013: element = this.down('component[name=' + key + ']'); dustin@1013: if (!element) { dustin@1013: continue; dustin@1013: } dustin@1013: content = errors[key]; dustin@1013: var errorText = ''; dustin@1013: for (var i = 0; i < content.length; i++) { dustin@1013: errorText += i18n.getMsg(content[i].toString()) + '\n'; dustin@1013: } dustin@1013: element.showErrors(errorText); dustin@1013: } dustin@1013: } dustin@1013: }, dustin@1013: dustin@1013: clearMessages: function() { dustin@1013: this.down('tfield[name=ortszusatztext]').clearWarningOrError(); dustin@1013: }, dustin@1013: dustin@1013: setReadOnly: function(value) { dustin@1013: this.down('tfield[name=ortszusatztext]').setReadOnly(value); tom@1147: this.down('textfield[name=ortszuordnungTyp]').setReadOnly(value); dustin@1013: } dustin@1013: }); dustin@1013: