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@760: dustin@760: initComponent: function() { dustin@760: var i18n = Lada.getApplication().bundle; dustin@760: 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({ dustin@760: 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: console.log(json); 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: // TODO handle Errors correctly, especially AuthenticationTimeouts 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@809: dustin@809: if(json.message){ dustin@809: Ext.Msg.alert(Lada.getApplication().bundle.getMsg('err.msg.save.title') dustin@809: +' #'+json.message, dustin@809: Lada.getApplication().bundle.getMsg(json.message)); dustin@809: } else { dustin@809: Ext.Msg.alert(Lada.getApplication().bundle.getMsg('err.msg.save.title'), dustin@809: Lada.getApplication().bundle.getMsg('err.msg.generic.body')); dustin@809: } dustin@809: } else { dustin@809: Ext.Msg.alert(Lada.getApplication().bundle.getMsg('err.msg.save.title'), dustin@809: Lada.getApplication().bundle.getMsg('err.msg.response.body')); dustin@809: } dustin@760: } dustin@760: }); dustin@760: } dustin@760: }]; dustin@760: this.width = 400; dustin@760: this.height = 300; 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@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: + '
' + i18n.getMsg('messprogtimeperiod') + '
' dustin@760: }, { dustin@760: xtype: 'datetime', dustin@760: fieldLabel: i18n.getMsg('from'), dustin@760: labelWidth: 90, dustin@807: margin: 5, 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@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@809: r += response.totalCount; dustin@809: r += ' ' + i18n.getMsg('probecreated'); dustin@809: r += '