<div class="row mb-3">
- <div class="col-lg-3">
- <div class="input-group">
- <div class="input-group-prepend">
- <span class="input-group-text" i18n>Owner</span>
- </div>
- <eg-org-select
- [limitPerms]="['ADMIN_PRINT_TEMPLATE']"
- [initialOrg]="contextOrg"
- (onChange)="orgOnChange($event)">
- </eg-org-select>
- </div>
+ <div class="col-lg-4">
+ <eg-org-family-select
+ [selectedOrgId]="initialOrg"
+ [limitPerms]="['ADMIN_PRINT_TEMPLATE']"
+ labelText="Owner" i18n-labelText
+ (ngModelChange)="orgOnChange($event)"
+ ngModel #orgFamily="ngModel">
+ </eg-org-family-select>
</div>
<div class="col-lg-3">
<div class="input-group">
<div class="input-group-prepend">
<span class="input-group-text" i18n>Template</span>
</div>
- <eg-combobox [entries]="entries" #templateSelector
+ <ng-template #entryTemplate let-r="result" let-owner="getOwnerName">
+ {{r.label}} ({{getOwnerName(r.id)}})
+ </ng-template>
+ <eg-combobox #templateSelector
+ [entries]="entries" [displayTemplate]="entryTemplate"
(onChange)="selectTemplate($event ? $event.id : null)">
</eg-combobox>
</div>
<button class="btn btn-info ml-2" (click)="applyChanges()" i18n>
Save Template and Refresh Preview
</button>
+ <span *ngIf="invalidJson" class="badge badge-danger ml-2" i18n>
+ Invalid Sample JSON!
+ </span>
</div>
</div>
<div class="row mt-2">
-import {Component, OnInit, ViewChild, TemplateRef} from '@angular/core';
+import {Component, OnInit, ViewChild, TemplateRef} from '@angular/core';
import {ActivatedRoute} from '@angular/router';
import {IdlService, IdlObject} from '@eg/core/idl.service';
import {PcrudService} from '@eg/core/pcrud.service';
import {NgbTabset, NgbTabChangeEvent} from '@ng-bootstrap/ng-bootstrap';
import {FmRecordEditorComponent} from '@eg/share/fm-editor/fm-editor.component';
import {SampleDataService} from '@eg/share/util/sample-data.service';
+import {OrgFamily} from '@eg/share/org-family-select/org-family-select.component';
/**
* Print Template Admin Page
export class PrintTemplateComponent implements OnInit {
- contextOrg: IdlObject;
entries: ComboboxEntry[];
template: IdlObject;
sampleJson: string;
+ invalidJson = false;
localeCode: string;
localeEntries: ComboboxEntry[];
compiledContent: string;
+ templateCache: {[id: number]: IdlObject} = {};
+ initialOrg: number;
+ selectedOrgs: number[];
@ViewChild('templateSelector') templateSelector: ComboboxComponent;
@ViewChild('tabs') tabs: NgbTabset;
}
ngOnInit() {
- this.contextOrg = this.org.get(this.auth.user().ws_ou());
+ this.initialOrg = this.auth.user().ws_ou();
+ this.selectedOrgs = [this.initialOrg];
this.localeCode = this.locale.currentLocaleCode();
this.locale.supportedLocales().subscribe(
l => this.localeEntries.push({id: l.code(), label: l.name()}));
return document.getElementById('template-preview-pane');
}
- orgOnChange(org: IdlObject) {
- this.contextOrg = org;
+ //orgOnChange(org: IdlObject) {
+ orgOnChange(family: OrgFamily) {
+ console.log('existing = ', this.selectedOrgs);
+ console.log('new = ', family.orgIds);
+ if (this.arrayEquals(this.selectedOrgs, family.orgIds)) {
+ return;
+ }
+ this.selectedOrgs = family.orgIds;
this.setTemplateInfo();
}
+ arrayEquals(arr1: any[], arr2: any[]): boolean {
+ if (arr1.length !== arr2.length) {
+ return false;
+ }
+ for (var i = 0; i < arr1.length; i++) { // exit on first failure.
+ if (!arr2.includes(arr1[i])) {
+ return false;
+ }
+ }
+ return true;
+ }
+
localeOnChange(code: string) {
if (code) {
this.localeCode = code;
this.pcrud.search('cpt',
{
- owner: this.contextOrg.id(),
+ owner: this.selectedOrgs,
locale: this.localeCode
},
{
- select: {cpt: ['id', 'label']},
+ select: {cpt: ['id', 'label', 'owner']},
order_by: {cpt: 'label'}
}
- ).subscribe(tmpl =>
+ ).subscribe(tmpl => {
+ this.templateCache[tmpl.id()] = tmpl;
this.entries.push({id: tmpl.id(), label: tmpl.label()})
- );
+ console.log('entry count = ', this.entries.length);
+ });
+ }
+
+ getOwnerName(id: number): string {
+ return this.org.get(this.templateCache[id].owner()).shortname();
}
selectTemplate(id: number) {
let data;
try {
data = JSON.parse(this.sampleJson);
+ this.invalidJson = false;
} catch (E) {
- // TODO: i18n/AlertDialog
- alert('Invalid Sample Data JSON');
+ this.invalidJson = true;
}
this.printer.compileRemoteTemplate({
}
openEditDialog() {
- // TODO: PENDING EXTERNAL FIXES
- //this.editDialog.record = this.template;
- this.editDialog.recordId = this.template.id();
+ this.editDialog.setRecord(this.template);
this.editDialog.mode = 'update';
this.editDialog.open({size: 'lg'});
}