@@ -21,6 +21,7 @@ import { IListItemAttachmentsProps } from '.';
21
21
import { IListItemAttachmentsState } from '.' ;
22
22
import SPservice from "../../services/SPService" ;
23
23
import { TooltipHost , DirectionalHint } from 'office-ui-fabric-react/lib/Tooltip' ;
24
+ import { Spinner , SpinnerSize } from 'office-ui-fabric-react/lib/Spinner' ;
24
25
import utilities from './utilities' ;
25
26
export class ListItemAttachments extends React . Component < IListItemAttachmentsProps , IListItemAttachmentsState > {
26
27
private _spservice : SPservice ;
@@ -34,8 +35,9 @@ export class ListItemAttachments extends React.Component<IListItemAttachmentsPro
34
35
file : null ,
35
36
showDialog : false ,
36
37
dialogMessage : '' ,
37
- Documents : [ ] ,
38
- deleteAttachment : false
38
+ attachments : [ ] ,
39
+ deleteAttachment : false ,
40
+ disableButton : false
39
41
} ;
40
42
// Get SPService Factory
41
43
this . _spservice = new SPservice ( this . props . context ) ;
@@ -54,9 +56,10 @@ export class ListItemAttachments extends React.Component<IListItemAttachmentsPro
54
56
const files : IListItemAttachmentFile [ ] = await this . _spservice . getListItemAttachments ( this . props . listId , this . props . itemId ) ;
55
57
for ( const _file of files ) {
56
58
59
+ const _previewImage = await this . _utilities . GetFileImageUrl ( _file ) ;
57
60
this . previewImages . push ( {
58
61
name : _file . FileName ,
59
- previewImageSrc : await this . _utilities . GetFileImageUrl ( _file ) ,
62
+ previewImageSrc : _previewImage ,
60
63
iconSrc : '' ,
61
64
imageFit : ImageFit . center ,
62
65
width : 187 ,
@@ -66,7 +69,7 @@ export class ListItemAttachments extends React.Component<IListItemAttachmentsPro
66
69
this . setState ( {
67
70
showDialog : false ,
68
71
dialogMessage : '' ,
69
- Documents : files
72
+ attachments : files
70
73
} ) ;
71
74
}
72
75
catch ( error ) {
@@ -89,13 +92,12 @@ export class ListItemAttachments extends React.Component<IListItemAttachmentsPro
89
92
< UploadAttachment
90
93
listId = { this . props . listId }
91
94
itemId = { this . props . itemId }
92
- iconButton = { true }
93
95
disabled = { this . props . disabled }
94
96
context = { this . props . context }
95
97
onAttachmentUpload = { this . _onAttachmentpload }
96
98
/>
97
99
98
- { this . state . Documents . map ( ( _file , i : number ) => {
100
+ { this . state . attachments . map ( ( _file , i : number ) => {
99
101
return (
100
102
< div className = { styles . documentCardWrapper } >
101
103
< TooltipHost
@@ -105,7 +107,7 @@ export class ListItemAttachments extends React.Component<IListItemAttachmentsPro
105
107
directionalHint = { DirectionalHint . rightCenter } >
106
108
107
109
< DocumentCard
108
- onClickHref = { _file . ServerRelativeUrl }
110
+ onClickHref = { ` ${ _file . ServerRelativeUrl } ?web=1` }
109
111
className = { styles . documentCard } >
110
112
< DocumentCardPreview previewImages = { [ this . previewImages [ i ] ] } />
111
113
< Label className = { styles . fileLabel } >
@@ -137,6 +139,7 @@ export class ListItemAttachments extends React.Component<IListItemAttachmentsPro
137
139
) ;
138
140
} ) }
139
141
{
142
+
140
143
< Dialog
141
144
isOpen = { this . state . showDialog }
142
145
type = { DialogType . normal }
@@ -145,11 +148,17 @@ export class ListItemAttachments extends React.Component<IListItemAttachmentsPro
145
148
subText = { this . state . dialogMessage }
146
149
isBlocking = { true } >
147
150
< DialogFooter >
151
+ < div style = { { marginBottom : 7 } } >
152
+ {
153
+ this . state . disableButton ? < Spinner size = { SpinnerSize . medium } /> : ''
154
+ }
155
+ </ div >
148
156
{
149
- this . state . deleteAttachment ? ( < PrimaryButton onClick = { this . _onConfirmedDeleteAttachment } > { strings . ListItemAttachmentsdialogOKbuttonLabelOnDelete } </ PrimaryButton > ) : ""
157
+ this . state . deleteAttachment ? ( < PrimaryButton disabled = { this . state . disableButton } onClick = { this . _onConfirmedDeleteAttachment } > { strings . ListItemAttachmentsdialogOKbuttonLabelOnDelete } </ PrimaryButton > ) : ""
150
158
}
151
159
{
152
- this . state . deleteAttachment ? ( < DefaultButton onClick = { this . _closeDialog } > { strings . ListItemAttachmentsdialogCancelButtonLabel } </ DefaultButton > ) : < PrimaryButton onClick = { this . _closeDialog } > { strings . ListItemAttachmentsdialogOKbuttonLabel } </ PrimaryButton >
160
+ this . state . deleteAttachment ? ( < DefaultButton disabled = { this . state . disableButton } onClick = { this . _closeDialog } > { strings . ListItemAttachmentsdialogCancelButtonLabel } </ DefaultButton > )
161
+ : < PrimaryButton onClick = { this . _closeDialog } > { strings . ListItemAttachmentsdialogOKbuttonLabel } </ PrimaryButton >
153
162
}
154
163
</ DialogFooter >
155
164
</ Dialog >
@@ -192,12 +201,18 @@ export class ListItemAttachments extends React.Component<IListItemAttachmentsPro
192
201
private _onConfirmedDeleteAttachment ( ) {
193
202
// Delete Attachment
194
203
const _file = this . state . file ;
204
+
205
+ this . setState ( {
206
+ disableButton : true ,
207
+ } ) ;
208
+
195
209
this . _spservice . deleteAttachment ( _file . FileName , this . props . listId , this . props . itemId , this . props . webUrl )
196
210
. then ( ( ) => {
197
211
198
212
this . setState ( {
199
213
showDialog : true ,
200
214
deleteAttachment : false ,
215
+ disableButton : false ,
201
216
file : null ,
202
217
dialogMessage : strings . ListItemAttachmentsfileDeletedMsg . replace ( '{0}' , _file . FileName ) ,
203
218
} ) ;
0 commit comments