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@1021: requires: [ mkrambach@1288: 'Lada.view.form.OrtInfo', tom@1338: 'Lada.view.widget.OrtszuordnungTyp', dustin@1021: 'Lada.view.widget.Verwaltungseinheit', dustin@1021: 'Lada.view.widget.Staat' dustin@1021: ], dustin@1021: dustin@1021: layout: 'fit', raimund@1274: margin: '5, 5, 0, 5', dustin@1013: border: 0, dustin@1013: mkrambach@1289: /** mkrambach@1289: * @cfg: the type of the record to be passed. Should be either 'probe' or 'mpr'. mkrambach@1289: * Variable naming of these differ slightly (see function initComponent and the mkrambach@1289: * two lada.data.model.ortszuordnung* ) mkrambach@1289: */ mkrambach@1289: type: null, mkrambach@1289: dustin@1013: record: null, dustin@1013: dustin@1022: trackResetOnLoad: true, dustin@1013: dustin@1013: initComponent: function() { dustin@1013: var i18n = Lada.getApplication().bundle; mkrambach@1288: var me = this; dustin@1013: this.items = [{ dustin@1013: xtype: 'fieldset', dustin@1013: title: i18n.getMsg('ortszuordnung.form.fset.title'), dustin@1021: layout: 'fit', dustin@1013: items: [{ raimund@1334: overflowY: 'auto', 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 raimund@1321: }, { raimund@1321: text: i18n.getMsg('discard'), raimund@1321: qtip: 'Ă„nderungen verwerfen', raimund@1321: icon: 'resources/img/dialog-cancel.png', raimund@1321: action: 'revert', mkrambach@1347: disabled: true dustin@1013: }] dustin@1013: }], dustin@1013: items: [{ raimund@1334: layout: 'hbox', dustin@1021: border: 0, raimund@1334: margin: '0, 0, 10, 0', dustin@1021: items: [{ raimund@1274: layout: 'vbox', raimund@1274: border: 0, mkrambach@1340: flex: 1, raimund@1274: items: [{ raimund@1334: layout: 'vbox', raimund@1334: border: 0, raimund@1334: margin: '0, 20, 0, 0', raimund@1334: items: [{ raimund@1334: xtype: 'tfield', raimund@1334: labelWidth: 125, raimund@1334: maxLength: 100, raimund@1334: name: 'ortszusatztext', raimund@1334: fieldLabel: i18n.getMsg('ortszuordnung.form.field.ortszusatztext') raimund@1334: }, { tom@1338: xtype: 'ortszuordnungtyp', raimund@1334: labelWidth: 125, raimund@1334: allowBlank: false, raimund@1334: editable: true, mkrambach@1339: name: 'ortszuordnungTyp', raimund@1334: disableKeyFilter: true, mstanko@1377: fieldLabel: i18n.getMsg('ortszuordnung.form.field.ortszuordnungtyp') raimund@1334: }, { raimund@1334: // this field is hidden because the user doesn't raimund@1334: // need to know the internal ortID raimund@1334: xtype: 'textfield', raimund@1334: allowBlank: false, raimund@1334: regex: /^[0-9]{1,45}$/, raimund@1334: submitValue: true, raimund@1334: hidden: true, mkrambach@1339: name: 'ortId', raimund@1334: listeners: { raimund@1334: change: me.changed raimund@1334: } raimund@1334: }] raimund@1334: }, mkrambach@1340: Ext.create('Lada.view.form.OrtInfo') raimund@1334: ] raimund@1334: }] dustin@1013: }] mkrambach@1288: }] mkrambach@1288: }]; dustin@1013: this.callParent(arguments); dustin@1013: }, dustin@1013: dustin@1013: setRecord: function(record) { dustin@1013: this.getForm().loadRecord(record); raimund@1335: this.record = record; mkrambach@1288: 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@1021: }, dustin@1021: dustin@1021: /** dustin@1021: * setOrt can be called from a CallbackFunction, ie select from a grid. mkrambach@1288: * it will set the ortId of this record dustin@1021: */ dustin@1021: setOrt: function(row, selRecord, index, opts) { mkrambach@1347: if (selRecord) { mkrambach@1347: var newOrtId = selRecord.get('id'); mkrambach@1347: } dustin@1021: if (newOrtId) { mkrambach@1341: this.getForm().setValues({ortId: newOrtId}); mkrambach@1289: this.setOrtInfo(selRecord); dustin@1021: } dustin@1013: }, dustin@1013: mkrambach@1289: setOrtInfo: function(ortrecord) { mkrambach@1289: var verwStore = Ext.StoreManager.get('verwaltungseinheiten'); mkrambach@1289: var verw = verwStore.getById(ortrecord.get('gemId')); mkrambach@1289: var staatStore = Ext.StoreManager.get('staaten'); mkrambach@1289: var staat = staatStore.getById(ortrecord.get('staatId')); mkrambach@1289: var ortinfo = this.down('ortinfo'); mkrambach@1289: ortinfo.loadRecord(ortrecord); mkrambach@1343: if (verw !== null) { mkrambach@1343: ortinfo.getForm().setValues({gemeinde: verw.get('bezeichnung')}); mkrambach@1350: } else { mkrambach@1350: ortinfo.getForm().setValues({gemeinde: ''}); mkrambach@1350: } mkrambach@1350: if (staat !== null) { mkrambach@1350: ortinfo.getForm().setValues({staat: staat.get('staatIso')}); mkrambach@1350: } else { mkrambach@1350: ortinfo.getForm().setValues({staat: ''}); mkrambach@1343: } mkrambach@1289: }, mkrambach@1289: 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: } mkrambach@1295: 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); mkrambach@1339: var fieldId = 'textfield[name=ortszuordnungTyp]'; mkrambach@1289: this.down(fieldId).setReadOnly(value); mkrambach@1288: }, mkrambach@1288: mkrambach@1288: /** mkrambach@1289: * Helper to trigger the forms' validity check mkrambach@1288: */ mkrambach@1289: changed: function(newValue, oldValue) { mkrambach@1288: var controller = Lada.app.getController( mkrambach@1288: 'Lada.controller.form.Ortszuordnung'); mkrambach@1288: var form = this.up('form').getForm(); mkrambach@1288: controller.validityChange(form, form.isValid()); dustin@1013: } dustin@1013: }); dustin@1013: