picklist clone dialog
authorJason Etheridge <jason@EquinoxInitiative.org>
Mon, 11 Nov 2019 01:48:22 +0000 (20:48 -0500)
committerGalen Charlton <gmc@equinoxinitiative.org>
Thu, 16 Jan 2020 21:38:28 +0000 (16:38 -0500)
Signed-off-by: Jason Etheridge <jason@EquinoxInitiative.org>
Open-ILS/src/eg2/src/app/staff/acq/search/acq-search.module.ts
Open-ILS/src/eg2/src/app/staff/acq/search/picklist-clone-dialog.component.html [new file with mode: 0644]
Open-ILS/src/eg2/src/app/staff/acq/search/picklist-clone-dialog.component.ts [new file with mode: 0644]
Open-ILS/src/eg2/src/app/staff/acq/search/picklist-results.component.html
Open-ILS/src/eg2/src/app/staff/acq/search/picklist-results.component.ts

index 6fa5ffe..3eaee44 100644 (file)
@@ -7,6 +7,7 @@ import {PurchaseOrderResultsComponent} from './purchase-order-results.component'
 import {InvoiceResultsComponent} from './invoice-results.component';
 import {PicklistResultsComponent} from './picklist-results.component';
 import {PicklistCreateDialogComponent} from './picklist-create-dialog.component';
