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