dustin@759: /* Copyright (C) 2013 by Bundesamt fuer Strahlenschutz dustin@759: * Software engineering by Intevation GmbH dustin@759: * dustin@759: * This file is Free Software under the GNU GPL (v>=3) dustin@759: * and comes with ABSOLUTELY NO WARRANTY! Check out dustin@759: * the documentation coming with IMIS-Labordaten-Application for details. dustin@759: */ dustin@759: dustin@759: /* dustin@759: * Window to edit a Messprogramm dustin@759: */ dustin@759: Ext.define('Lada.view.window.Messprogramm', { dustin@759: extend: 'Ext.window.Window', dustin@759: alias: 'widget.messprogramm', dustin@759: dustin@759: requires: [ dustin@759: 'Lada.view.form.Messprogramm', dustin@759: 'Lada.view.grid.Messmethoden', dustin@759: ], dustin@759: dustin@759: collapsible: true, dustin@759: maximizable: true, dustin@759: autoShow: true, dustin@759: autoScroll: true, dustin@759: layout: 'fit', dustin@759: constrain: true, dustin@759: dustin@759: record: null, dustin@759: dustin@759: initComponent: function() { dustin@759: var i18n = Lada.getApplication().bundle; dustin@759: dustin@759: if (this.record == null) { dustin@759: this.title = i18n.getMsg('messprogramm.window.create.title'); dustin@759: } dustin@759: else { dustin@759: this.title = i18n.getMsg('messprogramm.window.edit.title'); dustin@759: } dustin@759: dustin@759: this.buttons = [{ dustin@759: text: i18n.getMsg('close'), dustin@759: scope: this, dustin@759: handler: this.close dustin@759: }]; dustin@759: this.width = 700; dustin@759: dustin@759: // add listeners to change the window appearence when it becomes inactive dustin@759: this.on({ dustin@759: activate: function(){ dustin@759: this.getEl().removeCls('window-inactive'); dustin@759: }, dustin@759: deactivate: function(){ dustin@759: this.getEl().addCls('window-inactive'); dustin@759: } dustin@759: }); dustin@759: dustin@759: this.height = Ext.getBody().getViewSize().height - 30; dustin@759: // InitialConfig is the config object passed to the constructor on dustin@759: // creation of this window. We need to pass it throuh to the form as dustin@759: // we need the "Id" param to load the correct item. dustin@759: this.items = [{ dustin@759: border: 0, dustin@759: autoScroll: true, dustin@759: items: [{ dustin@759: xtype: 'messprogrammform', dustin@759: recordId: this.record? this.record.get('id') : null dustin@759: }, { dustin@759: //Messmethoden dustin@759: xtype: 'fieldset', dustin@759: title: i18n.getMsg('mmtmessprogramm.form.fieldset.title'), dustin@759: autoScroll: true, dustin@759: margin: 5, dustin@759: layout: { dustin@759: type: 'hbox', dustin@759: }, dustin@759: items: [{ dustin@759: xtype: 'messmethodengrid', dustin@759: recordId: this.record? this.record.get('id') : null, dustin@759: disabled: this.record? false : true, dustin@759: flex: 1 dustin@759: }] dustin@759: }] dustin@759: }]; dustin@759: this.callParent(arguments); dustin@759: }, dustin@759: dustin@759: /** dustin@759: * Init Data is longer than in other windows. dustin@759: * If the Window was used to CREATE a Messprogramm, dustin@759: * it will load an empty record dustin@759: * if it was used to EDIT an existing Messprogramm, dustin@759: * it will load this record AND create a grid to dustin@759: * enable the editing of Messmethoden dustin@759: * which are associated to the Messprogramm dustin@759: */ dustin@759: initData: function() { dustin@759: var i18n = Lada.getApplication().bundle; dustin@759: this.clearMessages(); dustin@759: me = this; dustin@759: dustin@759: // If a record was passed to this window, dustin@759: // create a Edit window dustin@759: if (this.record) { dustin@759: this.setLoading(true); dustin@759: Ext.ClassManager.get('Lada.model.Messprogramm').load(this.record.get('id'), { dustin@759: failure: function(record, action) { dustin@759: me.setLoading(false); dustin@759: // TODO dustin@759: console.log('An unhandled Failure occured. See following Response and Record'); dustin@759: console.log(action); dustin@759: console.log(record); dustin@759: }, dustin@759: success: function(record, response) { dustin@759: this.down('messprogrammform').setRecord(record); dustin@759: this.record = record; dustin@759: dustin@759: var json = Ext.decode(response.response.responseText); dustin@759: if (json) { dustin@759: this.setMessages(json.errors, json.warnings); dustin@759: } dustin@759: // If the Messprogramm is ReadOnly, disable Inputfields and grids dustin@759: if (this.record.get('readonly') === true) { dustin@759: this.down('messprogrammform').setReadOnly(true); dustin@759: this.disableChildren(); dustin@759: } dustin@759: else { dustin@759: this.down('messprogrammform').setReadOnly(false); dustin@759: this.enableChildren(); dustin@759: } dustin@759: me.setLoading(false); dustin@759: }, dustin@759: scope: this dustin@759: }); dustin@759: dustin@759: } dustin@759: // Create a Create Window dustin@759: else { dustin@759: var record = Ext.create('Lada.model.Messprogramm'); dustin@759: this.down('messprogrammform').setRecord(record); dustin@759: } dustin@759: }, dustin@759: dustin@759: //This was used in a Probewindow, I left it here for reference... dustin@759: /* dustin@759: enableAddMessungen: function() { dustin@759: this.down('fset[name=messungen]').down('messunggrid').setReadOnly(false); dustin@759: }, dustin@759: */ dustin@759: dustin@759: disableChildren: function() { dustin@759: // there are no children.... dustin@759: }, dustin@759: dustin@759: enableChildren: function() { dustin@759: // there are no children.... dustin@759: }, dustin@759: dustin@759: setMessages: function(errors, warnings) { dustin@759: this.down('messprogrammform').setMessages(errors, warnings); dustin@759: }, dustin@759: dustin@759: clearMessages: function() { dustin@759: this.down('messprogrammform').clearMessages(); dustin@759: } dustin@759: });