1
1
import { action } from "@ember/object" ;
2
2
import { inject as service } from "@ember/service" ;
3
3
import { tracked } from "@glimmer/tracking" ;
4
- import { restartableTask , dropTask } from "ember-concurrency" ;
4
+ import { task } from "ember-concurrency" ;
5
+ import lang from "flatpickr/dist/l10n" ;
5
6
import { DateTime } from "luxon" ;
6
7
7
8
import DocumentCard from "./document-card" ;
@@ -24,22 +25,34 @@ export default class SingleDocumentDetailsComponent extends DocumentCard {
24
25
@tracked editDate = false ;
25
26
@tracked validTitle = true ;
26
27
28
+ get locale ( ) {
29
+ return this . intl . primaryLocale . split ( "-" ) [ 0 ] ;
30
+ }
31
+
32
+ get flatpickrLocale ( ) {
33
+ return lang [ this . locale ] ;
34
+ }
35
+
27
36
get dateFormat ( ) {
28
- const language = this . intl . primaryLocale . split ( "-" ) [ 0 ] ;
29
37
const defaultFormat = "m/d/Y" ;
30
38
const formats = { de : "d.m.Y" , fr : "d.m.Y" , en : defaultFormat } ;
31
39
32
- return formats [ language ] ?? defaultFormat ;
40
+ return formats [ this . locale ] ?? defaultFormat ;
41
+ }
42
+
43
+ get isWordProcessingFormat ( ) {
44
+ return [
45
+ "application/vnd.oasis.opendocument.text" ,
46
+ "application/vnd.openxmlformats-officedocument.wordprocessingml.document" ,
47
+ ] . includes ( this . args . document . latestFile ?. value ?. mimeType ) ;
48
+ }
49
+
50
+ get displayWebDAVButton ( ) {
51
+ return this . config . enableWebDAV && this . isWordProcessingFormat ;
33
52
}
34
53
35
54
get displayConvertButton ( ) {
36
- return (
37
- this . config . enablePDFConversion &&
38
- [
39
- "application/vnd.oasis.opendocument.text" ,
40
- "application/vnd.openxmlformats-officedocument.wordprocessingml.document" ,
41
- ] . includes ( this . args . document . latestFile ?. value ?. mimeType )
42
- ) ;
55
+ return this . config . enablePDFConversion && this . isWordProcessingFormat ;
43
56
}
44
57
45
58
@action updateDocumentTitle ( { target : { value : title } } ) {
@@ -75,38 +88,37 @@ export default class SingleDocumentDetailsComponent extends DocumentCard {
75
88
this . documents . enableShortcuts ( ) ;
76
89
}
77
90
78
- @ restartableTask * saveDocument ( event ) {
91
+ saveDocument = task ( { restartable : true } , async ( event ) => {
79
92
event ?. preventDefault ( ) ;
80
93
81
94
try {
82
- yield this . args . document . save ( ) ;
95
+ await this . args . document . save ( ) ;
83
96
this . resetState ( ) ;
84
97
this . notification . success ( this . intl . t ( "alexandria.success.update" ) ) ;
85
98
} catch ( error ) {
86
99
this . args . document . rollbackAttributes ( ) ;
87
100
new ErrorHandler ( this , error ) . notify ( "alexandria.errors.update" ) ;
88
101
}
89
- }
102
+ } ) ;
90
103
91
- @ dropTask * uploadReplacement ( event ) {
104
+ uploadReplacement = task ( { drop : true } , async ( event ) => {
92
105
try {
93
106
const [ file ] = event . target . files ;
94
- yield this . documents . replace ( this . args . document , file ) ;
107
+ await this . documents . replace ( this . args . document , file ) ;
95
108
} catch ( error ) {
96
109
new ErrorHandler ( this , error ) . notify (
97
110
"alexandria.errors.replace-document" ,
98
111
) ;
99
112
}
100
- }
113
+ } ) ;
101
114
102
- @dropTask
103
- * convertDocument ( event ) {
115
+ convertDocument = task ( { drop : true } , async ( event ) => {
104
116
event ?. preventDefault ( ) ;
105
117
try {
106
118
const modelName = "document" ;
107
119
const adapter = this . store . adapterFor ( modelName ) ;
108
120
const url = adapter . buildURL ( modelName , this . args . document . id ) ;
109
- yield this . fetch . fetch ( `${ url } /convert` , {
121
+ await this . fetch . fetch ( `${ url } /convert` , {
110
122
method : "POST" ,
111
123
} ) ;
112
124
@@ -116,5 +128,18 @@ export default class SingleDocumentDetailsComponent extends DocumentCard {
116
128
} catch ( error ) {
117
129
new ErrorHandler ( this , error ) . notify ( "alexandria.errors.convert-pdf" ) ;
118
130
}
119
- }
131
+ } ) ;
132
+
133
+ openWebDAV = task ( { drop : true } , async ( event ) => {
134
+ event ?. preventDefault ( ) ;
135
+ try {
136
+ const fileId = this . args . document . latestFile . value . id ;
137
+
138
+ const file = await this . store . findRecord ( "file" , fileId ) ;
139
+
140
+ window . open ( file . webdavUrl , "_blank" ) ;
141
+ } catch ( error ) {
142
+ new ErrorHandler ( this , error ) . notify ( "alexandria.errors.open-webdav" ) ;
143
+ }
144
+ } ) ;
120
145
}
0 commit comments