]>
Commit | Line | Data |
---|---|---|
01366f9e TL |
1 | Ext.define('PVE.window.DownloadUrlToStorage', { |
2 | extend: 'Proxmox.window.Edit', | |
3 | alias: 'widget.pveStorageDownloadUrl', | |
4 | mixins: ['Proxmox.Mixin.CBind'], | |
5 | ||
6 | isCreate: true, | |
7 | ||
8 | method: 'POST', | |
9 | ||
10 | showTaskViewer: true, | |
11 | ||
12 | title: gettext('Download from URL'), | |
13 | submitText: gettext('Download'), | |
14 | ||
15 | cbindData: function(initialConfig) { | |
16 | var me = this; | |
17 | return { | |
18 | nodename: me.nodename, | |
19 | storage: me.storage, | |
20 | content: me.content, | |
21 | }; | |
22 | }, | |
23 | ||
24 | cbind: { | |
25 | url: '/nodes/{nodename}/storage/{storage}/download-url', | |
26 | }, | |
27 | ||
9ebd97fe TL |
28 | |
29 | viewModel: { | |
30 | data: { | |
a2692d6b TL |
31 | size: '-', |
32 | mimetype: '-', | |
9ebd97fe TL |
33 | enableQuery: true, |
34 | }, | |
a2692d6b TL |
35 | }, |
36 | ||
01366f9e TL |
37 | controller: { |
38 | xclass: 'Ext.app.ViewController', | |
39 | ||
40 | urlChange: function(field) { | |
9ebd97fe TL |
41 | this.resetMetaInfo(); |
42 | this.setQueryEnabled(); | |
43 | }, | |
44 | setQueryEnabled: function() { | |
45 | this.getViewModel().set('enableQuery', true); | |
46 | }, | |
47 | resetMetaInfo: function() { | |
48 | let vm = this.getViewModel(); | |
49 | vm.set('size', '-'); | |
50 | vm.set('mimetype', '-'); | |
01366f9e TL |
51 | }, |
52 | ||
53 | urlCheck: function(field) { | |
54 | let me = this; | |
55 | let view = me.getView(); | |
a2692d6b TL |
56 | |
57 | const queryParam = view.getValues(); | |
58 | ||
9ebd97fe TL |
59 | me.getViewModel().set('enableQuery', false); |
60 | me.resetMetaInfo(); | |
a2692d6b TL |
61 | let urlField = view.down('[name=url]'); |
62 | ||
01366f9e TL |
63 | Proxmox.Utils.API2Request({ |
64 | url: `/nodes/${view.nodename}/query-url-metadata`, | |
65 | method: 'GET', | |
66 | params: { | |
a2692d6b TL |
67 | url: queryParam.url, |
68 | 'verify-certificates': queryParam['verify-certificates'], | |
01366f9e TL |
69 | }, |
70 | waitMsgTarget: view, | |
a2692d6b TL |
71 | failure: res => { |
72 | urlField.setValidation(res.result.message); | |
73 | urlField.validate(); | |
74 | Ext.MessageBox.alert(gettext('Error'), res.htmlStatus); | |
9ebd97fe TL |
75 | // re-enable so one can directly requery, e.g., if it was just a network hiccup |
76 | me.setQueryEnabled(); | |
01366f9e TL |
77 | }, |
78 | success: function(res, opt) { | |
a2692d6b TL |
79 | urlField.setValidation(); |
80 | urlField.validate(); | |
01366f9e TL |
81 | |
82 | let data = res.result.data; | |
83 | view.setValues({ | |
84 | filename: data.filename || "", | |
a2692d6b TL |
85 | size: (data.size && Proxmox.Utils.format_size(data.size)) || gettext("Unknown"), |
86 | mimetype: data.mimetype || gettext("Unknown"), | |
01366f9e TL |
87 | }); |
88 | }, | |
89 | }); | |
90 | }, | |
91 | ||
92 | hashChange: function(field) { | |
93 | let checksum = Ext.getCmp('downloadUrlChecksum'); | |
94 | if (field.getValue() === '__default__') { | |
95 | checksum.setDisabled(true); | |
96 | checksum.setValue(""); | |
97 | checksum.allowBlank = true; | |
98 | } else { | |
99 | checksum.setDisabled(false); | |
100 | checksum.allowBlank = false; | |
101 | } | |
102 | }, | |
103 | }, | |
104 | ||
105 | items: [ | |
106 | { | |
107 | xtype: 'inputpanel', | |
108 | border: false, | |
109 | columnT: [ | |
110 | { | |
111 | xtype: 'fieldcontainer', | |
112 | layout: 'hbox', | |
113 | fieldLabel: gettext('URL'), | |
114 | items: [ | |
115 | { | |
116 | xtype: 'textfield', | |
117 | name: 'url', | |
a2692d6b | 118 | emptyText: gettext("Enter URL to download"), |
01366f9e TL |
119 | allowBlank: false, |
120 | flex: 1, | |
121 | listeners: { | |
122 | change: 'urlChange', | |
123 | }, | |
124 | }, | |
125 | { | |
126 | xtype: 'button', | |
127 | name: 'check', | |
a2692d6b | 128 | text: gettext('Query URL'), |
01366f9e | 129 | margin: '0 0 0 5', |
9ebd97fe TL |
130 | bind: { |
131 | disabled: '{!enableQuery}', | |
132 | }, | |
01366f9e TL |
133 | listeners: { |
134 | click: 'urlCheck', | |
135 | }, | |
136 | }, | |
137 | ], | |
138 | }, | |
139 | { | |
140 | xtype: 'textfield', | |
141 | name: 'filename', | |
142 | allowBlank: false, | |
143 | fieldLabel: gettext('File name'), | |
a2692d6b | 144 | emptyText: gettext("Please (re-)query URL to get meta information"), |
01366f9e TL |
145 | }, |
146 | ], | |
147 | column1: [ | |
148 | { | |
149 | xtype: 'displayfield', | |
150 | name: 'size', | |
151 | fieldLabel: gettext('File size'), | |
9ebd97fe TL |
152 | bind: { |
153 | value: '{size}', | |
154 | }, | |
01366f9e TL |
155 | }, |
156 | ], | |
157 | column2: [ | |
158 | { | |
159 | xtype: 'displayfield', | |
160 | name: 'mimetype', | |
161 | fieldLabel: gettext('MIME type'), | |
9ebd97fe TL |
162 | bind: { |
163 | value: '{mimetype}', | |
164 | }, | |
01366f9e TL |
165 | }, |
166 | ], | |
167 | advancedColumn1: [ | |
168 | { | |
169 | xtype: 'pveHashAlgorithmSelector', | |
170 | name: 'checksum-algorithm', | |
171 | fieldLabel: gettext('Hash algorithm'), | |
172 | allowBlank: true, | |
173 | hasNoneOption: true, | |
174 | value: '__default__', | |
175 | listeners: { | |
176 | change: 'hashChange', | |
177 | }, | |
178 | }, | |
179 | { | |
180 | xtype: 'textfield', | |
181 | name: 'checksum', | |
182 | fieldLabel: gettext('Checksum'), | |
183 | allowBlank: true, | |
184 | disabled: true, | |
185 | emptyText: gettext('none'), | |
186 | id: 'downloadUrlChecksum', | |
187 | }, | |
188 | ], | |
189 | advancedColumn2: [ | |
190 | { | |
191 | xtype: 'proxmoxcheckbox', | |
192 | name: 'verify-certificates', | |
193 | fieldLabel: gettext('Verify certificates'), | |
194 | uncheckedValue: 0, | |
195 | checked: true, | |
196 | listeners: { | |
197 | change: 'urlChange', | |
198 | }, | |
199 | }, | |
200 | ], | |
201 | }, | |
202 | { | |
203 | xtype: 'hiddenfield', | |
204 | name: 'content', | |
205 | cbind: { | |
206 | value: '{content}', | |
207 | }, | |
208 | }, | |
209 | ], | |
210 | ||
211 | initComponent: function() { | |
212 | var me = this; | |
213 | ||
214 | if (!me.nodename) { | |
215 | throw "no node name specified"; | |
216 | } | |
217 | if (!me.storage) { | |
218 | throw "no storage ID specified"; | |
219 | } | |
220 | ||
221 | me.callParent(); | |
222 | }, | |
223 | }); | |
224 |