]> git.proxmox.com Git - proxmox-widget-toolkit.git/blame_incremental - node/APT.js
follouwp: code cleanup for bond_mode_array
[proxmox-widget-toolkit.git] / node / APT.js
... / ...
CommitLineData
1Ext.define('apt-pkglist', {
2 extend: 'Ext.data.Model',
3 fields: [ 'Package', 'Title', 'Description', 'Section', 'Arch',
4 'Priority', 'Version', 'OldVersion', 'ChangeLogUrl', 'Origin' ],
5 idProperty: 'Package'
6});
7
8Ext.define('Proxmox.node.APT', {
9 extend: 'Ext.grid.GridPanel',
10
11 xtype: 'proxmoxNodeAPT',
12
13 upgradeBtn: undefined,
14
15 columns: [
16 {
17 header: gettext('Package'),
18 width: 200,
19 sortable: true,
20 dataIndex: 'Package'
21 },
22 {
23 text: gettext('Version'),
24 columns: [
25 {
26 header: gettext('current'),
27 width: 100,
28 sortable: false,
29 dataIndex: 'OldVersion'
30 },
31 {
32 header: gettext('new'),
33 width: 100,
34 sortable: false,
35 dataIndex: 'Version'
36 }
37 ]
38 },
39 {
40 header: gettext('Description'),
41 sortable: false,
42 dataIndex: 'Title',
43 flex: 1
44 }
45 ],
46
47 initComponent : function() {
48 var me = this;
49
50 if (!me.nodename) {
51 throw "no node name specified";
52 }
53
54 var store = Ext.create('Ext.data.Store', {
55 model: 'apt-pkglist',
56 groupField: 'Origin',
57 proxy: {
58 type: 'proxmox',
59 url: "/api2/json/nodes/" + me.nodename + "/apt/update"
60 },
61 sorters: [
62 {
63 property : 'Package',
64 direction: 'ASC'
65 }
66 ]
67 });
68
69 var groupingFeature = Ext.create('Ext.grid.feature.Grouping', {
70 groupHeaderTpl: '{[ "Origin: " + values.name ]} ({rows.length} Item{[values.rows.length > 1 ? "s" : ""]})',
71 enableGroupingMenu: false
72 });
73
74 var rowBodyFeature = Ext.create('Ext.grid.feature.RowBody', {
75 getAdditionalData: function (data, rowIndex, record, orig) {
76 var headerCt = this.view.headerCt;
77 var colspan = headerCt.getColumnCount();
78 return {
79 rowBody: '<div style="padding: 1em">' +
80 Ext.String.htmlEncode(data.Description) +
81 '</div>',
82 rowBodyCls: me.full_description ? '' : Ext.baseCSSPrefix + 'grid-row-body-hidden',
83 rowBodyColspan: colspan
84 };
85 }
86 });
87
88 var reload = function() {
89 store.load();
90 };
91
92 Proxmox.Utils.monStoreErrors(me, store, true);
93
94 var apt_command = function(cmd){
95 Proxmox.Utils.API2Request({
96 url: "/nodes/" + me.nodename + "/apt/" + cmd,
97 method: 'POST',
98 failure: function(response, opts) {
99 Ext.Msg.alert(gettext('Error'), response.htmlStatus);
100 },
101 success: function(response, opts) {
102 var upid = response.result.data;
103
104 var win = Ext.create('Proxmox.window.TaskViewer', {
105 upid: upid
106 });
107 win.show();
108 me.mon(win, 'close', reload);
109 }
110 });
111 };
112
113 var sm = Ext.create('Ext.selection.RowModel', {});
114
115 var update_btn = new Ext.Button({
116 text: gettext('Refresh'),
117 handler: function() {
118 Proxmox.Utils.checked_command(function() { apt_command('update'); });
119 }
120 });
121
122 var show_changelog = function(rec) {
123 if (!rec || !rec.data || !(rec.data.ChangeLogUrl && rec.data.Package)) {
124 return;
125 }
126
127 var view = Ext.createWidget('component', {
128 autoScroll: true,
129 style: {
130 'background-color': 'white',
131 'white-space': 'pre',
132 'font-family': 'monospace',
133 padding: '5px'
134 }
135 });
136
137 var win = Ext.create('Ext.window.Window', {
138 title: gettext('Changelog') + ": " + rec.data.Package,
139 width: 800,
140 height: 400,
141 layout: 'fit',
142 modal: true,
143 items: [ view ]
144 });
145
146 Proxmox.Utils.API2Request({
147 waitMsgTarget: me,
148 url: "/nodes/" + me.nodename + "/apt/changelog",
149 params: {
150 name: rec.data.Package,
151 version: rec.data.Version
152 },
153 method: 'GET',
154 failure: function(response, opts) {
155 win.close();
156 Ext.Msg.alert(gettext('Error'), response.htmlStatus);
157 },
158 success: function(response, opts) {
159 win.show();
160 view.update(Ext.htmlEncode(response.result.data));
161 }
162 });
163
164 };
165
166 var changelog_btn = new Proxmox.button.Button({
167 text: gettext('Changelog'),
168 selModel: sm,
169 disabled: true,
170 enableFn: function(rec) {
171 if (!rec || !rec.data || !(rec.data.ChangeLogUrl && rec.data.Package)) {
172 return false;
173 }
174 return true;
175 },
176 handler: function(b, e, rec) {
177 show_changelog(rec);
178 }
179 });
180
181 var verbose_desc_checkbox = new Ext.form.field.Checkbox({
182 boxLabel: gettext('Show details'),
183 value: false,
184 listeners: {
185 change: (f, val) => {
186 me.full_description = val;
187 me.getView().refresh();
188 }
189 }
190 });
191
192 if (me.upgradeBtn) {
193 me.tbar = [ update_btn, me.upgradeBtn, changelog_btn, '->', verbose_desc_checkbox ];
194 } else {
195 me.tbar = [ update_btn, changelog_btn, '->', verbose_desc_checkbox ];
196 }
197
198 Ext.apply(me, {
199 store: store,
200 stateful: true,
201 stateId: 'grid-update',
202 selModel: sm,
203 viewConfig: {
204 stripeRows: false,
205 emptyText: '<div style="display:table; width:100%; height:100%;"><div style="display:table-cell; vertical-align: middle; text-align:center;"><b>' + gettext('No updates available.') + '</div></div>'
206 },
207 features: [ groupingFeature, rowBodyFeature ],
208 listeners: {
209 activate: reload,
210 itemdblclick: function(v, rec) {
211 show_changelog(rec);
212 }
213 }
214 });
215
216 me.callParent();
217 }
218});