]>
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 | ||
a2692d6b TL |
28 | resetValues: function() { |
29 | this.setValues({ | |
30 | size: '-', | |
31 | mimetype: '-', | |
32 | }); | |
33 | }, | |
34 | ||
01366f9e TL |
35 | controller: { |
36 | xclass: 'Ext.app.ViewController', | |
37 | ||
38 | urlChange: function(field) { | |
a2692d6b TL |
39 | let view = this.getView(); |
40 | view.down('[name=check]').setDisabled(false); | |
41 | view.resetValues(); | |
01366f9e TL |
42 | }, |
43 | ||
44 | urlCheck: function(field) { | |
45 | let me = this; | |
46 | let view = me.getView(); | |
a2692d6b TL |
47 | |
48 | const queryParam = view.getValues(); | |
49 | ||
50 | view.down('[name=check]').setDisabled(true); | |
51 | view.resetValues(); | |
52 | let urlField = view.down('[name=url]'); | |
53 | ||
01366f9e TL |
54 | Proxmox.Utils.API2Request({ |
55 | url: `/nodes/${view.nodename}/query-url-metadata`, | |
56 | method: 'GET', | |
57 | params: { | |
a2692d6b TL |
58 | url: queryParam.url, |
59 | 'verify-certificates': queryParam['verify-certificates'], | |
01366f9e TL |
60 | }, |
61 | waitMsgTarget: view, | |
a2692d6b TL |
62 | failure: res => { |
63 | urlField.setValidation(res.result.message); | |
64 | urlField.validate(); | |
65 | Ext.MessageBox.alert(gettext('Error'), res.htmlStatus); | |
01366f9e TL |
66 | }, |
67 | success: function(res, opt) { | |
a2692d6b TL |
68 | urlField.setValidation(); |
69 | urlField.validate(); | |
01366f9e TL |
70 | |
71 | let data = res.result.data; | |
72 | view.setValues({ | |
73 | filename: data.filename || "", | |
a2692d6b TL |
74 | size: (data.size && Proxmox.Utils.format_size(data.size)) || gettext("Unknown"), |
75 | mimetype: data.mimetype || gettext("Unknown"), | |
01366f9e TL |
76 | }); |
77 | }, | |
78 | }); | |
79 | }, | |
80 | ||
81 | hashChange: function(field) { | |
82 | let checksum = Ext.getCmp('downloadUrlChecksum'); | |
83 | if (field.getValue() === '__default__') { | |
84 | checksum.setDisabled(true); | |
85 | checksum.setValue(""); | |
86 | checksum.allowBlank = true; | |
87 | } else { | |
88 | checksum.setDisabled(false); | |
89 | checksum.allowBlank = false; | |
90 | } | |
91 | }, | |
92 | }, | |
93 | ||
94 | items: [ | |
95 | { | |
96 | xtype: 'inputpanel', | |
97 | border: false, | |
98 | columnT: [ | |
99 | { | |
100 | xtype: 'fieldcontainer', | |
101 | layout: 'hbox', | |
102 | fieldLabel: gettext('URL'), | |
103 | items: [ | |
104 | { | |
105 | xtype: 'textfield', | |
106 | name: 'url', | |
a2692d6b | 107 | emptyText: gettext("Enter URL to download"), |
01366f9e TL |
108 | allowBlank: false, |
109 | flex: 1, | |
110 | listeners: { | |
111 | change: 'urlChange', | |
112 | }, | |
113 | }, | |
114 | { | |
115 | xtype: 'button', | |
116 | name: 'check', | |
a2692d6b | 117 | text: gettext('Query URL'), |
01366f9e TL |
118 | margin: '0 0 0 5', |
119 | listeners: { | |
120 | click: 'urlCheck', | |
121 | }, | |
122 | }, | |
123 | ], | |
124 | }, | |
125 | { | |
126 | xtype: 'textfield', | |
127 | name: 'filename', | |
128 | allowBlank: false, | |
129 | fieldLabel: gettext('File name'), | |
a2692d6b | 130 | emptyText: gettext("Please (re-)query URL to get meta information"), |
01366f9e TL |
131 | }, |
132 | ], | |
133 | column1: [ | |
134 | { | |
135 | xtype: 'displayfield', | |
136 | name: 'size', | |
137 | fieldLabel: gettext('File size'), | |
a2692d6b | 138 | value: '-', |
01366f9e TL |
139 | }, |
140 | ], | |
141 | column2: [ | |
142 | { | |
143 | xtype: 'displayfield', | |
144 | name: 'mimetype', | |
145 | fieldLabel: gettext('MIME type'), | |
a2692d6b | 146 | value: '-', |
01366f9e TL |
147 | }, |
148 | ], | |
149 | advancedColumn1: [ | |
150 | { | |
151 | xtype: 'pveHashAlgorithmSelector', | |
152 | name: 'checksum-algorithm', | |
153 | fieldLabel: gettext('Hash algorithm'), | |
154 | allowBlank: true, | |
155 | hasNoneOption: true, | |
156 | value: '__default__', | |
157 | listeners: { | |
158 | change: 'hashChange', | |
159 | }, | |
160 | }, | |
161 | { | |
162 | xtype: 'textfield', | |
163 | name: 'checksum', | |
164 | fieldLabel: gettext('Checksum'), | |
165 | allowBlank: true, | |
166 | disabled: true, | |
167 | emptyText: gettext('none'), | |
168 | id: 'downloadUrlChecksum', | |
169 | }, | |
170 | ], | |
171 | advancedColumn2: [ | |
172 | { | |
173 | xtype: 'proxmoxcheckbox', | |
174 | name: 'verify-certificates', | |
175 | fieldLabel: gettext('Verify certificates'), | |
176 | uncheckedValue: 0, | |
177 | checked: true, | |
178 | listeners: { | |
179 | change: 'urlChange', | |
180 | }, | |
181 | }, | |
182 | ], | |
183 | }, | |
184 | { | |
185 | xtype: 'hiddenfield', | |
186 | name: 'content', | |
187 | cbind: { | |
188 | value: '{content}', | |
189 | }, | |
190 | }, | |
191 | ], | |
192 | ||
193 | initComponent: function() { | |
194 | var me = this; | |
195 | ||
196 | if (!me.nodename) { | |
197 | throw "no node name specified"; | |
198 | } | |
199 | if (!me.storage) { | |
200 | throw "no storage ID specified"; | |
201 | } | |
202 | ||
203 | me.callParent(); | |
204 | }, | |
205 | }); | |
206 |