[fieldOptions]="{name:{isReadonly:true}}">
</eg-fm-record-editor>
+<ng-container *ngIf="createMode">
+ <eg-prompt-dialog #passwordDialog i18n-dialogTitle i18n-dialogBody
+ dialogTitle="Create SIP Password" i18n-dialogBody="Create a new password"
+ promptType="password">
+ </eg-prompt-dialog>
+</ng-container>
+
+<ng-container *ngIf="!createMode">
+ <eg-prompt-dialog #passwordDialog i18n-dialogTitle i18n-dialogBody
+ dialogTitle="Create SIP Password" i18n-dialogBody="Create a new password"
+ promptType="password">
+ </eg-prompt-dialog>
+</ng-container>
<div class="row mt-2" *ngIf="account">
<div class="col-lg-7">
</div>
</ng-template>
+ <ng-template #sipPassTemplate>
+ <button class="btn btn-outline-dark"
+ [ngClass]="{'border-danger' : !account.sip_password()}"
+ (click)="setPassword()">Set Password</button>
+ </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"
+ idlClass="sipacc" [mode]="createMode ? 'create' : 'update'"
+ hiddenFields="id" displayMode="inline"
+ fieldOrder="sip_username,sip_password,setting_group,usr,workstation,transient,activity_who,enabled"
[fieldOptions]="{
setting_group:{customTemplate:{template:grpTemplate}},
+ sip_password:{customTemplate:{template:sipPassTemplate}},
usr:{customTemplate:{template:usrTemplate}}}"
- [preSave]="accountPreSave"
- (recordSaved)="accountSaved()" [recordId]="accountId">
+ [preSave]="accountPreSave" [recordId]="createMode ? accountId : null"
+ (recordSaved)="accountSaved($event)">
</eg-fm-record-editor>
</div>
<div class="col-lg-5">
import {Component, Input, ViewChild, OnInit} from '@angular/core';
-import {ActivatedRoute} from '@angular/router';
+import {Router, ActivatedRoute} from '@angular/router';
import {Observable, of} from 'rxjs';
import {map, tap, switchMap, catchError} from 'rxjs/operators';
import {IdlService, IdlObject} from '@eg/core/idl.service';
import {StringComponent} from '@eg/share/string/string.component';
import {StringService} from '@eg/share/string/string.service';
import {DialogComponent} from '@eg/share/dialog/dialog.component';
+import {PromptDialogComponent} from '@eg/share/dialog/prompt.component';
import {FmRecordEditorComponent} from '@eg/share/fm-editor/fm-editor.component';
import {ComboboxEntry, ComboboxComponent} from '@eg/share/combobox/combobox.component';
import {GridComponent} from '@eg/share/grid/grid.component';
settingsSource: GridDataSource = new GridDataSource();
deleteGroupAccounts: IdlObject[] = [];
accountPreSave: (mode: string, account: IdlObject) => void;
+ createMode = false;
@ViewChild('cloneDialog') cloneDialog: FmRecordEditorComponent;
@ViewChild('settingDialog') settingDialog: FmRecordEditorComponent;
@ViewChild('settingGrid') settingGrid: GridComponent;
@ViewChild('deleteGroupDialog') deleteGroupDialog: DialogComponent;
+ @ViewChild('passwordDialog') passwordDialog: PromptDialogComponent;
constructor(
private route: ActivatedRoute,
+ private router: Router,
private idl: IdlService,
private pcrud: PcrudService
) {}
ngOnInit() {
this.route.paramMap.subscribe(map => {
+ if (map.get('id') === 'new') {
+ this.account = this.idl.create('sipacc'); // dummy
+ this.createMode = true;
+ return;
+ }
+
this.accountId = Number(map.get('id'));
this.loadAccount().toPromise(); // force it to run
});
this.fetchGroups();
this.usrCboxSource = term => {
- return this.pcrud.search('au', {
- deleted: 'f', active: 't',
- '-or': [
+
+ const filter: any = {deleted: 'f', active: 't'};
+
+ if (this.account && this.account.usr()) {
+ filter['-or'] = [
{id: this.account.usr().id()},
{usrname: {'ilike': `%${term}%`}}
- ],
- }, {
+ ];
+ } else {
+ filter.usrname = {'ilike': `%${term}%`};
+ }
+
+ return this.pcrud.search('au', filter, {
order_by: {au: 'usrname'},
limit: 50 // Avoid huge lists
}
};
this.accountPreSave = (mode: string, account: IdlObject) => {
- if (mode === 'update') {
+ if (this.account.setting_group()) {
// Migrate the setting group selected in our local group
// combobox to the object to be saved.
account.setting_group(this.account.setting_group().id());
}
openDeleteDialog() {
-
this.deleteGroupDialog.open().subscribe(
ok => {
if (ok) {
);
}
- accountSaved() {
- this.refreshAccount();
+ accountSaved(result) {
+ if (this.createMode) {
+ this.router.navigate(
+ [`/staff/admin/server/sip/account/${result.id()}`]);
+ } else {
+ this.refreshAccount();
+ }
}
editFirstSetting(rows: any) {
err => {} // todo toast
);
}
+
+
+ setPassword() {
+ this.passwordDialog.open().subscribe(value => {
+ // API will translate this into an actor.passwd entry.
+ this.account.sip_password(value);
+ });
+ }
}