]> git.proxmox.com Git - proxmox-widget-toolkit.git/blob - node/APT.js
new checked_command helper, add APT.js
[proxmox-widget-toolkit.git] / node / APT.js
1 Ext.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
8 Ext.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 // Usually you would style the my-body-class in CSS file
79 return {
80 rowBody: '<div style="padding: 1em">' +
81 Ext.String.htmlEncode(data.Description) +
82 '</div>',
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 if (me.upgradeBtn) {
182 me.tbar = [ update_btn, me.upgradeBtn, changelog_btn ];
183 } else {
184 me.tbar = [ update_btn, changelog_btn ];
185 }
186
187 Ext.apply(me, {
188 store: store,
189 stateful: true,
190 stateId: 'grid-update',
191 selModel: sm,
192 viewConfig: {
193 stripeRows: false,
194 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>'
195 },
196 features: [ groupingFeature, rowBodyFeature ],
197 listeners: {
198 activate: reload,
199 itemdblclick: function(v, rec) {
200 show_changelog(rec);
201 }
202 }
203 });
204
205 me.callParent();
206 }
207 });