Skip to content
Code-Schnipsel Gruppen Projekte

feat: pdf viewer via pdf.js

Zusammengeführt Henning Leutz requested to merge next-3.x into main
2 Dateien
+ 765
796
Änderungen vergleichen
  • Nebeneinander
  • In der Reihe
Dateien
2
@@ -4,887 +4,855 @@
@@ -4,887 +4,855 @@
*
*
* @event onOuput [FormData, this] - Fires if the user submits the popup with a chosen output format
* @event onOuput [FormData, this] - Fires if the user submits the popup with a chosen output format
*/
*/
define(
define('package/quiqqer/erp/bin/backend/controls/OutputDialog', [
'package/quiqqer/erp/bin/backend/controls/OutputDialog',
'qui/QUI',
[
'qui/controls/windows/Confirm',
'qui/controls/buttons/Select',
'qui/QUI',
'qui/controls/elements/Sandbox',
'qui/controls/windows/Confirm',
'qui/controls/buttons/Switch',
'qui/controls/buttons/Select',
'qui/controls/elements/Sandbox',
'package/quiqqer/erp/bin/backend/controls/Comments',
'qui/controls/buttons/Switch',
'package/quiqqer/erp/bin/backend/utils/ERPEntities',
'package/quiqqer/erp/bin/backend/controls/Comments',
'qui/utils/Form',
'package/quiqqer/erp/bin/backend/utils/ERPEntities',
'Ajax',
'qui/utils/Form',
'Locale',
'Mustache',
'Ajax',
'Locale',
'text!package/quiqqer/erp/bin/backend/controls/OutputDialog.html',
'Mustache',
'css!package/quiqqer/erp/bin/backend/controls/OutputDialog.css'
], function(
'text!package/quiqqer/erp/bin/backend/controls/OutputDialog.html',
QUI,
'css!package/quiqqer/erp/bin/backend/controls/OutputDialog.css'
QUIConfirm,
QUISelect,
],
QUISandbox,
function(
QUISwitch,
QUI,
ERPComments,
QUIConfirm,
ERPEntities,
QUISelect,
QUIFormUtils,
QUISandbox,
QUIAjax,
QUISwitch,
QUILocale,
ERPComments,
Mustache,
ERPEntities,
template
QUIFormUtils,
) {
QUIAjax,
'use strict';
QUILocale,
Mustache,
const lg = 'quiqqer/erp';
template
let PDF_SUPPORT = null;
) {
let CURRENT_VIEW = null;
'use strict';
return new Class({
const lg = 'quiqqer/erp';
let PDF_SUPPORT = null;
Extends: QUIConfirm,
let CURRENT_VIEW = null;
type: 'package/quiqqer/erp/bin/backend/controls/OutputDialog',
return new Class({
Binds: [
'$onOpen',
Extends: QUIConfirm,
'$onOutputChange',
type: 'package/quiqqer/erp/bin/backend/controls/OutputDialog',
'$onPrintFinish',
'$getPreview',
Binds: [
'$onChangeToEmail',
'$onOpen',
'$onChangeToPDF',
'$onOutputChange',
'$onChangeToPrint',
'$onPrintFinish',
'$resizeCommentsBox',
'$getPreview',
'$onChangeMailRecipient'
'$onChangeToEmail',
],
'$onChangeToPDF',
'$onChangeToPrint',
options: {
'$resizeCommentsBox',
entityId: false, // Clean entity ID WITHOUT prefix and suffix
'$onChangeMailRecipient'
entityType: false, // Entity type (e.g. "Invoice")
],
entityPlugin: false,
options: {
comments: false, // Comments as array [must be readble by package/quiqqer/erp/bin/backend/controls/Comments]
entityId: false, // Clean entity ID WITHOUT prefix and suffix
entityType: false, // Entity type (e.g. "Invoice")
showMarkAsSentOption: false, // show checkbox for "Mark as sent"
entityPlugin: false,
mailEditor: true, // shows editable subject and body for mail output
comments: false, // Comments as array [must be readble by package/quiqqer/erp/bin/backend/controls/Comments]
maxHeight: 800,
maxWidth: 1500
showMarkAsSentOption: false, // show checkbox for "Mark as sent"
},
mailEditor: true, // shows editable subject and body for mail output
initialize: function(options) {
maxHeight: 800,
this.parent(options);
maxWidth: 1500
},
this.setAttributes({
icon: 'fa fa-print',
initialize: function(options) {
title: QUILocale.get(lg, 'controls.OutputDialog.title'),
this.parent(options);
autoclose: false,
cancel_button: {
this.setAttributes({
textimage: 'fa fa-close',
icon: 'fa fa-print',
text: QUILocale.get('quiqqer/system', 'close')
title: QUILocale.get(lg, 'controls.OutputDialog.title'),
}
autoclose: false,
});
cancel_button: {
textimage: 'fa fa-close',
this.$Output = null;
text: QUILocale.get('quiqqer/system', 'close')
this.$PDFView = null;
 
this.$Preview = null;
 
this.$customerMail = null;
 
this.$Template = null;
 
 
this.$CommentsBox = null;
 
this.$Form = null;
 
this.$MessagesBox = null;
 
 
this.$mailSent = false;
 
 
this.$Mail = {
 
subject: false,
 
content: false,
 
attachedMediaFileIds: []
 
};
 
 
this.addEvents({
 
onOpen: this.$onOpen,
 
onSubmit: this.$onSubmit,
 
onOpenBegin: function() {
 
const winSize = QUI.getWindowSize();
 
let height = 800;
 
let width = 1400;
 
 
if (winSize.y * 0.9 < height) {
 
height = winSize.y * 0.9;
}
}
});
this.$Output = null;
this.$PDFView = null;
this.$Preview = null;
this.$customerMail = null;
this.$Template = null;
this.$CommentsBox = null;
this.$Form = null;
this.$MessagesBox = null;
this.$mailSent = false;
this.$Mail = {
subject: false,
content: false,
attachedMediaFileIds: []
};
this.addEvents({
if (winSize.x * 0.9 < width) {
onOpen: this.$onOpen,
width = winSize.x * 0.9;
onSubmit: this.$onSubmit,
}
onOpenBegin: function() {
const winSize = QUI.getWindowSize();
let height = 800;
let width = 1400;
if (winSize.y * 0.9 < height) {
this.setAttribute('maxHeight', height);
height = winSize.y * 0.9;
this.setAttribute('maxWidth', width);
}
}.bind(this)
 
});
 
},
 
 
/**
 
* event: on open
 
*/
 
$onOpen: function() {
 
const self = this,
 
Content = this.getContent();
 
 
this.Loader.show();
 
this.getContent().set('html', '');
 
 
const onError = function(error) {
 
self.close().then(function() {
 
self.destroy();
 
});
if (winSize.x * 0.9 < width) {
QUI.getMessageHandler().then(function(MH) {
width = winSize.x * 0.9;
if (typeof error === 'object' && typeof error.getMessage !== 'undefined') {
}
MH.addError(error.getMessage());
 
return;
 
}
this.setAttribute('maxHeight', height);
MH.addError(error);
this.setAttribute('maxWidth', width);
}.bind(this)
});
});
},
};
/**
Content.set({
* event: on open
html: Mustache.render(template, {
*/
entityId: this.getAttribute('entityId'),
$onOpen: function() {
labelEntityId: QUILocale.get(lg, 'controls.OutputDialog.labelEntityId'),
const self = this,
labelTemplate: QUILocale.get(lg, 'controls.OutputDialog.labelTemplate'),
Content = this.getContent();
labelOutputType: QUILocale.get(lg, 'controls.OutputDialog.labelOutputType'),
labelPDFView: QUILocale.get(lg, 'controls.OutputDialog.labelPDFView'),
this.Loader.show();
labelEmail: QUILocale.get('quiqqer/core', 'recipient'),
this.getContent().set('html', '');
showMarkAsSentOption: !!this.getAttribute('showMarkAsSentOption'),
mailEditor: !!this.getAttribute('mailEditor'),
const onError = function(error) {
labelOpenMailEditor: QUILocale.get(lg, 'controls.OutputDialog.labelOpenMailEditor'),
self.close().then(function() {
labelMarkAsSent: QUILocale.get(lg, 'controls.OutputDialog.labelMarkAsSent'),
self.destroy();
descMarkAsSent: QUILocale.get(lg, 'controls.OutputDialog.descMarkAsSent')
});
})
});
QUI.getMessageHandler().then(function(MH) {
if (typeof error === 'object' && typeof error.getMessage !== 'undefined') {
Content.addClass('quiqqer-erp-outputDialog');
MH.addError(error.getMessage());
return;
self.$MessagesBox = Content.getElement('.quiqqer-erp-outputDialog-messages');
 
 
// "To mail editor" button
 
if (this.getAttribute('mailEditor')) {
 
Content.getElement('.quiqqer-erp-outputDialog-openMailEditor').addEvent('click', function() {
 
require(
 
['package/quiqqer/erp/bin/backend/controls/OutputMailEditor'],
 
function(OutputMailEditor) {
 
new OutputMailEditor({
 
entityId: self.getAttribute('entityId'),
 
entityType: self.getAttribute('entityType'),
 
entityPlugin: self.getAttribute('entityPlugin'),
 
 
mailSubject: self.$Mail.subject,
 
mailContent: self.$Mail.content,
 
attachedMediaFileIds: self.$Mail.attachedMediaFileIds,
 
 
events: {
 
onMailSubmit: function(MailData) {
 
self.$Mail = MailData;
 
}
 
}
 
}).open();
}
}
);
MH.addError(error);
});
};
Content.set({
html: Mustache.render(template, {
entityId: this.getAttribute('entityId'),
labelEntityId: QUILocale.get(lg, 'controls.OutputDialog.labelEntityId'),
labelTemplate: QUILocale.get(lg, 'controls.OutputDialog.labelTemplate'),
labelOutputType: QUILocale.get(lg, 'controls.OutputDialog.labelOutputType'),
labelPDFView: QUILocale.get(lg, 'controls.OutputDialog.labelPDFView'),
labelEmail: QUILocale.get('quiqqer/core', 'recipient'),
showMarkAsSentOption: !!this.getAttribute('showMarkAsSentOption'),
mailEditor: !!this.getAttribute('mailEditor'),
labelOpenMailEditor: QUILocale.get(lg, 'controls.OutputDialog.labelOpenMailEditor'),
labelMarkAsSent: QUILocale.get(lg, 'controls.OutputDialog.labelMarkAsSent'),
descMarkAsSent: QUILocale.get(lg, 'controls.OutputDialog.descMarkAsSent')
})
});
});
 
}
Content.addClass('quiqqer-erp-outputDialog');
this.$Output = new QUISelect({
localeStorage: 'quiqqer-erp-output-dialog',
self.$MessagesBox = Content.getElement('.quiqqer-erp-outputDialog-messages');
name: 'output',
styles: {
// "To mail editor" button
border: 'none',
if (this.getAttribute('mailEditor')) {
width: '100%'
Content.getElement('.quiqqer-erp-outputDialog-openMailEditor').addEvent('click', function() {
},
require(
events: {
['package/quiqqer/erp/bin/backend/controls/OutputMailEditor'],
onChange: self.$onOutputChange
function(OutputMailEditor) {
new OutputMailEditor({
entityId: self.getAttribute('entityId'),
entityType: self.getAttribute('entityType'),
entityPlugin: self.getAttribute('entityPlugin'),
mailSubject: self.$Mail.subject,
mailContent: self.$Mail.content,
attachedMediaFileIds: self.$Mail.attachedMediaFileIds,
events: {
onMailSubmit: function(MailData) {
self.$Mail = MailData;
}
}
}).open();
}
);
});
}
}
});
this.$Output = new QUISelect({
localeStorage: 'quiqqer-erp-output-dialog',
this.$Output.appendChild(
name: 'output',
QUILocale.get(lg, 'controls.OutputDialog.data.output.print'),
styles: {
'print',
border: 'none',
'fa fa-print'
width: '100%'
);
},
events: {
this.$Output.appendChild(
onChange: self.$onOutputChange
QUILocale.get(lg, 'controls.OutputDialog.data.output.pdf'),
 
'pdf',
 
'fa fa-file-pdf-o'
 
);
 
 
this.$Output.appendChild(
 
QUILocale.get(lg, 'controls.OutputDialog.data.output.email'),
 
'email',
 
'fa fa-envelope-o'
 
);
 
 
this.$Output.inject(Content.getElement('.field-output'));
 
 
Promise.all([
 
this.$getTemplates(),
 
this.$getEntityData(),
 
this.checkPdfSupport()
 
]).then((result) => {
 
const templates = result[0];
 
const EntityData = result[1];
 
const pdfSupport = result[2];
 
 
if (!pdfSupport) {
 
if (typeof window.QUIQQER_OUTPUT_PDF === 'undefined') {
 
window.QUIQQER_OUTPUT_PDF = false;
}
}
});
this.$Output.appendChild(
QUILocale.get(lg, 'controls.OutputDialog.data.output.print'),
'print',
'fa fa-print'
);
this.$Output.appendChild(
QUILocale.get(lg, 'controls.OutputDialog.data.output.pdf'),
'pdf',
'fa fa-file-pdf-o'
);
this.$Output.appendChild(
QUILocale.get(lg, 'controls.OutputDialog.data.output.email'),
'email',
'fa fa-envelope-o'
);
this.$Output.inject(Content.getElement('.field-output'));
const PdfView = this.getElm().getElement('.quiqqer-erp-outputDialog-pdfView');
 
const Cell = PdfView.getParent('.field-container-field');
 
PdfView.setStyle('display', 'none');
Promise.all([
Cell.set(
this.$getTemplates(),
'html',
this.$getEntityData(),
QUILocale.get(lg, 'controls.OutputDialog.no_pdf_preview_support')
this.checkPdfSupport()
);
]).then((result) => {
} else {
const templates = result[0];
if (typeof window.QUIQQER_OUTPUT_PDF === 'undefined') {
const EntityData = result[1];
window.QUIQQER_OUTPUT_PDF = true;
const pdfSupport = result[2];
}
if (!pdfSupport) {
self.$PDFView = new QUISwitch({
if (typeof window.QUIQQER_OUTPUT_PDF === 'undefined') {
name: 'pdfView',
window.QUIQQER_OUTPUT_PDF = false;
status: window.QUIQQER_OUTPUT_PDF,
 
events: {
 
onChange: () => {
 
window.QUIQQER_OUTPUT_PDF = self.$PDFView.getStatus();
 
self.$renderPreview();
 
}
}
}
 
}).inject(self.getElm().getElement('.quiqqer-erp-outputDialog-pdfView'));
 
}
const PdfView = this.getElm().getElement('.quiqqer-erp-outputDialog-pdfView');
const Form = Content.getElement('form');
const Cell = PdfView.getParent('.field-container-field');
let Selected = false;
PdfView.setStyle('display', 'none');
Cell.set(
'html',
QUILocale.get(lg, 'controls.OutputDialog.no_pdf_preview_support')
);
} else {
if (typeof window.QUIQQER_OUTPUT_PDF === 'undefined') {
window.QUIQQER_OUTPUT_PDF = true;
}
self.$PDFView = new QUISwitch({
Content.getElement('.quiqqer-erp-outputDialog-options-entityId').set(
name: 'pdfView',
'html',
status: window.QUIQQER_OUTPUT_PDF,
EntityData.prefixedNumber
events: {
);
onChange: () => {
window.QUIQQER_OUTPUT_PDF = self.$PDFView.getStatus();
self.$renderPreview();
}
}
}).inject(self.getElm().getElement('.quiqqer-erp-outputDialog-pdfView'));
}
const Form = Content.getElement('form');
if (!templates.length) {
let Selected = false;
new Element('option', {
 
value: '#',
 
html: QUILocale.get(lg, 'controls.OutputDialog.no_templates_found')
 
}).inject(Form.elements.template);
Content.getElement('.quiqqer-erp-outputDialog-options-entityId').set(
Form.elements.template.disabled = true;
'html',
EntityData.prefixedNumber
);
if (!templates.length) {
const PreviewContent = self.getContent().getElement('.quiqqer-erp-outputDialog-preview');
new Element('option', {
value: '#',
html: QUILocale.get(lg, 'controls.OutputDialog.no_templates_found')
}).inject(Form.elements.template);
Form.elements.template.disabled = true;
new Element('div', {
 
'class': 'quiqqer-erp-outputDialog-nopreview',
 
html: QUILocale.get(lg, 'controls.OutputDialog.no_preview')
 
}).inject(PreviewContent);
const PreviewContent = self.getContent().getElement('.quiqqer-erp-outputDialog-preview');
self.$Output.disable();
 
self.getButton('submit').disable();
new Element('div', {
self.Loader.hide();
'class': 'quiqqer-erp-outputDialog-nopreview',
return;
html: QUILocale.get(lg, 'controls.OutputDialog.no_preview')
}
}).inject(PreviewContent);
self.$Output.disable();
for (let i = 0, len = templates.length; i < len; i++) {
self.getButton('submit').disable();
let Template = templates[i];
self.Loader.hide();
if (Template.isSystemDefault && EntityData.hideSystemDefaultTemplate) {
return;
continue;
}
}
for (let i = 0, len = templates.length; i < len; i++) {
new Element('option', {
let Template = templates[i];
value: Template.id,
html: Template.title,
if (Template.isSystemDefault && EntityData.hideSystemDefaultTemplate) {
'data-provider': Template.provider
continue;
}).inject(Form.elements.template);
}
new Element('option', {
if (!Selected && Template.isDefault) {
value: Template.id,
Selected = Template;
html: Template.title,
'data-provider': Template.provider
}).inject(Form.elements.template);
if (!Selected && Template.isDefault) {
Selected = Template;
}
}
}
 
}
Form.elements.template.addEvent('change', function(event) {
Form.elements.template.addEvent('change', function(event) {
self.$Template = {
id: event.target.value,
provider: event.target.getElement('option[value="' + event.target.value + '"]').get(
'data-provider')
};
self.$renderPreview();
});
// Set initial template and render preview
Form.elements.template.value = Selected.id;
self.$Template = {
self.$Template = {
id: Selected.id,
id: event.target.value,
provider: Selected.provider
provider: event.target.getElement('option[value="' + event.target.value + '"]').get(
 
'data-provider')
};
};
self.$renderPreview();
self.$renderPreview();
 
});
// Customer data
// Set initial template and render preview
self.$customerMail = EntityData.email;
Form.elements.template.value = Selected.id;
CURRENT_VIEW = null;
self.$Template = {
self.$onOutputChange();
id: Selected.id,
 
provider: Selected.provider
 
};
self.Loader.hide();
self.$renderPreview();
// Load comments
// Customer data
self.$CommentsBox = Content.getElement('.quiqqer-erp-outputDialog-comments');
self.$customerMail = EntityData.email;
self.$Form = Form;
CURRENT_VIEW = null;
 
self.$onOutputChange();
if (!self.getAttribute('comments') || !self.getAttribute('comments').length) {
self.Loader.hide();
if (self.$CommentsBox) {
self.$CommentsBox.destroy();
}
self.$CommentsBox = null;
// Load comments
return;
self.$CommentsBox = Content.getElement('.quiqqer-erp-outputDialog-comments');
 
self.$Form = Form;
 
 
if (!self.getAttribute('comments') || !self.getAttribute('comments').length) {
 
if (self.$CommentsBox) {
 
self.$CommentsBox.destroy();
}
}
new ERPComments({
self.$CommentsBox = null;
comments: self.getAttribute('comments')
return;
}).inject(self.$CommentsBox);
}
self.$resizeCommentsBox();
new ERPComments({
}).catch(function(e) {
comments: self.getAttribute('comments')
onError(e);
}).inject(self.$CommentsBox);
});
},
/**
self.$resizeCommentsBox();
* Render preview with selected template
}).catch(function(e) {
*/
onError(e);
$renderPreview: function() {
});
const self = this;
},
const PreviewContent = this.getContent().getElement('.quiqqer-erp-outputDialog-preview');
this.Loader.show();
/**
 
* Render preview with selected template
 
*/
 
$renderPreview: function() {
 
const self = this;
 
const PreviewContent = this.getContent().getElement('.quiqqer-erp-outputDialog-preview');
const showPreviewError = function() {
this.Loader.show();
PreviewContent.set('html', '');
new Element('div', {
const showPreviewError = function() {
'class': 'quiqqer-erp-outputDialog-nopreview',
PreviewContent.set('html', '');
html: QUILocale.get(lg, 'controls.OutputDialog.preview_error'),
styles: {
padding: 20
}
}).inject(PreviewContent);
};
if (this.$PDFView && this.$PDFView.getStatus()) {
new Element('div', {
this.showAsPDF();
'class': 'quiqqer-erp-outputDialog-nopreview',
return;
html: QUILocale.get(lg, 'controls.OutputDialog.preview_error'),
}
styles: {
 
padding: 20
 
}
 
}).inject(PreviewContent);
 
};
this.$getPreview().then(function(previewHtml) {
if (this.$PDFView && this.$PDFView.getStatus()) {
self.Loader.hide();
this.showAsPDF();
 
return;
 
}
if (!previewHtml) {
this.$getPreview().then(function(previewHtml) {
showPreviewError();
self.Loader.hide();
return;
}
PreviewContent.set('html', '');
if (!previewHtml) {
 
showPreviewError();
 
return;
 
}
new QUISandbox({
PreviewContent.set('html', '');
content: previewHtml,
styles: {
new QUISandbox({
height: '100%',
content: previewHtml,
padding: 20,
styles: {
width: '100%'
height: '100%',
},
padding: 20,
events: {
width: '100%'
onLoad: function(Box) {
},
Box.getElm().addClass('quiqqer-erp-outputDialog-preview');
events: {
}
onLoad: function(Box) {
 
Box.getElm().addClass('quiqqer-erp-outputDialog-preview');
}
}
}).inject(PreviewContent);
}
}).catch(function() {
}).inject(PreviewContent);
self.Loader.hide();
}).catch(function() {
showPreviewError();
self.Loader.hide();
});
showPreviewError();
},
});
 
},
 
 
/**
 
* event: on submit
 
*/
 
$onSubmit: function() {
 
const self = this;
 
let Run = Promise.resolve();
 
 
this.Loader.show();
 
 
const action = this.$Output.getValue();
 
 
switch (action) {
 
case 'print':
 
Run = this.print();
 
break;
 
 
case 'pdf':
 
Run = this.saveAsPdf();
 
break;
 
 
case 'email':
 
Run = this.$sendMail();
 
break;
 
}
/**
Run.then(function() {
* event: on submit
const Form = self.getContent().getElement('form');
*/
$onSubmit: function() {
const self = this;
let Run = Promise.resolve();
this.Loader.show();
self.fireEvent('output', [
 
QUIFormUtils.getFormData(Form),
 
self
 
]);
const action = this.$Output.getValue();
const Submit = self.getButton('submit');
switch (action) {
switch (action) {
case 'print':
case 'print':
Run = this.print();
self.$addMessage(QUILocale.get(lg, 'controls.OutputDialog.msg.output_print'));
break;
break;
case 'pdf':
case 'pdf':
Run = this.saveAsPdf();
self.$addMessage(QUILocale.get(lg, 'controls.OutputDialog.msg.output_pdf'));
break;
break;
case 'email':
case 'email':
Run = this.$sendMail();
self.$mailSent = true;
 
Submit.disable();
 
 
self.$addMessage(QUILocale.get(lg, 'controls.OutputDialog.msg.mail_sent', {
 
recipient: Form.elements.recipient.value
 
}));
break;
break;
}
}
Run.then(function() {
self.$resizeCommentsBox();
const Form = self.getContent().getElement('form');
self.Loader.hide();
}, function() {
self.fireEvent('output', [
self.Loader.hide();
QUIFormUtils.getFormData(Form),
});
self
},
]);
/**
const Submit = self.getButton('submit');
* Add message to log
*
switch (action) {
* @param {String} msg
case 'print':
*/
self.$addMessage(QUILocale.get(lg, 'controls.OutputDialog.msg.output_print'));
$addMessage: function(msg) {
break;
const Now = new Date();
case 'pdf':
new Element('div', {
self.$addMessage(QUILocale.get(lg, 'controls.OutputDialog.msg.output_pdf'));
'class': 'quiqqer-erp-outputDialog-messages-entry box message-success',
break;
html: '<b>' + Now.format('%H:%M:%S') + '</b> ' + msg
}).inject(this.$MessagesBox, 'top');
case 'email':
},
self.$mailSent = true;
Submit.disable();
/**
* Print the document
self.$addMessage(QUILocale.get(lg, 'controls.OutputDialog.msg.mail_sent', {
*
recipient: Form.elements.recipient.value
* @return {Promise}
}));
*/
break;
print: function() {
 
const self = this,
 
entityId = this.getAttribute('entityId');
 
 
return new Promise(function(resolve) {
 
const id = 'print-document-' + entityId;
 
 
self.Loader.show();
 
 
new Element('iframe', {
 
src: URL_OPT_DIR + 'quiqqer/erp/bin/output/backend/print.php?' + Object.toQueryString({
 
id: entityId,
 
t: self.getAttribute('entityType'),
 
ep: self.getAttribute('entityPlugin'),
 
oid: self.getId(),
 
tpl: self.$Template.id,
 
tplpr: self.$Template.provider
 
}),
 
id: id,
 
styles: {
 
position: 'absolute',
 
top: -200,
 
left: -200,
 
width: 50,
 
height: 50
}
}
 
}).inject(document.body);
self.$resizeCommentsBox();
self.addEvent('onPrintFinish', function(self, pId) {
self.Loader.hide();
if (pId === entityId) {
}, function() {
self.Loader.hide();
});
},
/**
* Add message to log
*
* @param {String} msg
*/
$addMessage: function(msg) {
const Now = new Date();
new Element('div', {
'class': 'quiqqer-erp-outputDialog-messages-entry box message-success',
html: '<b>' + Now.format('%H:%M:%S') + '</b> ' + msg
}).inject(this.$MessagesBox, 'top');
},
/**
* Print the document
*
* @return {Promise}
*/
print: function() {
const self = this,
entityId = this.getAttribute('entityId');
return new Promise(function(resolve) {
const id = 'print-document-' + entityId;
self.Loader.show();
new Element('iframe', {
src: URL_OPT_DIR + 'quiqqer/erp/bin/output/backend/print.php?' + Object.toQueryString({
id: entityId,
t: self.getAttribute('entityType'),
ep: self.getAttribute('entityPlugin'),
oid: self.getId(),
tpl: self.$Template.id,
tplpr: self.$Template.provider
}),
id: id,
styles: {
position: 'absolute',
top: -200,
left: -200,
width: 50,
height: 50
}
}).inject(document.body);
self.addEvent('onPrintFinish', function(self, pId) {
if (pId === entityId) {
resolve();
}
});
});
},
/**
* event: on print finish
*
* @param {String|Number} id
*/
$onPrintFinish: function(id) {
this.fireEvent('printFinish', [
this,
id
]);
(function() {
document.getElements('#print-document-' + id).destroy();
this.Loader.hide();
}).delay(1000, this);
},
/**
* Export the document as PDF
*
* @return {Promise}
*/
saveAsPdf: function() {
const self = this,
entityId = this.getAttribute('entityId');
return new Promise(function(resolve) {
const id = 'download-document-' + entityId,
Content = self.getContent(),
Form = Content.getElement('form');
new Element('iframe', {
src: URL_OPT_DIR + 'quiqqer/erp/bin/output/backend/download.php?' + Object.toQueryString({
id: entityId,
t: self.getAttribute('entityType'),
ep: self.getAttribute('entityPlugin'),
oid: self.getId(),
tpl: self.$Template.id,
tplpr: self.$Template.provider
}),
id: id,
styles: {
position: 'absolute',
top: -200,
left: -200,
width: 50,
height: 50
}
}).inject(document.body);
(function() {
resolve();
resolve();
}).delay(2000, this);
}
(function() {
document.getElements('#' + id).destroy();
}).delay(20000, this);
});
});
},
});
},
showAsPDF: function() {
this.Loader.show();
/**
* event: on print finish
const PreviewContent = this.getContent().getElement('.quiqqer-erp-outputDialog-preview');
*
const entityId = this.getAttribute('entityId');
* @param {String|Number} id
*/
PreviewContent.set('html', '');
$onPrintFinish: function(id) {
this.fireEvent('printFinish', [
return new Promise((resolve) => {
this,
const id = 'download-document-' + entityId;
id
]);
new Element('iframe', {
src: URL_OPT_DIR + 'quiqqer/erp/bin/output/backend/download.php?' + Object.toQueryString({
(function() {
id: entityId,
document.getElements('#print-document-' + id).destroy();
t: this.getAttribute('entityType'),
this.Loader.hide();
ep: this.getAttribute('entityPlugin'),
}).delay(1000, this);
oid: this.getId(),
},
tpl: this.$Template.id,
tplpr: this.$Template.provider,
/**
show: 1
* Export the document as PDF
}),
*
id: id,
* @return {Promise}
styles: {
*/
height: 'calc(100% - 5px)',
saveAsPdf: function() {
width: '100%',
const self = this,
border: 'none',
entityId = this.getAttribute('entityId');
padding: 0
}
return new Promise(function(resolve) {
}).inject(PreviewContent);
const id = 'download-document-' + entityId,
Content = self.getContent(),
(function() {
Form = Content.getElement('form');
resolve();
}).delay(2000, this);
new Element('iframe', {
 
src: URL_OPT_DIR + 'quiqqer/erp/bin/output/backend/download.php?' + Object.toQueryString({
 
id: entityId,
 
t: self.getAttribute('entityType'),
 
ep: self.getAttribute('entityPlugin'),
 
oid: self.getId(),
 
tpl: self.$Template.id,
 
tplpr: self.$Template.provider
 
}),
 
id: id,
 
styles: {
 
position: 'absolute',
 
top: -200,
 
left: -200,
 
width: 50,
 
height: 50
 
}
 
}).inject(document.body);
this.Loader.hide();
(function() {
});
resolve();
},
}).delay(2000, this);
/**
(function() {
* event : on output change
document.getElements('#' + id).destroy();
*/
}).delay(20000, this);
$onOutputChange: function() {
});
if (CURRENT_VIEW === this.$Output.getValue()) {
},
return;
}
showAsPDF: function() {
 
this.Loader.show();
 
 
const PreviewContent = this.getContent().getElement('.quiqqer-erp-outputDialog-preview');
 
const entityId = this.getAttribute('entityId');
 
const pdfUrl = URL_OPT_DIR + 'quiqqer/erp/bin/output/backend/download.php?' + Object.toQueryString({
 
id: entityId,
 
t: this.getAttribute('entityType'),
 
ep: this.getAttribute('entityPlugin'),
 
oid: this.getId(),
 
tpl: this.$Template.id,
 
tplpr: this.$Template.provider,
 
show: 1
 
});
 
 
PreviewContent.set('html', '');
 
 
return new Promise((resolve, reject) => {
 
(async () => {
 
try {
 
const module = await import(URL_OPT_DIR + 'bin/quiqqer-asset/pdfjs-dist/pdfjs-dist/build/pdf.mjs');
 
console.log(module);
 
 
PreviewContent.set('html', '<canvas id="pdf-canvas"></canvas>');
 
module.GlobalWorkerOptions.workerSrc = URL_OPT_DIR + 'bin/quiqqer-asset/pdfjs-dist/pdfjs-dist/build/pdf.worker.min.mjs';
 
 
module.getDocument(pdfUrl).promise.then((pdf) => {
 
pdf.getPage(1).then(page => {
 
const scale = 1.5;
 
const viewport = page.getViewport({scale});
 
const canvas = document.getElementById('pdf-canvas');
 
const context = canvas.getContext('2d');
 
canvas.height = viewport.height;
 
canvas.width = viewport.width;
 
 
page.render({
 
canvasContext: context,
 
viewport: viewport
 
});
 
 
this.Loader.hide();
 
resolve();
 
});
 
});
 
 
} catch (error) {
 
console.error('Fehler beim Laden des Moduls:', error);
 
this.Loader.hide();
 
reject();
 
}
 
})();
 
});
 
},
 
 
/**
 
* event : on output change
 
*/
 
$onOutputChange: function() {
 
if (CURRENT_VIEW === this.$Output.getValue()) {
 
return;
 
}
const Recipient = this.getElm().getElement('[name="recipient"]');
const Recipient = this.getElm().getElement('[name="recipient"]');
Recipient.getParent('tr').setStyle('display', 'none');
Recipient.getParent('tr').setStyle('display', 'none');
/*
/*
if (this.$PDFView && this.$PDFView.getStatus() === 1) {
if (this.$PDFView && this.$PDFView.getStatus() === 1) {
if (this.$Output.getValue() === 'pdf') {
if (this.$Output.getValue() === 'pdf') {
this.$PDFView.setSilentOff();
this.$PDFView.setSilentOff();
} else {
this.$PDFView.off();
}
} else {
} else {
(() => {
this.$PDFView.off();
this.$PDFView.setSilentOff();
}).delay(100);
}
}
*/
} else {
 
(() => {
 
this.$PDFView.setSilentOff();
 
}).delay(100);
 
}
 
*/
switch (this.$Output.getValue()) {
switch (this.$Output.getValue()) {
case 'print':
case 'print':
this.$onChangeToPrint();
this.$onChangeToPrint();
break;
break;
case 'pdf':
case 'pdf':
this.$onChangeToPDF();
this.$onChangeToPDF();
break;
break;
case 'email':
case 'email':
this.$onChangeToEmail();
this.$onChangeToEmail();
break;
break;
}
}
this.$resizeCommentsBox();
this.$resizeCommentsBox();
this.getButton('submit').enable();
this.getButton('submit').enable();
CURRENT_VIEW = this.$Output.getValue();
CURRENT_VIEW = this.$Output.getValue();
},
},
/**
/**
* event: on output change -> to print
* event: on output change -> to print
*/
*/
$onChangeToPrint: function() {
$onChangeToPrint: function() {
const Submit = this.getButton('submit');
const Submit = this.getButton('submit');
Submit.setAttribute('text', QUILocale.get(lg, 'controls.OutputDialog.data.output.print.btn'));
Submit.setAttribute('text', QUILocale.get(lg, 'controls.OutputDialog.data.output.print.btn'));
Submit.setAttribute('textimage', 'fa fa-print');
Submit.setAttribute('textimage', 'fa fa-print');
},
},
/**
/**
* event: on output change -> to pdf
* event: on output change -> to pdf
*/
*/
$onChangeToPDF: function() {
$onChangeToPDF: function() {
const Submit = this.getButton('submit');
const Submit = this.getButton('submit');
Submit.setAttribute('text', QUILocale.get(lg, 'controls.OutputDialog.data.output.pdf.btn'));
Submit.setAttribute('text', QUILocale.get(lg, 'controls.OutputDialog.data.output.pdf.btn'));
Submit.setAttribute('textimage', 'fa fa-file-pdf-o');
Submit.setAttribute('textimage', 'fa fa-file-pdf-o');
},
},
/**
/**
* event: on output change -> to Email
* event: on output change -> to Email
*/
*/
$onChangeToEmail: function() {
$onChangeToEmail: function() {
const Submit = this.getButton('submit');
const Submit = this.getButton('submit');
const Recipient = this.getElm().getElement('[name="recipient"]');
const Recipient = this.getElm().getElement('[name="recipient"]');
Recipient.getParent('tr').setStyle('display', null);
Recipient.getParent('tr').setStyle('display', null);
Submit.setAttribute('text', QUILocale.get(lg, 'controls.OutputDialog.data.output.email.btn'));
Submit.setAttribute('text', QUILocale.get(lg, 'controls.OutputDialog.data.output.email.btn'));
Submit.setAttribute('textimage', 'fa fa-envelope-o');
Submit.setAttribute('textimage', 'fa fa-envelope-o');
if (this.$customerMail && Recipient.value === '') {
if (this.$customerMail && Recipient.value === '') {
Recipient.value = this.$customerMail;
Recipient.value = this.$customerMail;
}
}
Recipient.removeEvent('keyup', this.$onChangeMailRecipient);
Recipient.removeEvent('keyup', this.$onChangeMailRecipient);
Recipient.addEvent('keyup', this.$onChangeMailRecipient);
Recipient.addEvent('keyup', this.$onChangeMailRecipient);
Recipient.focus();
Recipient.focus();
if (this.$mailSent) {
if (this.$mailSent) {
Submit.disable();
Submit.disable();
}
}
},
},
/**
/**
* If e-mail recipient changes
* If e-mail recipient changes
*/
*/
$onChangeMailRecipient: function() {
$onChangeMailRecipient: function() {
this.getButton('submit').enable();
this.getButton('submit').enable();
this.$mailSent = false;
this.$mailSent = false;
},
},
/**
/**
* Get data of the entity that is outputted
* Get data of the entity that is outputted
*
*
* @return {Promise}
* @return {Promise}
*/
*/
$getEntityData: function() {
$getEntityData: function() {
const self = this;
const self = this;
return new Promise(function(resolve, reject) {
return new Promise(function(resolve, reject) {
QUIAjax.get('package_quiqqer_erp_ajax_output_getEntityData', resolve, {
QUIAjax.get('package_quiqqer_erp_ajax_output_getEntityData', resolve, {
'package': 'quiqqer/erp',
'package': 'quiqqer/erp',
entityId: self.getAttribute('entityId'),
entityId: self.getAttribute('entityId'),
entityType: self.getAttribute('entityType'),
entityType: self.getAttribute('entityType'),
entityPlugin: self.getAttribute('entityPlugin'),
entityPlugin: self.getAttribute('entityPlugin'),
onError: reject
onError: reject
});
});
},
/**
* Fetch available templates based on entity type
*
* @return {Promise}
*/
$getTemplates: function() {
const self = this;
return new Promise(function(resolve, reject) {
QUIAjax.get('package_quiqqer_erp_ajax_output_getTemplates', resolve, {
'package': 'quiqqer/erp',
entityType: self.getAttribute('entityType'),
entityPlugin: self.getAttribute('entityPlugin'),
onError: reject
});
});
});
},
});
},
/**
* Fetch available templates based on entity type
/**
*
* Fetch available templates based on entity type
* @return {Promise}
*
*/
* @return {Promise}
$getPreview: function() {
*/
const self = this;
$getTemplates: function() {
const self = this;
return new Promise(function(resolve, reject) {
QUIAjax.get('package_quiqqer_erp_ajax_output_getPreview', resolve, {
return new Promise(function(resolve, reject) {
'package': 'quiqqer/erp',
QUIAjax.get('package_quiqqer_erp_ajax_output_getTemplates', resolve, {
entity: JSON.encode({
'package': 'quiqqer/erp',
id: self.getAttribute('entityId'),
entityType: self.getAttribute('entityType'),
type: self.getAttribute('entityType'),
entityPlugin: self.getAttribute('entityPlugin'),
plugin: self.getAttribute('entityPlugin')
onError: reject
}),
template: JSON.encode(self.$Template),
onError: reject
});
});
});
},
});
},
/**
* Get data of the entity that is outputted
/**
*
* Fetch available templates based on entity type
* @return {Promise}
*
*/
* @return {Promise}
$sendMail: function() {
*/
const self = this,
$getPreview: function() {
Form = this.getContent().getElement('form');
const self = this;
return new Promise(function(resolve, reject) {
return new Promise(function(resolve, reject) {
QUIAjax.post('package_quiqqer_erp_ajax_output_sendMail', resolve, {
QUIAjax.get('package_quiqqer_erp_ajax_output_getPreview', resolve, {
'package': 'quiqqer/erp',
'package': 'quiqqer/erp',
entityId: self.getAttribute('entityId'),
entity: JSON.encode({
entityType: self.getAttribute('entityType'),
id: self.getAttribute('entityId'),
entityPlugin: self.getAttribute('entityPlugin'),
type: self.getAttribute('entityType'),
template: self.$Template.id,
plugin: self.getAttribute('entityPlugin')
templateProvider: self.$Template.provider,
}),
mailSubject: self.$Mail.subject,
template: JSON.encode(self.$Template),
mailContent: self.$Mail.content,
onError: reject
mailAttachmentMediaFileIds: JSON.encode(self.$Mail.attachedMediaFileIds),
mailRecipient: Form.elements.recipient.value,
onError: reject
});
});
});
},
});
},
/**
* Resize the erp entity comments container
/**
*/
* Get data of the entity that is outputted
$resizeCommentsBox: function() {
*
if (!this.$Form || !this.$CommentsBox || !this.$MessagesBox) {
* @return {Promise}
return;
*/
}
$sendMail: function() {
const self = this,
const maxHeight = 685 - (710 - this.getContent().getSize().y);
Form = this.getContent().getElement('form');
const height = this.$Form.getSize().y + this.$MessagesBox.getSize().y;
return new Promise(function(resolve, reject) {
this.$CommentsBox.setStyle('height', (maxHeight - height));
QUIAjax.post('package_quiqqer_erp_ajax_output_sendMail', resolve, {
},
'package': 'quiqqer/erp',
entityId: self.getAttribute('entityId'),
checkPdfSupport: function() {
entityType: self.getAttribute('entityType'),
return new Promise((resolve) => {
entityPlugin: self.getAttribute('entityPlugin'),
if (PDF_SUPPORT !== null) {
template: self.$Template.id,
resolve(PDF_SUPPORT);
templateProvider: self.$Template.provider,
return;
mailSubject: self.$Mail.subject,
}
mailContent: self.$Mail.content,
mailAttachmentMediaFileIds: JSON.encode(self.$Mail.attachedMediaFileIds),
const PDFFrame = new Element('iframe', {
mailRecipient: Form.elements.recipient.value,
src: URL_OPT_DIR + 'quiqqer/erp/bin/output/backend/test.pdf',
onError: reject
styles: {
position: 'absolute',
top: -200,
left: -200,
width: 50,
height: 50
}
}).inject(document.body);
PDFFrame.onload = function() {
try {
const pdfDoc = PDFFrame.contentDocument || PDFFrame.contentWindow.document;
if (pdfDoc && pdfDoc.body && pdfDoc.body.innerHTML.includes('PDF') === false) {
PDF_SUPPORT = true;
} else {
// PDF kann nicht angezeigt werden, Fallback anzeigen
// pdfFrame.style.display = 'none';
// document.getElementById('pdfFallback').style.display = 'block';
PDF_SUPPORT = false;
}
} catch (error) {
// Möglicher Cross-Origin-Fehler oder PDF nicht unterstützt
// pdfFrame.style.display = 'none';
// document.getElementById('pdfFallback').style.display = 'block';
PDF_SUPPORT = false;
}
resolve(PDF_SUPPORT);
};
PDFFrame.onerror = function() {
// Fehler beim Laden des PDFs im iframe
// pdfFrame.style.display = 'none';
// document.getElementById('pdfFallback').style.display = 'block';
PDF_SUPPORT = false;
resolve(PDF_SUPPORT);
};
});
});
 
});
 
},
 
 
/**
 
* Resize the erp entity comments container
 
*/
 
$resizeCommentsBox: function() {
 
if (!this.$Form || !this.$CommentsBox || !this.$MessagesBox) {
 
return;
}
}
});
}
const maxHeight = 685 - (710 - this.getContent().getSize().y);
);
const height = this.$Form.getSize().y + this.$MessagesBox.getSize().y;
 
 
this.$CommentsBox.setStyle('height', (maxHeight - height));
 
},
 
 
checkPdfSupport: function() {
 
// da pdf.js integriert ist, ist unterstützung immer vorhanden
 
return new Promise((resolve) => {
 
PDF_SUPPORT = true;
 
resolve(true);
 
});
 
}
 
});
 
});
Lade