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) { raimund@1239: if (errors.parser) { raimund@1239: out.push('Die Probe(n) konnten nicht erfolgreich ' + raimund@1239: 'importiert werden.'); raimund@1239: } raimund@1239: else { raimund@1239: out.push(numErrors + ' Probe(n) konnten nicht ' + raimund@1239: 'erfolgreich importiert werden.'); raimund@1239: } 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) { tom@1425: var i18n = Lada.getApplication().bundle; 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: ''); raimund@729: if (numErrors > 0) { raimund@1239: out.push('Folgende Fehler traten beim Import auf:'); raimund@729: out.push('
'); raimund@729: out.push('
    '); raimund@729: var msgs; raimund@729: for (var key in errors) { raimund@729: msgs = errors[key]; raimund@1239: if (key !== 'parser') { raimund@1239: out.push('
  1. Probe: ' + key); raimund@1239: } raimund@729: out.push('
      '); raimund@1219: validation = [] raimund@1219: validation.push('Validierungsfehler: '); raimund@729: for (var i = msgs.length - 1; i >= 0; i--) { raimund@729: if (msgs[i].key === 'validation') { raimund@1219: validation.push('
        '); raimund@1423: var parts = msgs[i].value.split('#'); tom@1425: var str = i18n.getMsg(parts[0]) + raimund@1423: parts[1] === undefined ? '' : parts[1]; tom@1425: validation.push(str + ' (' tom@1425: + i18n.getMsg(msgs[i].code.toString()) + ')'); raimund@1219: validation.push('
      '); raimund@729: } raimund@729: else { tom@1425: out.push('
    1. ' + msgs[i].key + ' (' tom@1425: + i18n.getMsg(msgs[i].code.toString()) tom@1425: + '): ' + msgs[i].value + '
    2. ') raimund@729: } raimund@729: } raimund@1219: if (validation.length > 1) { raimund@1219: out.push('
    3. ') raimund@1219: out.push(validation.join('')); raimund@1219: out.push('
    4. ') raimund@1219: } raimund@729: out.push('
    '); raimund@1239: if (key !== 'parser') { raimund@1239: out.push('
  2. '); raimund@1239: } raimund@729: } raimund@729: out.push('
'); raimund@729: out.push('
'); raimund@729: } raimund@729: if (numWarnings > 0) { raimund@729: out.push('
'); raimund@729: out.push('Bei folgenden Proben traten Warnungen auf:'); raimund@729: out.push('
'); raimund@729: out.push('
    '); raimund@729: for (key in warnings) { raimund@729: out.push('
  1. ' + key); raimund@729: msgs = warnings[key]; raimund@729: out.push('
      '); raimund@1219: validation = [] raimund@1219: validation.push('Validierungswarnungen: '); raimund@729: for (var i = msgs.length - 1; i >= 0; i--) { raimund@729: if (msgs[i].key === 'validation') { raimund@1219: validation.push('
        '); raimund@1423: var parts = msgs[i].value.split('#'); tom@1425: var str = i18n.getMsg(parts[0]) + raimund@1423: parts[1] === undefined ? '' : parts[1]; tom@1425: validation.push(str + ' (' tom@1425: + i18n.getMsg(msgs[i].code.toString()) + ')'); raimund@1219: validation.push('
      '); raimund@729: } raimund@729: else { tom@1425: out.push('
    1. ' + msgs[i].key + ' (' tom@1425: + i18n.getMsg(msgs[i].code.toString()) tom@1425: + '): ' + msgs[i].value + '
    2. ') raimund@729: } raimund@729: } raimund@1219: if (validation.length > 1) { raimund@1219: out.push('
    3. ') raimund@1219: out.push(validation.join('')); raimund@1219: out.push('
    4. ') raimund@1219: } raimund@729: out.push('
    '); raimund@729: out.push('
  2. '); raimund@729: } raimund@729: out.push('
'); raimund@729: } raimund@729: out.push('
'); raimund@1223: out.push('') raimund@1219: if (numWarnings > 0 || numErrors > 0) { raimund@1219: this.down('button[name=download]').enable(); raimund@1219: } raimund@729: } raimund@729: return out.join(''); raimund@729: } raimund@729: });