dustin@760: /* Copyright (C) 2013 by Bundesamt fuer Strahlenschutz dustin@760: * Software engineering by Intevation GmbH dustin@760: * dustin@760: * This file is Free Software under the GNU GPL (v>=3) dustin@760: * and comes with ABSOLUTELY NO WARRANTY! Check out dustin@760: * the documentation coming with IMIS-Labordaten-Application for details. dustin@760: */ dustin@760: dustin@760: /* dustin@760: * Window to generate Proben from a Messprogramm dustin@760: */ dustin@760: Ext.define('Lada.view.window.GenProbenFromMessprogramm', { dustin@760: extend: 'Ext.window.Window', dustin@760: alias: 'widget.genpfm', dustin@760: dustin@760: collapsible: true, dustin@760: maximizable: true, dustin@760: autoShow: true, dustin@760: autoScroll: true, dustin@760: layout: 'fit', dustin@760: constrain: true, dustin@760: dustin@760: record: null, dustin@818: parentWindow: null, dustin@760: dustin@760: initComponent: function() { dustin@760: var i18n = Lada.getApplication().bundle; dustin@760: dustin@818: // add listeners to change the window appearence when it becomes inactive dustin@818: this.on({ dustin@818: activate: function(){ dustin@818: this.getEl().removeCls('window-inactive'); dustin@818: }, dustin@818: deactivate: function(){ dustin@818: this.getEl().addCls('window-inactive'); dustin@818: } dustin@818: }); dustin@818: dustin@760: this.title = i18n.getMsg('gpfm.window.title'); dustin@760: var me = this; dustin@760: this.buttons = [{ dustin@760: text: i18n.getMsg('cancel'), dustin@760: scope: this, dustin@760: handler: this.close dustin@760: }, { dustin@760: text: i18n.getMsg('generateproben'), dustin@760: handler: function() { dustin@760: var jsondata = { dustin@760: id: me.record.id, dustin@761: start: new Date(me.down('datetime [name=start]').getValue()).valueOf(), dustin@761: end: new Date(me.down('datetime [name=end]').getValue()).valueOf() dustin@760: }; dustin@760: dustin@760: dustin@760: Ext.Ajax.request({ raimund@831: url: 'lada-server/probe/messprogramm', dustin@760: method: 'POST', dustin@760: headers: { dustin@760: 'X-OPENID-PARAMS': Lada.openIDParams dustin@760: }, dustin@760: jsonData: jsondata, dustin@809: success: function(response) { dustin@809: var json = Ext.JSON.decode(response.responseText); dustin@809: Ext.Msg.show({ dustin@809: title: i18n.getMsg('success'), dustin@809: autoScroll: true, dustin@809: msg: me.evalResponse(json), dustin@809: buttons: Ext.Msg.OK, dustin@809: }); dustin@760: }, dustin@809: failure: function(response) { dustin@809: var json = Ext.JSON.decode(response.responseText); dustin@809: if (json) { dustin@809: if(json.errors.totalCount > 0 || json.warnings.totalCount > 0){ dustin@809: formPanel.setMessages(json.errors, json.warnings); dustin@809: } dustin@812: // TODO Move this handling of 699 and 698 to a more central place! dustin@812: // TODO i18n dustin@812: if (json.message === "699" || json.message === "698") { dustin@812: /* This is the unauthorized message with the authentication dustin@812: * redirect in the data */ dustin@809: dustin@812: /* We decided to handle this with a redirect to the identity dustin@812: * provider. In which case we have no other option then to dustin@812: * handle it here with relaunch. */ dustin@812: Ext.MessageBox.confirm('Erneutes Login erforderlich', dustin@812: 'Der Server konnte die Anfrage nicht authentifizieren.
'+ dustin@812: 'Für ein erneutes Login muss die Anwendung neu geladen werden.
' + dustin@812: 'Alle ungesicherten Daten gehen dabei verloren.
' + dustin@819: 'Soll die Anwendung jetzt neu geladen werden?', me.reload); dustin@812: } dustin@812: else if(json.message){ dustin@812: Ext.Msg.alert(Lada.getApplication().bundle.getMsg('err.msg.generic.title') dustin@809: +' #'+json.message, dustin@809: Lada.getApplication().bundle.getMsg(json.message)); dustin@809: } else { dustin@812: Ext.Msg.alert(Lada.getApplication().bundle.getMsg('err.msg.generic.title'), dustin@809: Lada.getApplication().bundle.getMsg('err.msg.generic.body')); dustin@809: } dustin@809: } else { dustin@812: Ext.Msg.alert(Lada.getApplication().bundle.getMsg('err.msg.generic.title'), dustin@809: Lada.getApplication().bundle.getMsg('err.msg.response.body')); dustin@809: } dustin@760: } dustin@760: }); dustin@760: } dustin@760: }]; dustin@832: this.width = 350; dustin@832: this.height = 250; dustin@760: dustin@760: // add listeners to change the window appearence when it becomes inactive dustin@760: this.on({ dustin@760: activate: function(){ dustin@760: this.getEl().removeCls('window-inactive'); dustin@760: }, dustin@760: deactivate: function(){ dustin@760: this.getEl().addCls('window-inactive'); dustin@818: }, dustin@818: close: function () { dustin@818: this.parentWindow.probenWindow = null; dustin@760: } dustin@760: }); dustin@760: dustin@760: // InitialConfig is the config object passed to the constructor on dustin@760: // creation of this window. We need to pass it throuh to the form as dustin@760: // we need the "Id" param to load the correct item. dustin@760: this.items = [{ dustin@760: border: 0, dustin@760: autoScroll: true, dustin@760: items: [{ dustin@807: xtype: 'panel', dustin@807: border: 0, dustin@807: margin: 5, dustin@807: layout: 'fit', dustin@807: html: '

' dustin@807: + i18n.getMsg('nameofmessprogramm') dustin@807: + '
' dustin@807: + this.record.get('name') dustin@807: + '

' dustin@760: }, { dustin@807: xtype: 'panel', dustin@807: border: 0, dustin@807: margin: 5, dustin@807: layout: 'fit', dustin@807: html: '

' + i18n.getMsg('messprogtimeperiod') + '

' dustin@760: }, { dustin@760: xtype: 'datetime', dustin@760: fieldLabel: i18n.getMsg('from'), dustin@760: labelWidth: 90, dustin@807: margin: 5, dustin@832: width: 300, dustin@760: name: 'start', dustin@760: format: 'd.m.Y H:i', dustin@760: period: 'start' dustin@760: }, { dustin@760: xtype: 'datetime', dustin@760: fieldLabel: i18n.getMsg('to'), dustin@760: labelWidth: 90, dustin@807: margin: 5, dustin@832: width: 300, dustin@760: name: 'end', dustin@760: format: 'd.m.Y H:i', dustin@760: period: 'end' dustin@760: }] dustin@760: }]; dustin@760: this.callParent(arguments); dustin@760: }, dustin@760: dustin@760: /** dustin@760: * Init dustin@760: */ dustin@760: initData: function() { dustin@760: var i18n = Lada.getApplication().bundle; dustin@760: me = this; dustin@760: }, dustin@809: dustin@809: /** dustin@809: * Parse ServerResponse when Proben have been generated dustin@809: */ dustin@809: evalResponse: function(response) { dustin@809: var i18n = Lada.getApplication().bundle; dustin@809: var r = ''; dustin@812: r += response.data.length; dustin@809: r += ' ' + i18n.getMsg('probecreated'); dustin@809: r += '
'; dustin@809: r += i18n.getMsg('probeids'); dustin@809: var i; dustin@809: for (i in response.data){ dustin@809: r += '
'; dustin@809: r += response.data[i].probeIdAlt dustin@809: } dustin@809: return r; dustin@812: }, dustin@812: dustin@812: reload: function(btn) { dustin@812: if (btn === 'yes') { dustin@812: location.reload(); dustin@812: } dustin@809: } dustin@760: });