+
+ compileRemoteTemplate(printReq: PrintRequest): Promise<PrintTemplateResponse> {
+
+ const formData: FormData = new FormData();
+
+ formData.append('ses', this.auth.token());
+ if (printReq.templateName) {
+ formData.append('template_name', printReq.templateName);
+ }
+ if (printReq.templateId) {
+ formData.append('template_id', '' + printReq.templateId);
+ }
+ if (printReq.templateOwner) {
+ formData.append('template_owner', '' + printReq.templateOwner);
+ }
+ formData.append('template_data', js2JSON(printReq.contextData));
+ formData.append('template_locale', this.locale.currentLocaleCode());
+
+ // Sometimes we want to know the time zone of the browser/user,
+ // regardless of any org unit settings.
+ if (OpenSRF.tz) {
+ formData.append('client_timezone', OpenSRF.tz);
+ }
+
+ return new Promise((resolve, reject) => {
+ const xhttp = new XMLHttpRequest();
+ xhttp.onreadystatechange = function() {
+ if (this.readyState === 4) {
+ if (this.status === 200) {
+ resolve({
+ content: xhttp.responseText,
+ contentType: this.getResponseHeader('content-type')
+ });
+ } else {
+ reject('Error compiling print template');
+ }
+ }
+ };
+ xhttp.open('POST', PRINT_TEMPLATE_PATH, true);
+ xhttp.send(formData);
+ });
+
+ }