LP#1626157 Billing types; grid additions, misc
authorBill Erickson <berickxx@gmail.com>
Thu, 3 May 2018 16:32:56 +0000 (12:32 -0400)
committerBill Erickson <berickxx@gmail.com>
Thu, 3 May 2018 16:32:56 +0000 (12:32 -0400)
Signed-off-by: Bill Erickson <berickxx@gmail.com>
12 files changed:
Open-ILS/src/eg2/src/app/share/dialog/dialog.component.ts
Open-ILS/src/eg2/src/app/share/fm-editor/fm-editor.component.html
Open-ILS/src/eg2/src/app/share/grid/grid-toolbar.component.html
Open-ILS/src/eg2/src/app/share/grid/grid-toolbar.component.ts
Open-ILS/src/eg2/src/app/share/grid/grid.component.html
Open-ILS/src/eg2/src/app/share/grid/grid.component.ts
Open-ILS/src/eg2/src/app/share/grid/grid.module.ts
Open-ILS/src/eg2/src/app/share/grid/grid.service.ts
Open-ILS/src/eg2/src/app/share/org-select/org-select.component.ts
Open-ILS/src/eg2/src/app/share/string/string.component.ts
Open-ILS/src/eg2/src/app/staff/admin/server/config/billing_type.component.html
Open-ILS/src/eg2/src/app/staff/admin/server/config/billing_type.component.ts

index 1f979fc..e1b3e42 100644 (file)
@@ -56,6 +56,7 @@ export class EgDialogComponent implements OnInit {
                     this.modalRef = null;
                 },
                 (result) => {
+                    console.log('dialog closed with ' + result);
                     reject(result);
                     this.modalRef = null;
                 }
index f3e7dad..e509ce1 100644 (file)
@@ -8,7 +8,7 @@
     </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>
index 4604fd8..77f38c2 100644 (file)
@@ -1,6 +1,14 @@
 
 <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>
 
index 01b5880..5920d97 100644 (file)
@@ -1,6 +1,8 @@
 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',
@@ -11,6 +13,7 @@ export class EgGridToolbarComponent implements OnInit {
 
     @Input() dataSource: EgGridDataSource;
     @Input() pager: Pager;
+    @Input() toolbarButtons: EgGridToolbarButton[];
 
     ngOnInit() {
 
index 4c5835c..60a48fc 100644 (file)
@@ -1,10 +1,10 @@
 
 <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">
 
@@ -15,6 +15,7 @@
       {{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>
index 570b542..01a2aa4 100644 (file)
@@ -3,7 +3,7 @@ import {EgGridDataSource} from './grid-data-source';
 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({
@@ -23,12 +23,14 @@ export class EgGridComponent implements OnInit {
     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() {
index a664b43..cbba8dd 100644 (file)
@@ -4,9 +4,9 @@ import {FormsModule} from '@angular/forms';
 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: [
@@ -14,8 +14,8 @@ import {EgGridService} from './grid.service';
         EgGridComponent,
         EgGridColumnComponent,
         EgGridHeaderComponent,
-        EgGridBodyComponent,
-        EgGridToolbarComponent
+        EgGridToolbarComponent,
+        EgGridToolbarButtonComponent
     ],
     imports: [
         CommonModule,
@@ -25,6 +25,7 @@ import {EgGridService} from './grid.service';
         // public components
         EgGridComponent,
         EgGridColumnComponent,
+        EgGridToolbarButtonComponent
     ],
     providers: [
         EgGridService
index 41bd1ba..2bab414 100644 (file)
@@ -105,5 +105,9 @@ export class EgGridColumnSet {
     }
 }
 
+export class EgGridToolbarButton {
+    label: string;
+    action: () => any;
+}
 
 
index 627dd4e..6f76875 100644 (file)
@@ -120,7 +120,10 @@ export class EgOrgSelectComponent implements OnInit {
     }
 
     // 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));
     }
 
index 8c81898..f6a858a 100644 (file)
@@ -44,6 +44,9 @@ export class EgStringComponent implements OnInit {
 
     // 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 => {
index 25023e7..684883c 100644 (file)
@@ -2,9 +2,17 @@
 </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>
+
 
index 2fde658..dce24df 100644 (file)
@@ -5,6 +5,7 @@ import {EgToastService} from '@eg/share/toast/toast.service';
 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'
@@ -15,12 +16,27 @@ export class BillingTypeComponent implements OnInit {
     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() {
@@ -39,13 +55,11 @@ export class BillingTypeComponent implements OnInit {
                 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 => { }
                 );
             }
         );