@@ -2,13 +2,13 @@ import { msg } from '@lit/localize';
22import { LitElement , html , css , TemplateResult , CSSResultGroup } from 'lit' ;
33import { customElement , property } from 'lit/decorators.js' ;
44import { when } from 'lit/directives/when.js' ;
5+ import {
6+ ModalConfig ,
7+ type ModalManagerInterface ,
8+ } from '@internetarchive/modal-manager' ;
9+ import type { ManageableItem } from '../models' ;
510import iaButtonStyle from '../styles/ia-button' ;
6-
7- export interface ManageableItem {
8- identifier : string ;
9- title ?: string ;
10- dateStr ?: string ;
11- }
11+ import './remove-items-modal-content' ;
1212
1313@customElement ( 'manage-bar' )
1414export class ManageBar extends LitElement {
@@ -18,9 +18,19 @@ export class ManageBar extends LitElement {
1818 @property ( { type : String } ) label = msg ( 'Select items to remove' ) ;
1919
2020 /**
21- * Specifies the context in which the collection browser is being used
21+ * The shared modal manager component for displaying modal dialogs on this page
2222 */
23- @property ( { type : String } ) pageContext ?: string ;
23+ @property ( { type : Object } ) modalManager ?: ModalManagerInterface ;
24+
25+ /**
26+ * Array of items that have been selected for management
27+ */
28+ @property ( { type : Object } ) selectedItems : Array < ManageableItem > = [ ] ;
29+
30+ /**
31+ * Message shows as note in the modal when removing items
32+ */
33+ @property ( { type : String } ) manageViewModalMsg ?: string ;
2434
2535 /**
2636 * Whether to show the "Select All" button (default false)
@@ -32,6 +42,11 @@ export class ManageBar extends LitElement {
3242 */
3343 @property ( { type : Boolean } ) showUnselectAll = false ;
3444
45+ /**
46+ * Whether to show "Item Manager the items" button (default false)
47+ */
48+ @property ( { type : Boolean } ) showItemManageButton = false ;
49+
3550 /**
3651 * Whether to active delete button for selectable items
3752 */
@@ -48,21 +63,20 @@ export class ManageBar extends LitElement {
4863 <butto n
4964 class= "ia-button danger"
5065 ?dis abled= ${ ! this . removeAllowed }
51- @click = ${ this . removeClicked }
66+ @click = ${ this . showRemoveItemsModal }
5267 >
5368 ${ msg ( 'Remove selected items' ) }
5469 </ butto n>
55- ${ this . pageContext === 'search'
56- ? html `
57- <butto n
58- class= "ia-button warning"
59- ?dis abled= ${ ! this . removeAllowed }
60- @click = ${ this . itemsManagerClicked }
61- >
62- ${ msg ( 'Item Manager the items' ) }
63- </ butto n>
64- `
65- : '' }
70+ ${ when (
71+ this . showItemManageButton ,
72+ ( ) => html ` <butto n
73+ class= "ia-button warning"
74+ ?dis abled= ${ ! this . removeAllowed }
75+ @click = ${ this . manageItemsClicked }
76+ >
77+ ${ msg ( 'Item Manager the items' ) }
78+ </ butto n> `
79+ ) }
6680 <div class= "selection-buttons" >
6781 ${ when (
6882 this . showSelectAll ,
@@ -92,12 +106,12 @@ export class ManageBar extends LitElement {
92106 this . dispatchEvent ( new CustomEvent ( 'cancel' ) ) ;
93107 }
94108
95- private removeClicked ( ) : void {
109+ private removeItemsClicked ( ) : void {
96110 this . dispatchEvent ( new CustomEvent ( 'removeItems' ) ) ;
97111 }
98112
99- private itemsManagerClicked ( ) : void {
100- this . dispatchEvent ( new CustomEvent ( 'itemsManager ' ) ) ;
113+ private manageItemsClicked ( ) : void {
114+ this . dispatchEvent ( new CustomEvent ( 'manageItems ' ) ) ;
101115 }
102116
103117 private selectAllClicked ( ) : void {
@@ -108,6 +122,88 @@ export class ManageBar extends LitElement {
108122 this . dispatchEvent ( new CustomEvent ( 'unselectAll' ) ) ;
109123 }
110124
125+ /**
126+ * Shows a modal dialog confirming the list of items to be removed
127+ * @param items Which items to list in the modal
128+ */
129+ private showRemoveItemsModal ( ) : void {
130+ const customModalContent = html `
131+ <remove-items- modal- content
132+ .items = ${ this . selectedItems }
133+ .message = ${ this . manageViewModalMsg }
134+ @confirm = ${ ( ) => this . removeItemsClicked ( ) }
135+ > </ remove-items- modal- content>
136+ ` ;
137+
138+ const config = new ModalConfig ( {
139+ showProcessingIndicator : false ,
140+ processingImageMode : 'processing' ,
141+ bodyColor : '#fff' ,
142+ headerColor : '#194880' ,
143+ showHeaderLogo : false ,
144+ closeOnBackdropClick : true ,
145+ title : html `${ msg ( 'Are you sure you want to remove these items?' ) } ` ,
146+ } ) ;
147+
148+ this . modalManager ?. classList . add ( 'remove-items' ) ;
149+ this . modalManager ?. showModal ( {
150+ config,
151+ customModalContent,
152+ userClosedModalCallback : ( ) => {
153+ this . modalManager ?. classList . remove ( 'remove-items' ) ;
154+ } ,
155+ } ) ;
156+ }
157+
158+ /**
159+ * Shows a modal dialog indicating that item removal is being processed
160+ */
161+ showRemoveItemsProcessingModal ( ) : void {
162+ const config = new ModalConfig ( {
163+ showProcessingIndicator : true ,
164+ processingImageMode : 'processing' ,
165+ bodyColor : '#fff' ,
166+ headerColor : '#194880' ,
167+ showHeaderLogo : false ,
168+ closeOnBackdropClick : true ,
169+ title : html `${ msg ( 'Removing selected items...' ) } ` ,
170+ } ) ;
171+
172+ this . modalManager ?. classList . add ( 'remove-items' ) ;
173+ this . modalManager ?. showModal ( {
174+ config,
175+ userClosedModalCallback : ( ) => {
176+ this . modalManager ?. classList . remove ( 'remove-items' ) ;
177+ } ,
178+ } ) ;
179+ }
180+
181+ /**
182+ * Shows a modal dialog indicating that an error occurred while removing items
183+ */
184+ showRemoveItemsErrorModal ( ) : void {
185+ const config = new ModalConfig ( {
186+ showProcessingIndicator : false ,
187+ processingImageMode : 'processing' ,
188+ bodyColor : '#fff' ,
189+ headerColor : '#691916' ,
190+ showHeaderLogo : false ,
191+ closeOnBackdropClick : true ,
192+ title : html `${ msg ( 'Error: unable to remove items' ) } ` ,
193+ message : html `${ msg (
194+ 'An error occurred while removing items. Please try again in a few minutes.'
195+ ) } `,
196+ } ) ;
197+
198+ this . modalManager ?. classList . add ( 'remove-items' ) ;
199+ this . modalManager ?. showModal ( {
200+ config,
201+ userClosedModalCallback : ( ) => {
202+ this . modalManager ?. classList . remove ( 'remove-items' ) ;
203+ } ,
204+ } ) ;
205+ }
206+
111207 static get styles ( ) : CSSResultGroup {
112208 return css `
113209 ${ iaButtonStyle }
0 commit comments