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;
tom@1236: var data = Ext.JSON.decode(me.data, true);
tom@1236: if (data) {
tom@1236: html = me.parseShortResponse(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);
tom@1236: if (data) {
tom@1236: download = me.parseResponse(data);
raimund@1222: }
raimund@1219: },
raimund@1219:
raimund@1219: /**
raimund@1219: * Parse the response and create a summary of the result
raimund@1219: * @param data
raimund@1219: */
tom@1236: parseShortResponse: function(data) {
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: }
tom@1236: if (!data.success) {
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 data the payload of the response
dustin@890: */
tom@1236: parseResponse: function(data) {
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: }
tom@1236: if (!data.success) {
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: '