popup dialog to remind user about subscriptions
[pve-manager.git] / www / manager / node / APT.js
CommitLineData
61a5235c
DM
1Ext.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: 'Section',
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
945ad565 29 var groupingFeature = Ext.create('Ext.grid.feature.Grouping', {
61a5235c
DM
30 groupHeaderTpl: '{[ "Section: " + values.name ]} ({rows.length} Item{[values.rows.length > 1 ? "s" : ""]})'
31 });
32
945ad565
DM
33 var rowBodyFeature = Ext.create('Ext.grid.feature.RowBody', {
34 getAdditionalData: function (data, rowIndex, record, orig) {
35 var headerCt = this.view.headerCt;
36 var colspan = headerCt.getColumnCount();
37 // Usually you would style the my-body-class in CSS file
38 return {
39 rowBody: '<div style="padding: 1em">' + data.Description + '</div>',
40 rowBodyColspan: colspan
41 };
42 }
43 });
44
61a5235c
DM
45 var reload = function() {
46 store.load();
47 };
48
945ad565 49 me.loadCount = 1; // avoid duplicate load mask
61a5235c
DM
50 PVE.Utils.monStoreErrors(me, store);
51
945ad565
DM
52 var apt_command = function(cmd){
53 PVE.Utils.API2Request({
54 url: "/nodes/" + nodename + "/apt/" + cmd,
55 method: 'POST',
56 failure: function(response, opts) {
57 Ext.Msg.alert('Error', response.htmlStatus);
58 },
59 success: function(response, opts) {
60 var upid = response.result.data;
61
62 var win = Ext.create('PVE.window.TaskProgress', {
63 upid: upid
64 });
65 win.show();
66 me.mon(win, 'close', reload);
67 }
68 });
69 };
70
eaf82342
DM
71 var sm = Ext.create('Ext.selection.RowModel', {});
72
945ad565
DM
73 var update_btn = new Ext.Button({
74 text: gettext('Update'),
75 handler: function(){
1556735e 76 PVE.Utils.checked_command(function() { apt_command('update'); });
945ad565
DM
77 }
78 });
79
8d3b220a 80 var upgrade_btn = new PVE.button.Button({
945ad565 81 text: gettext('Upgrade'),
8d3b220a
DM
82 dangerous: true,
83 confirmMsg: function(rec) {
84 return gettext('Are you sure you want to upgrade this node?');
85 },
945ad565 86 handler: function(){
1556735e 87 PVE.Utils.checked_command(function() { apt_command('upgrade'); });
945ad565
DM
88 }
89 });
90
eaf82342
DM
91 var show_changelog = function(rec) {
92 if (!rec || !rec.data || !(rec.data.ChangeLogUrl && rec.data.Package)) {
93 return;
94 }
95
96 var win = Ext.create('Ext.window.Window', {
97 title: gettext('Changelog') + ": " + rec.data.Package,
98 width: 800,
99 height: 400,
100 layout: 'fit',
101 modal: true,
102 items: {
103 xtype: 'component',
104 autoEl: {
105 frameborder: 0,
106 seamless: 1,
107 sandbox: "",
108 tag : "iframe",
109 src : rec.data.ChangeLogUrl
110 }
111 }
112 });
113 win.show();
114 };
115
116 var changelog_btn = new PVE.button.Button({
117 text: gettext('Changelog'),
118 selModel: sm,
119 disabled: true,
120 enableFn: function(rec) {
121 if (!rec || !rec.data || !(rec.data.ChangeLogUrl && rec.data.Package)) {
122 return false;
123 }
124 return true;
125 },
126 handler: function(b, e, rec) {
127 show_changelog(rec);
128 }
129 });
130
61a5235c
DM
131 Ext.apply(me, {
132 store: store,
133 stateful: false,
eaf82342 134 selModel: sm,
945ad565
DM
135 viewConfig: {
136 stripeRows: false,
137 emptyText: '<div style="display:table; width:100%; height:100%;"><div style="display:table-cell; vertical-align: middle; text-align:center;"><b>' + gettext('Your system is up to date.') + '</div></div>'
138 },
eaf82342 139 tbar: [ update_btn, upgrade_btn, changelog_btn ],
945ad565 140 features: [ groupingFeature, rowBodyFeature ],
61a5235c
DM
141 columns: [
142 {
143 header: gettext('Package'),
144 width: 200,
145 sortable: true,
146 dataIndex: 'Package'
147 },
148 {
945ad565
DM
149 text: gettext('Version'),
150 columns: [
151 {
152 header: gettext('current'),
153 width: 100,
154 sortable: false,
155 dataIndex: 'OldVersion'
156 },
157 {
158 header: gettext('new'),
159 width: 100,
160 sortable: false,
161 dataIndex: 'Version'
162 }
163 ]
61a5235c
DM
164 },
165 {
166 header: gettext('Description'),
167 sortable: false,
168 dataIndex: 'Title',
169 flex: 1
170 }
171 ],
172 listeners: {
eaf82342
DM
173 show: reload,
174 itemdblclick: function(v, rec) {
175 show_changelog(rec);
176 }
61a5235c
DM
177 }
178 });
179
180 me.callParent();
181 }
182}, function() {
183
184 Ext.define('apt-pkglist', {
185 extend: 'Ext.data.Model',
186 fields: [ 'Package', 'Title', 'Description', 'Section', 'Arch',
eaf82342 187 'Priority', 'Version', 'OldVersion', 'ChangeLogUrl' ],
61a5235c
DM
188 idProperty: 'Package'
189 });
190
191});