new provder modal
authorGalen Charlton <gmc@equinoxinitiative.org>
Thu, 26 Mar 2020 18:14:10 +0000 (14:14 -0400)
committerGalen Charlton <gmc@equinoxinitiative.org>
Thu, 26 Mar 2020 18:14:10 +0000 (14:14 -0400)
Signed-off-by: Galen Charlton <gmc@equinoxinitiative.org>
Open-ILS/src/eg2/src/app/staff/acq/provider/acq-provider.component.html
Open-ILS/src/eg2/src/app/staff/acq/provider/acq-provider.component.ts

index 8a92b77..e5a4153 100644 (file)
@@ -1,5 +1,7 @@
 <eg-staff-banner bannerText="Providers" i18n-bannerText>
 </eg-staff-banner>
+<eg-string #createString i18n-text text="New Provider Added"></eg-string>
+<eg-string #createErrString i18n-text text="Failed to Create New Provider"></eg-string>
 
 <div><div class="row">
 
 <div class="col-10">
 <div class="row mb-2">
   <div class="col-lg-2 offset-lg-10">
-    <button class="btn btn-primary" [hidden]="showSearchForm" (click)="showSearchForm = !showSearchForm" i18n>Show Search Form</button>
-    <button class="btn btn-primary" [hidden]="!showSearchForm"  (click)="showSearchForm = !showSearchForm" i18n>Hide Search Form</button>
+    <div class="btn-toolbar" role="toolbar">
+      <div class="button-grp mr-2">
+        <button class="btn btn-primary" [hidden]="showSearchForm" (click)="showSearchForm = !showSearchForm" i18n>Show Search Form</button>
+        <button class="btn btn-primary" [hidden]="!showSearchForm"  (click)="showSearchForm = !showSearchForm" i18n>Hide Search Form</button>
+      </div>
+      <div class="button-grp mr-2">
+        <button class="btn btn-primary" (click)="createNew()" i18n>New Provider</button>
+      </div>
+    </div>
   </div>
 </div>
 <div class="row mb-5" [hidden]="!showSearchForm">
@@ -66,3 +75,9 @@
 </div>
 
 </div></div>
+
+<eg-fm-record-editor #createDialog
+  idlClass="acqpro"
+  fieldOrder="active,name,code,currency_type,default_claim_policy,default_copy_count,edi_default,owner,url,san,prepayment_required"
+  hiddenFields="id,email,phone,fax_phone,holding_tag">
+</eg-fm-record-editor>
index 7f18906..daecf55 100644 (file)
@@ -6,6 +6,10 @@ import {IdlService, IdlObject} from '@eg/core/idl.service';
 import {PcrudService} from '@eg/core/pcrud.service';
 import {AcqProviderSummaryPaneComponent} from './summary-pane.component';
 import {ProviderRecordService} from './provider-record.service';
+import {FmRecordEditorComponent} from '@eg/share/fm-editor/fm-editor.component';
+import {StringComponent} from '@eg/share/string/string.component';
+import {ToastService} from '@eg/share/toast/toast.service';
+import {AuthService} from '@eg/core/auth.service';
 
 @Component({
   templateUrl: './acq-provider.component.html'
@@ -19,6 +23,9 @@ export class AcqProviderComponent implements OnInit, AfterViewInit {
     validTabTypes = ['details', 'addresses', 'contacts', 'attributes', 'holdings', 'edi_accounts', 'purchase_orders', 'invoices'];
     defaultTabType = 'details';
     @ViewChild('acqSearchProviderSummary', { static: true }) providerSummaryPane: AcqProviderSummaryPaneComponent;
+    @ViewChild('createDialog', { static: true }) createDialog: FmRecordEditorComponent;
+    @ViewChild('createString', { static: false }) createString: StringComponent;
+    @ViewChild('createErrString', { static: false }) createErrString: StringComponent;
 
     onTabChange: ($event: NgbTabChangeEvent) => void;
 
@@ -27,9 +34,11 @@ export class AcqProviderComponent implements OnInit, AfterViewInit {
     constructor(
         private router: Router,
         private route: ActivatedRoute,
+        private auth: AuthService,
         private pcrud: PcrudService,
         private idl: IdlService,
         private providerRecord: ProviderRecordService,
+        private toast: ToastService,
     ) {
     }
 
@@ -82,4 +91,26 @@ export class AcqProviderComponent implements OnInit, AfterViewInit {
 
     ngAfterViewInit() {}
 
+    createNew() {
+        this.createDialog.mode = 'create';
+        const provider = this.idl.create('acqpro');
+        provider.active(true);
+        provider.owner(this.auth.user().ws_ou());
+        provider.default_copy_count(1);
+        this.createDialog.record = provider;
+        this.createDialog.recordId = null;
+        this.createDialog.open({size: 'lg'}).subscribe(
+            ok => {
+                this.createString.current()
+                    .then(str => this.toast.success(str));
+                this.onDesireSummarize(ok.id());
+            },
+            rejection => {
+                if (!rejection.dismissed) {
+                    this.createErrString.current()
+                        .then(str => this.toast.danger(str));
+                }
+            }
+        );
+    }
 }