-
Notifications
You must be signed in to change notification settings - Fork 1
/
Copy pathrequest-helper-mixin.js
47 lines (43 loc) · 1.15 KB
/
request-helper-mixin.js
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
import {upload} from '@unicef-polymer/etools-ajax/upload-helper';
export const RequestHelperMixin = (baseClass) =>
class extends baseClass {
static get properties() {
return {
uploadEndpoint: {
type: String,
reflect: true,
attribute: 'upload-endpoint'
},
/* Expected format:
{
endpoint: 'url',
extraInfo: {itemid: 1},
rawFilePropertyName: 'attachment'
}
*/
endpointInfo: {
type: Object,
attribute: 'endpoint-info'
},
jwtLocalStorageKey: {
type: String,
reflect: true,
attribute: 'jwt-local-storage-key'
}
};
}
constructor() {
super();
this.uploadEndpoint = null;
this.endpointInfo = null;
this.jwtLocalStorageKey = '';
}
uploadRawFile(rawFile, requestKey, onProgressCallback) {
const config = {
endpointInfo: this.endpointInfo,
uploadEndpoint: this.uploadEndpoint,
jwtLocalStorageKey: this.jwtLocalStorageKey
};
return upload(config, rawFile, requestKey, onProgressCallback);
}
};