+import {PicklistCloneDialogComponent} from './picklist-clone-dialog.component';
 
 @NgModule({
   declarations: [
@@ -15,7 +16,8 @@ import {PicklistCreateDialogComponent} from './picklist-create-dialog.component'
     PurchaseOrderResultsComponent,
     InvoiceResultsComponent,
     PicklistResultsComponent,
-    PicklistCreateDialogComponent
+    PicklistCreateDialogComponent,
+    PicklistCloneDialogComponent
   ],
   imports: [
     StaffCommonModule,
diff --git a/Open-ILS/src/eg2/src/app/staff/acq/search/picklist-clone-dialog.component.html b/Open-ILS/src/eg2/src/app/staff/acq/search/picklist-clone-dialog.component.html
new file mode 100644 (file)
index 0000000..460e0c0
--- /dev/null
@@ -0,0 +1,23 @@
+<ng-template #dialogContent>
+  <div class="modal-header bg-info">
+    <h3 class="modal-title" i18n>Clone Selection List: {{leadListName}}</h3>
+    <button type="button" class="close"
+      i18n-aria-label aria-label="Close" (click)="close()">
+      <span aria-hidden="true">&times;</span>
+    </button>
+  </div>
+  <div class="modal-body">
+    <h4 i18n>Selection list name:</h4>
+    <input type="text" id="create-picklist-name"
+      class="form-control" [(ngModel)]="selectionListName">
+  </div>
+  <div class="modal-footer">
+    <button type="button" class="btn btn-success"
+      (click)="cloneList()" i18n>Clone</button>
+    <button type="button" class="btn btn-warning"
+      (click)="close()" i18n>Cancel</button>
+  </div>
+</ng-template>
+<eg-alert-dialog #fail i18n-dialogBody
+  dialogBody="Could not create this selection list.">
+</eg-alert-dialog>
diff --git a/Open-ILS/src/eg2/src/app/staff/acq/search/picklist-clone-dialog.component.ts b/Open-ILS/src/eg2/src/app/staff/acq/search/picklist-clone-dialog.component.ts
new file mode 100644 (file)
index 0000000..dd9317a
--- /dev/null
@@ -0,0 +1,56 @@
+import {Component, Input, ViewChild, TemplateRef, OnInit} from '@angular/core';
+import {Observable, from, empty, throwError} from 'rxjs';
+import {DialogComponent} from '@eg/share/dialog/dialog.component';
+import {IdlService, IdlObject} from '@eg/core/idl.service';
+import {NetService} from '@eg/core/net.service';
+import {AuthService} from '@eg/core/auth.service';
+import {NgbModal} from '@ng-bootstrap/ng-bootstrap';
+import {ComboboxEntry} from '@eg/share/combobox/combobox.component';
+
+@Component({
+  selector: 'eg-picklist-clone-dialog',
+  templateUrl: './picklist-clone-dialog.component.html'
+})
+
+export class PicklistCloneDialogComponent
+  extends DialogComponent implements OnInit {
+
+  @Input() grid: any;
+  selectionListName: String;
+  leadListName: String;
+  selections: IdlObject[];
+
+  constructor(
+    private idl: IdlService,
+    private net: NetService,
+    private auth: AuthService,
+    private modal: NgbModal
+  ) {
+    super(modal);
+  }
+
+  ngOnInit() {
+  }
+
+  update() {
+    this.leadListName = this.grid.context.getSelectedRows()[0].name();
+  }
+
+  cloneList() {
+    const picklist = this.idl.create('acqpl');
+    picklist.owner(this.auth.user().id())
+    picklist.name(this.selectionListName)
+    this.net.request(
+      'open-ils.acq',
+      'open-ils.acq.picklist.clone',
+      this.auth.token(),
+      this.grid.context.getSelectedRows()[0].id(),
+      this.selectionListName
+    ).subscribe(
+      new_id => this.close(new_id),
+      err => throwError(err)
+    );
+  }
+}
+
+
index 342312c..12edb90 100644 (file)
@@ -1,5 +1,7 @@
 <eg-string #createSelectionListString i18n-text text="Selection List Created">
 </eg-string>
+<eg-string #cloneSelectionListString i18n-text text="Selection List Cloned">
+</eg-string>
 
 <ng-template #nameTmpl let-selectionlist="row">
   <a href="/eg/acq/picklist/view/{{selectionlist.id()}}"
@@ -17,6 +19,9 @@
 <eg-picklist-create-dialog #picklistCreateDialog>
 </eg-picklist-create-dialog>
 
+<eg-picklist-clone-dialog #picklistCloneDialog [grid]="picklistResultsGrid">
+</eg-picklist-clone-dialog>
+
 <eg-grid #acqSearchPicklistsGrid
   persistKey="acq.search.selectionlists"
   [stickyHeader]="true"
     (onClick)="openCreateDialog()" [disableOnRows]="createNotAppropriate">
   </eg-grid-toolbar-action>
   <eg-grid-toolbar-action label="Clone Selected" i18n-label
-    (onClick)="cloneSelected($event)" [disableOnRows]="cloneNotAppropriate">
+    (onClick)="openCloneDialog($event)" [disableOnRows]="cloneNotAppropriate">
   </eg-grid-toolbar-action>
   <eg-grid-toolbar-action label="Merge Selected" i18n-label
-    (onClick)="mergeSelected($event)" [disableOnRows]="mergeNotAppropriate">
+    (onClick)="openMergeDialog($event)" [disableOnRows]="mergeNotAppropriate">
   </eg-grid-toolbar-action>
   <eg-grid-toolbar-action label="Delete Selected" i18n-label
-    (onClick)="deleteSelected($event)" [disableOnRows]="deleteNotAppropriate">
+    (onClick)="openDeleteConfirmation($event)" [disableOnRows]="deleteNotAppropriate">
   </eg-grid-toolbar-action>
 
   <eg-grid-column path="name" [cellTemplate]="nameTmpl"></eg-grid-column>
index 009362f..e310af8 100644 (file)
@@ -13,6 +13,7 @@ import {GridComponent} from '@eg/share/grid/grid.component';
 import {GridDataSource} from '@eg/share/grid/grid';
 import {AcqSearchService} from './acq-search.service';
 import {PicklistCreateDialogComponent} from './picklist-create-dialog.component';
+import {PicklistCloneDialogComponent} from './picklist-clone-dialog.component';
 
 @Component({
   selector: 'eg-picklist-results',
@@ -24,10 +25,13 @@ export class PicklistResultsComponent implements OnInit {
     gridSource: GridDataSource;
     @ViewChild('acqSearchPicklistsGrid', { static: true }) picklistResultsGrid: GridComponent;
     @ViewChild('picklistCreateDialog', { static: true }) picklistCreateDialog: PicklistCreateDialogComponent;
+    @ViewChild('picklistCloneDialog', { static: true }) picklistCloneDialog: PicklistCloneDialogComponent;
     @ViewChild('createSelectionListString', { static: true }) createSelectionListString: StringComponent;
+    @ViewChild('cloneSelectionListString', { static: true }) cloneSelectionListString: StringComponent;
 
     permissions: {[name: string]: boolean};
     noSelectedRows: (rows: IdlObject[]) => boolean;
+    oneSelectedRows: (rows: IdlObject[]) => boolean;
     createNotAppropriate: (rows: IdlObject[]) => boolean;
     cloneNotAppropriate: (rows: IdlObject[]) => boolean;
     mergeNotAppropriate: (rows: IdlObject[]) => boolean;
@@ -52,8 +56,9 @@ export class PicklistResultsComponent implements OnInit {
           then(perms => this.permissions = perms);
 
         this.noSelectedRows = (rows: IdlObject[]) => (rows.length === 0);
+        this.oneSelectedRows = (rows: IdlObject[]) => (rows.length === 1);
         this.createNotAppropriate = (rows: IdlObject[]) => (!this.permissions.CREATE_PICKLIST);
-        this.cloneNotAppropriate = (rows: IdlObject[]) => (!this.permissions.CREATE_PICKLIST || this.noSelectedRows(rows));
+        this.cloneNotAppropriate = (rows: IdlObject[]) => (!this.permissions.CREATE_PICKLIST || !this.oneSelectedRows(rows));
         this.mergeNotAppropriate = (rows: IdlObject[]) => (!this.permissions.UPDATE_PICKLIST || this.noSelectedRows(rows));
         this.deleteNotAppropriate = (rows: IdlObject[]) => (!this.permissions.UPDATE_PICKLIST || this.noSelectedRows(rows));
     }
@@ -67,4 +72,13 @@ export class PicklistResultsComponent implements OnInit {
         );
     }
 
+    openCloneDialog(rows: IdlObject[]) {
+        this.picklistCloneDialog.open().subscribe(
+            modified => {
+                this.cloneSelectionListString.current().then(msg => this.toast.success(msg));
+                this.picklistResultsGrid.reload(); // FIXME - spec calls for inserted grid row and not refresh
+            }
+        );
+        this.picklistCloneDialog.update(); // set the dialog title
+    }
 }