this.modalRef = null;
},
(result) => {
+ console.log('dialog closed with ' + result);
reject(result);
this.modalRef = null;
}
</button>
</div>
<div class="modal-body">
- <form role="form" class="form-validated">
+ <form #fmEditForm="ngForm" role="form" class="form-validated">
<div class="form-group row" *ngFor="let field of fields">
<div class="col-lg-3 offset-lg-1">
<label for="rec-{{field.name}}">{{field.label}}</label>
<div class="modal-footer">
<button type="button" class="btn btn-success" *ngIf="mode == 'view'"
(click)="close()" i18n>Close</button>
- <button type="button" class="btn btn-info" *ngIf="mode != 'view'"
+ <button type="button" class="btn btn-info"
+ [disabled]="fmEditForm.invalid" *ngIf="mode != 'view'"
(click)="save()" i18n>Save</button>
<button type="button" class="btn btn-warning ml-2" *ngIf="mode != 'view'"
(click)="cancel()" i18n>Cancel</button>
<div class="eg-grid-toolbar">
+ <div class="btn-toolbar" *ngIf="toolbarButtons.length">
+ <div class="btn-grp">
+ <button *ngFor="let btn of toolbarButtons" class="btn btn-light" (click)="btn.action()">
+ {{btn.label}}
+ </button>
+ </div>
+ </div>
+
<!-- push everything else to the right -->
<div class="flex-1"></div>
import {Component, Input, OnInit} from '@angular/core';
import {EgGridDataSource} from './grid-data-source';
import {Pager} from '@eg/share/util/pager';
+import {EgGridService, EgGridColumn, EgGridColumnSet, EgGridToolbarButton}
+ from '@eg/share/grid/grid.service';
@Component({
selector: 'eg-grid-toolbar',
@Input() dataSource: EgGridDataSource;
@Input() pager: Pager;
+ @Input() toolbarButtons: EgGridToolbarButton[];
ngOnInit() {
<div class="eg-grid">
- <eg-grid-toolbar [dataSource]="dataSource" [pager]="pager"></eg-grid-toolbar>
+ <eg-grid-toolbar [dataSource]="dataSource" [pager]="pager"
+ [toolbarButtons]="toolbarButtons"></eg-grid-toolbar>
<eg-grid-header [columnSet]="columnSet"></eg-grid-header>
<div class="eg-grid-row eg-grid-body-row"
- (dblclick)="onRowDblClick(row)"
[ngClass]="{'eg-grid-row-selected': selector[idx]}"
*ngFor="let row of dataSource.getPageOfRows(pager); let idx = index">
{{pager.rowNumber(idx)}}
</div>
<div class="eg-grid-cell eg-grid-body-cell" [ngStyle]="{flex:col.flex}"
+ (dblclick)="onRowDblClick(row)"
*ngFor="let col of columnSet.displayColumns()">
{{getDisplayValue(row, col)}}
</div>
import {EgIdlService} from '@eg/core/idl.service';
import {EgOrgService} from '@eg/core/org.service';
import {Pager} from '@eg/share/util/pager';
-import {EgGridService, EgGridColumn, EgGridColumnSet}
+import {EgGridService, EgGridColumn, EgGridColumnSet, EgGridToolbarButton}
from '@eg/share/grid/grid.service';
@Component({
columnSet: EgGridColumnSet;
selector: {[idx:number] : boolean};
onRowDblClick$: EventEmitter<any>;
+ toolbarButtons: EgGridToolbarButton[];
constructor(private gridSvc: EgGridService) {
this.pager = new Pager();
this.selector = {};
this.pager.limit = 10; // TODO
this.onRowDblClick$ = new EventEmitter<any>();
+ this.toolbarButtons = [];
}
ngOnInit() {
import {EgGridComponent} from './grid.component';
import {EgGridColumnComponent} from './grid-column.component';
import {EgGridHeaderComponent} from './grid-header.component';
-import {EgGridBodyComponent} from './grid-body.component';
import {EgGridToolbarComponent} from './grid-toolbar.component';
import {EgGridService} from './grid.service';
+import {EgGridToolbarButtonComponent} from './grid-toolbar-button.component';
@NgModule({
declarations: [
EgGridComponent,
EgGridColumnComponent,
EgGridHeaderComponent,
- EgGridBodyComponent,
- EgGridToolbarComponent
+ EgGridToolbarComponent,
+ EgGridToolbarButtonComponent
],
imports: [
CommonModule,
// public components
EgGridComponent,
EgGridColumnComponent,
+ EgGridToolbarButtonComponent
],
providers: [
EgGridService
}
}
+export class EgGridToolbarButton {
+ label: string;
+ action: () => any;
+}
}
// Fired by the typeahead to inform us of a change.
+ // TODO: this does not fire when the value is cleared :( -- implement
+ // change detection on this.selected to look specifically for NULL.
orgChanged(selEvent: NgbTypeaheadSelectItemEvent) {
+ console.log('change occurred ' + selEvent.item);
this.onChange.emit(this.org.get(selEvent.item.id));
}
// Apply the new context if provided, give our container a
// chance to update, then resolve with the current string.
+ // NOTE: talking to the native DOM element is not so great, but
+ // hopefully we can retire the EgString* code entirely once
+ // in-code translations are supported (Ang6?)
current(ctx?: any): Promise<string> {
if (ctx) this.ctx = ctx;
return new Promise(resolve => {
</eg-staff-banner>
<eg-grid #btGrid idlClass="cbt" [dataSource]="dataSource">
+ <eg-grid-toolbar-button label="New Billing Type" i18n-label [action]="createBillingType">
+ </eg-grid-toolbar-button>
</eg-grid>
-<fm-record-editor #btEditDialog idlClass="cbt">
+<fm-record-editor #btEditDialog idlClass="cbt" requiredFields="name,org_unit">
</fm-record-editor>
+<ng-template #successStrTmpl i18n>Billing Type Update Succeeded</ng-template>
+<eg-string #successString [template]="successStrTmpl"></eg-string>
+
+<ng-template #createStrTmpl i18n>Billing Type Succeessfully Created</ng-template>
+<eg-string #createString [template]="createStrTmpl"></eg-string>
+
import {Pager} from '@eg/share/util/pager';
import {EgPcrudService} from '@eg/core/pcrud.service';
import {FmRecordEditorComponent} from '@eg/share/fm-editor/fm-editor.component';
+import {EgStringComponent} from '@eg/share/string/string.component';
@Component({
templateUrl: './billing_type.component.html'
dataSource: EgGridDataSource;
@ViewChild('btGrid') btGrid: EgGridComponent;
@ViewChild('btEditDialog') btEditDialog: FmRecordEditorComponent;
+ @ViewChild('successString') successString: EgStringComponent;
+ @ViewChild('createString') createString: EgStringComponent;
+ createBillingType: () => any;
constructor(
private pcrud: EgPcrudService,
private toast: EgToastService
) {
this.dataSource = new EgGridDataSource();
+
+ this.createBillingType = () => {
+ this.btEditDialog.mode = 'create';
+ this.btEditDialog.open().then(
+ ok => {
+ this.createString.current()
+ .then(str => this.toast.success(str));
+ this.btGrid.reload();
+ },
+ err => { }
+ );
+ }
}
ngOnInit() {
this.btEditDialog.recId = bt.id();
this.btEditDialog.open().then(
ok => {
- // TODO: i18n
- this.toast.success('Billing Type Update Succeeded'),
- this.btGrid.reload()
+ this.successString.current()
+ .then(str => this.toast.success(str));
+ this.btGrid.reload();
},
- err => {
- this.toast.warning('Billing Type Update Canceled')
- }
+ err => { }
);
}
);