<eg-grid #grid idlClass="sipacc" [dataSource]="gridSource"
[stickyHeader]="true" [sortable]="true" (onRowActivate)="openAccount($event)">
- <eg-grid-toolbar-action label="Delete Selected" i18n-label (onClick)="deleteSelected">
+ <eg-grid-toolbar-action label="Delete Selected" i18n-label
+ (onClick)="deleteSelected($event)">
</eg-grid-toolbar-action>
- <!--
- <eg-grid-column name="test" [cellTemplate]="cellTmpl"
- [cellContext]="btGridTestContext" [sortable]="false">
- </eg-grid-column>
- <eg-grid-column [sortable]="false" path="owner.name"></eg-grid-column>
- <eg-grid-column [sortable]="false" path="datetime_test"
- datatype="timestamp" [datePlusTime]="true"></eg-grid-column>
- -->
</eg-grid>
+<eg-staff-banner bannerText="SIP Account" i18n-bannerText></eg-staff-banner>
+
+<div class="row" *ngIf="account">
+ <div class="col-lg-6">
+
+ <ng-template #usrTemplate>
+ <eg-combobox #usrCbox [entries]="usrCboxEntries"
+ [selectedId]="usrId" [asyncDataSource]="usrCboxSource">
+ </eg-combobox>
+ </ng-template>
+
+ <eg-fm-record-editor #editor
+ idlClass="sipacc" mode="update" hiddenFields="id" displayMode="inline"
+ fieldOrder="sip_username,setting_group,usr,workstation,transient,activity_who,enabled"
+ [fieldOptions]="{usr:{customTemplate:{template:usrTemplate}}}"
+ (recordSaved)="accountSaved()" [recordId]="accountId">
+ </eg-fm-record-editor>
+ </div>
+</div>
-<b>account</b>
import {Component, Input, ViewChild, OnInit} from '@angular/core';
+import {ActivatedRoute} from '@angular/router';
+import {Observable, of} from 'rxjs';
+import {map} from 'rxjs/operators';
import {IdlService, IdlObject} from '@eg/core/idl.service';
import {OrgService} from '@eg/core/org.service';
import {AuthService} from '@eg/core/auth.service';
import {StringService} from '@eg/share/string/string.service';
import {ConfirmDialogComponent} from '@eg/share/dialog/confirm.component';
import {FmRecordEditorComponent} from '@eg/share/fm-editor/fm-editor.component';
-import {ComboboxEntry} from '@eg/share/combobox/combobox.component';
+import {ComboboxEntry, ComboboxComponent} from '@eg/share/combobox/combobox.component';
@Component({
templateUrl: './account.component.html'
})
export class SipAccountComponent implements OnInit {
+ accountId: number;
+ account: IdlObject;
+ usrCboxSource: (term: string) => Observable<ComboboxEntry>;
+ usrCboxEntries: ComboboxEntry[];
+ usrId: number;
+
+ //@ViewChild() usrCbox: ComboboxComponent;
+
+ constructor(
+ private route: ActivatedRoute,
+ private pcrud: PcrudService
+ ) {}
+
ngOnInit() {
+ this.route.paramMap.subscribe(map => {
+ this.accountId = Number(map.get('id'));
+ this.loadAccount();
+ });
+
+ this.usrCboxSource = term => {
+ return this.pcrud.search('au',
+ { '-or': [
+ {id: this.account.usr().id()},
+ {usrname: {'ilike': `%${term}%`}}
+ ],
+ },
+ {order_by: {au: 'usrname'}}
+ ).pipe(map(user => {
+ return {id: user.id(), label: user.usrname()};
+ }));
+ };
+ }
+
+ loadAccount() {
+ this.pcrud.retrieve('sipacc', this.accountId, {
+ flesh: 1,
+ flesh_fields: {sipacc: ['usr', 'setting_group', 'workstation']}
+ }).subscribe(acc => {
+ this.account = acc;
+ this.usrId = acc.usr().id();
+ this.usrCboxEntries =
+ [{id: acc.usr().id(), label: acc.usr().usrname()}];
+ });
+ }
+
+ accountSaved() {
+ this.loadAccount();
}
}