raimund@729: /**
dustin@890: * This Window is shown, when Proben could be imported from a LAF file
raimund@729: */
raimund@729: Ext.define('Lada.view.window.ImportResponse', {
raimund@729: extend: 'Ext.window.Window',
raimund@729: alias: 'widget.importresponse',
raimund@729:
raimund@729: data: null,
raimund@729: message: null,
raimund@729: fileName: '',
raimund@729:
raimund@729: layout: 'fit',
raimund@729: /**
raimund@729: * @private
raimund@729: * Initialize the view.
raimund@729: */
raimund@729: initComponent: function() {
raimund@729: var me = this;
raimund@729: var html;
raimund@1219: var download;
raimund@1219: var i18n = Lada.getApplication().bundle;
raimund@729: if (me.data && me.message) {
raimund@1219: html = me.parseShortResponse(me.message, me.data);
raimund@729: }
raimund@1222: else {
raimund@1222: html = 'Der Import der Datei ' + this.fileName +
raimund@1222: ' war nicht erfolgreich.';
raimund@1222: }
raimund@729: this.bodyStyle = {background: '#fff'};
raimund@729: me.items = [{
raimund@729: xtype: 'panel',
raimund@729: html: html,
raimund@729: margin: 10,
raimund@729: border: false
raimund@729: }];
raimund@729:
raimund@1219: me.buttons = [{
raimund@1219: text: i18n.getMsg('close'),
raimund@1219: scope: this,
raimund@1219: name: 'close',
raimund@1219: handler: this.close
raimund@1219: }, {
raimund@1219: text: i18n.getMsg('download'),
raimund@1219: name: 'download',
raimund@1219: disabled: true,
raimund@1219: handler: function() {
raimund@1219: var blob = new Blob([download],{type: 'text/html'});
raimund@1219: saveAs(blob, 'report.html');
raimund@1219: }
raimund@1219: }];
raimund@729: this.callParent(arguments);
raimund@1222: if (me.data && me.message) {
raimund@1222: download = me.parseResponse(me.message, me.data);
raimund@1222: }
raimund@1219: },
raimund@1219:
raimund@1219: /**
raimund@1219: * Parse the response and create a summary of the result
raimund@1219: * @param msg
raimund@1219: * @param data
raimund@1219: */
raimund@1219: parseShortResponse: function(msg, data) {
raimund@1222: data = Ext.JSON.decode(data, true);
raimund@1219: var errors = data.data.errors;
raimund@1219: var warnings = data.data.warnings;
raimund@1219: var out = [];
raimund@1219: // There is a entry for each imported proben in the errors dict (might be
raimund@1219: // empty)
raimund@1219:
raimund@1219: var numErrors;
raimund@1219: var numWarnings;
raimund@1219: if (!Ext.isObject(errors)) {
raimund@1219: numErrors = 0;
raimund@1219: }
raimund@1219: else {
raimund@1219: numErrors = Object.keys(errors).length;
raimund@1219: }
raimund@1219: if (!Ext.isObject(warnings)) {
raimund@1219: numWarnings = 0;
raimund@1219: }
raimund@1219: else {
raimund@1219: numWarnings = Object.keys(warnings).length;
raimund@1219: }
raimund@1219: if (msg !== '200') {
raimund@1219: out.push('Der Import der Datei ' + this.fileName +
raimund@1219: ' war nicht erfolgreich. Der Importvorgang konnte ' +
raimund@1219: 'aufgrund eines Fehlers im Server nicht beendet werden.');
raimund@1219: }
raimund@1219: else {
raimund@1219: if (numErrors > 0) {
tom@1226: out.push(numErrors + ' Probe(n) konnten nicht vollständig '
tom@1226: + 'erfolgreich importiert werden.');
raimund@1219: out.push('
');
raimund@1219: out.push('
');
raimund@1219: }
raimund@1219: if (numWarnings > 0) {
raimund@1219: out.push('Bei ' + numWarnings + ' Probe(n) traten Warnungen auf. ');
raimund@1219: out.push('
');
raimund@1219: out.push('
');
raimund@1219: }
raimund@1219: if (numErrors > 0 || numWarnings > 0) {
raimund@1219: out.push('Der ausfĂĽhrliche Bericht steht als Download bereit.');
raimund@1219: out.push('
');
raimund@1219: }
raimund@1219: else {
raimund@1219: out.push('Die Proben wurden importiert.');
raimund@1219: out.push('
');
raimund@1219: }
raimund@1219: }
raimund@1219: return out.join('');
raimund@729: },
raimund@729:
dustin@890: /**
dustin@890: * Parse the Response
dustin@890: * @param msg the Lada-Erro-Code
dustin@890: * @param data the payload of the response
dustin@890: */
raimund@729: parseResponse: function(msg, data) {
raimund@1222: data = Ext.JSON.decode(data, true);
raimund@729: var errors = data.data.errors;
raimund@729: var warnings = data.data.warnings;
raimund@729: var out = [];
raimund@729: // There is a entry for each imported proben in the errors dict (might be
raimund@729: // empty)
raimund@729:
raimund@729: var numErrors;
raimund@729: var numWarnings;
raimund@1219: if (!Ext.isObject(errors)) {
raimund@729: numErrors = 0;
raimund@729: }
raimund@729: else {
raimund@729: numErrors = Object.keys(errors).length;
raimund@729: }
raimund@1219: if (!Ext.isObject(warnings)) {
raimund@729: numWarnings = 0;
raimund@729: }
raimund@729: else {
raimund@729: numWarnings = Object.keys(warnings).length;
raimund@729: }
raimund@729: if (msg !== '200') {
raimund@729: out.push('Der Import der Datei ' + this.fileName +
raimund@729: ' war nicht erfolgreich. Der Importvorgang konnte ' +
raimund@729: 'aufgrund eines Fehlers im Server nicht beendet werden.');
raimund@729: }
raimund@729: else {
raimund@1223: out.push('' +
raimund@1223: '